I don't believe I understand entirely what you're wanting to do...I've
provided an example below that works, but I fear might not do what you want
since it's a bit unclear to me.  It sounds like if you're successful in
setting up what you're requesting all you'll be testing is RhinoMocks and
not your class.  Please clarify further

    [TestFixture]
    public class TestForFabian
    {
        [Test]
        public void TestIFilter()
        {
            // Arrange
            var filterMock = MockRepository.GenerateMock<IFilter>();
            var list = new List<string> {"one", "two", "three"};

            filterMock.Expect(mock => mock.Filter(list)).Return(list);

            // Act
            var returnedList = filterMock.Filter(list);

            // Assert
            Assert.That(returnedList, Is.EqualTo(list));
        }
    }

    public interface IFilter
    {
        List<string> Filter(List<string> items);
    }

On Thu, Mar 5, 2009 at 4:45 AM, Fabian Schmied <[email protected]>wrote:

>
> I have the following interface method declaration:
>
> public interface IFilter
> {
>  List<string> Filter (List<string> items);
> }
>
> And I want to create a mock filter object that:
> - checks the argument, and then
> - returns the argument passed to it.
>
> var filterMock = MockRepository.GenerateMock<IFilter>();
> filterMock
>    .Expect (mock => mock.Filter(Arg<List<string>>.List.ContainsAll (...)))
>    .Return (???);
>
> Is there nothing I can pass as "???" to make the mock return the same
> argument that was passed to it? Note that I don't want to set up a
> "fake" result to return from the mock.
>
> Things I've tried:
> - "Do (mi => mi.ReturnValue = mi.Arguments[0])" to set the return
> value; this doesn't work ("Method '...' requires a return value or an
> exception to throw.").
> - "Callback (...)", but this doesn't work together with the
> constraints, so I have to do the argument checking by hand (which I
> find isn't nice).
> - "Arg.Matches (items => { storedItems = items; return items.Contains
> (...); })", so that I could do "Return (storedItems)", but this
> doesn't work as Arg.Matches requires a LINQ Expression, not simply a
> delegate. And the assign statement cannot be transformed into an
> Expression.
>
> Any other ideas?
>
> (This is Rhino Mocks RC 3.5.0.2. Telling me that newer versions have a
> feature for this would also work :) )
>
> Fabian
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Rhino.Mocks" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/RhinoMocks?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to