public void Given_question_requires_booleanresponse_When_no_corresponding_answer_return_false()
        {
            // Given 
            var questions = new List<Question>()
                            {
                                new Question()
                                {
                                    Id = 1, 
                                    QuestionType = QuestionType.YesNo
                                }
                            };

            var checklist = new Checklist()
            {
                Sections = new List<Section>()
                                                         {
                                                             new Section()
                                                             {
                                                                 Questions = questions
                                                             }
                                                         }
            };

            var employeeChecklist = new EmployeeChecklist()
                                    {
                                        Checklist = checklist,
                                        Answers = new List<PersonalAnswer>()
                                    };

            // When
            var result = employeeChecklist.AreAllQuestionsAnswered();

            // Then
            Assert.IsFalse(result);
        }
        public void Given_many_recipient_When_LastRecipientEmail_called_returns_latest_email()
        {
            var emailAddress1 = "*****@*****.**";
            var emailAddress2 = "*****@*****.**";
            var emailAddress3 = "*****@*****.**";

            var now = DateTime.Now;

            var employeeChecklist = new EmployeeChecklist
                                        {
                                            EmployeeChecklistEmails = new List<EmployeeChecklistEmail>
                                                                          {
                                                                              new EmployeeChecklistEmail
                                                                                  {
                                                                                      RecipientEmail = emailAddress1,
                                                                                      CreatedOn = now.AddDays(-7)
                                                                                  },
                                                                              new EmployeeChecklistEmail
                                                                                  {
                                                                                      RecipientEmail = emailAddress2,
                                                                                      CreatedOn = now.AddDays(-3)
                                                                                  },
                                                                              new EmployeeChecklistEmail
                                                                                  {
                                                                                      RecipientEmail = emailAddress3,
                                                                                      CreatedOn = now.AddDays(-1)
                                                                                  }
                                                                          }
                                        };

            Assert.That(employeeChecklist.LastRecipientEmail, Is.EqualTo(emailAddress3));
        }
        public void Given_checklist_then_reference_of_the_PRA_Reference_is_created_from_the_employee_checklist_Reference()
        {
            //GIVEN
            var employeeChecklist = new EmployeeChecklist();
            employeeChecklist.Employee = new Employee() { Forename = "Sandor", Surname = "Clegane" };
            employeeChecklist.ReferencePrefix = "RefPrefix";
            employeeChecklist.ReferenceIncremental = 5;
            employeeChecklist.Checklist = new Checklist() { Title = "Checklist Title" };
            employeeChecklist.PersonalRiskAssessment = new PersonalRiskAssessment();

            _employeeChecklistRepository.Setup(x => x.GetById(It.IsAny<Guid>()))
                .Returns(employeeChecklist);

            PersonalRiskAssessment savedPRA = null;
            _personalRiskAssessmentRepo.Setup(x => x.Save(It.IsAny<PersonalRiskAssessment>()))
                .Callback<PersonalRiskAssessment>(pra => savedPRA = pra);

            var target = GetTarget();

            //when
            target.CreateRiskAssessmentFromChecklist(Guid.NewGuid(), Guid.NewGuid());
            
            //THEN
            Assert.That(savedPRA.Reference, Is.EqualTo(employeeChecklist.FriendlyReference));
        }
        public void Given_no_recipients_When_LastRecipientEmail_called_Then_returns_null()
        {
            var employeeChecklist = new EmployeeChecklist()
                                        {
                                            EmployeeChecklistEmails = new List<EmployeeChecklistEmail>()
                                        };

            Assert.That(employeeChecklist.LastRecipientEmail, Is.Null);
        }
        public EmployeeChecklistDto MapWithCompletedOnEmployeesBehalfBy(EmployeeChecklist entity)
        {
            var dto = Map(entity);

            dto.CompletedOnEmployeesBehalfBy = entity.CompletedOnEmployeesBehalfBy != null
                                                   ? new UserDtoMapper().MapIncludingEmployeeAndSite(entity.CompletedOnEmployeesBehalfBy)
                                                   : null;

            return dto;
        } 
Пример #6
0
 public static PersonalAnswer Create(EmployeeChecklist employeeChecklist, Question question, bool? booleanResponse, string additionalInfo, UserForAuditing getNsbSystemUser)
 {
     return new PersonalAnswer
                {
                    EmployeeChecklist = employeeChecklist,
                    Question = question,
                    BooleanResponse = booleanResponse,
                    AdditionalInfo = additionalInfo,
                    CreatedOn = DateTime.Now,
                    CreatedBy = getNsbSystemUser
                };
 }
        public void Given_an_EmployeeChecklist_is_already_completed_When_I_try_to_complete_it_again_Then_I_get_a_validation_error()
        {
            //Given
            var employeeChecklist = new EmployeeChecklist
                                        {
                                            CompletedDate = DateTime.Now
                                        };

            //When
            var messages = employeeChecklist.ValidateComplete();

            //Then
            Assert.That(messages.Count, Is.EqualTo(1));
            Assert.That(messages[0].Text, Is.EqualTo("This checklist has already been completed once and cannot be resubmitted."));
        }
Пример #8
0
        public void When_Regenerate_Then_should_call_correct_methods()
        {

            // Given
            var target = CreateService();
            var request = new ResendEmployeeChecklistEmailRequest()
                              {
                                  ResendUserId = Guid.NewGuid(),
                                  RiskAssessmentId = 500,
                                  EmployeeChecklistId = Guid.NewGuid()
                              };


            var user = new UserForAuditing();
            _userRepository
                .Setup(x => x.GetById(request.ResendUserId))
                .Returns(user);

            var employeeChecklistEmail = new EmployeeChecklist()
                                             {
                                                 EmployeeChecklistEmails = new List<EmployeeChecklistEmail>()
                                                                               {
                                                                                   new EmployeeChecklistEmail()
                                                                               },
                                                 Employee = new Employee
                                                                {
                                                                    ContactDetails = new List<EmployeeContactDetail>
                                                                                         {
                                                                                             new EmployeeContactDetail
                                                                                                 {
                                                                                                     Email = "*****@*****.**"
                                                                                                 }
                                                                                         }
                                                                }
                                             };
            _employeeChecklistRepository
                .Setup(x => x.GetByIdAndRiskAssessmentId(request.EmployeeChecklistId, request.RiskAssessmentId))
                .Returns(employeeChecklistEmail);

            // When
            target.Regenerate(request);
            
            // Then
            _userRepository.VerifyAll();
            _employeeChecklistRepository.VerifyAll();
            _employeeChecklistEmailRepository.Verify(x => x.Save(It.IsAny<EmployeeChecklistEmail>()), Times.Once());
            _employeeChecklistEmailRepository.Verify(x => x.Flush(), Times.Once());
        }
        public void Given_only_one_recipient_When_LastRecipientEmail_called_returns_expected_email()
        {
            var emailAddress = "*****@*****.**";

            var employeeChecklist = new EmployeeChecklist
                                        {
                                            EmployeeChecklistEmails = new List<EmployeeChecklistEmail>
                                                                          {
                                                                              new EmployeeChecklistEmail
                                                                                  {
                                                                                      RecipientEmail = emailAddress
                                                                                  }
                                                                          }
                                        };

            Assert.That(employeeChecklist.LastRecipientEmail, Is.EqualTo(emailAddress));
        }
Пример #10
0
        public void Given_all_required_fields_are_available_Then_create_answer_method_creates_an_object()
        {
            //Given
            var employeeChecklist = new EmployeeChecklist();
            var question = new Question();
            bool? booleanResponse = false;
            var user = new UserForAuditing();
            string additionalInfo = "Additional Info";

            //When
            var result = PersonalAnswer.Create(employeeChecklist, question, booleanResponse,additionalInfo, user);

            //Then
            Assert.That(result.BooleanResponse, Is.EqualTo(booleanResponse));
            Assert.That(result.AdditionalInfo, Is.EqualTo(additionalInfo));
            Assert.That(result.CreatedOn.Value.Date, Is.EqualTo(DateTime.Today));
            Assert.That(result.CreatedBy, Is.EqualTo(user));
            Assert.That(result.EmployeeChecklist, Is.EqualTo(employeeChecklist));
            Assert.That(result.Question, Is.EqualTo(question));
        }
        public void Setup()
        {
            _user = new UserForAuditing() { Id = Guid.NewGuid(), Employee = new EmployeeForAuditing() { Id = Guid.NewGuid() } };
            _userRepo = new Mock<IUserForAuditingRepository>();
            _userRepo.Setup(x => x.GetById(_user.Id))
                .Returns(() => _user);

            _employeeChecklistId = Guid.NewGuid();
            _employeeChecklist = new EmployeeChecklist()
                                 {
                                     Id = _employeeChecklistId
                                 };

            _employeeChecklistRepo = new Mock<IEmployeeChecklistRepository>();
            _employeeChecklistRepo
                .Setup(x => x.GetById(_employeeChecklistId))
                .Returns(() => _employeeChecklist);

            _log = new Mock<IPeninsulaLog>();
        }
Пример #12
0
        public void Given_all_required_fields_are_available_Then_update_answer_method_updates_object()
        {
            //Given
            var employeeChecklist = new EmployeeChecklist();
            var question = new Question();
            bool? booleanResponse = false;
            var user = new UserForAuditing();
            string additionalInfo = "Additional Info";

            var answer = PersonalAnswer.Create(employeeChecklist, question, booleanResponse, additionalInfo, user);

            //When
            answer.Update(true,"New Additional Info", user);

            //Then
            Assert.That(answer.BooleanResponse, Is.EqualTo(true));
            Assert.That(answer.AdditionalInfo, Is.EqualTo("New Additional Info"));
            Assert.That(answer.LastModifiedOn.Value.Date, Is.EqualTo(DateTime.Today));
            Assert.That(answer.LastModifiedBy, Is.EqualTo(user));
        }
 public EmployeeChecklistDto Map(EmployeeChecklist entity)
 {
     var dto = new EmployeeChecklistDto
               {
                   Id = entity.Id,
                   Employee = new EmployeeDtoMapper().MapWithNationalityAndContactDetailsAndEmergencyContactDetails(entity.Employee),
                   Checklist = new ChecklistDtoMapper().MapWithSections(entity.Checklist),
                   Answers = new PersonalAnswerDtoMapper().Map(entity.Answers),
                   StartDate = entity.StartDate,
                   CompletedDate = entity.CompletedDate,
                   Password = entity.Password,
                   FriendlyReference = entity.FriendlyReference,
                   CompletionNotificationEmailAddress = entity.CompletionNotificationEmailAddress,
                   DueDateForCompletion = entity.DueDateForCompletion,
                   SendCompletedChecklistNotificationEmail = entity.SendCompletedChecklistNotificationEmail ?? false,
                   LastRecipientEmail = entity.LastRecipientEmail,
                   LastMessage = entity.LastMessage,
                   IsFurtherActionRequired = entity.IsFurtherActionRequired,
                   AssessedByEmployee = new EmployeeForAuditingDtoMapper().Map(entity.AssessedByEmployee),
                   AssessmentDate = entity.AssessmentDate
               };
     return dto;
 }
        public void Given_an_answer_exists_when_DoesAnAnswerObjectExistForQuestion_then_return_true()
        {
            var questions = new List<Question>()
                            {
                                new Question()
                                {
                                    Id = 1, 
                                    QuestionType = QuestionType.YesNo
                                }
                            };

            var checklist = new Checklist()
            {
                Sections = new List<Section>()
                                                         {
                                                             new Section()
                                                             {
                                                                 Questions = questions
                                                             }
                                                         }
            };

            var employeeChecklist = new EmployeeChecklist()
            {
                Checklist = checklist,
                Answers = new List<PersonalAnswer>()
                          {
                              new PersonalAnswer() {
                                  BooleanResponse = true,
                                  Question = new Question()
                                {
                                    Id = 1, 
                                    QuestionType = QuestionType.YesNo
                                }}
                          }
            };
            var result = employeeChecklist.DoesAnAnswerObjectExistForQuestion(employeeChecklist.Answers[0].Question);

            Assert.IsTrue(result);
        }
        public void Given_a_question_is_text_only_When_IsQuestionAnswered_returns_true()
        {
            var questions = new List<Question>()
                            {
                                new Question()
                                {
                                    Id = 1, 
                                    QuestionType = QuestionType.AdditionalInfo
                                }
                            };

            var checklist = new Checklist()
            {
                Sections = new List<Section>()
                                                         {
                                                             new Section()
                                                             {
                                                                 Questions = questions
                                                             }
                                                         }
            };

            var employeeChecklist = new EmployeeChecklist()
            {
                Checklist = checklist,
                Answers = new List<PersonalAnswer>()
                          {
                              new PersonalAnswer() {
                                  BooleanResponse = null,
                                  AdditionalInfo = "the answer",
                                  Question = new Question()
                                {
                                    Id = 1, 
                                    QuestionType = QuestionType.AdditionalInfo
                                }}
                          }
            };
            var result = employeeChecklist.IsQuestionAnswered(employeeChecklist.Answers[0].Question);

            Assert.IsTrue(result);
        }
        public void Given_an_question_is_unanswered_when_IsQuestionAnswered_then_returns_false()
        {
            var questions = new List<Question>()
                            {
                                new Question()
                                {
                                    Id = 1, 
                                    QuestionType = QuestionType.YesNo
                                }
                            };

            var checklist = new Checklist()
            {
                Sections = new List<Section>()
                                                         {
                                                             new Section()
                                                             {
                                                                 Questions = questions
                                                             }
                                                         }
            };

            var employeeChecklist = new EmployeeChecklist()
            {
                Checklist = checklist,
                Answers = new List<PersonalAnswer>()
                          {
                              new PersonalAnswer() {
                                  BooleanResponse = null,
                                  Question = new Question()
                                {
                                    Id = 1, 
                                    QuestionType = QuestionType.YesNo
                                }}
                          }
            };
            var result = employeeChecklist.IsQuestionAnswered(employeeChecklist.Answers[0].Question);

            Assert.IsFalse(result);
        }
        public void Given_an_answer_does_not_exist_when_DoesAnAnswerObjectExistForQuestion_then_return_false()
        {
            var questions = new List<Question>()
                            {
                                new Question()
                                {
                                    Id = 1, 
                                    QuestionType = QuestionType.YesNo
                                }
                            };

            var checklist = new Checklist()
            {
                Sections = new List<Section>()
                                                         {
                                                             new Section()
                                                             {
                                                                 Questions = questions
                                                             }
                                                         }
            };

            var employeeChecklist = new EmployeeChecklist()
            {
                Checklist = checklist,
                Answers = new List<PersonalAnswer>()
                         
            };
            var result = employeeChecklist.DoesAnAnswerObjectExistForQuestion(questions[0]);

            Assert.IsFalse(result);
        }
 public virtual void AddChecklist(EmployeeChecklist checklist, UserForAuditing user)
 {
     checklist.PersonalRiskAssessment.EmployeeChecklists.Remove(checklist);
     checklist.PersonalRiskAssessment = this;
     checklist.PersonalRiskAssessment.PersonalRiskAssessementEmployeeChecklistStatus =
         PersonalRiskAssessementEmployeeChecklistStatusEnum.Generated;
     EmployeeChecklists.Add(checklist);
     checklist.SetLastModifiedDetails(user);
     SetLastModifiedDetails(user);
 }