Actually it is very simple. Forget all you know about Mocks and Stubs and Fowler and everything.
In Rhino Mocks, a mock can either return canned answers and check if certain calls have been performed, it depends what you specify in each case. Additionally, there is a special feature: a mock can be told that a property should behave like a property normally does (say like a field), this means that you don't have to specify the canned answer using mock.Stub( x => x.Property).Return(blah); you just assign the value to the property mock.Property = blah and the property will return this value whenever it is read. On the other side, for such a property AssertWasCalled does not work anymore. Obviously property behaviour only works if there is a getter and a setter. Since your Item has both a getter and a setter, property behaviour is used. Now, a Stub in Rhino Mocks is just a mock which has property behaviour defined for each property. Nothing more, nothing less. On 13 Nov., 13:23, kbaltrinic <[email protected]> wrote: > Alex, > > Thanks for the reply. That did fix the problem but it is unclear to > me why I would need a dynamic mock in this case. > > For example, how does the orginial test differ from the following, > which works? > > public interface IIndexed2 > { > object Item_get(string key); > void Item_set(string key, object value); > } > > [Test] > public void testCallToIndexer2() > { > var indexed = MockRepository.GenerateStub<IIndexed2>(); > indexed.Item_set("Key", "Value"); > indexed.AssertWasCalled(i => i.Item_set("Key", "Value")); > } > > For my better understanding, can you or anyone else shed some light on > this? > > --Ken > > On Nov 12, 8:11 am, Alex McMahon <[email protected]> wrote: > > > does MockRepository.GenerateMock<IIndexed>() have the same result? > > > 2009/11/12 kbaltrinic <[email protected]> > > > > I am have trouble asserting that an indexer was called using AAA and > > > AssertWasCalled. Here is an example test that is failing. This is > > > with Rhino Mocks 3.6.0.0 and NUnit 2.5.2.9222. Am I missing something > > > obvious? > > > > public interface IIndexed { object this[string key] { get; > > > set; } } > > > > [Test] > > > public void testCallToIndexer() > > > { > > > var indexed = MockRepository.GenerateStub<IIndexed>(); > > > indexed["Key"] = "Value"; > > > indexed.AssertWasCalled(i => i["Key"] = "Value"); > > > > //indexed.AssertWasCalled(i => i["Key"] = "Value", > > > // options => options.IgnoreArguments()); <--Also > > > tried this with basically the same result. > > > } > > > > Results: > > > > Rhino.Mocks.Exceptions.ExpectationViolationException : > > > IIndexed.set_Item("Key", "Value"); Expected #1, Actual #0. > > > at Rhino.Mocks.RhinoMocksExtensions.AssertWasCalled(T mock, Action`1 > > > action, Action`1 setupConstraints) > > > at Rhino.Mocks.RhinoMocksExtensions.AssertWasCalled(T mock, Func`2 > > > action) > > > at Tests.ExampleTests.testCallToIndexer() in ExampleTests.cs: line 89 > > > > Thanks for the help, > > > --Ken- Hide quoted text - > > > - Show quoted text - > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
