public void When_CreateFurtherControlMeasureTask_called_Then_correct_methods_are_called()
        {
            // Arrange
            var target = GetTarget();

            var documentsToSaveViewModel = new DocumentsToSaveViewModel();
            var viewmodel = new AddRiskAssessmentFurtherControlMeasureTaskViewModel()
                                {
                                    TaskAssignedToId = Guid.NewGuid(),
                                    RiskAssessmentHazardId = 500,
                                    
                                };

            var userId = target.CurrentUser.UserId;

            var result = new MultiHazardRiskAssessmentFurtherControlMeasureTaskDto()
                             {
                                 CreatedDate = DateTime.Now.ToShortDateString()
                             };

            _furtherControlMeasureTaskService
                .Setup(x => x.AddFurtherControlMeasureTask(It.Is<SaveFurtherControlMeasureTaskRequest>(y => y.CompanyId == viewmodel.CompanyId &&
                                                                                           y.Title == viewmodel.Title &&
                                                                                           y.Description == viewmodel.Description &&
                                                                                           y.Reference == viewmodel.Reference &&
                                                                                           y.UserId == userId)))
                .Returns(result);

            // Act
            target.CreateFurtherControlMeasureTask(viewmodel, documentsToSaveViewModel);

            // Assert
            _furtherControlMeasureTaskService.VerifyAll();
            _businessSafeSessionManager.Verify(x => x.CloseSession(), Times.Exactly(1));
        }
Esempio 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 Give_IsRecurring_is_false_When_CreateFurtherControlMeasureTask_Then_Set_TaskRecurringType_to_None()
        {
            //given
            var target = GetTarget();
            
            var viewModel = new AddRiskAssessmentFurtherControlMeasureTaskViewModel()
            {
                TaskAssignedToId = Guid.NewGuid(),
                RiskAssessmentHazardId = 500,
                IsRecurring = false,
                TaskReoccurringTypeId = (int)TaskReoccurringType.Monthly

            };

            var result = new MultiHazardRiskAssessmentFurtherControlMeasureTaskDto()
            {
                CreatedDate = DateTime.Now.ToShortDateString()
            };

            _furtherControlMeasureTaskService
                .Setup(x => x.AddFurtherControlMeasureTask(It.IsAny<SaveFurtherControlMeasureTaskRequest>()))
                .Returns(result);
            
            //when

            target.CreateFurtherControlMeasureTask(viewModel, new DocumentsToSaveViewModel());

            //then
            _furtherControlMeasureTaskService
                .Verify(x => x.AddFurtherControlMeasureTask(It.Is<SaveFurtherControlMeasureTaskRequest>(y => y.TaskReoccurringTypeId == (int)TaskReoccurringType.None)), Times.Once());
        }
        public void When_CreateFurtherControlMeasureTask_called_Then_correct_view_is_returned()
        {
            // Arrange
            var target = GetTarget();

            var documentsToSaveViewModel = new DocumentsToSaveViewModel();
            var viewmodel = new AddRiskAssessmentFurtherControlMeasureTaskViewModel()
                                {
                                    TaskAssignedToId = Guid.NewGuid(),
                                    RiskAssessmentHazardId = 500
                                };

            var dto = new MultiHazardRiskAssessmentFurtherControlMeasureTaskDto()
            {
                CreatedDate = DateTime.Now.ToShortDateString()
            };
            _furtherControlMeasureTaskService
              .Setup(x => x.AddFurtherControlMeasureTask(It.Is<SaveFurtherControlMeasureTaskRequest>(y => y.CompanyId == viewmodel.CompanyId)))
              .Returns(dto);

            // Act
            var result = target.CreateFurtherControlMeasureTask(viewmodel, documentsToSaveViewModel) as JsonResult;


            // Assert
            Assert.That(result.Data.ToString(), Contains.Substring("Success = True, Id = 0, RiskAssessmentHazardId = 500"));
        }