I don't think Rhino Mocks is for the type of test you are describing. If you
are passing in a concrete List<T> instance then there is nothing being
mocked, and thus no way to set up expectations when calling Save(). Now, if
Save() instead takes IList<T> you could pass in a mock list and then set up
expectations about how the IList<T> should be used internally.

If you want to deal with concrete instances of things while still checking
them for certain state, you may wish to look into C# code contracts. At the
beginning of your Save() method you could have this:

Contract.Requires(list != null);
Contract.Requires(list.Count > 0);

That would give you compile-time checking of all arguments passed into
Save().

On Tue, Sep 22, 2009 at 12:01 PM, vin <[email protected]> wrote:

>
> Hi,
>
> Ok, I knew I should have put more thought into the sample!
>
> That is fine if the object isn't changed again later.
> That is the case in my simple example, but what if the example cleared
> the list after it was saved?
>
> So change the function to
> public static void Incrementer(List<int> list)
> {
>  list.Add(1);
>  dummy.Save(list);
>  list.Clear();
> }
>
> I want to know what the value of list was when dummy.Save() was
> called, I need to perform the test when Save() is called.
> If I was to pass in a different instance of List<int> from the one
> specified in the mock the code will fail on the Save() call because
> the objects are not the same, I need to be able to force a comparison
> at the same point in the execution.
>
> I suppose fundamentally I want the option of testing equivalence
> instead of equality, they may be the same objects but they have
> different states and it is the state I care about.
>
> Looking at it another way imagine if I knew the list I passed in would
> be copied into a newly created local list.
> I know what the contents of the new list will be but I couldn't pass
> that as a value to my mock since they are different objects so I would
> have to ignore the arguments completely.
>
> Hope that makes more sense?
>
>  Vin
>
> On Sep 22, 5:01 pm, Nathan Alden <[email protected]> wrote:
> > If you wish to do state-based testing like "list.Count == 1" then simply
> use
> > NUnit's Assert class:
> >
> > Assert.That(list.Count, Is.EqualTo(1));
> >
>  > On Tue, Sep 22, 2009 at 10:58 AM, vin <[email protected]> wrote:
> >
> > > Hi,
> >
> > > I am trying to do something I thought would be common but can't find
> > > anywhere.
> > > I'll include full code below.
> >
> > > I want to have a Mocked object and make sure it calls a function, fine
> > > so far.
> > > The function takes an argument and I want to make sure the argument
> > > has changed from what I passed in.
> > > It will still be the same object but it's properties have changed.
> >
> > > So I am mocking a function that takes a List<int> as an argument, and
> > > I don't want the test to be "is this the same object" I want it to be
> > > "is the Count on the object equal to 1".
> >
> > > Is this possible?
> >
> > > Hopefully the code will explain this better.
> >
> > >  Thanks, Vin
> >
> > > namespace TestingMocks
> > > {
> > >    [TestClass]
> > >    public class TestingMock
> > >    {
> > >        [TestMethod]
> > >        public void TestMe()
> > >        {
> > >            MockRepository mocks = new MockRepository();
> >
> > >            List<int> list = new List<int>();
> >
> > >            Dummy dummy = mocks.DynamicMock<Dummy>();
> > >            using (mocks.Ordered())
> > >            {
> > >                dummy.Save(list);
> > >                Testing.dummy = dummy;
> > >            }
> > >            mocks.ReplayAll();
> >
> > >            Testing.Incrementer(list);
> >
> > >            mocks.VerifyAll();
> > >        }
> > >    }
> >
> > >    public class Testing
> > >    {
> > >        public static Dummy dummy { get; set; }
> >
> > >        public static void Incrementer(List<int> list)
> > >        {
> > >            list.Add(1);
> > >            dummy.Save(list);
> > >        }
> > >    }
> >
> > >    public class Dummy
> > >    {
> > >        public virtual void Save(List<int> list)
> > >        {
> > >        }
> > >    }
> > > }
> >
>

--~--~---------~--~----~------------~-------~--~----~
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