使用FakeItEasy的Out和Ref参数

Cha*_*let 25 .net c# tdd mocking fakeiteasy

我有一个方法,其out参数返回许多记录.我想知道如何用FakeItEasy来嘲笑它.

Pat*_*gne 44

您应该使用.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"));
}
Run Code Online (Sandbox Code Playgroud)