gpt4 book ai didi

unit-testing - 从 FakeItEasy A.CallTo() 返回不同的对象

转载 作者:行者123 更新时间:2023-12-02 15:40:21 24 4
gpt4 key购买 nike

对于我的测试,我需要第一次调用 stub 来返回一个对象,下一次调用返回一个不同的对象。我已经在 record() block 中的其他模拟对象框架中看到了这一点,但我还没有弄清楚如何在 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);

感谢任何帮助。

最佳答案

有两种方法,其中一种是您在自己的答案中提到的方法:

A.CallTo(() => foo.Bar()).ReturnsNextFromSequence(new[] { response1, response2 });

另一种方式是:

A.CallTo(() => foo.Bar()).Returns(response2);
A.CallTo(() => foo.Bar()).Returns(response1).Once();

关于unit-testing - 从 FakeItEasy A.CallTo() 返回不同的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15253279/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com