machine / machine.specifications

Machine.Specifications is a Context/Specification framework for .NET that removes language noise and simplifies tests.
MIT License
886 stars 178 forks source link

Support returning different results from stub method calls #358

Open chrisalexander opened 9 years ago

chrisalexander commented 9 years ago

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!

SimonHohenadl commented 9 years ago

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.