想要测试的BAL代码。
public List<string> GetColorGroupCodes()
{
var colorGrpCodes = (IEnumerable<POCO.ColourGroup>)colorsRepository.GetColorGroups().Result;
var colGrpCodes = (from col in colorGrpCodes select col.GroupCode + "-" + col.Description).ToList();
return colGrpCodes;
}
我可以为colorsRepository.GetColorGroups()
设置moq。但是我无法在moq服务调用之后为下一行设置moq。请参阅以下方法中的评论以更多地了解我的问题。
[Fact]
public void GetColorGroupCodes()
{
var mockColorsRepository = CommonRepository.CreateInstanceOfIMock<IColorsRepository>();
var objectsList = Data();// it given the mocked response data as List
mockColorsRepository.Setup(rep => rep.GetColorGroups()).Returns(Task.FromResult<IEnumerable<Web.POCO.ColourGroup>>(objectsList));
// Now i can mockup the rep.GetColorGroups() and can retrun which is nead for the next logic **`(from col in colorGrpCodes select col.GroupCode + "-" + col.Description).ToList();`** in BAL
// But i don't know how to mock the logic **`(from col in colorGrpCodes select col.GroupCode + "-" + col.Description).ToList();`** via moq and return data as **`List<string>`** data type.
ColorsValidator colorsValidator = new ColorsValidator(mockColorsRepository.Object);
CoCApiResponse response = colorsValidator.GetColorsList();
Assert.Equal(response.Result, objectsList);
}
我只需要模拟它并返回逻辑返回的内容。可能吗?或者请提出其他想法,如果我有任何错误的理解。