[英]Moq mock method with out specifying input parameter
我在使用Moq的測試中有一些代碼:
public class Invoice
{
...
public bool IsInFinancialYear(FinancialYearLookup financialYearLookup)
{
return InvoiceDate >= financialYearLookup.StartDate && InvoiceDate <= financialYearLookup.EndDate;
}
...
}
所以在單元測試中我試圖模擬這個方法並讓它返回true
mockInvoice.Setup(x => x.IsInFinancialYear()).Returns(true);
無論如何都要寫這一行,所以我不必指定IsInFinancialYear
的輸入。 即。 所以它在代碼中沒有輸入參數是什么,它將返回true傳遞給它的什么?
嘗試使用It.IsAny<FinancialYearLookup>()
接受任何參數:
mockInvoice.Setup(x => x.IsInFinancialYear(It.IsAny<FinancialYearLookup>())).Returns(true);
您可以嘗試以下方法:
https://7pass.wordpress.com/2014/05/20/moq-setup-and-ignore-all-arguments/
允許:
mock
.SetupIgnoreArgs(x => x.Method(null, null, null)
.Return(value);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.