public void TestListAllCompletedUserTasksFromTheDatabase() { TaskBusiness mockTaskBusiness = new TaskBusiness(_mockContext.Object); UserBusiness mockUserBusiness = new UserBusiness(_mockContext.Object); string userName = "******"; string passwordHash = "passwordHash"; User mockUser = mockUserBusiness.FetchUser(userName, passwordHash); Task mockTask1 = new Task() { TaskId = 3, Date = DateTime.Now, Name = "name", IsDone = true, UserId = 1 }; Task mockTask2 = new Task() { TaskId = 4, Date = DateTime.Now, Name = "name", IsDone = true, UserId = 1 }; mockTaskBusiness.AddTask(mockTask1); mockTaskBusiness.AddTask(mockTask2); int count = mockTaskBusiness.ListAllCompletedTasks(mockUser).Count(); int expectedCount = mockTaskBusiness.GetPODbContext.Tasks.Where(x => x.UserId == mockUser.UserId && x.IsDone == true).ToList().Count(); Assert.AreEqual(expectedCount, count, "Not all tasks were fetched!"); }
public IHttpActionResult PostTask([FromBody] Task taskToAdd) { TaskBusiness tb = new TaskBusiness(); taskToAdd.Task_ID = Guid.NewGuid().ToString(); tb.AddTask(taskToAdd); return(Ok(taskToAdd)); }
public void TestAddNullTaskToTheDatabase() { TaskBusiness mockTaskBusiness = new TaskBusiness(_mockContext.Object); Task mockTask = null; Assert.Catch(() => mockTaskBusiness.AddTask(mockTask), "Null task added to the database!"); }
public void TestAddNewTaskToTheDatabase() { TaskBusiness mockTaskBusiness = new TaskBusiness(_mockContext.Object); Task mockTask = new Task() { TaskId = 3, Date = DateTime.Now, Name = "name", IsDone = false, UserId = 1 }; mockTaskBusiness.AddTask(mockTask); Assert.Contains(mockTask, mockTaskBusiness.GetPODbContext.Tasks.ToList(), "Task not added properly!"); }
public void TestCompleteTaskFromTheDatabase() { TaskBusiness mockTaskBusiness = new TaskBusiness(_mockContext.Object); UserBusiness mockUserBusiness = new UserBusiness(_mockContext.Object); string userName = "******"; string passwordHash = "passwordHash"; User mockUser = mockUserBusiness.FetchUser(userName, passwordHash); Task mockTask = new Task() { TaskId = 3, Date = DateTime.Now, Name = "name", IsDone = false, UserId = 1 }; mockTaskBusiness.AddTask(mockTask); mockTaskBusiness.CompleteTask(mockTask.TaskId, mockUser); mockTask = mockTaskBusiness.FetchTaskById(mockTask.TaskId, mockUser); Assert.AreEqual(mockTask.IsDone, true, "Wrong task was fetched!"); }