【发布时间】:2017-12-09 16:33:30
【问题描述】:
我正在通过 moq 创建一个模拟界面。
我的应用程序代码使用不同的输入组合调用我的模拟的不同方法。当我用错误的输入执行 verify() 时,会抛出一个异常,列出所有方法调用。
我想获取这些方法调用,执行一些清理操作并以不同的格式显示给用户。是否可以在调用验证之前获取所有方法调用?
示例代码:
var mock = new Mock<ILoveThisFramework>();
mock.Setup(framework => framework.DownloadExists("2.0.0.0"))
.Returns(true);
// Hand mock.Object as a collaborator and exercise it,
// like calling methods on it...
ILoveThisFramework lovable = mock.Object;
bool download = lovable.DownloadExists("2.0.0.0");
// Verify that the given method was indeed called with the expected value at most once
// it will throw exception which will include method invocations. I want to get method invocations out and reformat them.
mock.Verify(framework => framework.DownloadExists("3.0.0.0"), Times.AtMostOnce());
【问题讨论】:
标签: c# .net unit-testing moq