public void Given_employee_is_assigned_to_task_due_tomorrow_then_return_task()
        {
            //GIVEN
            var employee = new Employee() { Id = Guid.NewGuid(), NotificationType = NotificationType.Daily};
           
            var riskAssessement = new HazardousSubstanceRiskAssessment();
            var riskAssessementReview = new RiskAssessmentReview()
                                            {
                                                RiskAssessment = riskAssessement, 
                                                ReviewAssignedTo = employee
                                            };

            riskAssessementReview.RiskAssessmentReviewTask = new RiskAssessmentReviewTask()
            {
                TaskAssignedTo = employee, 
                RiskAssessmentReview = riskAssessementReview, 
                TaskCompletionDueDate = DateTime.Now.AddDays(1)
            };

            riskAssessement.Reviews.Add(riskAssessementReview);
            _riskAssessments.Add(riskAssessement);

            var target = new GetDueRiskAssessmentReviewTasksForEmployeeQuery( _queryableWrapper.Object);

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

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

        }
        public void Given_employee_is_risk_assesor_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 };
            var riskAssessementReview = new RiskAssessmentReview() { RiskAssessment = riskAssessement, };
            riskAssessementReview.RiskAssessmentReviewTask = new RiskAssessmentReviewTask()
            {
                RiskAssessmentReview = riskAssessementReview,
                TaskCompletedDate = DateTime.Now.AddDays(-5),
                TaskStatus = TaskStatus.Completed
            };

            riskAssessement.Reviews.Add(riskAssessementReview);
            _riskAssessments.Add(riskAssessement);

            var target = new GetCompletedRiskAssessmentReviewTasksForEmployeeQuery( _queryableWrapper.Object );

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

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

        }
        public void Given_a_valid_request_When_CompleteRiskAssessmentReview_called_Then_review_repo_asked_to_retrieve_associated_RiskAssessmentReview()
        {
            //Given
            var target = CreateRiskAssessmentReviewService();
            var model = new CompleteRiskAssessmentReviewRequest()
                            {
                                RiskAssessmentReviewId = 1234,
                                ClientId = 5678,
                                NextReviewDate = DateTime.Now
                            };

            var riskAssessmentReview = new RiskAssessmentReview
            {
                RiskAssessmentReviewTask = new RiskAssessmentReviewTask(),
                RiskAssessment = new GeneralRiskAssessment()
            };

            _riskAssessmentReviewRepo
                .Setup(x => x.GetByIdAndCompanyId(1234, 5678))
                .Returns(riskAssessmentReview);

            //When
            target.CompleteRiskAssessementReview(model);

            //Then
            _riskAssessmentReviewRepo.Verify(x => x.GetByIdAndCompanyId(model.RiskAssessmentReviewId, model.ClientId), Times.Once());
        }
        public void Given_no_further_control_measure_tasks_and_1_review_tasks_then_CompletionDueDate_is_next_review_date()
        {
            var riskAss = new FireRiskAssessment();
            var reviewTask = new RiskAssessmentReview() {CompletionDueDate = new DateTime(2013, 5, 7)};
            
            riskAss.AddReview(reviewTask);

            Assert.AreEqual(reviewTask.CompletionDueDate, riskAss.CompletionDueDate.Value);
        }
Beispiel #5
0
        public void UpdateReviewDate(int RiskAssessmentId, int Userid, int OrganizationId)
        {
            RiskAssessmentReview review = new RiskAssessmentReview();

            review.RiskAssessmentId = RiskAssessmentId;
            review.ReviewDate       = DateTime.Now;
            review.OrganizationId   = OrganizationId;
            this._IRiskAssessmentReviewRepository.Add(review, Userid, OrganizationId);
            this._unitOfWork.Save();
        }
        public void Given_a_review_has_been_added_then_the_next_review_date_equals_the_CompletionDueDate_of_the_review_added()
        {
            //GIVEN
            var review = new RiskAssessmentReview();
            review.CompletionDueDate = DateTime.Now.AddDays(10);
            var target = new GeneralRiskAssessment();

            //WHEN
            target.AddReview(review);

            //THEN
            Assert.That(target.NextReviewDate, Is.EqualTo(review.CompletionDueDate));
        }
        public void When_complete_review_already_completed_Then_should_throw_correct_exception()
        {
            //Given
            var review = new RiskAssessmentReview();
            review.CompletedDate = new DateTime();
            review.CompletedBy = new Employee();
            var userForAuditing = new UserForAuditing();
            var user = new User();

            //When
            //Then
            Assert.Throws<AttemptingToCompleteRiskAssessmentReviewThatIsCompletedException>(() => review.Complete("comments", userForAuditing, DateTime.Now, false, null, user));
        }
        public void When_complete_review_without_archive_or_next_review_set_Then_should_throw_correct_exception()
        {
            //Given
            var review = new RiskAssessmentReview();
            review.CompletedDate = new DateTime();
            review.CompletedBy = new Employee();
            var userForAudting = new UserForAuditing();
            var user = new User();

            //When
            //Then

            Assert.Throws<AttemptingToCompleteRiskAssessmentReviewWithoutArchiveOrNextReviewDateSetException>(() => review.Complete("comments", userForAudting, null, false, null, user));
        }
        public void Given_a_review_is_deleted_then_the_next_review_date_equals_null()
        {
            //GIVEN
            var review = new RiskAssessmentReview();
            review.CompletionDueDate = DateTime.Now.AddDays(10);
            var target = new GeneralRiskAssessment();
            target.AddReview(review);

            //WHEN
            review.MarkForDelete(null);

            //THEN
            Assert.That(target.NextReviewDate, Is.EqualTo(null));
        }
 public RiskAssessmentReviewDto Map(RiskAssessmentReview entity)
 {
     return new RiskAssessmentReviewDto()
                {
                    RiskAssessment = new RiskAssessmentDtoMapper().MapWithEmployeesAndNonEmployeesAndSiteAndRiskAssessor(entity.RiskAssessment),
                    Comments = entity.Comments,
                    CompletedBy = entity.CompletedBy != null ? new EmployeeDtoMapper().MapWithNationalityAndContactDetailsAndEmergencyContactDetails(entity.CompletedBy) : null,
                    CompletedDate = entity.CompletedDate,
                    CompletionDueDate = entity.CompletionDueDate,
                    Id = entity.Id,
                    IsReviewOutstanding = entity.IsReviewOutstanding,
                    ReviewAssignedTo = entity.ReviewAssignedTo != null ? new EmployeeDtoMapper().MapWithUser(entity.ReviewAssignedTo) : null,
                    RiskAssessmentReviewTask = entity.RiskAssessmentReviewTask != null ? new TaskDtoMapper().MapWithAssignedTo(entity.RiskAssessmentReviewTask) as RiskAssessmentReviewTaskDto : null
                };
 }
        public void Given_a_reviews_CompletionDueDate_is_changed_then_the_next_review_date_equals_the_new_CompletionDueDate()
        {
            //GIVEN
            var review = new RiskAssessmentReview();
            review.CompletionDueDate = DateTime.Now.AddDays(10);
            review.RiskAssessmentReviewTask = new RiskAssessmentReviewTask();
            var target = new GeneralRiskAssessment();
            target.AddReview(review);

            //WHEN
            review.Edit(null,null,DateTime.Now.AddDays(20)); 

            //THEN
            Assert.That(target.NextReviewDate, Is.EqualTo(review.CompletionDueDate));
        }
        public void Given_a_review_is_completed_then_the_next_review_date_equals_the_next_review_date_specified_during_completion()
        {
            //GIVEN
            var expectedNextReviewDate = DateTime.Now.AddDays(50);
            var review = new RiskAssessmentReview();
            review.CompletionDueDate = DateTime.Now.AddDays(10);
            review.RiskAssessmentReviewTask = new RiskAssessmentReviewTask();
            var target = new GeneralRiskAssessment();
            target.AddReview(review);

            //WHEN
            review.Complete("Comments", null, expectedNextReviewDate, false, new List<CreateDocumentParameters>(), new User(){Employee = new Employee()});

            //THEN
            Assert.That(target.NextReviewDate, Is.EqualTo(expectedNextReviewDate));
        }
        public void Given_a_valid_request_When_AddRiskAssessmentReview_called_Then_review_repo_asked_to_add_a_RiskAssessmentReview()
        {
            //Given
            var target = CreateRiskAssessmentReviewService();
            var request = new AddRiskAssessmentReviewRequest()
                              {
                                  CompanyId = 1234,
                                  ReviewDate = DateTime.Now,
                                  ReviewingEmployeeId = Guid.NewGuid(),
                                  RiskAssessmentId = 1234,
                                  AssigningUserId = Guid.NewGuid()
                              };
            var riskAssessmentReviewToSaveToRepo = new RiskAssessmentReview();

            _employeeRepo
                .Setup(x => x.GetByIdAndCompanyId(It.IsAny<Guid>(), It.IsAny<long>()))
                .Returns(new Employee() { Id = request.ReviewingEmployeeId, CompanyId = request.CompanyId});

            _userForAuditingRepo
                .Setup(x => x.GetByIdAndCompanyId(It.IsAny<Guid>(), It.IsAny<long>()))
                .Returns(new UserForAuditing() { Id = request.AssigningUserId, CompanyId = request.CompanyId });

            _riskAssessmentRepo
                .Setup(x => x.GetByIdAndCompanyId(It.IsAny<long>(), It.IsAny<long>()))
                .Returns(new GeneralRiskAssessment() { Id = request.RiskAssessmentId });

            _riskAssessmentReviewRepo
                .Setup(x => x.Save(It.IsAny<RiskAssessmentReview>()))
                .Callback<RiskAssessmentReview>(x => riskAssessmentReviewToSaveToRepo = x);

            _responsibilityTaskCategoryRepository
                .Setup(x => x.GetGeneralRiskAssessmentTaskCategory())
                .Returns(new TaskCategory {Id = 3});

            //When
            target.Add(request);

            //Then
            _riskAssessmentReviewRepo.Verify(x => x.Save(It.IsAny<RiskAssessmentReview>()), Times.Once());
            Assert.That(riskAssessmentReviewToSaveToRepo.CompletionDueDate, Is.EqualTo(request.ReviewDate));
            Assert.That(riskAssessmentReviewToSaveToRepo.ReviewAssignedTo.Id, Is.EqualTo(request.ReviewingEmployeeId));
            Assert.That(riskAssessmentReviewToSaveToRepo.RiskAssessment.Id, Is.EqualTo(request.RiskAssessmentId));
            Assert.That(riskAssessmentReviewToSaveToRepo.CreatedBy.Id, Is.EqualTo(request.AssigningUserId));
        }
        public static new RiskAssessmentReviewTask Create(
            string reference,
            string title,
            string description,
            DateTime? taskCompletionDueDate,
            TaskStatus taskStatus,
            Employee assignedTo,
            UserForAuditing user,
            IEnumerable<CreateDocumentParameters> createDocumentParameterObjects,
            TaskCategory taskCategory,
            int taskReoccurringTypeId,
            DateTime? taskReoccurringEndDate,
            RiskAssessmentReview riskAssessmentReview,
            bool sendTaskNotification,
            bool sendTaskCompletedNotification,
            bool sendTaskOverdueNotification,
            bool sendTaskDueTomorrowNotification,
            Guid taskGuid
            )
        {
            var riskAssessmentReviewTask = new RiskAssessmentReviewTask();

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

            riskAssessmentReviewTask.RiskAssessmentReview = riskAssessmentReview;

            return riskAssessmentReviewTask;
        }
        public void When_complete_Then_should_set_associated_RiskAssessmentReviewTask_to_complete()
        {
            //Given
            var mockReviewTask = new Mock<RiskAssessmentReviewTask>();
            mockReviewTask.Setup(x => x.Complete(It.IsAny<string>(), null, null, It.IsAny<UserForAuditing>(), It.IsAny<User>()));

            var review = new RiskAssessmentReview()
                             {
                                 RiskAssessmentReviewTask = mockReviewTask.Object,
                                 RiskAssessment = new GeneralRiskAssessment()
                             };
            var userForAuditing = new UserForAuditing();
            var user = new User();
            
            //When
            review.Complete("comments", userForAuditing, DateTime.Now, false, null, user);

            //Then
            mockReviewTask.Verify(x => x.Complete("comments", null, new List<long>(), userForAuditing, user), Times.Once());
        }
        public void Given_a_valid_request_When_Edit_is_called_Then_review_repo_asked_to_add_a_RiskAssessmentReview()
        {
            //Given
            var target = CreateRiskAssessmentReviewService();
            var request = new EditRiskAssessmentReviewRequest()
            {
                RiskAssessmentReviewId = 1234,
                CompanyId = 5678,
                ReviewDate = DateTime.Now,
                ReviewingEmployeeId = Guid.NewGuid(),
                AssigningUserId = Guid.NewGuid(),
            };

            _employeeRepo
                .Setup(x => x.GetByIdAndCompanyId(request.ReviewingEmployeeId, request.CompanyId))
                .Returns(new Employee() { Id = request.ReviewingEmployeeId, CompanyId = request.CompanyId });

            _userForAuditingRepo
                .Setup(x => x.GetByIdAndCompanyId(request.AssigningUserId, request.CompanyId))
                .Returns(new UserForAuditing() { Id = request.AssigningUserId, CompanyId = request.CompanyId });

            var riskAssessmentReview = new RiskAssessmentReview
            {
                Id = request.RiskAssessmentReviewId,
                RiskAssessmentReviewTask = new RiskAssessmentReviewTask(),
                RiskAssessment = new GeneralRiskAssessment()
            };

            _riskAssessmentReviewRepo
                .Setup(x => x.GetByIdAndCompanyId(request.RiskAssessmentReviewId, request.CompanyId))
                .Returns(riskAssessmentReview);

            //When
            target.Edit(request);

            //Then
            _employeeRepo.VerifyAll();
            _userForAuditingRepo.VerifyAll();
            _riskAssessmentReviewRepo.VerifyAll();
            _riskAssessmentReviewRepo.Verify(x => x.SaveOrUpdate(riskAssessmentReview));
        }
        private static bool DoesTaskNeedToBeNotified(RiskAssessmentReview task, Guid employeeId)
        {
            if (task.RiskAssessmentReviewTask == null) return false;

            // Risk Assessor
            if (task.RiskAssessment != null &&
                task.RiskAssessment.RiskAssessor != null &&
                task.RiskAssessment.RiskAssessor.Employee != null &&
                task.RiskAssessment.RiskAssessor.Employee.Id == employeeId)
            {
                var notificationType = task.RiskAssessment.RiskAssessor.Employee.NotificationType;
                var notificationFrequency =
                    task.RiskAssessment.RiskAssessor.Employee.NotificationFrequecy;

                return (
                            (notificationType == NotificationType.Daily ||
                            (notificationType == NotificationType.Weekly && task.RiskAssessmentReviewTask.TaskCompletionDueDate.HasValue &&
                            QueriesHelper.SimplifyDate(task.RiskAssessmentReviewTask.TaskCompletionDueDate.Value) >= QueriesHelper.SimplifyDate(DateTime.Today.AddDays(-7))) ||
                            (notificationType == NotificationType.Monthly && notificationFrequency.HasValue && task.RiskAssessmentReviewTask.TaskCompletionDueDate.HasValue &&
                            QueriesHelper.SimplifyDate(task.RiskAssessmentReviewTask.TaskCompletionDueDate.Value) >= QueriesHelper.GetPreviousMonthsDate(notificationFrequency.Value)))
                       );
            }
            else if (task.RiskAssessmentReviewTask.TaskAssignedTo != null && task.RiskAssessmentReviewTask.TaskAssignedTo.Id == employeeId)
            {
                var notificationType = task.RiskAssessmentReviewTask.TaskAssignedTo.NotificationType;
                var notificationFrequency = task.RiskAssessmentReviewTask.TaskAssignedTo.NotificationFrequecy;

                return (
                            (notificationType == NotificationType.Daily) ||
                            (notificationType == NotificationType.Weekly && task.RiskAssessmentReviewTask.TaskCompletionDueDate.HasValue &&
                            QueriesHelper.SimplifyDate(task.RiskAssessmentReviewTask.TaskCompletionDueDate.Value) >= QueriesHelper.SimplifyDate(DateTime.Today.AddDays(-7))) 
                       ||
                            (notificationType == NotificationType.Monthly && notificationFrequency.HasValue && task.RiskAssessmentReviewTask.TaskCompletionDueDate.HasValue &&
                            QueriesHelper.SimplifyDate(task.RiskAssessmentReviewTask.TaskCompletionDueDate.Value) >= QueriesHelper.GetPreviousMonthsDate(notificationFrequency.Value))
                       );
            }
            else
            {
                return false;
            }
        }
        public void When_complete_Then_should_set_properties_correctly()
        {
            //Given
            var review = new RiskAssessmentReview()
            {
                RiskAssessmentReviewTask = new RiskAssessmentReviewTask(),
                RiskAssessment = new GeneralRiskAssessment()
            };
            var user = new User{ Employee = new Employee() };
            var userForAuditing = new UserForAuditing() ;

            //When
            review.Complete("comments", userForAuditing, DateTime.Now, false, new List<CreateDocumentParameters>(), user);

            //Then
            Assert.That(review.LastModifiedOn.Value.Date, Is.EqualTo(DateTime.Today));
            Assert.That(review.LastModifiedBy, Is.EqualTo(userForAuditing));
            Assert.That(review.Comments, Is.EqualTo("comments"));
            Assert.That(review.CompletedDate.Value.Date, Is.EqualTo(DateTime.Today.Date));
            Assert.That(review.LastModifiedBy, Is.EqualTo(userForAuditing));
        }
        public void SetUp()
        {
            base.SetUp();

            _documentParameterHelper.Setup(
                x => x.GetCreateDocumentParameters(It.IsAny<List<CreateDocumentRequest>>(), It.IsAny<long>())).Returns(new List<CreateDocumentParameters>()
                                                                                                                       {
                                                                                                                           new CreateDocumentParameters()
                                                                                                                           {
                                                                                                                               ClientId = 54321,
                                                                                                                               CreatedOn = DateTime.Today,
                                                                                                                               CreatedBy = new UserForAuditing(),
                                                                                                                               Description = "description",
                                                                                                                               DocumentLibraryId = 1,
                                                                                                                               DocumentOriginType = DocumentOriginType.TaskCreated,
                                                                                                                               DocumentType = new DocumentType(),
                                                                                                                               Extension = ".biz",
                                                                                                                               Filename = "filename",
                                                                                                                               FilesizeByte = 12345
                                                                                                                           }
                                                                                                                       });

            newEmptyUser = new User() { Employee = new Employee() };
            newEmptyRiskAssessmentReview = new RiskAssessmentReview() { RiskAssessmentReviewTask = new RiskAssessmentReviewTask() };

            _userRepo = new Mock<IUserRepository>();
            _userRepo.Setup(x => x.GetByIdAndCompanyId(It.IsAny<Guid>(), It.IsAny<long>())).Returns(newEmptyUser);

            _employeeRepo = new Mock<IEmployeeRepository>();
            _riskAssessmentRepo = new Mock<IRiskAssessmentRepository>();

            _riskAssessmentReviewRepo = new Mock<IRiskAssessmentReviewRepository>();
            _riskAssessmentReviewRepo.Setup(x => x.GetByIdAndCompanyId(It.IsAny<long>(), It.IsAny<long>())).Returns(newEmptyRiskAssessmentReview);
            _riskAssessmentReviewRepo.Setup(x => x.SaveOrUpdate(It.IsAny<RiskAssessmentReview>()));

            _responsibilityTaskCategoryRepository = new Mock<ITaskCategoryRepository>();
            _log = new Mock<IPeninsulaLog>();
        }
        public void Given_valid_request_When_calling_search_method_on_riskassessmentreviews_Then_should_return_correct_results()
        {
            // Given
            const int riskAssessmentId = 1;
            var riskAssessmentReview = new RiskAssessmentReview()
                                           {
                                               RiskAssessment = new GeneralRiskAssessment() { Id = 1 },
                                               ReviewAssignedTo = new Employee{ User = new User{ Id = Guid.NewGuid()}},
                                               CompletedBy = new Employee()
                                           };

            var riskAssessmentReviews = new List<RiskAssessmentReview>() { riskAssessmentReview };

            _riskAssessmentReviewRepo.Setup(x => x.Search(riskAssessmentId)).Returns(riskAssessmentReviews);

            var target = CreateRiskAssessmentReviewService();

            // When
            var result = target.Search(riskAssessmentId);

            // Then
            Assert.That(result.Count(), Is.EqualTo(1));
        }
        private static bool IsTaskDue(RiskAssessmentReview task)
        {
            return (
                       task.ReviewAssignedTo != null &&
                       task.RiskAssessmentReviewTask != null &&
                       task.RiskAssessmentReviewTask.TaskCompletionDueDate != null &&
                       (
                            (task.ReviewAssignedTo.NotificationType == NotificationType.Daily &&
                            QueriesHelper.SimplifyDate(task.RiskAssessmentReviewTask.TaskCompletionDueDate.Value) == QueriesHelper.SimplifyDate(DateTime.Now.AddDays(1)))
                            ||
                            (task.ReviewAssignedTo.NotificationType == NotificationType.Weekly &&
                            task.RiskAssessmentReviewTask.TaskCompletionDueDate.Value < DateTime.Now.AddDays(7))
                            ||
                            (task.ReviewAssignedTo.NotificationType == NotificationType.Monthly &&
                            task.RiskAssessmentReviewTask.TaskCompletionDueDate.Value < DateTime.Now.AddDays(30)))

                    ||

                        (task.RiskAssessmentReviewTask != null &&
                        task.RiskAssessmentReviewTask.TaskCompletionDueDate != null &&
                        task.RiskAssessmentReviewTask.RiskAssessmentReview != null &&
                        task.RiskAssessmentReviewTask.RiskAssessmentReview.RiskAssessment != null &&
                        task.RiskAssessmentReviewTask.RiskAssessmentReview.RiskAssessment.RiskAssessor != null &&
                        task.RiskAssessmentReviewTask.RiskAssessmentReview.RiskAssessment.RiskAssessor.Employee != null &&
                        (
                        (task.RiskAssessmentReviewTask.RiskAssessmentReview.RiskAssessment.RiskAssessor.Employee.NotificationType == NotificationType.Daily &&
                        QueriesHelper.SimplifyDate(task.RiskAssessmentReviewTask.TaskCompletionDueDate.Value) == QueriesHelper.SimplifyDate(DateTime.Now.AddDays(1)))
                        || 
                        (task.RiskAssessmentReviewTask.RiskAssessmentReview.RiskAssessment.RiskAssessor.Employee.NotificationType == NotificationType.Weekly
                                && task.RiskAssessmentReviewTask.TaskCompletionDueDate.Value < DateTime.Now.AddDays(7))
                        ||
                        (task.RiskAssessmentReviewTask.RiskAssessmentReview.RiskAssessment.RiskAssessor.Employee.NotificationType == NotificationType.Monthly
                            && task.RiskAssessmentReviewTask.TaskCompletionDueDate.Value < DateTime.Now.AddDays(30)))
                        )
                    );
        }
        public void Given_a_valid_request_When_CompleteRiskAssessmentReview_called_Then_review_repo_asked_to_update_associated_RiskAssessmentReview()
        {
            //Given
            var passedRiskAssessmentReview = new RiskAssessmentReview
                                                 {
                                                     RiskAssessmentReviewTask = new RiskAssessmentReviewTask(),
                                                     RiskAssessment = new GeneralRiskAssessment()
                                                 };

            _riskAssessmentReviewRepo
                .Setup(x => x.GetByIdAndCompanyId(1234, 5678))
                .Returns(passedRiskAssessmentReview);

            _riskAssessmentReviewRepo.Setup(x => x.SaveOrUpdate(It.IsAny<RiskAssessmentReview>())).Callback
                <RiskAssessmentReview>(y => passedRiskAssessmentReview = y);

            var target = CreateRiskAssessmentReviewService();

            var model = new CompleteRiskAssessmentReviewRequest()
            {
                RiskAssessmentReviewId = 1234,
                ClientId = 5678,
                CompletedComments = "some comments",
                IsComplete = true,
                ReviewingUserId = Guid.NewGuid(),
                NextReviewDate = DateTime.Now,
                Archive = false
            };

            //When
            target.CompleteRiskAssessementReview(model);

            //Then
            _riskAssessmentReviewRepo.Verify(x => x.SaveOrUpdate(It.IsAny<RiskAssessmentReview>()), Times.Once());
            Assert.That(passedRiskAssessmentReview.Comments, Is.EqualTo(model.CompletedComments));
        }
 public void AddToRiskAssessmentReviews(RiskAssessmentReview riskAssessmentReview)
 {
     base.AddObject("RiskAssessmentReviews", riskAssessmentReview);
 }
 public static RiskAssessmentReview CreateRiskAssessmentReview(int ID, global::System.DateTime dateDue, int riskAssessmentReview_RiskAssessment, byte[] rowVersion)
 {
     RiskAssessmentReview riskAssessmentReview = new RiskAssessmentReview();
     riskAssessmentReview.Id = ID;
     riskAssessmentReview.DateDue = dateDue;
     riskAssessmentReview.RiskAssessmentReview_RiskAssessment = riskAssessmentReview_RiskAssessment;
     riskAssessmentReview.RowVersion = rowVersion;
     return riskAssessmentReview;
 }
        public static RiskAssessmentReview Create(
            RiskAssessment riskAssessment,
            UserForAuditing user,
            Employee assignedToEmployee,
            DateTime completionDueDate,
            ITaskCategoryRepository responsibilityTaskCategoryRepository,
            bool sendTaskNotification,
            bool sendTaskCompletedNotification,
            bool sendTaskOverdueNotification,
            bool sendTaskDueTomorrowNotification,
            Guid taskGuid
            )
        {
            var result = new RiskAssessmentReview()
            {
                RiskAssessment = riskAssessment,
                ReviewAssignedTo = assignedToEmployee,
                CreatedBy = user,
                CreatedOn = DateTime.Now,
                CompletionDueDate = completionDueDate,
                LastModifiedBy = user,
                LastModifiedOn = DateTime.Now
                
            };

            riskAssessment.AddReview(result);
            TaskCategory taskCategory = null;
            string description = null;

            if(riskAssessment as HazardousSubstanceRiskAssessment != null)
            {
                taskCategory = responsibilityTaskCategoryRepository.GetHazardousSubstanceRiskAssessmentTaskCategory();
                description = "HSRA Review";
            }

            if (riskAssessment as GeneralRiskAssessment != null)
            {
                taskCategory = responsibilityTaskCategoryRepository.GetGeneralRiskAssessmentTaskCategory();
                description = "GRA Review";
            }

            if (riskAssessment as PersonalRiskAssessment != null)
            {
                taskCategory = responsibilityTaskCategoryRepository.GetPersonalRiskAssessmentTaskCategory();
                description = "PRA Review";
            }

            if (riskAssessment as FireRiskAssessment != null)
            {
                taskCategory = responsibilityTaskCategoryRepository.GetFireRiskAssessmentTaskCategory();
                description = "FRA Review";
            }

            if (riskAssessment.LastModifiedBy == null)
            {
                riskAssessment.LastModifiedBy = user;
                riskAssessment.LastModifiedOn = DateTime.Now;
            }

            result.RiskAssessmentReviewTask = RiskAssessmentReviewTask.Create(
                riskAssessment.Reference,
                riskAssessment.Title,
                description,
                completionDueDate,
                TaskStatus.Outstanding,
                assignedToEmployee,
                user,
                new List<CreateDocumentParameters>(),
                taskCategory,
                (int)TaskReoccurringType.None,
                null,
                result,
                sendTaskNotification,
                sendTaskCompletedNotification,
                sendTaskOverdueNotification,
                sendTaskDueTomorrowNotification,
                taskGuid);

            return result;
        }
        public void When_complete_review_already_completed_Then_task_remains_incomplete()
        {
            //Given
            var mockReviewTask = new Mock<RiskAssessmentReviewTask>();
            mockReviewTask.Setup(x => x.Complete(It.IsAny<string>(), null, null, It.IsAny<UserForAuditing>(), It.IsAny<User>()));
            var userForAuditing = new UserForAuditing
                           {
                               Id = Guid.NewGuid()
                           };
            var employee = new Employee();
            var user = new User();
            var review = new RiskAssessmentReview()
            {
                CompletedBy = It.IsAny<Employee>(),
                CompletedDate = It.IsAny<DateTime>(),
                RiskAssessmentReviewTask = mockReviewTask.Object
            };

            //When

            //Then
            Assert.Throws<AttemptingToCompleteRiskAssessmentReviewThatIsCompletedException>(() => review.Complete("comments", userForAuditing, DateTime.Now, false, null, user));
            mockReviewTask.Verify(x => x.Complete("comments", null, null, userForAuditing, user), Times.Never());
        }
        public void Given_notification_set_to_weekly_and_task_is_due_in_less_than_a_week_return_task()
        {
            //GIVEN
            var employee = new Employee() { Id = Guid.NewGuid(), NotificationType = NotificationType.Weekly};
            var riskAssessor = new RiskAssessor() { Id = 5596870, Employee = employee };

            var riskAssessement = new HazardousSubstanceRiskAssessment() { RiskAssessor = riskAssessor };
            var riskAssessementReview = new RiskAssessmentReview() { RiskAssessment = riskAssessement, };
            riskAssessementReview.RiskAssessmentReviewTask = new RiskAssessmentReviewTask()
            {
                RiskAssessmentReview = riskAssessementReview,
                TaskCompletionDueDate = DateTime.Now.AddDays(4)
            };

            riskAssessement.Reviews.Add(riskAssessementReview);
            _riskAssessments.Add(riskAssessement);

            var target =
                new GetDueRiskAssessmentReviewTasksForEmployeeQuery(
                    _queryableWrapper.Object);

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

            //THEN
            Assert.That(result.Count, Is.EqualTo(1));
        }
        public void Given_employee_is_assignee_and_notification_frequency_is_set_to_monthly_on_26th_then_return_tasks_since_26th_of_previous_month()
        {
            //GIVEN
            var employee = new Employee() { Id = Guid.NewGuid(), NotificationType = NotificationType.Monthly, NotificationFrequecy = 26 };

            var riskAssessement = new HazardousSubstanceRiskAssessment() { };
            var riskAssessementReview = new RiskAssessmentReview() { RiskAssessment = riskAssessement, };
            riskAssessementReview.RiskAssessmentReviewTask = new RiskAssessmentReviewTask()
            {
                TaskAssignedTo = employee,
                RiskAssessmentReview = riskAssessementReview,
                TaskCompletedDate = null,
                TaskCompletionDueDate = new DateTime(DateTime.Now.Year, DateTime.Now.AddMonths(-1).Month, 27), //27th of last month,
                Id = 1
            };

            riskAssessement.Reviews.Add(riskAssessementReview);
            _riskAssessments.Add(riskAssessement);


            var riskAssessement1 = new HazardousSubstanceRiskAssessment() { };
            var riskAssessementReview1 = new RiskAssessmentReview() { RiskAssessment = riskAssessement1, };
            riskAssessementReview1.RiskAssessmentReviewTask = new RiskAssessmentReviewTask()
            {
                TaskAssignedTo = employee,
                RiskAssessmentReview = riskAssessementReview1,
                TaskCompletedDate = null,
                TaskCompletionDueDate = new DateTime(DateTime.Now.Year, DateTime.Now.AddMonths(-1).Month, 28), //28th of last month,
                Id = 2
            };

            riskAssessement.Reviews.Add(riskAssessementReview1);
            _riskAssessments.Add(riskAssessement1);

            var riskAssessement2 = new HazardousSubstanceRiskAssessment() { };
            var riskAssessementReview2 = new RiskAssessmentReview() { RiskAssessment = riskAssessement2, };
            riskAssessementReview2.RiskAssessmentReviewTask = new RiskAssessmentReviewTask()
            {
                TaskAssignedTo = employee,
                RiskAssessmentReview = riskAssessementReview2,
                TaskCompletedDate = null,
                TaskCompletionDueDate = new DateTime(DateTime.Now.Year, DateTime.Now.AddMonths(-1).Month, 23), //23th of last month,
                Id = 3
            };

            riskAssessement.Reviews.Add(riskAssessementReview2);
            _riskAssessments.Add(riskAssessement2);

            var target =
                new GetOverdueRiskAssessmentReviewTasks(
                    _queryableWrapper.Object);

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

            //THEN
            Assert.That(result.Count, Is.EqualTo(2));
            Assert.That(result[0].RiskAssessmentReview.RiskAssessmentReviewTask.Id, Is.EqualTo(1));
            Assert.That(result[1].RiskAssessmentReview.RiskAssessmentReviewTask.Id, Is.EqualTo(2));

        }
        public void Given_employee_is_risk_assessor_and_notification_frequency_is_set_to_weekly_then_return_tasks_since_previous_week()
        {
            //GIVEN
            var employee = new Employee() { Id = Guid.NewGuid(), NotificationType = NotificationType.Weekly, NotificationFrequecy = (int)DayOfWeek.Wednesday };
            var riskAssessor = new RiskAssessor() { Id = 5596870, Employee = employee };

            var riskAssessement = new HazardousSubstanceRiskAssessment() { RiskAssessor = riskAssessor };
            var riskAssessementReview = new RiskAssessmentReview() { RiskAssessment = riskAssessement, };
            riskAssessementReview.RiskAssessmentReviewTask = new RiskAssessmentReviewTask()
            {
                RiskAssessmentReview = riskAssessementReview,
                TaskCompletionDueDate = DateTime.Now.AddDays(-5)
            };

            riskAssessement.Reviews.Add(riskAssessementReview);
            _riskAssessments.Add(riskAssessement);

            var target =
                new GetOverdueRiskAssessmentReviewTasks(
                    _queryableWrapper.Object);

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

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