public void Given_valid_post_When_CreateFurtherControlMeasureTask_Then_mapped_request_to_service_has_correct_values_and_returns_json()
        {
            // Given
            var controller = GetTarget();
            var returnedTaskDto = new HazardousSubstanceRiskAssessmentFurtherControlMeasureTaskDto()
            {
                Id = 123,
                Title = "title",
                Description = "description",
                CreatedDate = "23/06/1980",
                TaskCompletionDueDate = "23/06/2016",
                TaskAssignedTo = new EmployeeDto()
                {
                    Id = Guid.NewGuid(),
                    FullName = "Marcellas Wallace"
                }
            };
            var passedSaveFurtherControlMeasureTaskRequest = new SaveFurtherControlMeasureTaskRequest();

            _furtherControlMeasureTaskService
                .Setup(x => x.AddFurtherControlMeasureTask(It.IsAny<SaveFurtherControlMeasureTaskRequest>()))
                .Returns(returnedTaskDto)
                .Callback<SaveFurtherControlMeasureTaskRequest>(y => passedSaveFurtherControlMeasureTaskRequest = y);

            // When
            var postedAddEditFurtherControlMeasureTaskViewModel = new AddHazardousSubstanceFurtherControlMeasureTaskViewModel()
                                                                  {
                                                                      RiskAssessmentId = 1,
                                                                      Reference = "Test",
                                                                      Description = "Test",
                                                                      Title = "Test",
                                                                      CompanyId = 1,
                                                                      TaskAssignedToId = new Guid(),
                                                                      TaskCompletionDueDate = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss"),
                                                                      ExistingDocuments = new ExistingDocumentsViewModel()
                                                                  };

            var result = controller.NewFurtherControlMeasureTask(postedAddEditFurtherControlMeasureTaskViewModel, new DocumentsToSaveViewModel());

            // Then
            _furtherControlMeasureTaskService
                .Verify(x => x.AddFurtherControlMeasureTask(It.IsAny<SaveFurtherControlMeasureTaskRequest>()));
            Assert.That(passedSaveFurtherControlMeasureTaskRequest.RiskAssessmentId, Is.EqualTo(postedAddEditFurtherControlMeasureTaskViewModel.RiskAssessmentId));
            Assert.That(passedSaveFurtherControlMeasureTaskRequest.Reference, Is.EqualTo(postedAddEditFurtherControlMeasureTaskViewModel.Reference));
            Assert.That(passedSaveFurtherControlMeasureTaskRequest.Description, Is.EqualTo(postedAddEditFurtherControlMeasureTaskViewModel.Description));
            Assert.That(passedSaveFurtherControlMeasureTaskRequest.Title, Is.EqualTo(postedAddEditFurtherControlMeasureTaskViewModel.Title));
            Assert.That(passedSaveFurtherControlMeasureTaskRequest.CompanyId, Is.EqualTo(postedAddEditFurtherControlMeasureTaskViewModel.CompanyId));
            Assert.That(passedSaveFurtherControlMeasureTaskRequest.TaskAssignedToId, Is.EqualTo(postedAddEditFurtherControlMeasureTaskViewModel.TaskAssignedToId));
            Assert.That(passedSaveFurtherControlMeasureTaskRequest.TaskCompletionDueDate.Value.ToString("dd/MM/yyyy HH:mm:ss"), Is.EqualTo(postedAddEditFurtherControlMeasureTaskViewModel.TaskCompletionDueDate));


            dynamic data = result.Data;
            var success = data.GetType().GetProperty("Success").GetValue(data, null);
            var id = data.GetType().GetProperty("Id").GetValue(data, null);
            var createdDate = data.GetType().GetProperty("CreatedOn").GetValue(data, null);

            Assert.That(success, Is.EqualTo(true));
            Assert.That(id, Is.EqualTo(returnedTaskDto.Id));
            Assert.That(createdDate, Is.EqualTo(returnedTaskDto.CreatedDate));
        }
Ejemplo n.º 2
0
        public TaskDto MapWithAssignedTo(Task entity)
        {
            TaskDto dto = null;

            if (entity.Self as ResponsibilityTask != null)
            {
                var responsibilityTask = (ResponsibilityTask) entity;
                dto = new ResponsibilityTaskDto()
                          {
                              Responsibility = new ResponsibilityDto()
                                                   {
                                                       Id = responsibilityTask.Responsibility.Id,
                                                       Title = responsibilityTask.Responsibility.Title,
                                                       Description = responsibilityTask.Responsibility.Description
                                                   }
                          };

            }

            if (entity.Self as ActionTask != null)
            {
                dto = new ActionTaskDto();
            }


            if (entity.Self as RiskAssessmentReviewTask != null)
            {
                dto = new RiskAssessmentReviewTaskDto();
            }

            if (entity.Self as MultiHazardRiskAssessmentFurtherControlMeasureTask != null)
            {

                if (entity.RiskAssessment.Self is GeneralRiskAssessment)
                {
                    dto = new MultiHazardRiskAssessmentFurtherControlMeasureTaskDto();

                    dto.DefaultDocumentType = DocumentTypeEnum.GRADocumentType; //TODO: This does not belong here, it belongs in the entity then map that. PTD.
                }

                if (entity.RiskAssessment.Self is PersonalRiskAssessment)
                {
                    dto = new MultiHazardRiskAssessmentFurtherControlMeasureTaskDto();
                    dto.DefaultDocumentType = DocumentTypeEnum.PRADocumentType; //TODO: This does not belong here, it belongs in the entity then map that. PTD.
                }

            }

            if (entity.Self as HazardousSubstanceRiskAssessmentFurtherControlMeasureTask != null)
            {
                dto = new HazardousSubstanceRiskAssessmentFurtherControlMeasureTaskDto();

                dto.DefaultDocumentType = DocumentTypeEnum.HSRADocumentType; //TODO: This does not belong here, it belongs in the entity then map that. PTD.
            }

            if (entity.Self as FireRiskAssessmentFurtherControlMeasureTask != null)
            {
                dto = new FireRiskAssessmentFurtherControlMeasureTaskDto();
                dto.DefaultDocumentType = DocumentTypeEnum.FRADocumentType; //TODO: This does not belong here, it belongs in the entity then map that. PTD.
            }

            return PopulateTaskDto(entity, dto);
        }
        public void Given_isrecurring_is_false_When_CreateFurtherControlMeasureTask_Then_setl_recurringType_to_none()
        {
            // Given
            var controller = GetTarget();
            var returnedTaskDto = new HazardousSubstanceRiskAssessmentFurtherControlMeasureTaskDto()
            {
                Id = 123,
                Title = "title",
                Description = "description",
                CreatedDate = "23/06/1980",
                TaskCompletionDueDate = "23/06/2016",
                TaskAssignedTo = new EmployeeDto()
                {
                    Id = Guid.NewGuid(),
                    FullName = "Marcellas Wallace"
                },
                IsReoccurring = false,
                TaskReoccurringType = TaskReoccurringType.FiveYearly
            };
            _furtherControlMeasureTaskService
                .Setup(x => x.AddFurtherControlMeasureTask(It.IsAny<SaveFurtherControlMeasureTaskRequest>()))
                .Returns(returnedTaskDto);

            // When
            var postedAddEditFurtherControlMeasureTaskViewModel = new AddHazardousSubstanceFurtherControlMeasureTaskViewModel()
            {
                RiskAssessmentId = 1,
                Reference = "Test",
                Description = "Test",
                Title = "Test",
                CompanyId = 1,
                TaskAssignedToId = new Guid(),
                TaskCompletionDueDate = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss"),
                ExistingDocuments = new ExistingDocumentsViewModel()
            };

            var result = controller.NewFurtherControlMeasureTask(postedAddEditFurtherControlMeasureTaskViewModel, new DocumentsToSaveViewModel());

            // Then
            _furtherControlMeasureTaskService
                .Verify(x => x.AddFurtherControlMeasureTask(It.Is<SaveFurtherControlMeasureTaskRequest>(y => y.TaskReoccurringTypeId == (int)TaskReoccurringType.None)));

        }