【问题标题】:Out and Ref parameters with FakeItEasyFakeItEasy 的 Out 和 Ref 参数
【发布时间】:2011-07-26 10:49:52
【问题描述】:

我有一个方法,它有一个返回多个记录的 out 参数。我想知道如何用 FakeItEasy 模拟它。

【问题讨论】:

    标签: c# .net tdd mocking fakeiteasy


    【解决方案1】:

    你应该使用 .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"));
    }
    

    【讨论】:

    • @Patrik Hägne,如果我在一个函数中有 2 个输出参数,那么如何将它传递给 AssignsOutAndRefParameters() 函数。
    • @UmeshaMS, `.AssignsOutAndRefParameters("out1", "out2")
    猜你喜欢
    • 1970-01-01
    • 2012-08-08
    • 2016-08-07
    • 2021-07-03
    • 2012-03-01
    • 1970-01-01
    • 2011-07-03
    • 2013-03-16
    相关资源
    最近更新 更多