Cor*_*ork 8 unit-testing fakeiteasy
对于我的测试,我需要第一次调用stub来返回一个对象,然后下一次调用返回一个不同的对象.我已经在record()块中的其他模拟对象框架中看到过这个,但我还没弄清楚如何在FakeItEasy中做到这一点.FakeItEasy是我们商店的强制框架,我使用AutoFixture来制作假货.
我查看了NextCall,但看起来我不能指定返回值.
这是我想要做的事情的想法:
ReceiveMessageResponse queueResponse1 = fixture.Create<ReceiveMessageResponse>();
ReceiveMessageResponse queueResponse2 = fixture.Create<ReceiveMessageResponse>(seed);
A.CallTo(() => sqsClient.ReceiveMessage(null)).WithAnyArguments().Returns(queueResponse1);
//The following should happen the second time...
A.CallTo(() => sqsClient.ReceiveMessage(null)).WithAnyArguments().Returns(queueResponse2);
Run Code Online (Sandbox Code Playgroud)
任何帮助表示赞赏.
Pat*_*gne 17
有两种方法,其中一种是你在自己的答案中提到的方法:
A.CallTo(() => foo.Bar()).ReturnsNextFromSequence(new[] { response1, response2 });
Run Code Online (Sandbox Code Playgroud)
另一种方式是:
A.CallTo(() => foo.Bar()).Returns(response2);
A.CallTo(() => foo.Bar()).Returns(response1).Once();
Run Code Online (Sandbox Code Playgroud)
当然,它每次都会发生.在发布后的几分钟内,我自己就找到了答案.
我最终使用:
ReturnsNextFromSequence(new [] {queueResponse1, queueResponse2});
Run Code Online (Sandbox Code Playgroud)
我不确定它是首选的方法,但它对我来说很有用.
| 归档时间: |
|
| 查看次数: |
3064 次 |
| 最近记录: |