1
我試圖建立一個模擬從集合返回數據:起訂量返回使用Where()
private IList<DutyCategory> dutyCategories;
private Mock<IDutyCategoryService> mockService;
[TestInitialize()]
public void UnitTestSetup()
{
dutyCategories = new List<DutyCategory>()
{
new DutyCategory(){Description = "Description",ID = 1,IsActive = true,Name = "Test 1",OrganizationID = 1}
};
mockService = new Mock<IDutyCategoryService>();
mockService.Setup(a => a.GetDutyCategories()).ReturnsAsync(dutyCategories);
mockService.Setup(a => a.GetDutyCategoriesByOrganization(It.IsAny<int>()))
.ReturnsAsync((int id) => dutyCategories.Where(n=>n.OrganizationID == id));
}
,在UnitTestSetup最後一行就是問題所在。我得到以下錯誤:
Cannot convert lambda expression to type 'System.Collections.Generic.IEnumerable' because it is not a delegate type
我該如何嘲笑GetDutyCategoriesByOrganization,以便它返回列表dutyCategories的子集?