gpt4 book ai didi

c# - 使用 Microsoft Fakes 设置参数

转载 作者:太空狗 更新时间:2023-10-30 00:14:13 25 4
gpt4 key购买 nike

所以我正在尝试 Microsoft Fakes,我喜欢它,但是我有一个带有 out 参数的静态方法,但我不知道如何使用它:

静态伪造方法:

public static class Foo
{
public static bool TryBar(string str, out string stuff)
{
stuff = str;

return true;
}
}

测试:

[TestFixture]
public class MyTestTests
{
[Test]
public void MyTest()
{
using (ShimsContext.Create())
{
string output;
ShimFoo.TryBarStringStringOut = (input, out output) =>
{
output = "Yada yada yada";

return false;
};
}
}
}

现在我在测试中遇到错误,声称我的输出参数错误(“无法解析符号‘输出’”)。我一直在尝试获取一些有关如何处理参数的文档,但找不到任何内容。有没有人有经验?

最佳答案

只要你问,你就会想办法。对于其他遇到此问题的人,我是这样解决的:

[TestFixture]
public class MyTestTests
{
[Test]
public void MyTest()
{
using (ShimsContext.Create())
{
ShimFoo.TryBarStringStringOut = (string input, out string output) =>
{
output = "Yada yada yada";

return false;
};
}
}
}

关于c# - 使用 Microsoft Fakes 设置参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31205357/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com