public void Given_task_with_twenty_history_record_When_get_task_history_Then_returns_correct_history_only_ten()
        {
            //Given
            var today = DateTime.Today;
            MultiHazardRiskAssessmentFurtherControlMeasureTask previousTask = null;
            for (int i = 20; i > 0; i--)
            {
                var historytask = new MultiHazardRiskAssessmentFurtherControlMeasureTask
                                      {
                                          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 MultiHazardRiskAssessmentFurtherControlMeasureTask { 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()));
            }
        }
Ejemplo n.º 2
0
        public void When_requesting_Create_values_are_set_correctly()
        {
            //Given
            var user = new UserForAuditing();
            var task = new MultiHazardRiskAssessmentFurtherControlMeasureTask();

            var createParams = new CreateDocumentParameters()
            {
                ClientId = 1234,
                Description = "Woo hoo",
                DocumentLibraryId = 1,
                DocumentType = new DocumentType(),
                Extension = ".biz",
                Filename = "FooBar",
                FilesizeByte = 2000,
                CreatedBy = user,
                CreatedOn = _now
            };


            //When
            var result = TaskDocument.Create(createParams, task);

            //Then
            Assert.That(result.ClientId, Is.EqualTo(createParams.ClientId));
            Assert.That(result.Title, Is.EqualTo(createParams.Filename));
            Assert.That(result.Description, Is.EqualTo(createParams.Description));
            Assert.That(result.DocumentLibraryId, Is.EqualTo(createParams.DocumentLibraryId));
            Assert.That(result.DocumentType, Is.EqualTo(createParams.DocumentType));
            Assert.That(result.Extension, Is.EqualTo(createParams.Extension));
            Assert.That(result.Filename, Is.EqualTo(createParams.Filename));
            Assert.That(result.FilesizeByte, Is.EqualTo(createParams.FilesizeByte));
            Assert.That(result.CreatedBy, Is.EqualTo(user));
            Assert.That(result.CreatedOn, Is.EqualTo(_now));
        }
Ejemplo n.º 3
0
        public void when_Filename_length_is_greater_than_100_the_task_document_title_is_truncated_to_length_100()
        {
            //Given
            var user = new UserForAuditing();
            var task = new MultiHazardRiskAssessmentFurtherControlMeasureTask();

            var createParams = new CreateDocumentParameters()
                                   {
                                       ClientId = 1234,
                                       Description = "Woo hoo",
                                       DocumentLibraryId = 1,
                                       DocumentType = new DocumentType(),
                                       Extension = ".biz",
                                       Filename = "Edinburgh Hazardous Substance Risk Assessment_Edinburgh Hazardous Substance Risk Assessment_02_09_2013.txt",
                                       FilesizeByte = 2000,
                                       CreatedBy = user,
                                       CreatedOn = _now
                                   };


            //When
            var result = TaskDocument.Create(createParams, task);

            Assert.AreEqual(100, result.Title.Length);

        }
        public void Given_task_is_not_recurring_When_HasCompletedTasks_is_called_Then_returns_false()
        {
            var task = new MultiHazardRiskAssessmentFurtherControlMeasureTask
                           {
                               TaskReoccurringType = TaskReoccurringType.None
                           };

            Assert.That(task.HasCompletedTasks(), Is.False);
        }
Ejemplo n.º 5
0
        public void When_reassign_task_set_as_completed_Then_should_throw_correct_exception()
        {
            //Given
            var task = new MultiHazardRiskAssessmentFurtherControlMeasureTask { TaskStatus = TaskStatus.Completed };
            var user = new UserForAuditing();

            //When
            //Then
            Assert.Throws<AttemptingToReassignFurtherActionTaskThatIsCompletedException>(() => task.ReassignTask(null, user));
        }
Ejemplo n.º 6
0
        public void When_mark_for_delete_for_task_set_as_completed_Then_should_throw_correct_exception()
        {
            //Given
            var task = new MultiHazardRiskAssessmentFurtherControlMeasureTask {TaskStatus = TaskStatus.Completed};
            var user = new UserForAuditing();

            //When
            //Then
            Assert.Throws<AttemptingToDeleteFurtherControlMeasureTaskThatIsCompletedException>(() => task.MarkForDelete(user));
        }
        public void Given_a_MulitHazardFCMTask_Type_when_DefaultDocumentType_returns_GRA_DocumentType()
        {
            //given
            var task = new MultiHazardRiskAssessmentFurtherControlMeasureTask();

            //when
            var result = task.DefaultDocumentType;

            //then
            Assert.AreEqual(DocumentTypeEnum.GRADocumentType, result);
        }
Ejemplo n.º 8
0
        public void When_complete_task_already_completed_Then_should_throw_correct_exception()
        {
            //Given
            var task = new MultiHazardRiskAssessmentFurtherControlMeasureTask();
            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 MultiHazardRiskAssessmentFurtherControlMeasureTaskDto MapWithAssignedToAndRiskAssessmentHazard(MultiHazardRiskAssessmentFurtherControlMeasureTask entity)
        {
            var dto = new TaskDtoMapper().MapWithAssignedTo(entity) as MultiHazardRiskAssessmentFurtherControlMeasureTaskDto;

            dto.RiskAssessmentHazard =
                entity.MultiHazardRiskAssessmentHazard != null
                    ? new RiskAssessmentHazardDtoMapper().Map(
                        entity.MultiHazardRiskAssessmentHazard)
                    : null;

            return dto;
        }
        public void Given_task_with_no_history_When_get_task_history_Then_returns_correct_history()
        {
            //Given
            var task = new MultiHazardRiskAssessmentFurtherControlMeasureTask { TaskReoccurringType = TaskReoccurringType.None };

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


            //Then
            Assert.That(result.Count(), Is.EqualTo(0));
        }
        public void When_mark_as_no_longer_required_completed_task_Then_should_throw_correct_exceptions()
        {
            //Given
            var task = new MultiHazardRiskAssessmentFurtherControlMeasureTask();
            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 Given_reoccurring_task_that_has_gone_past_last_end_date_When_get_schedule_Then_returns_correct_schedule()
        {
            //Given
            var task = new MultiHazardRiskAssessmentFurtherControlMeasureTask { 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 MultiHazardRiskAssessmentFurtherControlMeasureTask {TaskReoccurringType = TaskReoccurringType.None};
            
            //When
            var result = task.GetReoccurringSchedule();

            
            //Then
            Assert.That(result.ScheduledDates.Count(), Is.EqualTo(0));    
        }
Ejemplo n.º 14
0
        public void When_complete_Then_set_completed_by_to_full_user_entity_of_completing_user()
        {
            //Given
            var userId = Guid.NewGuid();
            var task = new MultiHazardRiskAssessmentFurtherControlMeasureTask();
            var completingUserForAuditing = new UserForAuditing { Id = userId };

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

            //Then
            Assert.That(task.TaskCompletedBy, Is.EqualTo(completingUserForAuditing));
        }
Ejemplo n.º 15
0
        public void When_mark_for_delete_Then_taskstatus_remains_the_same()
        {
            //Given
            var task = new MultiHazardRiskAssessmentFurtherControlMeasureTask {TaskStatus = TaskStatus.Outstanding};
            ;
            var user = new UserForAuditing();

            //When
            task.MarkForDelete(user);

            //Then
            Assert.That(task.TaskStatus, Is.EqualTo(TaskStatus.Outstanding));
        }
Ejemplo n.º 16
0
        public void When_mark_for_delete_Then_should_set_properties_correctly()
        {
            //Given
            var task = new MultiHazardRiskAssessmentFurtherControlMeasureTask();
            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));
        }
Ejemplo n.º 17
0
        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_task_with_one_history_record_When_get_task_history_Then_returns_correct_history()
        {
            //Given
            var historytask = new MultiHazardRiskAssessmentFurtherControlMeasureTask { TaskAssignedTo = new Employee() { Forename = "Vince", Surname = "Lee" }, TaskReoccurringType = TaskReoccurringType.None, TaskCompletedDate = DateTime.Today, TaskCompletionDueDate = DateTime.Today.AddDays(-1) };
            var task = new MultiHazardRiskAssessmentFurtherControlMeasureTask { 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()));
        }
Ejemplo n.º 19
0
        public void When_reassign_Then_should_set_properties_correctly()
        {
            //Given
            var task = new MultiHazardRiskAssessmentFurtherControlMeasureTask();
            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));
            
        }
        public void ReoccuringScheduleReturnsAtMostFiveResults()
        {
            // Given
            var task = new MultiHazardRiskAssessmentFurtherControlMeasureTask
            {
                TaskStatus = TaskStatus.Outstanding,
                TaskReoccurringType = TaskReoccurringType.Weekly,
                TaskCompletionDueDate = new DateTime(2080, 6, 23),
                TaskReoccurringEndDate = new DateTime(2080, 12, 23)
            };

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

            // Then
            Assert.That(result.ScheduledDates.Count(), Is.EqualTo(5));
        }
        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 MultiHazardRiskAssessmentFurtherControlMeasureTask { 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_mark_as_no_longer_required_Then_should_set_properties_correctly()
        {
            //Given
            var task = new MultiHazardRiskAssessmentFurtherControlMeasureTask();
            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: add this back in when archive is back.
            //Assert.That(task.Archive.Count(x => x.ArchiveAction == FurtherActionTaskArchiveAction.MarkAsNoLongerRequired.ToString()),Is.EqualTo(1));
        }
        public void ReoccuringScheduleOnlyCalculatesScheduleWithinBoundsOfTasksRecurringStartAndEndDates()
        {
            // Given
            var task = new MultiHazardRiskAssessmentFurtherControlMeasureTask
            {
                TaskStatus = TaskStatus.Outstanding,
                TaskReoccurringType = TaskReoccurringType.Weekly,
                TaskCompletionDueDate = new DateTime(2080, 6, 23),
                TaskReoccurringEndDate = new DateTime(2080, 7, 23)
            };

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

            // Then
            Assert.That(result.ScheduledDates.Count(), Is.EqualTo(5));
        }
Ejemplo n.º 24
0
        public void When_complete_Then_should_set_properties_correctly()
        {
            //Given
            var task = new MultiHazardRiskAssessmentFurtherControlMeasureTask();
            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));
        }
        public void Given_riskassessment_one_hazard_one_further_control_measure_Then_should_not_be_able_to_delete()
        {
            //Given
            var hazard = new Hazard();
            var user = new UserForAuditing();

            var furtherControlMeasure = new MultiHazardRiskAssessmentFurtherControlMeasureTask();

            var riskAssessment = GeneralRiskAssessment.Create("", "", default(long), null);
            var riskAssessmentHazard = MultiHazardRiskAssessmentHazard.Create(riskAssessment, hazard, user);
            riskAssessmentHazard.FurtherControlMeasureTasks.Add(furtherControlMeasure);
            riskAssessment.Hazards.Add(riskAssessmentHazard);

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

            //Then
            Assert.True(result);
        }
        public static MultiHazardRiskAssessmentFurtherControlMeasureTask 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 sendTaskDueTomorrowNotification,
            Guid taskGuid
            )
        {
            var furtherControlMeasureTask = new MultiHazardRiskAssessmentFurtherControlMeasureTask();

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

            return furtherControlMeasureTask;
        }
        public void Given_further_control_measure_task__when_AddingDocuments_then_createdBy_and_createddate_are_the_same_as_the_request_object()
        {
            //given
            var fcmTask = new MultiHazardRiskAssessmentFurtherControlMeasureTask();
            fcmTask.CreatedBy = new UserForAuditing() {Id = Guid.NewGuid()};
            fcmTask.CreatedOn = DateTime.Now.AddDays(-5);
            fcmTask.Reference = "ref";
            fcmTask.MultiHazardRiskAssessmentHazard = MultiHazardRiskAssessmentHazard.Create(new GeneralRiskAssessment(){Reference = "test"}, new Hazard(), fcmTask.CreatedBy);

            _furtherControlMeasureTaskRepository.Setup(x => x.GetByIdAndCompanyId(It.IsAny<long>(), It.IsAny<long>()))
                .Returns(() => fcmTask);

            var expectedCreatedBy = new UserForAuditing() {Id = Guid.NewGuid()};
            var expectedCreatedOn = DateTime.Now;

            _userForAuditingRepository.Setup(x => x.GetByIdAndCompanyId(It.IsAny<Guid>(), It.IsAny<long>()))
                .Returns(() => expectedCreatedBy);

            _documentTypeRepository.Setup(x => x.GetById(It.IsAny<long>()))
                .Returns(() => new DocumentType());

            var request = new AddDocumentsToTaskRequest()
                              {
                                  CompanyId = 123,
                                  DocumentLibraryIds = new List<DocumentLibraryFile>() {new DocumentLibraryFile() {Id = 23, Description = "123", Filename = "image.png"}}
                                  ,
                                  TaskId = 123
                                  ,
                                  UserId = expectedCreatedBy.Id
                              };

            var target = GetTarget();

            //when
            var result = target.AddDocumentsToTask(request);

            //then
            Assert.AreEqual(expectedCreatedOn.Date, result.First().CreatedOn.Value.Date);
            Assert.AreEqual(expectedCreatedBy.Id, result.First().CreatedBy.Id);
            
        }
        public void Given_task_is_recurring_and_does_not_have_completed_tasks_When_HasCompletedTasks_is_called_Then_returns_false()
        {
            var task = new MultiHazardRiskAssessmentFurtherControlMeasureTask
            {
                TaskStatus = TaskStatus.Outstanding,
                TaskReoccurringType = TaskReoccurringType.Weekly,
                PrecedingTask = new MultiHazardRiskAssessmentFurtherControlMeasureTask
                {
                    TaskStatus = TaskStatus.Outstanding,
                    TaskReoccurringType = TaskReoccurringType.Weekly,
                    PrecedingTask = new MultiHazardRiskAssessmentFurtherControlMeasureTask
                    {
                        TaskStatus = TaskStatus.Outstanding,
                        TaskReoccurringType =
                            TaskReoccurringType.Weekly,
                    }
                }
            };

            Assert.That(task.HasCompletedTasks(), Is.False);
        }
        public void Given_task_is_recurring_and_has_completed_tasks_but_not_most_recent_one_When_HasCompletedTasks_is_called_Then_returns_true()
        {
            var task = new MultiHazardRiskAssessmentFurtherControlMeasureTask
            {
                TaskStatus = TaskStatus.Outstanding,
                TaskReoccurringType = TaskReoccurringType.Weekly,
                PrecedingTask = new MultiHazardRiskAssessmentFurtherControlMeasureTask
                {
                    TaskStatus = TaskStatus.Outstanding,
                    TaskReoccurringType = TaskReoccurringType.Weekly,
                    PrecedingTask = new MultiHazardRiskAssessmentFurtherControlMeasureTask
                    {
                        TaskStatus = TaskStatus.Completed,
                        TaskReoccurringType =
                            TaskReoccurringType.Weekly,
                    }
                }
            };

            Assert.That(task.HasCompletedTasks());
        }
        public void When_addfurtheractiontasks_Then_should_add_correctly()
        {
            //Given
            var user = new UserForAuditing();
            var hazard = new Hazard();
            var riskAssessment = new GeneralRiskAssessment();
            
            var target = MultiHazardRiskAssessmentHazard.Create(riskAssessment, hazard, user);

            var furtherActionTask = new MultiHazardRiskAssessmentFurtherControlMeasureTask();
            
            //When
            target.AddFurtherActionTask(furtherActionTask, user);

            //Then
            Assert.That(target.FurtherControlMeasureTasks.Count, Is.EqualTo(1));
            Assert.That(target.FurtherControlMeasureTasks.First().MultiHazardRiskAssessmentHazard, Is.EqualTo(target));
            Assert.That(target.LastModifiedBy, Is.EqualTo(user));
            Assert.That(target.LastModifiedOn.Value.Date, Is.EqualTo(DateTime.Today.Date));
            
        }