2
votes

I am stubbing the return value of a method using rhino mocks. However, I want to return the same dummy value for any argument that is passed in.

How do I do this without pre-registering every input to return the same output?

3
thanks for the answers. The were all good so I picked the top one.user880954

3 Answers

3
votes

_testHelper is helper class where you are returning a dummy value from GetMethodValue(). you have to write GetMethodValue() in your _testHelper class.

SetupResult.For(_Repository.MethodName(null)).IgnoreArguments().Return(_testHelper.GetMethodNameResultValue());
3
votes

You'd use MyClass.Expect(x=>x.MyMethod(someArg)).Return(stubValue).IgnoreArguments()

3
votes

You can use IgnoreArguments() constraint as shown below:

mockedInstance.Expect(instance => instance.MethodCall(null))
              .IgnoreArguments()
              .Return(preDefinedValue)
              .Repeat()
              .Any();

Also by specifying Repeat().Any() preDefinedValue will be returned for each call of a method.

See Rhino Mocks wiki for more examples.