public void Given_the_risk_assessor_is_NOT_different_when_Update_RA_summary_then_further_control_measure_completed_email_notification_value_is_NOT_updated()
        {
            //Given
            var hazard = new MultiHazardRiskAssessmentHazard();
            //create mocked tasks
            var furtherControlMeasureTasks = new List<Mock<MultiHazardRiskAssessmentFurtherControlMeasureTask>>()
                                                 {
                                                     new Mock<MultiHazardRiskAssessmentFurtherControlMeasureTask>() {CallBase = true},
                                                     new Mock<MultiHazardRiskAssessmentFurtherControlMeasureTask>() {CallBase = true}
                                                 };

            //Add mocked tasks to risk assessement
            furtherControlMeasureTasks.ForEach(x => hazard.FurtherControlMeasureTasks.Add(x.Object));

            var riskAss = GeneralRiskAssessment.Create("", "", 123, new UserForAuditing());
            riskAss.Hazards.Add(hazard);
            riskAss.RiskAssessor = new RiskAssessor() { Id = 1, DoNotSendTaskCompletedNotifications = true };

            //when
            riskAss.UpdateSummary("new title", "new ref", new DateTime(), new RiskAssessor() { Id = 1, DoNotSendTaskCompletedNotifications = true }, new Site(), new UserForAuditing());

            //then
            furtherControlMeasureTasks.ForEach(task => task.VerifySet(x => x.SendTaskCompletedNotification,Times.Never()));

        }
        public void When_got_no_further_control_measures_Then_should_be_able_to_delete()
        {
            //Given
            var riskAssessmentHazard = new MultiHazardRiskAssessmentHazard();

            //When
            var result = riskAssessmentHazard.CanDeleteHazard();

            //Then
            Assert.True(result);
        }
        public void When_got_one_further_control_measures_Then_should_not_be_able_to_delete()
        {
            //Given
            var riskAssessmentHazard = new MultiHazardRiskAssessmentHazard();
            riskAssessmentHazard.AddFurtherActionTask(new MultiHazardRiskAssessmentFurtherControlMeasureTask(), new UserForAuditing());

            //When
            var result = riskAssessmentHazard.CanDeleteHazard();

            //Then
            Assert.False(result);
        }
 public static HazardDto MapWithoutFurtherActionTasks(MultiHazardRiskAssessmentHazard riskAssessmentHazard)
 {
     return new HazardDto()
     {
         Id = riskAssessmentHazard.Hazard.Id,
         RiskAssessmentHazardId = riskAssessmentHazard.Id,
         Name = riskAssessmentHazard.Hazard.Name,
         IsSystemDefault = riskAssessmentHazard.Hazard.CompanyId == 0,
         Description = riskAssessmentHazard.Description,
         ControlMeasures = GetRiskAssessmentControlMeasures(riskAssessmentHazard).ToList(),
         RiskAssessmentId = riskAssessmentHazard.Hazard.RiskAssessmentId
     };
 }
        public void When_MarkAsDeleted_Then_set_deleted_to_true()
        {
            //Given
            var riskAssessmentHazard = new MultiHazardRiskAssessmentHazard();
            var user = new UserForAuditing();
            var controlMeasure = MultiHazardRiskAssessmentControlMeasure.Create("Control Measure Description", riskAssessmentHazard, user);

            //When
            controlMeasure.MarkAsDeleted(user);

            //Then
            Assert.That(controlMeasure.Deleted, Is.True);
        }
        public void When_MarkAsDeleted_Then_set_last_modified()
        {
            //Given
            var riskAssessmentHazard = new MultiHazardRiskAssessmentHazard();
            var user = new UserForAuditing();
            var controlMeasure = MultiHazardRiskAssessmentControlMeasure.Create("Control Measure Description", riskAssessmentHazard, user);

            //When
            controlMeasure.MarkAsDeleted(user);

            //Then
            Assert.That(controlMeasure.LastModifiedBy, Is.EqualTo(user));
            Assert.That(controlMeasure.LastModifiedOn.Value.Date, Is.EqualTo(DateTime.Today));
        }
        public void When_got_one_further_control_measures_but_is_deleted_Then_should_be_able_to_delete()
        {
            //Given
            var riskAssessmentHazard = new MultiHazardRiskAssessmentHazard();
            var user = new UserForAuditing();
            var riskAssessmentFurtherActionTask = new MultiHazardRiskAssessmentFurtherControlMeasureTask();
            riskAssessmentFurtherActionTask.MarkForDelete(user);
            riskAssessmentHazard.AddFurtherActionTask(riskAssessmentFurtherActionTask, user);

            //When
            var result = riskAssessmentHazard.CanDeleteHazard();

            //Then
            Assert.True(result);
        }
        public void Given_hazard_has_been_deleted_and_no_review_tasks_then_CompletionDueDate_is_null()
        {
            //given
            var riskAss = new Mock<MultiHazardRiskAssessment>() { CallBase = true };
            var hazard = new MultiHazardRiskAssessmentHazard() { Id = 124124 };
            hazard.AddFurtherActionTask(new MultiHazardRiskAssessmentFurtherControlMeasureTask() { Id = 12312, Deleted = false, TaskCompletionDueDate = DateTime.Now }, null);
            hazard.Deleted = true;

            var hazards = new List<MultiHazardRiskAssessmentHazard>() { hazard };

            riskAss.Setup(x => x.Hazards)
                .Returns(() => hazards);

            //THEN
            Assert.IsNull(riskAss.Object.CompletionDueDate);
        }
        public void Given_all_required_felds_are_available_Then_create_RiskAssessmentControlMeasure_method_creates_an_object()
        {
            //Given
            const string controlMeasure = "CM1";
            var riskAssessmentHazard = new MultiHazardRiskAssessmentHazard(); 
            var assignedTo = new UserForAuditing();

            //When
            var result = MultiHazardRiskAssessmentControlMeasure.Create(controlMeasure, riskAssessmentHazard, assignedTo);

            //Then
            Assert.That(result.ControlMeasure,Is.EqualTo(controlMeasure));
            
            Assert.That(result.CreatedOn, Is.Not.Null);
            Assert.That(result.CreatedBy, Is.Not.Null);
            Assert.That(result.MultiHazardRiskAssessmentHazard, Is.Not.Null);
            
        }
        public void Given_further_control_measure_tasks_and_no_review_tasks_then_CompletionDueDate_is_next_FCM_CompletionDueDate()
        {
            //given
            var expectedCompletionDueDate = new DateTime(2013, 4, 1);
            var riskAss = new Mock<MultiHazardRiskAssessment>() { CallBase = true };
            var hazard = new MultiHazardRiskAssessmentHazard() {Id = 124124};
            hazard.AddFurtherActionTask(new MultiHazardRiskAssessmentFurtherControlMeasureTask() { Id = 12312, Deleted = false, TaskCompletionDueDate = DateTime.Now }, null);
            hazard.AddFurtherActionTask(new MultiHazardRiskAssessmentFurtherControlMeasureTask() { Id = 1231234, Deleted = false, TaskCompletionDueDate = expectedCompletionDueDate }, null);

            var hazards = new List<MultiHazardRiskAssessmentHazard>() { hazard };

            riskAss.Setup(x => x.Hazards)
                .Returns(() => hazards);

            //THEN
            Assert.AreEqual(expectedCompletionDueDate, riskAss.Object.CompletionDueDate.Value);

        }
        public RiskAssessmentHazardDto Map(MultiHazardRiskAssessmentHazard riskAssessmentHazard)
        {
            var riskAssessmentHazardDto = new RiskAssessmentHazardDto
                                              {
                                                  Id = riskAssessmentHazard.Id,
                                                  Description = riskAssessmentHazard.Description,
                                                  Hazard = riskAssessmentHazard.Hazard != null ? 
                                                        new HazardDto //todo: ptd - replace this with its own mapper.
                                                               {
                                                                   Id = riskAssessmentHazard.Hazard.Id,
                                                                   Name = riskAssessmentHazard.Hazard.Name
                                                               } 
                                                        : null,
                                                        // Temporary until we start using multihazardriskassessment
                                                  RiskAssessment = GeneralRiskAssessmentDto.CreateFrom(riskAssessmentHazard.MultiHazardRiskAssessment)
                                              };

            return riskAssessmentHazardDto;
        }
        public void When_clone_for_risk_assessment_templating_Then_should_have_correct_result()
        {
            //Given
            var riskAssessmentHazard = new MultiHazardRiskAssessmentHazard();
            var user = new UserForAuditing();
            var controlMeasure = MultiHazardRiskAssessmentControlMeasure.Create("Control Measure Description", riskAssessmentHazard, user);

            var clonedRiskAssessmentHazard = new MultiHazardRiskAssessmentHazard();

            //When
            var result = controlMeasure.CloneForRiskAssessmentTemplating(clonedRiskAssessmentHazard, user);

            //Then
            Assert.That(result.ControlMeasure, Is.EqualTo(controlMeasure.ControlMeasure));
            Assert.That(result.MultiHazardRiskAssessmentHazard, Is.EqualTo(clonedRiskAssessmentHazard));
            Assert.That(result.CreatedOn.Value.Date, Is.EqualTo(DateTime.Now.Date));
            Assert.That(result.CreatedBy, Is.EqualTo(user));

        }
        public void Given_a_review_task_has_a_completion_due_date_after_the_next_further_control_measure_tasks_then_CompletionDueDate_is_the_next_FCM_completion_due_date()
        {
            //given
            var nextFCMCompletionDueDate = new DateTime(2013, 2, 16);
            var nextReviewDate = new DateTime(2013, 3, 4);
            var riskAss = new Mock<MultiHazardRiskAssessment>() { CallBase = true };
            var hazard = new MultiHazardRiskAssessmentHazard() { Id = 124124 };
            hazard.AddFurtherActionTask(new MultiHazardRiskAssessmentFurtherControlMeasureTask() { Id = 12312, Deleted = false, TaskCompletionDueDate = DateTime.Now }, null);
            hazard.AddFurtherActionTask(new MultiHazardRiskAssessmentFurtherControlMeasureTask() { Id = 1231234, Deleted = false, TaskCompletionDueDate = nextFCMCompletionDueDate }, null);
            riskAss.Object.Reviews = new List<RiskAssessmentReview>()
                                                 {

                                                     new RiskAssessmentReview() {Id = 2, CompletionDueDate = nextReviewDate}
                                                 };


            var hazards = new List<MultiHazardRiskAssessmentHazard>() { hazard };

            riskAss.Setup(x => x.Hazards)
                .Returns(() => hazards);

            //THEN
            Assert.AreEqual(nextFCMCompletionDueDate, riskAss.Object.CompletionDueDate.Value);

        }
 private static IEnumerable<ControlMeasureDto> GetRiskAssessmentControlMeasures(MultiHazardRiskAssessmentHazard riskAssessmentHazard)
 {
     return new ControlMeasureDtoMapper().Map(riskAssessmentHazard.ControlMeasures);
 }
 private static List<TaskDto> GetRiskAssessmentFurtherActionTasks(MultiHazardRiskAssessmentHazard riskAssessmentHazard)
 {
     return new TaskDtoMapper().MapWithAssignedTo(riskAssessmentHazard.FurtherControlMeasureTasks).ToList();
 }
 private void AttachClonedRiskAssessmentHazardToRiskAssessment(MultiHazardRiskAssessmentHazard clonedHazard)
 {
     if (!Hazards.Any(x => clonedHazard.Hazard.Id > 0 && x.Hazard.Id == clonedHazard.Hazard.Id))
     {
         Hazards.Add(clonedHazard);
     }
     
 }
        public void Given_a_review_task_has_a_completion_due_date_after_the_next_further_control_measure_tasks_then_CompletionDueDate_is_the_next_FCM_completion_due_date()
        {
            //given
            var nextFCMCompletionDueDate = new DateTime(2013, 2, 16);
            var nextReviewDate = new DateTime(2013, 3, 4);
            var riskAss = new HazardousSubstanceRiskAssessment();
            var hazard = new MultiHazardRiskAssessmentHazard() { Id = 124124 };
            riskAss.AddFurtherControlMeasureTask(new HazardousSubstanceRiskAssessmentFurtherControlMeasureTask() { Id = 12312, Deleted = false, TaskCompletionDueDate = DateTime.Now }, null);
            riskAss.AddFurtherControlMeasureTask(new HazardousSubstanceRiskAssessmentFurtherControlMeasureTask() { Id = 1231234, Deleted = false, TaskCompletionDueDate = nextFCMCompletionDueDate }, null);
            riskAss.Reviews = new List<RiskAssessmentReview>()
                                                 {

                                                     new RiskAssessmentReview() {Id = 2, CompletionDueDate = nextReviewDate}
                                                 };


            //THEN
            Assert.AreEqual(nextFCMCompletionDueDate, riskAss.CompletionDueDate.Value);
        }
 public ControlMethodDoesNotExistInHazard(MultiHazardRiskAssessmentHazard riskAssessmentHazard, long controlMeasureId)
     : base(string.Format("Could not find control measure for Risk Assessment Hazard Id {0}. Control Measure Id {1}", riskAssessmentHazard.Id, controlMeasureId))
 { }