The reason I said to try a dynamicMock is that I think conceptually a stub is used to return canned answers but shouldn't really be used to verify that calls were made to the stub. This difference is only partially enforced in the code I think. So it looks like you're allowed to call AssertWasCalled on a stub for a method (I personally think this should fail), but not for an indexer.
I personally never use GenerateStub() and favour the move to just having a single type of Fake, and removing the differences between them. It looks like there is an inconsistency in RhinoMocks in this area. Does that explain a bit? 2009/11/13 kbaltrinic <[email protected]> > > 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 -~----------~----~----~----~------~----~------~--~---
