You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
public class TaskService
{
public List<Task> GetTasks(int contactId, DataContext dbContext)
{
ITaskRepository taskRepo = new TaskRepository(dbContext);
List<Task> tasks = taskRepo.GetTasksFromDB(contactId).ToList();
......
return tasks;
}
}
How can I mock the local variable taskRepo when I writing test for method GetTasks?
I have test code like this:
public void GetTasksTest()
{
var taskService = new Mock<TaskService>();
var tasks = new List<Task> { new Task { Id = 111 } };
// But how to mock the method `taskRepo.GetTasksFromDB(contactId).ToList()`?
// And I don't want to pass taskRepo as a parameter.
}
The text was updated successfully, but these errors were encountered:
For example I have a method like this:
How can I mock the local variable
taskRepo
when I writing test for methodGetTasks
?I have test code like this:
The text was updated successfully, but these errors were encountered: