Hello,
in order to test another class, I want to create a stub for an interface IFoo:
public interface IFoo
{
int DoSomething(int value);
}
The stub is created in the SetUp (or TestInitialize)-method for the test fixture and stored in a property as almost all test methods need an IFoo:
this.Foo = MockRepository.GenerateStub<IFoo>();
As IFoo.DoSomething needs just to return the passed value in all cases except one I added this behavior to my SetUp method:
this.Foo.Stub(f => f.DoSomething(0)).IgnoreArguments().Return(0).WhenCalled(mi => mi.ReturnValue = mi.Arguments[0]);
Now, however, this one test requires different behavior: Rather than returning the passed argument, a constant should be returned if the passed value equals another constant. The following approach (written in the test method itself) does not work:
this.Foo.Stub(f => f.DoSomething(42)).Return(43);
The previous specified, more general stub seems to override the more specific stub.
Is there any way to specify both specific and general stubs on RhinoMock-objects?
One workaround would be recreating the stub in the test-method itself - a duplication I would like to avoid. I could live with this version, however.
What I also do not want is a explicit exclusion of the "42" in the general statement via Constraints as this will effect the other tests negatively.
Calling BackToRecord is also not an option as it seems to reset other stubs, too.
Thanks for your answers!