开发者

Out and Ref parameters with FakeItEasy

I have a method that has an out parameter th开发者_StackOverflow社区at returns a number of records. I would like to know how to mock it with FakeItEasy.


You should use the .AssignsOutAndRefParameters configuration method:

[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"));
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜