我正在使用Moq对Dynamics 365插件开发进行单元测试。
我的问题是...我该如何嘲笑“故障” ExecuteMultiResponse?
答案 0 :(得分:1)
如何模拟“错误的” ExecuteMultiResponse?
不能。它是sealed
,因此不能从其派生来创建模拟或存根。
不过,您仍然可以创建该类的实例,并在测试中使用它
//Arrange
var response = new ExecuteMultipleResponse();
//create a faulted Item
var item = new ExecuteMultipleResponseItem() {
Faulted = true,
//..can also add response.
}
//add faulted item to response to make it faulted as well
response.Responses.Add(item);
//response should now also be faulted.
response.Faulted.Should().BeTrue(); //using FluentAssertions
//...use response in test as needed