public void TestCompleteTask() { try { var orgSvc = TaskServices.CreateService(); // No Error should be thrown var data = new List <TaskManager.DataModel.Task>() { new DataModel.Task { TaskId = 1, TaskName = "SampleTask", ParentTaskName = "Myparent", StartDate = DateTime.Now, EndDate = DateTime.Now, IsCompleted = false }, new DataModel.Task { TaskId = 2, TaskName = "Another task", ParentTaskName = "Another parent", StartDate = DateTime.Now, EndDate = DateTime.Now, IsCompleted = false } }.AsQueryable(); var mockSet = new Mock <DbSet <TaskManager.DataModel.Task> >(); mockSet.As <IQueryable <TaskManager.DataModel.Task> >().Setup(m => m.Provider).Returns(data.Provider); mockSet.As <IQueryable <TaskManager.DataModel.Task> >().Setup(m => m.Expression).Returns(data.Expression); mockSet.As <IQueryable <TaskManager.DataModel.Task> >().Setup(m => m.ElementType).Returns(data.ElementType); mockSet.As <IQueryable <TaskManager.DataModel.Task> >().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator()); mockSet.As <IQueryable <TaskManager.DataModel.Task> >().Setup(m => m.Provider).Returns(data.Provider); var mockContext = new Mock <TaskManagerContext>(); mockContext.Setup(m => m.tasks).Returns(mockSet.Object); var service = new TaskServices(mockContext.Object); List <TaskDTO> taskList = service.GetTasks(); Assert.That(taskList.Count == 2); } catch (Exception ex) { Console.WriteLine(ex.Message); Assert.That(1 == 0); } }
public TasksController() { _repository = TaskServices.CreateService(); }