With Rhino.Mocks, as soon as I cheat on an interface, I can:
- Set "return" values ββfor non-empty methods on the mocked object
- See how and with which values ββcertain methods were called with
However, is it possible to selectively define an implementation for methods on mocking objects?
Ideally, I would like to do this (RhinoImplement is the Rhino extension I hope!):
var messages = new List<IMessage>(); IBus bus = MockRepository.GenerateMock<IBus>(); bus.RhinoImplement(b => b.Send(Arg<IMessage>.Is.Anything), imess => messages.Add(imess));
Update with answer
Thanks to Patrick below, the correct code to achieve the above:
var messages = new List<IMessage>(); IBus bus = MockRepository.GenerateMock<IBus>(); bus .Expect(b => b.Send(Arg<IMessage>.Is.Anything)) .WhenCalled(invocation => messages.Add((IMessage)invocation.Arguments[0])) .Repeat.Any()
source share