我正在编写单元测试,我需要使用以下签名模拟目标方法依赖项之一的 out 参数:
bool TryProcessRequest(out string)
我正在使用JustMock并尝试使用DoInstead
安排子句,但似乎不是那么明显。
请告诉我如何实现这一点,非常感谢提前。
此选项可能适合您:
var mock = Mock.Create<IYourInterface>();
string expectedResult = "result";
Mock.Arrange(() => mock.TryProcessRequest(out expectedResult)).Returns(true);
string actualResult;
bool isCallSuccessful = mock.TryProcessRequest(out actualResult);
因此,为此您需要创建一个具有所需值的局部变量并将其用于输出位置。