Moq示例使用out和ref需要 [英] Moq Example using out and ref needed

查看:95
本文介绍了Moq示例使用out和ref需要的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试对一些实现参数的旧方法进行测试. 你能给我一个例子怎么做吗?

I am trying to build a test against some legacy method that implement out parameters. Could you give me an example how to do this?

推荐答案

只需在测试中分配outref参数.

Just assign the out or ref parameter from the test.

使用此界面:

public interface ILegacy
{
    bool Foo(out string bar);
}

您可以编写这样的测试:

You can write a test like this:

[TestMethod]
public void Test13()
{
    string bar = "ploeh";

    var legacyStub = new Mock<ILegacy>();
    legacyStub.Setup(l => l.Foo(out bar))
        .Returns(true);

    Assert.IsTrue(legacyStub.Object.Foo(out bar));
    Assert.AreEqual("ploeh", bar);
}

这篇关于Moq示例使用out和ref需要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆