【发布时间】:2011-07-26 10:49:52
【问题描述】:
我有一个方法,它有一个返回多个记录的 out 参数。我想知道如何用 FakeItEasy 模拟它。
【问题讨论】:
标签: c# .net tdd mocking fakeiteasy
我有一个方法,它有一个返回多个记录的 out 参数。我想知道如何用 FakeItEasy 模拟它。
【问题讨论】:
标签: c# .net tdd mocking fakeiteasy
你应该使用 .AssignsOutAndRefParameters 配置方法:
[Test]
public void Output_and_reference_parameters_can_be_configured()
{
var fake = A.Fake<IDictionary<string, string>>();
string ignored = null;
A.CallTo(() => fake.TryGetValue("test", out ignored))
.Returns(true)
.AssignsOutAndRefParameters("foo");
// This would of course be within you SUT.
string outputValue = null;
fake.TryGetValue("test", out outputValue);
Assert.That(outputValue, Is.EqualTo("foo"));
}
【讨论】: