machine.specifications icon indicating copy to clipboard operation
machine.specifications copied to clipboard

Support returning different results from stub method calls

Open chrisalexander opened this issue 11 years ago • 1 comments

RhinoMocks allows for the ability to return different objects the second, third, fourth etc. time that a method is called. This is particularly useful when you are mocking a factory for use in the class under test, for example:

Factory = MockRepository.GenerateStub<IFactory>();
Factory.Stub(f => f.Create(Arg<string>.Is.Anything)).Return(Object1).Repeat.Once();
Factory.Stub(f => f.Create(Arg<string>.Is.Anything)).Return(Object2).Repeat.Once();

This will mean Factory.Create(string.Any) will return Object1 the first time it is called, and Object2 the second time.

Is there potential for support this in Machine.Fakes? Thanks!

chrisalexander avatar Jan 22 '15 21:01 chrisalexander

It looks like the other mocking frameworks support this as well: http://nsubstitute.github.io/help/multiple-returns/ https://github.com/Moq/moq4/wiki/Quickstart https://github.com/FakeItEasy/FakeItEasy/wiki/Specifying-return-values

So, it should be possible to implement this in Machine.Fakes. The interesting part is how to design the API for it and whether all frameworks can be accommodated.

SimonHohenadl avatar Jan 28 '15 08:01 SimonHohenadl