开发者

RhinoMocks - Specifying return for functions called later

开发者 https://www.devze.com 2022-12-17 07:52 出处:网络
Using RhinoMocks - how can I say \"whenever some function is called from now on - it should return some value\".

Using RhinoMocks - how can I say "whenever some function is called from now on - it should return some value".

I'd like to say something like this:

fakeCalculator.WhenCalled(factory => factory.AddNumbers(1, 2)).Return(3); 

And then - when the AddNumbers function is called with 1 and 2 - it will return 3. I.e. I want to define this ahead, and then trigger the function. The reason is that I depend on this behavior for开发者_如何学Python my mock which is injected into another class - which will again call the AddNumbers function.


Something like this:

MockRepository mocks = new MockRepository();
IFactory factory = mocks.DynamicMock<IFactory>();

using(mocks.Record()) {
    factory.AddNumbers(1, 2);
    LastCall.Return(3);

    factory.AddNumbers(2, 3);
    LastCall.Return(5);
}

int result = factory.AddNumbers(1, 2);
Assert.AreEqual(3, result);

result = factory.AddNumbers(2, 3);
Assert.AreEqual(5, result);
0

精彩评论

暂无评论...
验证码 换一张
取 消