public JsonResult AssignTask(AssignActionPlanTaskViewModel model) { JsonResult result; ValidateAssignActionPlanTaskViewModel(model); if (!ModelState.IsValid) { result = ModelStateErrorsAsJson(); } else { result = Json(new {Success = true}); ExecuteAssignActionTaskCommand(model); } return result; }
private void ValidateAssignActionPlanTaskViewModel(AssignActionPlanTaskViewModel model) { if (model.ActionId == default(long)) { ModelState.AddModelError("ActionId", "Invalid ActionId."); } if (model.AssignedTo == null || model.AssignedTo == Guid.Empty) { ModelState.AddModelError("AssignedTo", "Please select an assignee for the selected task."); } DateTime dueDate = DateTime.MinValue; if (model.DueDate == null || !DateTime.TryParse(model.DueDate, out dueDate)) { ModelState.AddModelError("DueDate", "Please select a valid due date for the selected task."); } else { if (dueDate < DateTime.Now.Date) { ModelState.AddModelError("DueDate", "Due date cannot be in the past."); } } }
private void ExecuteAssignActionTaskCommand(AssignActionPlanTaskViewModel model) { var command = _assignActionPlanTaskCommand .WithCompanyId(CurrentUser.CompanyId) .WithUserId(CurrentUser.UserId) .WithActionId(model.ActionId) .WithAssignedTo(model.AssignedTo) .WithDueDate(model.DueDate) .WithSendTaskNotification(true) .WithSendTaskCompletedNotification(true) .WithSendTaskOverdueNotification(true); command.Execute(); }
public void Given_valid_model_When_Assign_Task_Then_Creates_Assign_Task_Command() { // Given var model = new AssignActionPlanTaskViewModel { ActionId = 1L, AssignedTo = Guid.NewGuid(), DueDate = DateTime.Now.ToShortDateString() }; var target = GetTarget(); // When target.AssignTask(model); // Then _assignActionPlanTaskCommand.Verify(x => x.WithCompanyId(It.Is<long>(y => y == TestControllerHelpers.CompanyIdAssigned))); _assignActionPlanTaskCommand.Verify(x => x.WithActionId(It.Is<long>(y => y == model.ActionId))); _assignActionPlanTaskCommand.Verify(x => x.WithAssignedTo(It.Is<Guid?>(y => y == model.AssignedTo))); _assignActionPlanTaskCommand.Verify(x => x.WithDueDate(It.Is<string>(y => y == model.DueDate))); }
public void Given_Invalid_Model_When_Assign_Task_Then_Modelstate_Contains_Errors() { //given var model = new AssignActionPlanTaskViewModel(); var target = GetTarget(); //when target.AssignTask(model); //then Assert.That(target.ModelState.IsValid, Is.False); Assert.That(target.ModelState.ContainsKey("ActionId"), Is.True); Assert.That(target.ModelState.ContainsKey("AssignedTo"), Is.True); Assert.That(target.ModelState.ContainsKey("DueDate"), Is.True); }
public void Given_Valid_Model_When_Assign_Task_Then_Return_Json_Ssuccess_Equals_True() { //given var model = new AssignActionPlanTaskViewModel { ActionId = 1L, AssignedTo = Guid.NewGuid(), DueDate = DateTime.Now.ToShortDateString() }; var target = GetTarget(); //when dynamic result = target.AssignTask(model); //then Assert.That(result.Data.Success, Is.True); }
public void Given_valid_model_When_Assign_Task_Then_Executes_Assign_Task_Command() { // Given var model = new AssignActionPlanTaskViewModel { ActionId = 1L, AssignedTo = Guid.NewGuid(), DueDate = DateTime.Now.ToShortDateString() }; var target = GetTarget(); _assignActionPlanTaskCommand.Setup(x => x.Execute()).Verifiable(); // When target.AssignTask(model); // Then _assignActionPlanTaskCommand.Verify(); }