gpt4 book ai didi

c# - 如何获得最小起订量设置以根据输入更改输出参数?

转载 作者:太空宇宙 更新时间:2023-11-03 15:33:07 24 4
gpt4 key购买 nike

最小起订量支持设置输出参数 - 没问题。我希望能够根据调用中传递的内容通过 Returns() 或 Callback() 设置参数。我的用例涉及模拟一个带有 out 参数的方法。

这是我用来做实验的东西,到目前为止每次都是负面结果:

public interface ITestClass
{
string method(string inString, out string outString);
}

public class TestClass : ITestClass
{
public string method(string inString, out string outString)
{
outString = inString + " was passed in";
return (inString + " was returned");
}
}

[TestFixture]
public class OutTest
{
[Test]
public void Test()
{
//Arrange
Mock<ITestClass> mock = new Mock<ITestClass>(MockBehavior.Strict);
string stringParm = "value that will be assigned to out parameter";
mock.Setup(t => t.method(It.IsAny<string>(), out stringParm))
.Returns((string i, string o) =>
{
return i + " was returned"; // o = stringParm already
})
.Callback((string s, string oo) =>
{
stringParm = s + " was passed in"; // oo = stringParm already
});
TestClass real = new TestClass();
string testString = DateTime.Now.ToLongTimeString();

//Act
string realOut;
string mockOut;
string realResult = real.method(testString, out realOut);
string mockResult = mock.Object.method(testString, out mockOut);

//Assert
realResult.Should().Be(mockResult); // passes
realOut.Should().Be(mockOut); // fails - mockout = original stringParm
}
}

最佳答案

我知道这并不理想,但为什么不传递结果预期的 mockOut 而不是 "value that will be assigned to out parameter"

string stringParm = "foo was passed in"

关于c# - 如何获得最小起订量设置以根据输入更改输出参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33041021/

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