[英]Mock a function that takes in a List of objects
I want to write a test for a method with the following signature 我想为具有以下签名的方法编写测试
public List<CrateRecallTaskWithComms> PopulateCrateRecallTask(List<Task> listOfBaseTasks)
{
var crateRecallTasksWithComms = new List<CrateRecallTaskWithComms>();
foreach (var task in listOfBaseTasks)
{
// do stuff
var crateRecallTasksWithComms = new CrateRecallTaskWithComms()
{
// populate properties
}
// add to list
crateRecallTasksWithComms.Add(crateRecallTasksWithComms);
}
// return populated list
return crateRecallTasksWithComms;
}
I am using the Mock
library to mock this method, however I cannot get it work! 我正在使用
Mock
库来模拟此方法,但是我无法使其正常工作! Here is my test code so far: 到目前为止,这是我的测试代码:
_crateRecallService = new Mock<CrateRecallsService>();
_crateRecallService.Setup(m => m.PopulateCrateRecallTask(It.IsAny<List<Task>>()).Returns());
I am getting error at the It.IsAny<>
bit, the error says: 我在
It.IsAny<>
位出现错误,错误提示:
Argument type
System.Collections.Generic.List<Zenos.Intranet.Domain.Tasks.Task>
is not assignable to parameter typeSystem.Collections.Generic.List<Task>
无法将参数类型
System.Collections.Generic.List<Task>
System.Collections.Generic.List<Zenos.Intranet.Domain.Tasks.Task>
分配给参数类型System.Collections.Generic.List<Task>
What am I doing wrong? 我究竟做错了什么?
There seems to be two classes named Task
. 似乎有两个名为
Task
类。
I think your method expects a list of System.Task
, but you're setting it up with a list of Zenos.Intranet.Domain.Tasks.Task
. 我认为您的方法需要一个
System.Task
列表,但是您正在使用Zenos.Intranet.Domain.Tasks.Task
列表进行Zenos.Intranet.Domain.Tasks.Task
。 You're probably missing a using
directive to disambiguate between the two types.. 您可能缺少
using
指令来区分这两种类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.