public JsonResult CompleteTask(CompleteTaskViewModel completeTaskViewModel, DocumentsToSaveViewModel documentsToSaveViewModel)
        {
            if (!ModelState.IsValid)
            {
                throw new ArgumentException("Invalid Arguments To Complete Task");
            }

            var request = new CompleteTaskRequest
                              {
                                  CompanyId = completeTaskViewModel.CompanyId,
                                  FurtherControlMeasureTaskId = completeTaskViewModel.FurtherControlMeasureTaskId,
                                  CompletedComments = completeTaskViewModel.CompletedComments,
                                  UserId = CurrentUser.UserId,
                                  CreateDocumentRequests = documentsToSaveViewModel.CreateDocumentRequests,
                                  DocumentLibraryIdsToDelete = documentsToSaveViewModel.DeleteDocumentRequests,
                                  CompletedDate = DateTimeOffset.Now
                              };

            using (var session = _businessSafeSessionManager.Session)
            {
                _furtherControlMeasureTaskService.CompleteFurtherControlMeasureTask(request);
                _businessSafeSessionManager.CloseSession();
            }

            using (var session = _businessSafeSessionManager.Session)
            {
                _furtherControlMeasureTaskService.SendTaskCompletedEmail(request);
                 _businessSafeSessionManager.CloseSession();
            }

            return Json(new SaveTaskResultViewModel
            {
                Success = true,
                Id = completeTaskViewModel.FurtherControlMeasureTaskId,
            });
        }
Пример #2
0
        public void When_invalid_view_model_Then_should_throw_correct_exception()
        {
            // Given
            var target = CreateController();
            var viewModel = new CompleteTaskViewModel();

            target.ModelState.AddModelError("Anything", "Some Error Doesn't Matter");

            // When

            // Then
            Assert.Throws<ArgumentException>(() => target.CompleteTask(viewModel, null));
        }
Пример #3
0
        public void When_complete_task_with_completed_notification_Then_should_call_correct_methods()
        {
            // Given
            var target = CreateController();
            var viewModel = new CompleteTaskViewModel()
                                {
                                    CompanyId = 1,
                                    FurtherControlMeasureTaskId = 4,
                                    CompletedComments = "Testing"
                                };

            _furtherControlMeasureTaskService
                .Setup(x => x.CompleteFurtherControlMeasureTask(It.IsAny<CompleteTaskRequest>()));

            _furtherControlMeasureTaskService
                .Setup(x => x.GetByIdAndCompanyId(It.IsAny<long>(), It.IsAny<long>()))
                .Returns(_furtherControlMeasureTaskDtoWithCompletedNotification);

            // When
            target.CompleteTask(viewModel, new DocumentsToSaveViewModel());


            // Then
            _furtherControlMeasureTaskService
                .Verify(x => x.CompleteFurtherControlMeasureTask(It.Is<CompleteTaskRequest>(y => y.GetType() == typeof(CompleteTaskRequest))));
            _furtherControlMeasureTaskService
                .Verify(x => x.CompleteFurtherControlMeasureTask(It.Is<CompleteTaskRequest>(y => y.CompanyId == viewModel.CompanyId)));
            _furtherControlMeasureTaskService
                .Verify(x => x.CompleteFurtherControlMeasureTask(It.Is<CompleteTaskRequest>(y => y.FurtherControlMeasureTaskId == viewModel.FurtherControlMeasureTaskId)));
            _furtherControlMeasureTaskService
                .Verify(x => x.CompleteFurtherControlMeasureTask(It.Is<CompleteTaskRequest>(y => y.CompletedComments == viewModel.CompletedComments)));
            _furtherControlMeasureTaskService
                .Verify(x => x.CompleteFurtherControlMeasureTask(It.Is<CompleteTaskRequest>(y => y.UserId == target.CurrentUser.UserId)));
             _furtherControlMeasureTaskService
                .Verify(x => x.CompleteFurtherControlMeasureTask(It.Is<CompleteTaskRequest>(y => y.CompletedDate.Date == DateTime.Now.Date)));
            
            _furtherControlMeasureTaskService
                .Verify(x => x.SendTaskCompletedEmail(It.IsAny<CompleteTaskRequest>()),Times.Once());


        }
Пример #4
0
        public void When_complete_task_with_valid_request_Then_should_return_correct_result()
        {
            // Given
            var target = CreateController();
            var viewModel = new CompleteTaskViewModel();

            _furtherControlMeasureTaskService
               .Setup(x => x.GetByIdAndCompanyId(It.IsAny<long>(), It.IsAny<long>()))
               .Returns(_furtherControlMeasureTaskDtoWithCompletedNotification);

            // When
            var result = target.CompleteTask(viewModel, new DocumentsToSaveViewModel());

            // Then
            dynamic data = result.Data;
            Assert.That(data.Success, Is.EqualTo(true));
        }