【发布时间】:2019-12-09 16:01:00
【问题描述】:
我知道这个问题以前在这里被问过,但我很困惑为什么这个测试失败了。这是我正在运行的测试:
public void SubmitWebservicePurchaseOrder_Calls_addQuickAddItemListToPO()
{
var input = new PurchaseOrderWebserviceSubmitDTO();
_service.SubmitWebservicePurchaseOrder(input);
var dict = It.IsAny<Dictionary<long, QuickAddOrCSVLineItem>>();
_purchaseOrderMock.Verify(x => x.addQuickAddItemListToPO(It.IsAny<long>(), It.Is<bool>(y => y == false), ref dict), Times.Once);
}
这是错误的内容:
Result Message:
Moq.MockException :
Expected invocation on the mock once, but was 0 times: x => x.addQuickAddItemListToPO(It.IsAny<Int64>(), It.Is<Boolean>(y => y == False), .dict)
No setups configured.
Performed invocations:
IPurchaseOrders.CreateNewPO(OMS.DataLayer.poHeader)
IPurchaseOrders.addQuickAddItemListToPO(0, False, System.Collections.Generic.Dictionary`2[System.Int64,OMS.DataServices.QuickAddOrCSVLineItem])
IPurchaseOrders.GetPOHeaderInfoWithUserToken(0, 00000000, 00000000)
函数SubmitWebservicePurchaseOrder 肯定在调用addQuickAddItemListToPO,但我仍然收到此错误...有人知道为什么吗?我之前没有用 MOQ 做太多工作,也不确定如何调试...
【问题讨论】:
-
你能发一个minimal reproducible example吗?
-
向我们展示您尝试设置模型的代码,因为这表明没有提供设置。您应该首先针对接口创建一个新的模拟对象。然后你设置任何输入值。
-
需要查看您的模拟设置和被测代码,否则我们无法为您提供比错误消息更多的信息。