28

いくつかのレコードを返すoutパラメーターを持つメソッドがあります。FakeItEasyでモックする方法を教えてください。

4

1 に答える 1

48

.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"));
}
于 2011-03-31T07:07:01.833 に答える