Stub return value for all inputs in Rhino Mocks

南笙酒味 提交于 2020-01-15 05:53:05

问题


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?


回答1:


_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());



回答2:


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




回答3:


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.



来源:https://stackoverflow.com/questions/7498995/stub-return-value-for-all-inputs-in-rhino-mocks

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!