public void Given_task_with_twenty_history_record_When_get_task_history_Then_returns_correct_history_only_ten()
        {
            //Given
            var today = DateTime.Today;
            HazardousSubstanceRiskAssessmentFurtherControlMeasureTask previousTask = null;
            for (int i = 20; i > 0; i--)
            {
                var historytask = new HazardousSubstanceRiskAssessmentFurtherControlMeasureTask
                                      {
                                          TaskAssignedTo = new Employee() { Forename = "Vince", Surname = "Lee" }, 
                                          PrecedingTask = previousTask,
                                          TaskReoccurringType = TaskReoccurringType.Weekly,
                                          TaskCompletedDate = today.AddDays(-i),
                                          TaskCompletionDueDate = today.AddDays(-i)
                                      };
                previousTask = historytask;
            }
            var task = new HazardousSubstanceRiskAssessmentFurtherControlMeasureTask { TaskReoccurringType = TaskReoccurringType.Weekly, PrecedingTask = previousTask };

            //When
            var result = task.GetPreviousHistory();


            //Then
            Assert.That(result.Count(), Is.EqualTo(10));
            for (int j = 0; j < result.Count(); j++)
            {
                var expectedDate = today.AddDays(-j - 1);
                Assert.That(result.ElementAt(result.Count() - 1 - j).DueDate.ToShortDateString(), Is.EqualTo(expectedDate.ToShortDateString()));
            }
        }
        public void Given_employee_is_risk_assessor_then_return_task()
        {
            //GIVEN
            var employee = new Employee() { Id = Guid.NewGuid(), NotificationType = NotificationType.Daily};
            var riskAssessor = new RiskAssessor() { Id = 5596870, Employee = employee }; 
            var riskAssessement = new HazardousSubstanceRiskAssessment() { RiskAssessor = riskAssessor, Status = RiskAssessmentStatus.Live};
            var hazardousSubstanceRiskAssessmentFurtherControlMeasureTask =
                new HazardousSubstanceRiskAssessmentFurtherControlMeasureTask() 
                {   
                    HazardousSubstanceRiskAssessment = riskAssessement, 
                    TaskCompletedDate = DateTime.Now,
                    TaskStatus = TaskStatus.Completed
                };

            riskAssessement.FurtherControlMeasureTasks.Add(hazardousSubstanceRiskAssessmentFurtherControlMeasureTask);

            _hsRiskAssessments.Add(riskAssessement);

            var target = new GetCompletedHazardousSubstanceRiskAssessmentFurtherControlMeasureTasksForEmployeeQuery(null);

            //WHEN
            var result = target.Execute(employee.Id, null);

            //THEN
            Assert.That(result.Count, Is.EqualTo(1));
        }
        public void When_mark_for_delete_for_task_set_as_completed_Then_should_throw_correct_exception()
        {
            //Given
            var task = new HazardousSubstanceRiskAssessmentFurtherControlMeasureTask {TaskStatus = TaskStatus.Completed};
            var user = new UserForAuditing();

            //When
            //Then
            Assert.Throws<AttemptingToDeleteFurtherControlMeasureTaskThatIsCompletedException>(() => task.MarkForDelete(user));
        }
        public void When_reassign_task_set_as_completed_Then_should_throw_correct_exception()
        {
            //Given
            var task = new HazardousSubstanceRiskAssessmentFurtherControlMeasureTask { TaskStatus = TaskStatus.Completed };
            var user = new UserForAuditing();

            //When
            //Then
            Assert.Throws<AttemptingToReassignFurtherActionTaskThatIsCompletedException>(() => task.ReassignTask(null, user));
        }
        public void Given_a_HSRAFCMTask_Type_when_DefaultDocumentType_returns_HSRA_DocumentType()
        {
            //given
            var hsrTask = new HazardousSubstanceRiskAssessmentFurtherControlMeasureTask();

            //when
            var result = hsrTask.DefaultDocumentType;

            //then
            Assert.AreEqual(DocumentTypeEnum.HSRADocumentType, result);
        }
        public void Given_reoccurring_task_that_has_gone_past_last_end_date_When_get_schedule_Then_returns_correct_schedule()
        {
            //Given
            var task = new HazardousSubstanceRiskAssessmentFurtherControlMeasureTask { TaskReoccurringType = TaskReoccurringType.Weekly, TaskReoccurringEndDate = DateTime.Today.AddDays(-1)};

            //When
            var result = task.GetReoccurringSchedule();


            //Then
            Assert.That(result.ScheduledDates.Count(), Is.EqualTo(0));
        }
        public void Given_not_reoccurring_task_When_get_schedule_Then_returns_correct_schedule()
        {
            //Given
            var task = new HazardousSubstanceRiskAssessmentFurtherControlMeasureTask {TaskReoccurringType = TaskReoccurringType.None};
            
            //When
            var result = task.GetReoccurringSchedule();

            
            //Then
            Assert.That(result.ScheduledDates.Count(), Is.EqualTo(0));    
        }
        public void When_mark_as_no_longer_required_completed_task_Then_should_throw_correct_exceptions()
        {
            //Given
            var task = new HazardousSubstanceRiskAssessmentFurtherControlMeasureTask();
            var user = new UserForAuditing();

            task.Complete("", new List<CreateDocumentParameters>(), new List<long>(), user, null, DateTime.Now);

            //When
            //Then
            Assert.Throws<AttemptingToMarkAsNoLongerRequiredFurtherActionTaskThatIsCompletedException>(() => task.MarkAsNoLongerRequired(user));
        }
        public void When_complete_task_already_completed_Then_should_throw_correct_exception()
        {
            //Given
            var task = new HazardousSubstanceRiskAssessmentFurtherControlMeasureTask();
            var user = new UserForAuditing();

            task.Complete("comments", new List<CreateDocumentParameters>(), new List<long>(), user, null, DateTime.Now);

            //When
            //Then
            Assert.Throws<AttemptingToCompleteTaskThatIsCompletedException>(() => task.Complete("comments", new List<CreateDocumentParameters>(), new List<long>(), user, null, DateTime.Now));
        }
        public void Given_task_with_no_history_When_get_task_history_Then_returns_correct_history()
        {
            //Given
            var task = new HazardousSubstanceRiskAssessmentFurtherControlMeasureTask { TaskReoccurringType = TaskReoccurringType.None };

            //When
            var result = task.GetPreviousHistory();


            //Then
            Assert.That(result.Count(), Is.EqualTo(0));
        }
        public void When_mark_for_delete_Then_taskstatus_remains_the_same()
        {
            //Given
            var task = new HazardousSubstanceRiskAssessmentFurtherControlMeasureTask {TaskStatus = TaskStatus.Outstanding};
            ;
            var user = new UserForAuditing();

            //When
            task.MarkForDelete(user);

            //Then
            Assert.That(task.TaskStatus, Is.EqualTo(TaskStatus.Outstanding));
        }
        public void Given_riskassessment_one_further_control_measure_Then_should_not_be_able_to_delete()
        {
            //Given
            var riskAssessment = HazardousSubstanceRiskAssessment.Create("", "", default(long), null, new HazardousSubstance());
            var task = new HazardousSubstanceRiskAssessmentFurtherControlMeasureTask();
            riskAssessment.FurtherControlMeasureTasks.Add(task);
            

            //When
            var result = riskAssessment.HasUndeletedTasks();

            //Then
            Assert.True(result);
        }
        public void When_mark_for_delete_Then_should_set_properties_correctly()
        {
            //Given
            var task = new HazardousSubstanceRiskAssessmentFurtherControlMeasureTask();
            var user = new UserForAuditing();

            //When
            task.MarkForDelete(user);

            //Then
            Assert.That(task.Deleted, Is.True);
            Assert.That(task.LastModifiedOn.Value.Date, Is.EqualTo(DateTime.Today));
            Assert.That(task.LastModifiedBy, Is.EqualTo(user));
        }
        public void Given_riskassessment_one_outstanding_further_control_measure_Then_should_return_true()
        {
            //Given
            var riskAssessment = HazardousSubstanceRiskAssessment.Create("", "", default(long), null, new HazardousSubstance());
            var task = new HazardousSubstanceRiskAssessmentFurtherControlMeasureTask();
            task.TaskStatus = TaskStatus.Outstanding;
            riskAssessment.FurtherControlMeasureTasks.Add(task);
            
            //When
            var result = riskAssessment.HasUncompletedTasks();

            //Then
            Assert.True(result);
        }
        public void Given_Add_FurtherControlMeasureTask_Then_FurtherControlMeasureTask_Is_Added_To_TaskList()
        {
            //Given
            var user = new UserForAuditing();
            var riskAssessment = Domain.Entities.HazardousSubstanceRiskAssessment.Create("title", "reference", 200, user, null);
            var furtherControlMeasureTask = new HazardousSubstanceRiskAssessmentFurtherControlMeasureTask();

            //When
            riskAssessment.AddFurtherControlMeasureTask(furtherControlMeasureTask, user);

            //Then
            Assert.That(riskAssessment.FurtherControlMeasureTasks.Count, Is.EqualTo(1));
            Assert.That(riskAssessment.LastModifiedBy, Is.EqualTo(user));
            Assert.That(riskAssessment.LastModifiedOn.Value.Date, Is.EqualTo(DateTime.Now.Date));
        }
        public void Given_task_with_one_history_record_When_get_task_history_Then_returns_correct_history()
        {
            //Given
            var historytask = new HazardousSubstanceRiskAssessmentFurtherControlMeasureTask { TaskAssignedTo = new Employee() { Forename = "Vince", Surname = "Lee" }, TaskReoccurringType = TaskReoccurringType.None, TaskCompletedDate = DateTime.Today, TaskCompletionDueDate = DateTime.Today.AddDays(-1) };
            var task = new HazardousSubstanceRiskAssessmentFurtherControlMeasureTask { TaskAssignedTo = new Employee() { Forename = "Vince", Surname = "Lee" }, TaskReoccurringType = TaskReoccurringType.None, PrecedingTask = historytask };

            //When
            var result = task.GetPreviousHistory();


            //Then
            Assert.That(result.Count(), Is.EqualTo(1));
            Assert.That(result.First().DueDate.ToShortDateString(), Is.EqualTo(historytask.TaskCompletionDueDate.Value.ToShortDateString()));
            Assert.That(result.First().CompletedDate, Is.EqualTo(historytask.TaskCompletedDate.Value.DateTime.ToShortDateString()));
        }
        public void Given_riskassessment_one_further_control_measure_which_is_deleted_Then_should_return_true()
        {
            //Given
            var riskAssessment = HazardousSubstanceRiskAssessment.Create("", "", default(long), null, new HazardousSubstance());
            var task = new HazardousSubstanceRiskAssessmentFurtherControlMeasureTask()
                           {
                               Deleted = true
                           };
            riskAssessment.FurtherControlMeasureTasks.Add(task);

            //When
            var result = riskAssessment.HasUncompletedTasks();

            //Then
            Assert.False(result);
        }
        public void When_mark_as_no_longer_required_Then_should_set_properties_correctly()
        {
            //Given
            var task = new HazardousSubstanceRiskAssessmentFurtherControlMeasureTask();
            var user = new UserForAuditing();

            //When
            task.MarkAsNoLongerRequired(user);

            //Then
            Assert.That(task.LastModifiedOn.Value.Date, Is.EqualTo(DateTime.Today));
            Assert.That(task.LastModifiedBy, Is.EqualTo(user));
            Assert.That(task.TaskStatus, Is.EqualTo(TaskStatus.NoLongerRequired));
            // todo: doesn't archive yet
            //Assert.That(task.Archive.Count(x => x.ArchiveAction == FurtherActionTaskArchiveAction.MarkAsNoLongerRequired.ToString()),Is.EqualTo(1));
        }
        public void Given_3monthly_reoccurring_task_that_has_no_last_end_date_When_get_schedule_Then_returns_correct_schedule_with_five_dates()
        {
            //Given
            var task = new HazardousSubstanceRiskAssessmentFurtherControlMeasureTask { TaskReoccurringType = TaskReoccurringType.ThreeMonthly, TaskCompletionDueDate = DateTime.Today };

            //When
            var result = task.GetReoccurringSchedule();


            //Then
            Assert.That(result.ScheduledDates.Count(), Is.EqualTo(5));
            Assert.That(result.ScheduledDates.First(), Is.EqualTo(DateTime.Today.ToShortDateString()));
            Assert.That(result.ScheduledDates.Skip(1).Take(1).First(), Is.EqualTo(DateTime.Today.AddMonths(1 * 3).ToShortDateString()));
            Assert.That(result.ScheduledDates.Skip(2).Take(1).First(), Is.EqualTo(DateTime.Today.AddMonths(2 * 3).ToShortDateString()));
            Assert.That(result.ScheduledDates.Skip(3).Take(1).First(), Is.EqualTo(DateTime.Today.AddMonths(3* 3).ToShortDateString()));
            Assert.That(result.ScheduledDates.Skip(4).Take(1).First(), Is.EqualTo(DateTime.Today.AddMonths(4* 3).ToShortDateString()));
        }
        public void When_reassign_Then_should_set_properties_correctly()
        {
            //Given
            var task = new HazardousSubstanceRiskAssessmentFurtherControlMeasureTask();
            var user = new UserForAuditing();
            var employeeReassigningTo = new Employee();

            //When
            task.ReassignTask(employeeReassigningTo, user);

            //Then
            Assert.That(task.TaskAssignedTo, Is.EqualTo(employeeReassigningTo));
            Assert.That(task.LastModifiedOn.Value.Date, Is.EqualTo(DateTime.Today));
            Assert.That(task.LastModifiedBy, Is.EqualTo(user));

            // todo: doesn't archive yet
            //Assert.That(task.Archive.Count(x => x.ArchiveAction == FurtherActionTaskArchiveAction.Reassign.ToString()), Is.EqualTo(1));
        }
        public void When_complete_Then_should_set_properties_correctly()
        {
            //Given
            var task = new HazardousSubstanceRiskAssessmentFurtherControlMeasureTask();
            var user = new UserForAuditing();

            //When
            task.Complete("comments", new List<CreateDocumentParameters>(), new List<long>(), user, null, DateTime.Now);

            //Then
            Assert.That(task.LastModifiedOn.Value.Date, Is.EqualTo(DateTime.Today));
            Assert.That(task.LastModifiedBy, Is.EqualTo(user));
            Assert.That(task.TaskStatus, Is.EqualTo(TaskStatus.Completed));
            Assert.That(task.TaskCompletedComments, Is.EqualTo("comments"));
            Assert.That(task.TaskCompletedDate.Value.Date, Is.EqualTo(DateTime.Today.Date));
            Assert.That(task.LastModifiedBy, Is.EqualTo(user));
            // todo: doesn't archive yet
            //Assert.That(task.Archive.Count(x => x.ArchiveAction == FurtherActionTaskArchiveAction.Complete.ToString()), Is.EqualTo(1));
        }
        public static HazardousSubstanceRiskAssessmentFurtherControlMeasureTask Create(
            string reference,
            string title,
            string description,
            DateTime? taskCompletionDueDate,
            TaskStatus taskStatus,
            Employee assignedTo,
            UserForAuditing user,
            IEnumerable<CreateDocumentParameters> createDocumentParameterObjects,
            TaskCategory furtherControlMeasureTaskCategory,
            int taskReoccurringTypeId,
            DateTime? taskReoccurringEndDate,
            bool sendTaskNotification,
            bool sendTaskCompletedNotification,
            bool sendTaskOverdueNotification,
            bool sendTaskDueForTomorrowNotification,
            Guid taskGuid
            )
        {
            var furtherControlMeasureTask = new HazardousSubstanceRiskAssessmentFurtherControlMeasureTask();

            furtherControlMeasureTask.SetValuesForCreate(
                reference,
                title,
                description,
                taskCompletionDueDate,
                taskStatus,
                assignedTo,
                user,
                createDocumentParameterObjects,
                furtherControlMeasureTaskCategory,
                taskReoccurringTypeId,
                taskReoccurringEndDate,
                sendTaskNotification,
                sendTaskCompletedNotification,
                sendTaskOverdueNotification,
                sendTaskDueForTomorrowNotification,
                taskGuid,null);

            return furtherControlMeasureTask;
        }
        public void Given_employee_is_assigned_to_task_then_return_task()
        {
            //GIVEN
            var employee = new Employee() { Id = Guid.NewGuid(), NotificationType = NotificationType.Daily};
            var riskAssessement = new HazardousSubstanceRiskAssessment();
            var hazardousSubstanceRiskAssessmentFurtherControlMeasureTask = 
                new HazardousSubstanceRiskAssessmentFurtherControlMeasureTask() {TaskAssignedTo = employee, TaskCompletionDueDate = DateTime.Now.AddDays(-5)};
            riskAssessement.FurtherControlMeasureTasks.Add(hazardousSubstanceRiskAssessmentFurtherControlMeasureTask);

            _hsRiskAssessments.Add(riskAssessement);

            var target =
                new GetOverdueHazardousSubstanceRiskAssessmentFurtherControlMeasureTasksForEmployeeQuery(
                    _queryableWrapper.Object);

            //WHEN
            var result = target.Execute(employee.Id, null);

            //THEN
            Assert.That(result.Count, Is.EqualTo(1));

        }
        private static bool DoesTaskNeedToBeNotified(HazardousSubstanceRiskAssessmentFurtherControlMeasureTask task, Guid employeeId)
        {
            // Risk Assessor
            if (task.HazardousSubstanceRiskAssessment != null &&
                task.HazardousSubstanceRiskAssessment.RiskAssessor != null &&
                task.HazardousSubstanceRiskAssessment.RiskAssessor.Employee.Id == employeeId)
            {
                var notificationType = task.HazardousSubstanceRiskAssessment.RiskAssessor.Employee.NotificationType;
                var notificationFrequency = task.HazardousSubstanceRiskAssessment.RiskAssessor.Employee.NotificationFrequecy;
                
                return (task.HazardousSubstanceRiskAssessment.RiskAssessor != null && task.HazardousSubstanceRiskAssessment.RiskAssessor.Employee.Id == employeeId &&
                        ( 
                            (notificationType == NotificationType.Daily) ||
                            (notificationType == NotificationType.Weekly && task.TaskCompletionDueDate.HasValue && 
                            QueriesHelper.SimplifyDate(task.TaskCompletionDueDate.Value) >= QueriesHelper.SimplifyDate(DateTime.Now.AddDays(-7))) ||
                            (notificationType == NotificationType.Monthly && notificationFrequency.HasValue && task.TaskCompletionDueDate.HasValue && 
                            QueriesHelper.SimplifyDate(task.TaskCompletionDueDate.Value) >= QueriesHelper.GetPreviousMonthsDate(notificationFrequency.Value))
                        ));
            }
            else if (task.TaskAssignedTo != null && task.TaskAssignedTo.Id == employeeId)
            {
                var notificationType = task.TaskAssignedTo.NotificationType;
                var notificationFrequency = task.TaskAssignedTo.NotificationFrequecy;

                return ( 
                            (notificationType == NotificationType.Daily) ||
                            (notificationType == NotificationType.Weekly && task.TaskCompletionDueDate.HasValue &&
                            QueriesHelper.SimplifyDate(task.TaskCompletionDueDate.Value) >= QueriesHelper.SimplifyDate(DateTime.Now.AddDays(-7))) ||
                            (notificationType == NotificationType.Monthly && notificationFrequency.HasValue && task.TaskCompletionDueDate.HasValue && 
                            QueriesHelper.SimplifyDate(task.TaskCompletionDueDate.Value) >= QueriesHelper.GetPreviousMonthsDate(notificationFrequency.Value))
                      );
            }
            else
            {
                return false;
            }
        }
        public void When_AddFurtherControlMeasureTask_Then_associated_risk_assessment_saved()
        {
            // Given
            var creatingUserId = Guid.NewGuid();
            var assignedToEmployeeId = Guid.NewGuid();

            var saveRequest = new SaveFurtherControlMeasureTaskRequest()
                              {
                                  RiskAssessmentId = 1234,
                                  CompanyId = 5678,
                                  Title = "new title",
                                  Reference = "new reference",
                                  Description = "new description",
                                  UserId = creatingUserId,
                                  TaskAssignedToId = assignedToEmployeeId,
                                  TaskCompletionDueDate = DateTime.Now
                              };

            _userRepository
                .Setup(x => x.GetByIdAndCompanyId(It.IsAny<Guid>(), It.IsAny<long>()))
                .Returns(new UserForAuditing() { Id = creatingUserId });

            _employeeRepository
                .Setup(x => x.GetByIdAndCompanyId(It.IsAny<Guid>(), It.IsAny<long>()))
                .Returns(new Employee() { Id = assignedToEmployeeId });

            var returnedRiskAssessment = new Mock<HazardousSubstanceRiskAssessment>();
            returnedRiskAssessment.Setup(x => x.Id).Returns(1234);
            returnedRiskAssessment.Setup(x => x.Reviews).Returns(new List<RiskAssessmentReview>());

            _riskAssessmentRepository
                .Setup(x => x.GetByIdAndCompanyId(It.IsAny<long>(), It.IsAny<long>()))
                .Returns(returnedRiskAssessment.Object);

            var passedFurtherControlMeasureTask = new HazardousSubstanceRiskAssessmentFurtherControlMeasureTask();

            returnedRiskAssessment
                .Setup(x => x.AddFurtherControlMeasureTask(It.IsAny<HazardousSubstanceRiskAssessmentFurtherControlMeasureTask>(), It.IsAny<UserForAuditing>()))
                .Callback<HazardousSubstanceRiskAssessmentFurtherControlMeasureTask, UserForAuditing>((task, user) => passedFurtherControlMeasureTask = task);

            // When
            _target.AddFurtherControlMeasureTask(saveRequest);

            // Then
            _riskAssessmentRepository.Verify(x => x.GetByIdAndCompanyId(saveRequest.RiskAssessmentId, saveRequest.CompanyId));
            _riskAssessmentRepository.Verify(x => x.SaveOrUpdate(It.IsAny<Domain.Entities.HazardousSubstanceRiskAssessment>()));
            _responsibilityTaskCategoryRepository.Verify(x => x.GetHazardousSubstanceRiskAssessmentTaskCategory(), Times.Once());
            _userRepository.Verify(x => x.GetByIdAndCompanyId(creatingUserId, saveRequest.CompanyId));
            returnedRiskAssessment.Verify(x => x.AddFurtherControlMeasureTask(It.IsAny<HazardousSubstanceRiskAssessmentFurtherControlMeasureTask>(), It.IsAny<UserForAuditing>()));

            Assert.That(passedFurtherControlMeasureTask.Title, Is.EqualTo(saveRequest.Title));
            Assert.That(passedFurtherControlMeasureTask.Reference, Is.EqualTo(saveRequest.Reference));
            Assert.That(passedFurtherControlMeasureTask.Description, Is.EqualTo(saveRequest.Description));
            Assert.That(passedFurtherControlMeasureTask.CreatedBy.Id, Is.EqualTo(saveRequest.UserId));
            Assert.That(passedFurtherControlMeasureTask.TaskAssignedTo.Id, Is.EqualTo(saveRequest.TaskAssignedToId));
            Assert.That(passedFurtherControlMeasureTask.TaskCompletionDueDate, Is.EqualTo(saveRequest.TaskCompletionDueDate));
            Assert.That(passedFurtherControlMeasureTask.Category.Id, Is.EqualTo(6));
        }
        public void When_AddFurtherControlMeasureTask_Then_Returned_DTO_Has_Correct_Values()
        {
            // Given
            var creatingUserId = Guid.NewGuid();
            var assignedToEmployeeId = Guid.NewGuid();

            var saveRequest = new SaveFurtherControlMeasureTaskRequest()
            {
                RiskAssessmentId = 1234,
                CompanyId = 5678,
                Title = "new title",
                Reference = "new reference",
                Description = "new description",
                UserId = creatingUserId,
                TaskAssignedToId = assignedToEmployeeId,
                TaskCompletionDueDate = DateTime.Now
            };

            _userRepository
                .Setup(x => x.GetByIdAndCompanyId(It.IsAny<Guid>(), It.IsAny<long>()))
                .Returns(new UserForAuditing() { Id = creatingUserId });

            _employeeRepository
                .Setup(x => x.GetByIdAndCompanyId(It.IsAny<Guid>(), It.IsAny<long>()))
                .Returns(new Employee() { Id = assignedToEmployeeId });

            var returnedRiskAssessment = new Mock<HazardousSubstanceRiskAssessment>();
            returnedRiskAssessment.Setup(x => x.Id).Returns(1234);
            returnedRiskAssessment.Setup(x => x.Reviews).Returns(new List<RiskAssessmentReview>());

            _riskAssessmentRepository
                .Setup(x => x.GetByIdAndCompanyId(It.IsAny<long>(), It.IsAny<long>()))
                .Returns(returnedRiskAssessment.Object);

            var passedFurtherControlMeasureTask = new HazardousSubstanceRiskAssessmentFurtherControlMeasureTask();

            returnedRiskAssessment
                .Setup(x => x.AddFurtherControlMeasureTask(It.IsAny<HazardousSubstanceRiskAssessmentFurtherControlMeasureTask>(), It.IsAny<UserForAuditing>()))
                .Callback<HazardousSubstanceRiskAssessmentFurtherControlMeasureTask, UserForAuditing>((task, user) => passedFurtherControlMeasureTask = task);

            // When
            var result = _target.AddFurtherControlMeasureTask(saveRequest);

            // Then
            Assert.That(DateTime.Parse(result.CreatedDate), Is.GreaterThan(DateTime.MinValue));
        }
 public virtual void AddFurtherControlMeasureTask(HazardousSubstanceRiskAssessmentFurtherControlMeasureTask furtherControlMeasureTask, UserForAuditing user)
 {
     FurtherControlMeasureTasks.Add(furtherControlMeasureTask);
     SetLastModifiedDetails(user);
 }
        public void Given_a_recurring_task_with_a_preceding_task_completed_When_TaskPreviousHistory_requested_Then_returned_TaskHistoryRecord_has_corresponding_values_set()
        {
            // Given
            var taskCompletedDate = new DateTime(1980, 6, 23);
            var taskDueDate = new DateTime(1989, 12, 20);
            var completedBy = "Kim Howard";
            var completedByParts = completedBy.Split();

            var mockFcmA = new Mock<HazardousSubstanceRiskAssessmentFurtherControlMeasureTask>();
            mockFcmA.Setup(x => x.TaskCompletedDate).Returns(taskCompletedDate);
            mockFcmA.Setup(x => x.TaskCompletionDueDate).Returns(taskDueDate);
            mockFcmA.Setup(x => x.TaskAssignedTo).Returns(new Employee() { Forename = completedByParts[0], Surname = completedByParts[1] });
            var fcmA = new HazardousSubstanceRiskAssessmentFurtherControlMeasureTask()
                           {
                               PrecedingTask = mockFcmA.Object
                           };

            // When
            var result = fcmA.GetPreviousHistory();
            
            // Then
            Assert.That(result.Count(), Is.EqualTo(1));
            Assert.That(result.First().CompletedDate, Is.EqualTo(taskCompletedDate.ToShortDateString()));
            Assert.That(result.First().DueDate.ToShortDateString(), Is.EqualTo(taskDueDate.ToShortDateString()));
            Assert.That(result.First().CompletedBy, Is.EqualTo(completedBy));
        }