public void Given_person_seen_is_an_employee_and_not_in_list_when_AddPersonSeen_then_added_to_list()
        {
            //GIVEN
            var checklist = new BusinessSafe.Domain.Entities.SafeCheck.Checklist();

            var employee = new Employee();
            employee.Id = Guid.NewGuid();
            employee.Forename = "Alester";
            employee.Surname = "Oakheart";
            employee.SetEmail("*****@*****.**",null);

            var personSeen = ChecklistPersonSeen.Create(employee);

            //WHEN
            checklist.AddPersonSeen(personSeen);


            //THEN
            Assert.That(checklist.PersonsSeen.Count, Is.EqualTo(1));
            Assert.That(checklist.PersonsSeen[0].Id, Is.Not.EqualTo(string.Empty));
            Assert.That(checklist.PersonsSeen[0].Employee.Id, Is.EqualTo(employee.Id));
            Assert.That(checklist.PersonsSeen[0].FullName, Is.EqualTo(employee.FullName));
            Assert.That(checklist.PersonsSeen[0].EmailAddress, Is.EqualTo(employee.GetEmail()));
            Assert.That(checklist.PersonsSeen[0].Checklist, Is.EqualTo(checklist));

        }
        public void given_submitted_checklists_has_a_client_document_when_Handle_then_attachment_added_to_email()
        {
            //GIVEN
            var handler = GetTarget();
            var message = new SendSubmitChecklistEmail() {ChecklistId = Guid.NewGuid()};
            var clientDocumentId = 12345;
            var docLibraryId = 123456;
            var checklist = new Checklist()
                                {
                                    Id = Guid.NewGuid(),
                                    MainPersonSeenName = "Test User",
                EmailReportToPerson = true,
                                    EmailAddress = "*****@*****.**",
                                    Jurisdiction = "UK",
                                    ExecutiveSummaryDocumentLibraryId = clientDocumentId,
                                    ClientId = 123123,
                                    ActionPlan = new ActionPlan() {ExecutiveSummaryDocumentLibraryId = clientDocumentId},
                                    VisitDate = new DateTime(2014, 05, 01),
                                    SiteId = 1
                                };

            var docLibDocument = new DocumentDto()
                                     {
                                         PhysicalFilePath = @"C:\docLib\2014\1\1\",
                                         PhysicalFilename = "thefilename.pdf",
                                         Extension = ".pdf"
                                     };

            var siteAddress = new SiteAddressDto() {AddressLine1 = "Address", Postcode = "M1 1AA"};

            _checklistRepository.Setup(c => c.GetById(It.IsAny<Guid>()))
                .Returns(() => checklist);

            _clientDocumentService.Setup(x => x.GetById(clientDocumentId))
                .Returns(() => new ClientDocumentDto() {Id = clientDocumentId, DocumentLibraryId = docLibraryId});

            _docLibraryService.Setup((x => x.GetDocumentsByIds(It.IsAny<GetDocumentsByIdsRequest>())))
                .Returns(() => new[] {docLibDocument});

            _clientService.Setup(x => x.GetSite(It.IsAny<long>(), It.IsAny<long>()))
                .Returns(() => siteAddress);

            AttachmentType[] emailedAttachments = new AttachmentType[0];

            _emailSender.Setup(x => x.SendWithDifferentAttachmentName(It.IsAny<RazorEmailResult>(), It.IsAny<AttachmentType[]>()))
                .Callback<RazorEmailResult, AttachmentType[]>(
                    (emailResult, attachments) => emailedAttachments = attachments);

            //WHEN
            handler.Handle(message);

            //THEN
            Assert.That(emailedAttachments.Length, Is.GreaterThan(0));
            Assert.That(emailedAttachments[0].NewFileName,
                        Is.EqualTo(String.Format("Visit Report - {0} - {1} - {2}{3}", siteAddress.AddressLine1,
                                                 siteAddress.Postcode, checklist.VisitDate.Value.ToShortDateString(), docLibDocument.Extension)));
            Assert.That(emailedAttachments[0].OldFileName, Is.EqualTo(docLibDocument.PhysicalFilePath + docLibDocument.PhysicalFilename));
        }
        public void Given_person_seen_is_not_an_employee_and_not_in_list_when_AddPersonSeen_then_added_to_list()
        {
            //GIVEN
            var checklist = new BusinessSafe.Domain.Entities.SafeCheck.Checklist();
            var personSeen = ChecklistPersonSeen.Create(Guid.NewGuid(), "Alester Oakheart", "*****@*****.**");
            var personSeenToRemove = ChecklistPersonSeen.Create(personSeen.Id, "Alester Oakheart", "*****@*****.**");
            checklist.AddPersonSeen(personSeen);

            //WHEN
            checklist.RemovePersonSeen(personSeenToRemove);

            //THEN
            Assert.That(checklist.PersonsSeen.Count, Is.EqualTo(0));
        }
        public void Given_checklist_has_other_email_address_when_AddOtherEmails_with_same_email_address_then_duplicate_not_added_to_list()
        {
            //Given
            var checklist = new BusinessSafe.Domain.Entities.SafeCheck.Checklist();

            var otherEmail = ChecklistOtherEmail.Create("*****@*****.**", "name1");
         

            //When
            checklist.AddOtherEmailAddresses(otherEmail);
            checklist.AddOtherEmailAddresses(otherEmail);

            //Then
            Assert.That(checklist.OtherEmails.Count(), Is.EqualTo(1));
        }
        public void Given_checklist_has_no_other_email_address_when_AddOtherEmails_then_added_to_list()
        {
            //Given
            var checklist = new BusinessSafe.Domain.Entities.SafeCheck.Checklist();

            var otherEmail = ChecklistOtherEmail.Create("*****@*****.**", "name1");

            //When
            checklist.AddOtherEmailAddresses(otherEmail);

            //Then
            Assert.That(checklist.OtherEmails.Count(), Is.EqualTo(1));
            Assert.That(checklist.OtherEmails[0].Id, Is.Not.EqualTo(string.Empty));
            Assert.That(checklist.OtherEmails[0].Checklist, Is.EqualTo(checklist));
            Assert.That(checklist.OtherEmails[0].EmailAddress, Is.EqualTo(otherEmail.EmailAddress));
            Assert.That(checklist.OtherEmails[0].Name, Is.EqualTo(otherEmail.Name));
        }
Esempio n. 6
0
        public void Given_a_checklist_has_immediate_risk_notifications_attached_When_GetChecklist_called_Then_IRNs_are_returned()
        {
            var site = new SiteAddressResponse() { Id = 1212431241, SiteName = "the site name", Address1 = "Address1", Postcode = "the postcode", };

            var checklist1 = new Checklist();
            checklist1.Id = Guid.NewGuid();
            checklist1.ClientId = 2424;
            checklist1.SiteId = (int?)site.Id;
            var immediateRiskNotification1 = new ImmediateRiskNotification();
            immediateRiskNotification1.Id = Guid.NewGuid();
            immediateRiskNotification1.Reference = "Reference 1";
            immediateRiskNotification1.Title = "Title 1";
            immediateRiskNotification1.SignificantHazardIdentified = "Significant Hazard Identified 1";
            immediateRiskNotification1.RecommendedImmediateAction = "Recommended Imediate Action 1";
            checklist1.ImmediateRiskNotifications.Add(immediateRiskNotification1);
            var immediateRiskNotification2 = new ImmediateRiskNotification();
            immediateRiskNotification2.Id = Guid.NewGuid();
            immediateRiskNotification2.Reference = "Reference 2";
            immediateRiskNotification2.Title = "Title 2";
            immediateRiskNotification2.SignificantHazardIdentified = "Significant Hazard Identified 2";
            immediateRiskNotification2.RecommendedImmediateAction = "Recommended Imediate Action 2";
            checklist1.ImmediateRiskNotifications.Add(immediateRiskNotification2);

            checklist1.AddImmediateRiskNotification(immediateRiskNotification1);
            checklist1.AddImmediateRiskNotification(immediateRiskNotification2);

            checklistRepo
                .Setup(x => x.GetById(checklist1.Id))
                .Returns(checklist1);

            var target = new ChecklistController(dependencyFactory.Object);

            var result = target.GetChecklist(checklist1.Id);

            Assert.That(result.ImmediateRiskNotifications.Count, Is.EqualTo(2));
            Assert.That(result.ImmediateRiskNotifications[0].Id, Is.EqualTo(immediateRiskNotification1.Id));
            Assert.That(result.ImmediateRiskNotifications[0].Reference, Is.EqualTo(immediateRiskNotification1.Reference));
            Assert.That(result.ImmediateRiskNotifications[0].Title, Is.EqualTo(immediateRiskNotification1.Title));
            Assert.That(result.ImmediateRiskNotifications[0].SignificantHazard, Is.EqualTo(immediateRiskNotification1.SignificantHazardIdentified));
            Assert.That(result.ImmediateRiskNotifications[0].RecommendedImmediate, Is.EqualTo(immediateRiskNotification1.RecommendedImmediateAction));
            Assert.That(result.ImmediateRiskNotifications[1].Id, Is.EqualTo(immediateRiskNotification2.Id));
            Assert.That(result.ImmediateRiskNotifications[1].Reference, Is.EqualTo(immediateRiskNotification2.Reference));
            Assert.That(result.ImmediateRiskNotifications[1].Title, Is.EqualTo(immediateRiskNotification2.Title));
            Assert.That(result.ImmediateRiskNotifications[1].SignificantHazard, Is.EqualTo(immediateRiskNotification2.SignificantHazardIdentified));
            Assert.That(result.ImmediateRiskNotifications[1].RecommendedImmediate, Is.EqualTo(immediateRiskNotification2.RecommendedImmediateAction));
        }
        public void given_checklist_when_copyWithResponses_then_new_client_id_set()
        {
            //given
            var userForAuditing = new UserForAuditing() { Id = Guid.NewGuid() };
            var copiedByUserName = "******";
            var checklist = new Checklist() { Id = Guid.NewGuid(), ClientId = 11111, ChecklistCreatedBy = "previousCreatedBy", CreatedOn = DateTime.Now.AddDays(-10), ChecklistCreatedOn = DateTime.Now.AddDays(-10) };


            var siteId = 213123;
            var clientID = 99999;

            //when
            var result = checklist.CopyToSiteWithResponses(siteId, clientID, userForAuditing, copiedByUserName, false);

            //then
            Assert.That(result.Id, Is.Not.EqualTo(checklist.Id));
            Assert.That(result.ClientId, Is.EqualTo(clientID));
        }
        public void Given_an_employee_is_a_persons_seen_to_be_removed_when_RemovePersonsSeenNotInList_then_removed_from_persons_seen_list()
        {
            //GIVEN
            var personSeen1 = ChecklistPersonSeen.Create(Guid.NewGuid(), "Diana Smith", "*****@*****.**");
            var personSeen2 = ChecklistPersonSeen.Create(Guid.NewGuid(), "Petyr Littlefinger", "*****@*****.**");
            var personSeenEmployee = ChecklistPersonSeen.Create(new Employee() { Id = Guid.NewGuid() });
            var checklist = new BusinessSafe.Domain.Entities.SafeCheck.Checklist();

            checklist.AddPersonSeen(personSeen1);
            checklist.AddPersonSeen(personSeen2);
            checklist.AddPersonSeen(personSeenEmployee);

            //WHEN
            checklist.RemovePersonsSeenNotInList(new List<ChecklistPersonSeen>() { personSeen1, personSeen2 });

            //THEN
            Assert.That(checklist.PersonsSeen.Count, Is.EqualTo(2));

        }
        public void Given_person_seen_is_an_employee_and_in_list_when_RemovePersonSeen_then_removed_from_list()
        {
            //GIVEN
            var checklist = new BusinessSafe.Domain.Entities.SafeCheck.Checklist();

            var employee = new Employee();
            employee.Id = Guid.NewGuid();
            employee.Forename = "Alester";
            employee.Surname = "Oakheart";
            employee.SetEmail("*****@*****.**",null);

            var personSeenToRemove = ChecklistPersonSeen.Create(employee);
            var personSeen = ChecklistPersonSeen.Create(employee);
            checklist.AddPersonSeen(personSeen);

            //WHEN
            checklist.RemovePersonSeen(personSeenToRemove);


            //THEN
            Assert.That(checklist.PersonsSeen.Count, Is.EqualTo(0));
        }
        public void Given_new_answers_when_UpdateAnswers_then_new_answers_added_to_the_database()
        {
            // Given
            var newAnswer = new ChecklistAnswer()
                                {
                                    Id = Guid.NewGuid(),
                                    ActionRequired = "the action required",
                                    AssignedTo = new BusinessSafe.Domain.Entities.Employee() {Id = Guid.NewGuid()}
                                    ,
                                    EmployeeNotListed = "employee not listed",
                                    GuidanceNotes = "the guidance notes",
                                    SupportingEvidence = "the supporting evidence",
                                    Question = new Question() {Id = new Guid()}
                                    , Response = new QuestionResponse(){Id = Guid.NewGuid()}
                                    , Timescale = new Timescale(){ Id = 2L}
                                };
            var newAnswers = new List<ChecklistAnswer>() { newAnswer };

            var checklist = new Checklist();

           checklist.UpdateAnswers(newAnswers,new UserForAuditing());

            // When
            Assert.That(checklist.Answers.Count, Is.EqualTo(1));
            Assert.That(checklist.Answers.First().ActionRequired, Is.EqualTo(newAnswer.ActionRequired));
            Assert.That(checklist.Answers.First().AssignedTo, Is.EqualTo(newAnswer.AssignedTo));
            Assert.That(checklist.Answers.First().EmployeeNotListed, Is.EqualTo(newAnswer.EmployeeNotListed));
            Assert.That(checklist.Answers.First().GuidanceNotes, Is.EqualTo(newAnswer.GuidanceNotes));
            Assert.That(checklist.Answers.First().SupportingEvidence, Is.EqualTo(newAnswer.SupportingEvidence));
            Assert.That(checklist.Answers.First().Question, Is.EqualTo(newAnswer.Question));
            Assert.That(checklist.Answers.First().Response, Is.EqualTo(newAnswer.Response));
            Assert.That(checklist.Answers.First().Timescale, Is.EqualTo(newAnswer.Timescale));
            Assert.That(checklist.Answers.First().LastModifiedBy, Is.Not.Null);
            Assert.That(checklist.Answers.First().LastModifiedOn, Is.Not.Null);

        }
        public void Given_checklist_has_other_email_address_when_AddOtherEmails_where_email_exists_then_check_detatils_changed()
        {
            //Given
            var checklist = new BusinessSafe.Domain.Entities.SafeCheck.Checklist();

            var otherEmail = ChecklistOtherEmail.Create("*****@*****.**", "name1");
            
            //When
            checklist.AddOtherEmailAddresses(otherEmail);

            var newEmail = "*****@*****.**";
            var newName = "Name2";
            
            // create new object to stop test refering to new object
            var newOtherEmail = ChecklistOtherEmail.Create(newEmail, newName);
            newOtherEmail.Id = otherEmail.Id;

            checklist.AddOtherEmailAddresses(newOtherEmail);

            //Then
            Assert.That(checklist.OtherEmails.Count(), Is.EqualTo(1));
            Assert.That(checklist.OtherEmails[0].EmailAddress, Is.EqualTo(newEmail));
            Assert.That(checklist.OtherEmails[0].Name, Is.EqualTo(newName));
        }
        public void Given_checklist_has_other_email_address_when_modify_and_AddOtherEmails_then_other_email_address_is_modified_in_list()
        {
            //Given
            var checklist = new BusinessSafe.Domain.Entities.SafeCheck.Checklist();
            
            var originalEmailAddress = "*****@*****.**";
            var modifiedEmailAddress = "*****@*****.**";
            var name = "name1";

            var originalOtherEmail = ChecklistOtherEmail.Create(originalEmailAddress, name);
            
            var guid = originalOtherEmail.Id;
            var modifiedOtherEmail = ChecklistOtherEmail.Create(guid, modifiedEmailAddress, name);

            //When
            checklist.AddOtherEmailAddresses(originalOtherEmail);
            checklist.AddOtherEmailAddresses(modifiedOtherEmail);


            //Then
            Assert.That(checklist.OtherEmails.Count(), Is.EqualTo(1));
            Assert.That(checklist.OtherEmails[0].EmailAddress, Is.EqualTo(modifiedEmailAddress));
            Assert.That(checklist.OtherEmails[0].Name, Is.EqualTo(name));
        }
Esempio n. 13
0
        public void Setup()
        {
            ResourceUrl = string.Format("{0}{1}/", ApiBaseUrl, "Checklists");

            _checklistRepository = ObjectFactory.GetInstance<ICheckListRepository>();
            _questionRepository = ObjectFactory.GetInstance<IQuestionRepository>();
            _questionResponseRepository = ObjectFactory.GetInstance<IQuestionResponseRepository>();
            _userForAuditingRepository = ObjectFactory.GetInstance<IUserForAuditingRepository>();

            //Creats a new checklist if does not exist.
            _checklist = _checklistRepository.GetById(ApiTestChecklistId);

            if (_checklist == null)
            {

                _checklist = new SC.Checklist()
                {
                    Id = ApiTestChecklistId,
                    ClientId = ApiTestClientId,
                    SiteId = APiTestSiteId,
                    CoveringLetterContent = ApiTestCoveringLetterContents,
                    CreatedBy = _userForAuditingRepository.GetSystemUser(),
                   CreatedOn = DateTime.Now,
                    LastModifiedBy = _userForAuditingRepository.GetSystemUser(),
                    LastModifiedOn = DateTime.Now
                };

                var questions = _questionRepository.GetAll().Take(1).ToList();

                //_checklist.UpdateQuestions(questions, new UserForAuditing());
                foreach (var question in questions)
                {
                    _checklist.Questions.Add(new ChecklistQuestion
                    {
                        Checklist = _checklist,
                        Question = question,
                        CreatedBy = _userForAuditingRepository.GetSystemUser(),
                        CreatedOn = DateTime.Now,
                        LastModifiedBy = _userForAuditingRepository.GetSystemUser(),
                        LastModifiedOn = DateTime.Now
                    });
                }

                var response = questions.First().PossibleResponses
                    .Where(r => r.ResponseType.Equals("Positive"))
                    .Select(
                        r => new SC.ChecklistAnswer()
                        {
                            SupportingEvidence = r.SupportingEvidence,
                            ActionRequired = r.ActionRequired,
                            Question = questions.First(),
                            Response = r,
                            CreatedBy = _userForAuditingRepository.GetSystemUser(),
                            CreatedOn = DateTime.Now,
                            LastModifiedBy = _userForAuditingRepository.GetSystemUser(),
                            LastModifiedOn = DateTime.Now
                        })
                    .ToList();

                _checklist.UpdateAnswers(response, _userForAuditingRepository.GetSystemUser());

                _checklistRepository.SaveOrUpdate(_checklist);
            }

            _totalNumberOfChecklistQuestions = _checklist.Questions.Count();
            _totalNumberOfChecklistAnswers = _checklist.Answers.Count();

            ObjectFactory.Container.GetInstance<IBusinessSafeSessionManager>().CloseSession();
        }
 private string GetClientAccountNumber(List<CompanyDetails> clientDetails, Checklist checklist)
 {
     return GetClientAccountNumber(clientDetails, checklist.ClientId);
 }
 private SiteAddressResponse GetVisitSiteAddress(List<SiteAddressResponse> visitSites, Checklist checklist)
 {
     return GetVisitSiteAddress(visitSites, checklist.ClientId, checklist.SiteId);
 }
        private void AddQuestionToChecklist(Checklist checklist, QuestionAnswerViewModel questionAnswerViewModel,
            UserForAuditing systemUser)
        {
            var question = _questionRepository.GetById(questionAnswerViewModel.Question.Id);

            if (question == null)
            {
                // adding a bespoke question
                var category = _categoryRepository.GetById(questionAnswerViewModel.Question.CategoryId);

                if (category == null)
                {
                    throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.BadRequest,
                        String.Format("Unknown Category - Id {0}",
                            questionAnswerViewModel.
                                Question.CategoryId.
                                ToString())));
                }

                question = Question.Create(
                    questionAnswerViewModel.Question.Id,
                    questionAnswerViewModel.Question.Text,
                    category,
                    true, // is custom (bespoke) question
                    questionAnswerViewModel.Question.SpecificToClientId,
                    systemUser);

            }
            else if (question.CustomQuestion && question.Title != questionAnswerViewModel.Question.Text)
            {
                // update bespoke question text
                question.Title = questionAnswerViewModel.Question.Text;
            }

            if (questionAnswerViewModel.Question.PossibleResponses != null)
            {
                foreach (var possibleResponse in questionAnswerViewModel.Question.PossibleResponses)
                {
                    var questionResponse = _questionResponseRepository.GetById(possibleResponse.Id);
                    if (questionResponse == null)
                    {
                        questionResponse = new QuestionResponse
                        {
                            Id = possibleResponse.Id,
                            Title = possibleResponse.Title,
                            SupportingEvidence = possibleResponse.SupportingEvidence,
                            ActionRequired = possibleResponse.ActionRequired,
                            ResponseType = possibleResponse.ResponseType,
                            GuidanceNotes = possibleResponse.GuidanceNotes,
                            CreatedBy = systemUser,
                            CreatedOn = DateTime.Now,
                            LastModifiedBy = systemUser,
                            LastModifiedOn = DateTime.Now,
                            ReportLetterStatement = possibleResponse.ReportLetterStatement
                        };
                    }
                    else
                    {
                        questionResponse.ReportLetterStatement = possibleResponse.ReportLetterStatement;
                    }

                    question.AddQuestionResponse(questionResponse);
                }
            }


            ChecklistQuestion checklistQuestion = new ChecklistQuestion()
            {
                Id = Guid.NewGuid(),
                Checklist = checklist,
                Question = question,
                CreatedBy = systemUser,
                CreatedOn = DateTime.Now,
                CategoryNumber = questionAnswerViewModel.CategoryNumber,
                QuestionNumber = questionAnswerViewModel.QuestionNumber
            };

            checklist.UpdateQuestion(checklistQuestion, systemUser);

        }
        private void UpdateQuestions(Checklist checklist, ChecklistViewModel model, UserForAuditing systemUser)
        {
            var newQuestionAnswerViewModels = model.Questions
                .Where(
                    questionAnswerViewModel =>
                        !checklist.Questions.Any(
                            checklistQuestion => checklistQuestion.Question.Id == questionAnswerViewModel.Question.Id));

            var existingQuestions = model.Questions
                .Where(
                    questionAnswerViewModel =>
                        checklist.Questions.Any(
                            checklistQuestion => checklistQuestion.Question.Id == questionAnswerViewModel.Question.Id));

            var removedQuestions = checklist.Questions
                .Where(
                    checklistQuestion =>
                        !model.Questions.Any(qaVwModel => qaVwModel.Question.Id == checklistQuestion.Question.Id));

            newQuestionAnswerViewModels.ToList()
                .ForEach(
                    questionAnswerViewModel => AddQuestionToChecklist(checklist, questionAnswerViewModel, systemUser));

            existingQuestions.ToList()
                .ForEach(
                    questionAnswerViewModel => AddQuestionToChecklist(checklist, questionAnswerViewModel, systemUser));

            RemoveQuestions(removedQuestions, systemUser);
        }
        public void UnMarkChecklistAsFavourite(Checklist checklist, string user, UserForAuditing userForAuditing)
        {
            var favChecklist = _favouriteChecklistRepository.Get(checklist.Id, user);

            if (favChecklist != null)
            {
                favChecklist.MarkForDelete(userForAuditing);
                _favouriteChecklistRepository.SaveOrUpdate(favChecklist);
            }
        }
        public void given_checklist_when_copyWithResponses_with_question_marked_as_acceptable_then_SupportingDocumentationDate_is_not_set()
        {
            //given
            var siteId = 213123;
            var clientId = 54321;
            var userForAuditing = new UserForAuditing() { Id = Guid.NewGuid() };
            var copiedByUserName = "******";

            var question = Question.Create(Guid.NewGuid(), "Title",
              new Category() { Id = Guid.NewGuid(), Title = "Care" }, false, userForAuditing);
            
            var answer = new ChecklistAnswer()
            {
                Id = Guid.NewGuid(),
                AssignedTo = new BusinessSafe.Domain.Entities.Employee() { Id = Guid.NewGuid() },
                EmployeeNotListed = "employee not listed",
                Timescale = new Timescale() { Id = 2L },
                Question = question,
                Response = new QuestionResponse()
                {
                    Id = Guid.NewGuid(),
                    SupportingEvidence = "sp",
                    GuidanceNotes = "the guidance notes",
                    ActionRequired = "the action required",
                    ResponseType = "Positive",
                    Question = question

                },
                SupportingDocumentationDate = DateTime.Now.Date,
                SupportingDocumentationStatus = "SS",
                SupportingEvidence = "se"
            };

            var answersList = new List<ChecklistAnswer>() { answer };
            var checklist = new Checklist() { Id = Guid.NewGuid() };

            checklist.Questions.Add(new ChecklistQuestion() { Id = Guid.NewGuid(), Question = question, Checklist = checklist, CategoryNumber = 1, QuestionNumber = 4 });
            checklist.UpdateAnswers(answersList, new UserForAuditing());

            //when
            var result = checklist.CopyToSiteWithResponses(siteId, clientId, userForAuditing, copiedByUserName, false);

            //then
            Assert.That(result.Answers.Count, Is.EqualTo(1));
            Assert.That(result.Answers[0].Question.Id, Is.EqualTo(checklist.Answers[0].Question.Id));
            Assert.AreEqual(null, result.Answers[0].SupportingDocumentationDate);            
        }
        public void given_checklist_when_copyWithResponses_then_Answers_to_all_non_mandatory_questions_are_set()
        {
            //given
            var siteId = 213123;
            var clientId = 54321;
            var userForAuditing = new UserForAuditing() { Id = Guid.NewGuid() };
            var copiedByUserName = "******";
            

            var question1 = Question.Create(Guid.NewGuid(), "Title",
               new Category() { Id = Guid.NewGuid(), Title = "Care" }, true, userForAuditing);

            var responseId = Guid.NewGuid();
            var questionResponse1 = new QuestionResponse() {
                    Id = responseId,
                    Title = "Acceptable",
                    SupportingEvidence = "sp",
                    GuidanceNotes = "the guidance notes",
                    ActionRequired = "the action required",
                    ResponseType = "Positive",
                    Question = question1,
                };
            var questionResponse2 = new QuestionResponse() { Id = Guid.NewGuid(), Question = question1, Title = "Unacceptable", ResponseType = "Negative"};

            question1.PossibleResponses.Add(questionResponse1);
            question1.PossibleResponses.Add(questionResponse2);

           
            var answer = new ChecklistAnswer()
            {
                Id = Guid.NewGuid(),
                AssignedTo = new BusinessSafe.Domain.Entities.Employee() { Id = Guid.NewGuid() },
                EmployeeNotListed = "employee not listed",
                Timescale = new Timescale() { Id = 2L },
                Question = question1,
                Response = new QuestionResponse()
                {
                    Id = responseId,
                    Title = "Acceptable",
                    SupportingEvidence = "sp",
                    GuidanceNotes = "the guidance notes",
                    ActionRequired = "the action required",
                    ResponseType = "Positive",
                    Question = question1,
                },
                SupportingDocumentationDate = DateTime.Now.Date,
                SupportingDocumentationStatus = "SS",
                SupportingEvidence = "se"
            };

            
            var answersList = new List<ChecklistAnswer>() { answer };
            var checklist = new Checklist() { Id = Guid.NewGuid() };

            checklist.Questions.Add(new ChecklistQuestion() { Id = Guid.NewGuid(), Question = question1, Checklist = checklist, CategoryNumber = 1, QuestionNumber = 4 });
            
            checklist.UpdateAnswers(answersList, new UserForAuditing());

            //when
            var result = checklist.CopyToSiteWithResponses(siteId, clientId, userForAuditing, copiedByUserName, false);

            Assert.That(result.Answers.Count, Is.EqualTo(checklist.Answers.Count()));

            Assert.That(result.Answers[0].Id, Is.Not.EqualTo(checklist.Answers[0].Id));
            Assert.That(result.Answers[0].Question.Id, Is.Not.EqualTo(checklist.Answers[0].Question.Id));
            Assert.That(result.Answers[0].Timescale, Is.EqualTo(null));
            Assert.That(result.Answers[0].AssignedTo, Is.EqualTo(null));
            Assert.That(result.Answers[0].EmployeeNotListed, Is.EqualTo(checklist.Answers[0].EmployeeNotListed));


            Assert.That(result.Answers[0].Response.Question.Id, Is.Not.EqualTo(checklist.Answers[0].Question.Id));
            Assert.That(result.Answers[0].Response.Title, Is.EqualTo(checklist.Answers[0].Response.Title));
            Assert.That(result.Answers[0].Response.ActionRequired, Is.EqualTo(checklist.Answers[0].Response.ActionRequired));
            Assert.That(result.Answers[0].Response.GuidanceNotes, Is.EqualTo(checklist.Answers[0].Response.GuidanceNotes));
            Assert.That(result.Answers[0].Response.SupportingEvidence, Is.EqualTo(checklist.Answers[0].Response.SupportingEvidence));
            Assert.That(result.Answers[0].Response.SupportingEvidence, Is.EqualTo(checklist.Answers[0].Response.SupportingEvidence));
            Assert.That(result.Answers[0].Response.ResponseType, Is.EqualTo(checklist.Answers[0].Response.ResponseType));
            
        }
        public void given_checklist_when_copyWithResponses_then_IRNs_are_copied()
        {
            //given
            var siteId = 213123;
            var clientId = 54321;
            var userForAuditing = new UserForAuditing() { Id = Guid.NewGuid() };
            var copiedByUserName = "******";

            var checklist = new Checklist() { Id = Guid.NewGuid() };

            Guid IRN1Id = Guid.NewGuid();
            var irn1 = ImmediateRiskNotification.Create( IRN1Id, 
                                                        "IRN 1 Some reference", 
                                                        "IRN 1 Title",
                                                        "IRN 1 Significant hazard identifed",
                                                        "IRN 1 Recommended immediate action",
                                                        checklist,
                                                        userForAuditing);

            Guid IRN2Id = Guid.NewGuid();
            var irn2 = ImmediateRiskNotification.Create(IRN2Id,
                                                        "IRN 2 Some reference",
                                                        "IRN 2 Title",
                                                        "IRN 2 Significant hazard identifed",
                                                        "IRN 2 Recommended immediate action",
                                                        checklist,
                                                        userForAuditing);

            checklist.AddImmediateRiskNotification(irn1);
            checklist.AddImmediateRiskNotification(irn2);
            
            //when
            var result = checklist.CopyToSiteWithResponses(siteId, clientId, userForAuditing, copiedByUserName, false);

            Assert.That(result.ImmediateRiskNotifications.Count, Is.EqualTo(checklist.ImmediateRiskNotifications.Count()));

            Assert.That(result.ImmediateRiskNotifications[0].Id, Is.Not.EqualTo(checklist.ImmediateRiskNotifications[0].Id));
            Assert.That(result.ImmediateRiskNotifications[0].Reference, Is.EqualTo(checklist.ImmediateRiskNotifications[0].Reference));
            Assert.That(result.ImmediateRiskNotifications[0].Title, Is.EqualTo(checklist.ImmediateRiskNotifications[0].Title));
            Assert.That(result.ImmediateRiskNotifications[0].SignificantHazardIdentified, Is.EqualTo(checklist.ImmediateRiskNotifications[0].SignificantHazardIdentified));
            Assert.That(result.ImmediateRiskNotifications[0].RecommendedImmediateAction, Is.EqualTo(checklist.ImmediateRiskNotifications[0].RecommendedImmediateAction));
            Assert.That(result.ImmediateRiskNotifications[0].Checklist.Id, Is.EqualTo(result.Id));

            Assert.That(result.ImmediateRiskNotifications[1].Id, Is.Not.EqualTo(checklist.ImmediateRiskNotifications[1].Id));
            Assert.That(result.ImmediateRiskNotifications[1].Reference, Is.EqualTo(checklist.ImmediateRiskNotifications[1].Reference));
            Assert.That(result.ImmediateRiskNotifications[1].Title, Is.EqualTo(checklist.ImmediateRiskNotifications[1].Title));
            Assert.That(result.ImmediateRiskNotifications[1].SignificantHazardIdentified, Is.EqualTo(checklist.ImmediateRiskNotifications[1].SignificantHazardIdentified));
            Assert.That(result.ImmediateRiskNotifications[1].RecommendedImmediateAction, Is.EqualTo(checklist.ImmediateRiskNotifications[1].RecommendedImmediateAction));                                                          
            Assert.That(result.ImmediateRiskNotifications[1].Checklist.Id, Is.EqualTo(result.Id));
        }
        public void AutoAssignChecklist(Checklist checklist)
        {
            if (checklist.Status == Checklist.STATUS_COMPLETED
                && !String.IsNullOrEmpty(checklist.ChecklistCreatedBy)
                && checklist.QaAdvisor == null)
            {
                if (DoesChecklistNeedToBeChecked(checklist))
                {
                    // add QAassigned check here
                    QaAdvisor qaAdvisor = null;

                    var consultant = _consultantRepo.GetByFullname(checklist.ChecklistCompletedBy);
                    bool updateLastQaAdvisorAssignedRequired = (consultant != null) && !consultant.QaAdvisorAssigned.HasValue;

                    if (consultant == null)
                    {
                        qaAdvisor = GetNextQaAdvisorInTheRotation();
                    }
                    else
                    {
                        qaAdvisor = consultant.QaAdvisorAssigned.HasValue ? _qaAdvisorRepository.GetById(consultant.QaAdvisorAssigned.Value) : GetNextQaAdvisorInTheRotation();
                    }

                    if (qaAdvisor != null)
                    {
                        AssignChecklistToQaAdvisor(checklist, qaAdvisor);

                        // do not update lastQaAdvisor list if consultant has a one-to-one relation with Advisor
                        if (updateLastQaAdvisorAssignedRequired)
                        {
                            UpdateLastQaAdvisorAssigned(qaAdvisor);
                        }
                    }
                }
                else
                {
                    //assign to default hs & reports team
                    var qaAdvisor = GetHSReportsAdvisor();
                    AssignChecklistToQaAdvisor(checklist, qaAdvisor);
                }
            }
        }
        public void given_checklist_when_copyWithoutResponses_then_non_mandatory_questions_set()
        {
            //given
            var siteId = 213123;
            var clientId = 123;
            var userForAuditing = new UserForAuditing() { Id = Guid.NewGuid() };
            var copiedByUserName = "******";
            var question = Question.Create(Guid.NewGuid(), "Title",
                new Category() { Id = Guid.NewGuid(), Title = "Care" }, true, userForAuditing);

            var checklist = new Checklist()
            {
                Id = Guid.NewGuid(),
                ChecklistCreatedBy = "previousCreatedBy",
                CreatedOn = DateTime.Now.AddDays(-10),
                ChecklistCreatedOn = DateTime.Now.AddDays(-10),
                Jurisdiction = "UK",
                Status = "Submitted",
                ClientId = clientId,
                ChecklistTemplate = new ChecklistTemplate() { Id = Guid.NewGuid() }
            };

            checklist.Questions.Add(new ChecklistQuestion() { Id = Guid.NewGuid(), Question = question, Checklist = checklist, CategoryNumber = 1, QuestionNumber = 2 });

            //when
            var result = checklist.CopyToSiteWithoutResponses(siteId, clientId, userForAuditing, copiedByUserName, false);

            //then
            Assert.That(result.Questions.Count, Is.EqualTo(checklist.Questions.Count));
            Assert.That(result.Questions[0].Id, Is.Not.EqualTo(checklist.Questions[0].Id));
            Assert.That(result.Questions[0].Question.Id, Is.Not.EqualTo(checklist.Questions[0].Question.Id));
            Assert.That(result.Questions[0].CategoryNumber, Is.EqualTo(checklist.Questions[0].CategoryNumber));
            Assert.That(result.Questions[0].QuestionNumber, Is.EqualTo(checklist.Questions[0].QuestionNumber));
            Assert.That(result.Questions[0].Question.CustomQuestion, Is.EqualTo(checklist.Questions[0].Question.CustomQuestion));
            Assert.That(result.Questions[0].Question.Category.Id, Is.EqualTo(checklist.Questions[0].Question.Category.Id));
        }
        public void AssignChecklistToQaAdvisor(Checklist checklist, QaAdvisor qaAdvisor)
        {
            if (checklist.Status == Checklist.STATUS_SUBMITTED)
                return;

            if (checklist.QaAdvisor == null)
            {
                checklist.QaAdvisorAssignedOn = DateTime.Now;
            }

            checklist.QaAdvisor = qaAdvisor;
            checklist.Status = Checklist.STATUS_ASSIGNED;

            var sendChecklistAssignedEmail = new SendChecklistAssignedEmail
            {
                ChecklistId = checklist.Id,
                AssignedToId = qaAdvisor.Id
            };

            if (checklist.ClientId.HasValue)
            {
                var clientDetail = _clientDetailsService.Get(checklist.ClientId.Value);

                var site = checklist.SiteId.HasValue
                    ? _clientDetailsService.GetSite(checklist.ClientId.Value, checklist.SiteId.Value)
                    : null;

                var postcode = site != null ? site.Postcode : "";

                sendChecklistAssignedEmail.Can = clientDetail.CAN;
                sendChecklistAssignedEmail.SiteName = site != null ? site.SiteName : "";
                sendChecklistAssignedEmail.Address1 = site != null ? site.Address1 : "";
                sendChecklistAssignedEmail.Address2 = site != null ? site.Address2 : "";
                sendChecklistAssignedEmail.Address3 = site != null ? site.Address3 : "";
                sendChecklistAssignedEmail.Address4 = site != null ? site.Address4 : "";
                sendChecklistAssignedEmail.Address5 = site != null ? site.Address5 : "";
                sendChecklistAssignedEmail.Postcode = postcode;
            }
            else
            {
                sendChecklistAssignedEmail.Can = "Not specified";
                sendChecklistAssignedEmail.Postcode = "Not specified";
            }

            _bus.Send(sendChecklistAssignedEmail);
        }
        public void Given_a_checklist_exists_when_a_new_question_is_added_with_answer_Then_the_question_and_answer_is_added_to_the_checklist()
        {
            var checklist = new Checklist();
            checklist.Id = Guid.NewGuid();
            var questions = GetListOfQuestions();
            //checklist.UpdateQuestions(questions, new UserForAuditing());

            foreach (var question in questions)
            {
                checklist.Questions.Add(new ChecklistQuestion { Checklist = checklist, Question = question });
            } 
            
            checklist.Questions[0].CategoryNumber = 1;
            checklist.Questions[0].QuestionNumber = 1;
            checklist.Questions[1].CategoryNumber = 1;
            checklist.Questions[1].QuestionNumber = 2;
            checklist.Questions[2].CategoryNumber = 2;
            checklist.Questions[2].QuestionNumber = 1;

          

            var checklistViewModel = GetChecklistViewModelFromQuestions(questions);
            checklistViewModel.Id = checklist.Id;
            checklistViewModel.Questions[0].CategoryNumber = 1;
            checklistViewModel.Questions[0].QuestionNumber = 1;
            checklistViewModel.Questions[1].CategoryNumber = 1;
            checklistViewModel.Questions[1].QuestionNumber = 2;
            checklistViewModel.Questions[2].CategoryNumber = 2;
            checklistViewModel.Questions[2].QuestionNumber = 1;

            //Add new questions to API.
            var newQuestionAnswer = GetQuestionAnswerViewModel();
            newQuestionAnswer.Answer = new AnswerViewModel();
            newQuestionAnswer.Answer.SelectedResponseId = newQuestionAnswer.Question.PossibleResponses[0].Id;
            checklistViewModel.Questions.Add(newQuestionAnswer);
            checklistViewModel.SiteId = 1; 

            checklistViewModel.Site = new SiteViewModel
            {
                Id = (int)_peninsulaSiteId,
                Address1 = "1 Green Lane",
                Postcode = "M1 1AA"
            };

            checklistViewModel.SiteId = (int)_peninsulaSiteId;

            checklistViewModel.SiteVisit = new SiteVisitViewModel
            {
                VisitDate = "14/02/2000"
            };

            _checklistRepository
                .Setup(x => x.GetById(checklist.Id))
                .Returns(checklist);

            foreach (var question in questions)
            {
                _questionRepository
                    .Setup(x => x.GetById(question.Id))
                    .Returns(question);
            }

            var controller = GetTarget();

            var response = controller.PostChecklist(checklist.Id, checklistViewModel);

            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
            Assert.That(checklist.Questions.Count, Is.EqualTo(4));
            Assert.That(checklist.Questions[0].Question.Id, Is.EqualTo(questions[0].Id));
            Assert.That(checklist.Questions[1].Question.Id, Is.EqualTo(questions[1].Id));
            Assert.That(checklist.Questions[2].Question.Id, Is.EqualTo(questions[2].Id));
            Assert.That(checklist.Questions[3].Question.Id, Is.EqualTo(newQuestionAnswer.Question.Id));
            Assert.That(checklist.Answers.Count, Is.EqualTo(1));
            Assert.That(checklist.Answers[0].Question, Is.EqualTo(checklist.Questions[3].Question));
            Assert.That(checklist.Answers[0].Response, Is.EqualTo(checklist.Questions[3].Question.PossibleResponses[0]));
            Assert.That(checklist.Questions[3].Question.SpecificToClientId, Is.EqualTo(newQuestionAnswer.Question.SpecificToClientId));
            

        }
        public void Given_imediate_risk_notifications_exist_in_existing_checklist_When_PostChecklist_is_called_Then_IRNs_are_created_and_deleted_and_remain_accordingly()
        {
            var checklist = new Checklist();

            var immediateRiskNotification1 = ImmediateRiskNotification.Create(
                Guid.NewGuid(),
                "Reference 1",
                "Title 1",
                "Significant Hazard Identified 1",
                "Recommended Immediate Action 1",
                checklist,
                new UserForAuditing());

            var immediateRiskNotification2 = ImmediateRiskNotification.Create(
                Guid.NewGuid(),
                "Reference 2",
                "Title 2",
                "Significant Hazard Identified 2",
                "Recommended Immediate Action 2",
                checklist,
                new UserForAuditing());

            checklist.ImmediateRiskNotifications.Add(immediateRiskNotification1);
            checklist.ImmediateRiskNotifications.Add(immediateRiskNotification2);

            var checklistViewModel = new ChecklistViewModel();
            checklistViewModel.ClientId = 2323;
            checklistViewModel.SiteId = (int)_peninsulaSiteId;

            var immediateRiskNotificationViewModel1 = new ImmediateRiskNotificationViewModel();
            immediateRiskNotificationViewModel1.Id = immediateRiskNotification1.Id;
            immediateRiskNotificationViewModel1.Reference = immediateRiskNotification1.Reference;
            immediateRiskNotificationViewModel1.Title = immediateRiskNotification1.Title;
            immediateRiskNotificationViewModel1.SignificantHazard = immediateRiskNotification1.SignificantHazardIdentified;
            immediateRiskNotificationViewModel1.RecommendedImmediate = immediateRiskNotification1.RecommendedImmediateAction;

            var immediateRiskNotificationViewModel2 = new ImmediateRiskNotificationViewModel();
            immediateRiskNotificationViewModel2.Id = Guid.NewGuid();
            immediateRiskNotificationViewModel2.Reference = "Reference 3";
            immediateRiskNotificationViewModel2.Title = "Title 3";
            immediateRiskNotificationViewModel2.SignificantHazard = "Significant Hazard Identified 3";
            immediateRiskNotificationViewModel2.RecommendedImmediate = "Recommended Immediate Action 3";

            checklistViewModel.ImmediateRiskNotifications.Add(immediateRiskNotificationViewModel1);
            checklistViewModel.ImmediateRiskNotifications.Add(immediateRiskNotificationViewModel2);
            checklistViewModel.SiteId = 1;

            _checklistRepository
                .Setup(x => x.GetById(checklist.Id))
                .Returns(checklist);

            Checklist savedChecklist = null;

            _checklistRepository.Setup(x => x.SaveOrUpdate(It.IsAny<Checklist>()))
                .Callback(
                    delegate(Checklist x)
                    {
                        savedChecklist = x;
                    }
                );

            var controller = GetTarget();
            var response = controller.PostChecklist(checklistViewModel.Id, checklistViewModel);
            Assert.That(savedChecklist, Is.Not.Null);
            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
            Assert.That(savedChecklist.Status, Is.EqualTo(checklistViewModel.Status));
            Assert.That(savedChecklist.Questions.Count, Is.EqualTo(0));
            Assert.That(savedChecklist.ImmediateRiskNotifications, Is.Not.Null);
            Assert.That(savedChecklist.ImmediateRiskNotifications.Count, Is.EqualTo(3));
            Assert.That(savedChecklist.ImmediateRiskNotifications.Count(x => !x.Deleted), Is.EqualTo(2));
            Assert.That(savedChecklist.ImmediateRiskNotifications[0].Title, Is.EqualTo(immediateRiskNotificationViewModel1.Title));
            Assert.That(savedChecklist.ImmediateRiskNotifications[0].Reference, Is.EqualTo(immediateRiskNotificationViewModel1.Reference));
            Assert.That(savedChecklist.ImmediateRiskNotifications[0].SignificantHazardIdentified, Is.EqualTo(immediateRiskNotificationViewModel1.SignificantHazard));
            Assert.That(savedChecklist.ImmediateRiskNotifications[0].RecommendedImmediateAction, Is.EqualTo(immediateRiskNotificationViewModel1.RecommendedImmediate));
            Assert.That(savedChecklist.ImmediateRiskNotifications[0].Checklist, Is.EqualTo(savedChecklist));
            Assert.That(savedChecklist.ImmediateRiskNotifications[0].Deleted, Is.False);
            Assert.That(savedChecklist.ImmediateRiskNotifications[1].Title, Is.EqualTo(immediateRiskNotification2.Title));
            Assert.That(savedChecklist.ImmediateRiskNotifications[1].Reference, Is.EqualTo(immediateRiskNotification2.Reference));
            Assert.That(savedChecklist.ImmediateRiskNotifications[1].SignificantHazardIdentified, Is.EqualTo(immediateRiskNotification2.SignificantHazardIdentified));
            Assert.That(savedChecklist.ImmediateRiskNotifications[1].RecommendedImmediateAction, Is.EqualTo(immediateRiskNotification2.RecommendedImmediateAction));
            Assert.That(savedChecklist.ImmediateRiskNotifications[1].Checklist, Is.EqualTo(savedChecklist));
            Assert.That(savedChecklist.ImmediateRiskNotifications[1].Deleted, Is.True);
            Assert.That(savedChecklist.ImmediateRiskNotifications[2].Title, Is.EqualTo(immediateRiskNotificationViewModel2.Title));
            Assert.That(savedChecklist.ImmediateRiskNotifications[2].Reference, Is.EqualTo(immediateRiskNotificationViewModel2.Reference));
            Assert.That(savedChecklist.ImmediateRiskNotifications[2].SignificantHazardIdentified, Is.EqualTo(immediateRiskNotificationViewModel2.SignificantHazard));
            Assert.That(savedChecklist.ImmediateRiskNotifications[2].RecommendedImmediateAction, Is.EqualTo(immediateRiskNotificationViewModel2.RecommendedImmediate));
            Assert.That(savedChecklist.ImmediateRiskNotifications[2].Checklist, Is.EqualTo(savedChecklist));
            Assert.That(savedChecklist.ImmediateRiskNotifications[2].Deleted, Is.False);
        }
        public void Given_a_checklist_exists_when_a_question_is_removed_and_others_are_moved_up_then_category_number_and_question_number_are_updated()
        {
            var checklist = new Checklist();
            checklist.Id = Guid.NewGuid();
            var questions = GetListOfQuestions();
            foreach (var question in questions)
            {
                checklist.Questions.Add(new ChecklistQuestion { Checklist = checklist, Question = question });
            }

            checklist.Questions[0].CategoryNumber = 1;
            checklist.Questions[0].QuestionNumber = 1;
            checklist.Questions[1].CategoryNumber = 1;
            checklist.Questions[1].QuestionNumber = 2;
            checklist.Questions[2].CategoryNumber = 1;
            checklist.Questions[2].QuestionNumber = 3;

            _checklistRepository
              .Setup(x => x.GetById(checklist.Id))
              .Returns(checklist);


            var checklistViewModel = GetChecklistViewModelFromQuestions(questions);
            checklistViewModel.Id = checklist.Id;
            checklistViewModel.SiteId = 23;
            checklistViewModel.Questions[0].CategoryNumber = 1;
            checklistViewModel.Questions[0].QuestionNumber = 1;
            checklistViewModel.Questions[1].CategoryNumber = 1;
            checklistViewModel.Questions[1].QuestionNumber = 2;
            checklistViewModel.Questions[2].CategoryNumber = 1;
            checklistViewModel.Questions[2].QuestionNumber = 2;

            checklistViewModel.Questions.RemoveAt(1);


            foreach (var question in questions)
            {
                _questionRepository
                    .Setup(x => x.GetById(question.Id))
                    .Returns(question);
            }

            var controller = GetTarget();

            var response = controller.PostChecklist(checklist.Id, checklistViewModel);

            Assert.That(checklist.Questions[0].Question.Id, Is.EqualTo(questions[0].Id));
            Assert.That(checklist.Questions[0].CategoryNumber, Is.EqualTo(1));
            Assert.That(checklist.Questions[0].QuestionNumber, Is.EqualTo(1));
        
            Assert.That(checklist.Questions[1].Question.Id, Is.EqualTo(questions[1].Id));
            Assert.That(checklist.Questions[1].Deleted, Is.EqualTo(true));

            Assert.That(checklist.Questions[2].Question.Id, Is.EqualTo(questions[2].Id));
            Assert.That(checklist.Questions[2].CategoryNumber, Is.EqualTo(1));
            Assert.That(checklist.Questions[2].QuestionNumber, Is.EqualTo(2));

        }
        public void given_checklist_when_copyWithoutResponses_then_initial_Values_set()
        {
            //given
            var clientId = 123;
            var userForAuditing = new UserForAuditing() { Id = Guid.NewGuid() };
            var copiedByUserName = "******";
            var checklist = new Checklist()
            {
                Id = Guid.NewGuid(), 
                ChecklistCreatedBy = "previousCreatedBy", 
                CreatedOn = DateTime.Now.AddDays(-10), 
                ChecklistCreatedOn = DateTime.Now.AddDays(-10),
                Jurisdiction = "UK",
                Status = "Submitted",
                ClientId = clientId,
                ChecklistTemplate = new ChecklistTemplate() { Id=Guid.NewGuid()}
            };

            var siteId = 213123;            

            //when
            var result = checklist.CopyToSiteWithoutResponses(siteId, clientId, userForAuditing, copiedByUserName, false);

            //then
            Assert.That(result.Id, Is.Not.EqualTo(checklist.Id));
            Assert.That(result.ClientId, Is.EqualTo(clientId));
            Assert.That(result.Jurisdiction, Is.EqualTo(checklist.Jurisdiction));
            Assert.That(result.Status, Is.EqualTo("Draft"));
            Assert.That(result.ChecklistCreatedBy, Is.EqualTo(copiedByUserName));
            Assert.That(result.ChecklistCreatedOn.Value.Date, Is.Not.EqualTo(checklist.CreatedOn.Value.Date));

        }
        public void given_checklist_when_copyWithoutResponses_then_deleted_questions_not_set()
        {
            //given
            var siteId = 213123;
            var clientId = 123;
            var userForAuditing = new UserForAuditing() { Id = Guid.NewGuid() };
            var copiedByUserName = "******";

            var question1 = Question.Create(Guid.NewGuid(), "Title",
                new Category() { Id = Guid.NewGuid(), Title = "Care" }, false, userForAuditing);

            var question2 = Question.Create(Guid.NewGuid(), "Title",
                new Category() { Id = Guid.NewGuid(), Title = "Care" }, true, userForAuditing);

            var question3 = Question.Create(Guid.NewGuid(), "Title",
               new Category() { Id = Guid.NewGuid(), Title = "Care" }, false, userForAuditing);
            question3.Deleted = true;

            var question4 = Question.Create(Guid.NewGuid(), "Title",
               new Category() { Id = Guid.NewGuid(), Title = "Care" }, true, userForAuditing);
            question4.Deleted = true;

            var checklist = new Checklist()
            {
                Id = Guid.NewGuid(),
                ChecklistCreatedBy = "previousCreatedBy",
                CreatedOn = DateTime.Now.AddDays(-10),
                ChecklistCreatedOn = DateTime.Now.AddDays(-10),
                Jurisdiction = "UK",
                Status = "Submitted",
                ClientId = clientId,
                ChecklistTemplate = new ChecklistTemplate() { Id = Guid.NewGuid() }
            };

            checklist.Questions.Add(new ChecklistQuestion() { Id = Guid.NewGuid(), Question = question1, Checklist = checklist, CategoryNumber = 1, QuestionNumber = 4 });
            checklist.Questions.Add(new ChecklistQuestion() { Id = Guid.NewGuid(), Question = question2, Checklist = checklist, CategoryNumber = 2, QuestionNumber = 3 });
            checklist.Questions.Add(new ChecklistQuestion() { Id = Guid.NewGuid(), Question = question3, Checklist = checklist, CategoryNumber = 3, QuestionNumber = 2 });
            checklist.Questions.Add(new ChecklistQuestion() { Id = Guid.NewGuid(), Question = question4, Checklist = checklist, CategoryNumber = 4, QuestionNumber = 1});

            //when
            var result = checklist.CopyToSiteWithoutResponses(siteId, clientId, userForAuditing, copiedByUserName, false);

            //then
            Assert.That(result.Questions.Count, Is.EqualTo(2));
        }
        public bool DoesChecklistNeedToBeChecked(Checklist checklist)
        {
            if ( checklist.Status == Checklist.STATUS_COMPLETED
                && !String.IsNullOrEmpty( checklist.ChecklistCreatedBy)
                && checklist.QaAdvisor == null ){

                var consultant = _consultantRepo.GetByFullname(checklist.ChecklistCreatedBy);

                if (consultant == null)
                {
                    return false;
                }

                if (checklist.SpecialReport && consultant.PercentageOfChecklistsToSendToQualityControl != 100)
                {
                    return false;
                }

                var consultantCompletedCount = _getCompleteChecklistQuery.Count(checklist.ChecklistCreatedBy);
                var nthChecklistToSendToQualityControl = consultant.PercentageOfChecklistsToSendToQualityControl == 0 ? 0 : 100 / consultant.PercentageOfChecklistsToSendToQualityControl;

                //if nthChecklistToSendToQualityControl == 1 then this means send every checklist to quality control;
                return  nthChecklistToSendToQualityControl == 1 || consultantCompletedCount > 0 && nthChecklistToSendToQualityControl > 0 && consultantCompletedCount % nthChecklistToSendToQualityControl == 0;
            }

            return false;
        }