public ComplianceReviewReportViewModel GetViewModel(ChecklistViewModel checklistViewModel) { _model = new ComplianceReviewReportViewModel(); if (!checklistViewModel.AllQuestionTemplate) { AddSiteVisitDetails(checklistViewModel); AddSiteDetails(checklistViewModel); AddImmediateRiskNotifications(checklistViewModel); ParseAnswers(checklistViewModel); AddCountOfDifferentResponses(checklistViewModel); } else { ParseAllQuestions(checklistViewModel); } AddSectionSelections(checklistViewModel); return _model; }
private void AddSiteDetails(ChecklistViewModel checklistViewModel) { if (_model.Site == null) { _model.Site = new SiteViewModel(); } if (checklistViewModel.SiteId != null && checklistViewModel.ClientId != null) { _model.Site.Id = (int) checklistViewModel.SiteId; SiteAddressResponse response = _clientDetailsService.GetSite(checklistViewModel.ClientId.Value, checklistViewModel.SiteId.Value); if ( response != null) { _model.Site.SiteName = response.SiteName; _model.Site.Address1 = response.Address1; _model.Site.Address2 = response.Address2; _model.Site.Address3 = response.Address3; _model.Site.Address4 = response.Address4; _model.Site.Postcode = response.Postcode; } } }
private static void AddStylesheetToCoveringLetterContent(ChecklistViewModel model) { var docType = @"<!DOCTYPE html>"; var stylesheet = @"<style type=""text/css""> body, html, p {font-family:Arial, Helvetica, sans-serif; font-size:18pt; font-weight: normal;text-align:justify;} </style>"; model.CoveringLetterContent = string.Format(@"{2}<html><head>{0}</head><body>{1}</body></html>", stylesheet, model.CoveringLetterContent, docType); }
private void CreateComplianceReviewPDF(ChecklistViewModel model) { var checklistPdfCreator = ObjectFactory.GetInstance<IChecklistPdfCreator>(); checklistPdfCreator.ChecklistViewModel = model; model.ContentPath = string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority, "/content"); var filename = checklistPdfCreator.GetFileName(); var pdfBytes = checklistPdfCreator.GetBytes(); // get the object representing the HTTP response to browser HttpResponse httpResponse = System.Web.HttpContext.Current.Response; // add the Content-Type and Content-Disposition HTTP headers httpResponse.AddHeader("Content-Type", "application/pdf"); httpResponse.AddHeader("Content-Disposition", String.Format("attachment; filename={1}; size={0}", pdfBytes.Length.ToString(),filename)); // write the PDF document bytes as attachment to HTTP response httpResponse.BinaryWrite(pdfBytes); // Note: it is important to end the response, otherwise the ASP.NET // web page will render its content to PDF document stream httpResponse.End(); }
private ChecklistViewModel CreateChecklistViewModel() { ChecklistViewModel chkModel = new ChecklistViewModel(); chkModel.SiteVisit = new SiteVisitViewModel() { AreasVisited = "Visited area", AreasNotVisited = "Non-visited area", EmailAddress = "*****@*****.**", VisitDate = DateTime.Now.ToShortDateString(), VisitBy = "Barney Rubble", VisitType = "Initial visit" }; chkModel.SiteVisit.PersonSeen = new PersonSeenViewModel() { JobTitle = "Dogsbody", Name = "Fred Flintstone", Salutation = "Mr" }; chkModel.SiteVisit.SelectedImpressionType = new ImpressionTypeViewModel() { Id = Guid.NewGuid(), Title = "the title", Comments = "some comments" }; return chkModel; }
private void ParseAnswers(ChecklistViewModel checklistViewModel) { if (checklistViewModel.Questions != null) { AddComplianceReviewItems(checklistViewModel); AddActionPlanItems(checklistViewModel); } }
public void Given_A_New_Checklist_Is_Being_Saved_Then_Returns_Status_OK() { ChecklistViewModel model = new ChecklistViewModel() { Id = Guid.NewGuid(), SiteId = 1234, Site = new SiteViewModel() { Id = 222, Address1 = "Address", Postcode = "MA 1AA" }, }; model.SiteVisit = new SiteVisitViewModel() { AreasNotVisited = "Ground floor", AreasVisited = "First floor", EmailAddress = "*****@*****.**", VisitDate = DateTime.Now.Date, VisitBy = "ABC", VisitType = "Fire & Safety check", PersonSeen = new PersonSeenViewModel() { Name = "Richard"} }; model.SiteVisit.SelectedImpressionType = new ImpressionTypeViewModel() {Id = _impressionTypeId}; model.Questions = new List<QuestionAnswerViewModel>(); model.Questions.Add(new QuestionAnswerViewModel() { Question = new QuestionViewModel() { Id = Guid.Parse("614D9A92-78ED-4D37-BD86-BD963C053EC5"), PossibleResponses = new List<QuestionResponseViewModel>(), Text = "Question 1" }, Answer = new AnswerViewModel() { QuestionId = Guid.Parse("614D9A92-78ED-4D37-BD86-BD963C053EC5"), SelectedResponseId = Guid.Parse("A415F8B0-65F8-4947-B390-0018465F46CE"), AssignedTo = new AssignedToViewModel() { Id = Guid.Empty, NonEmployeeName= "Nauman Asif"} } } ); ResourceUrl = string.Format("{0}{1}/{2}", ApiBaseUrl, "checklists", model.Id.ToString()); // Given var client = new RestClient(Url.AbsoluteUri); client.Authenticator = new NtlmAuthenticator("continuous.int", "is74rb80pk52"); var request = new RestRequest(ResourceUrl); request.AddHeader("Content-Type", "application/json"); request.RequestFormat = DataFormat.Json; request.Method = Method.POST; request.AddBody(model); // When var response = client.Execute(request); // Then Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); }
public ComplianceReviewReportViewModel GetViewModel(ChecklistViewModel checklistViewModel) { _model = new ComplianceReviewReportViewModel(); AddSiteVisitDetails(checklistViewModel); AddSiteDetails(checklistViewModel); AddImmediateRiskNotifications(checklistViewModel); ParseAnswers(checklistViewModel); return _model; }
public void Given_2_acceptable_responses_and_1_unacceptable_responses_then_CountOfFurtherActionRequiredItems_is_1() { var checklistViewModel = new ChecklistViewModel(); checklistViewModel.Questions.Add(CreateQuestionAnswerViewModel(ACCEPTABLE_RESPONSE)); checklistViewModel.Questions.Add(CreateQuestionAnswerViewModel(ACCEPTABLE_RESPONSE)); checklistViewModel.Questions.Add(CreateQuestionAnswerViewModel(IMPROVEMENT_REQUIRED_RESPONSE)); checklistViewModel.Questions.Add(CreateQuestionAnswerViewModel(UNACCEPTABLE_RESPONSE)); checklistViewModel.Questions.Add(CreateQuestionAnswerViewModel(NOT_APPLICABLE_RESPONSE)); var target = GetTarget(); var result = target.GetViewModel(checklistViewModel); Assert.That(result.CountOfFurtherActionRequiredItems, Is.EqualTo(1)); }
public void Given_2_acceptable_responses_and_3_not_acceptable_responses_then_counts_CountOfSatisfactory_is_2() { var checklistViewModel = new ChecklistViewModel(); checklistViewModel.Questions.Add(CreateQuestionAnswerViewModel(ACCEPTABLE_RESPONSE)); checklistViewModel.Questions.Add(CreateQuestionAnswerViewModel(ACCEPTABLE_RESPONSE)); checklistViewModel.Questions.Add(CreateQuestionAnswerViewModel(IMPROVEMENT_REQUIRED_RESPONSE)); checklistViewModel.Questions.Add(CreateQuestionAnswerViewModel(UNACCEPTABLE_RESPONSE)); checklistViewModel.Questions.Add(CreateQuestionAnswerViewModel(NOT_APPLICABLE_RESPONSE)); var target = GetTarget(); var result = target.GetViewModel(checklistViewModel); Assert.That(result.CountOfSatisfactory, Is.EqualTo(2)); }
private void AddImmediateRiskNotifications(ChecklistViewModel checklistViewModel) { foreach( ImmediateRiskNotificationViewModel irn in checklistViewModel.ImmediateRiskNotifications) { ImmediateRiskNotificationPlanItem item = new ImmediateRiskNotificationPlanItem() { SignificantHazardIdentified = irn.SignificantHazard, RecommendedImmediateAction = irn.RecommendedImmediate, AllocatedTo = checklistViewModel.SiteVisit.PersonSeen == null ? String.Empty : checklistViewModel.SiteVisit.PersonSeen.Name }; _model.ImmediateRiskNotifications.Add( item); } }
private int AddQuestionsToActionPlan(ChecklistViewModel checklistViewModel, string title, int index) { var questions = checklistViewModel.Questions .Where( x => x.Answer != null && GetSelectedResponse(x) != null && GetSelectedResponse(x).Title == title ) .OrderBy( x => GetTimescalePriority(x.Answer.Timescale)) .ThenBy(x => x.CategoryNumber) .ThenBy(x => x.QuestionNumber) .ToList(); questions.ForEach(x =>{ index++; _model.ActionPlanItems.Add(CreateActionPlanItem(x, index)); }); return index; }
private void AddActionPlanItems(ChecklistViewModel checklistViewModel) { int index = 0; index = AddQuestionsToActionPlan(checklistViewModel, "Unacceptable", index); AddQuestionsToActionPlan(checklistViewModel, "Improvement Required", index); }
public void Given_all_question_template_has_been_selected_Then_all_questions_returned_in_compliance_review_items() { var checklistViewModel = new ChecklistViewModel(); checklistViewModel.Questions.Add(CreateQuestionAnswerViewModel(ACCEPTABLE_RESPONSE)); checklistViewModel.Questions.Add(CreateQuestionAnswerViewModel(ACCEPTABLE_RESPONSE)); checklistViewModel.Questions.Add(CreateQuestionAnswerViewModel(IMPROVEMENT_REQUIRED_RESPONSE)); checklistViewModel.Questions.Add(CreateQuestionAnswerViewModel(UNACCEPTABLE_RESPONSE)); checklistViewModel.Questions.Add(CreateQuestionAnswerViewModel(NOT_APPLICABLE_RESPONSE)); checklistViewModel.AllQuestionTemplate = true; var target = GetTarget(); var result = target.GetViewModel(checklistViewModel); Assert.That(result.ComplianceReviewItems.Count, Is.EqualTo(5)); }
public void Given_mixed_responses_then_only_acceptable_answers_shown_in_compliance_review() { var checklistViewModel = new ChecklistViewModel(); checklistViewModel.Questions.Add(CreateQuestionAnswerViewModel(ACCEPTABLE_RESPONSE)); checklistViewModel.Questions.Add(CreateQuestionAnswerViewModel(ACCEPTABLE_RESPONSE)); checklistViewModel.Questions.Add(CreateQuestionAnswerViewModel(IMPROVEMENT_REQUIRED_RESPONSE)); checklistViewModel.Questions.Add(CreateQuestionAnswerViewModel(UNACCEPTABLE_RESPONSE)); checklistViewModel.Questions.Add(CreateQuestionAnswerViewModel(NOT_APPLICABLE_RESPONSE)); var target = GetTarget(); var result = target.GetViewModel(checklistViewModel); Assert.That(result.ComplianceReviewItems.Count, Is.EqualTo(2)); }
private void AddActionPlanItems(ChecklistViewModel checklistViewModel) { var unacceptableResponses = GetQuestionsByResponseTitle(checklistViewModel, "Unacceptable").ToList(); var improvementRequiredResponses = GetQuestionsByResponseTitle(checklistViewModel, "Improvement Required").ToList(); unacceptableResponses.ForEach(x => { _model.ActionPlanItems.Add(CreateActionPlanItem(x, ResponseType.Unacceptable)); }); improvementRequiredResponses.ForEach(x => { _model.ActionPlanItems.Add(CreateActionPlanItem(x, ResponseType.ImprovementRequired)); }); // AddQuestionsToActionPlan(checklistViewModel, "Unacceptable"); // AddQuestionsToActionPlan(checklistViewModel, "Improvement Required"); }
public void Given_a_question_has_been_allocated_to_a_nonemployee_then_an_ActionPlanItem_is_created_with_allocatedTo_nonemployeename() { var checklistViewModel = new ChecklistViewModel(); QuestionAnswerViewModel model = CreateQuestionAnswerViewModel(IMPROVEMENT_REQUIRED_RESPONSE); model.Answer.AssignedTo = new AssignedToViewModel() { Id = Guid.NewGuid(), // redundant, as no employees in database NonEmployeeName = "Norman Notemployedhere" }; checklistViewModel.Questions.Add(model); var target = GetTarget(); var result = target.GetViewModel(checklistViewModel); Assert.AreEqual(model.Answer.AssignedTo.NonEmployeeName, result.ActionPlanItems[0].AllocatedTo); }
private void AddSiteVisitDetails(ChecklistViewModel checklistViewModel) { if (checklistViewModel.SiteVisit != null) { if (checklistViewModel.SiteVisit.PersonSeen != null) { _model.PersonSeen = checklistViewModel.SiteVisit.PersonSeen.Name; } if (!string.IsNullOrEmpty(checklistViewModel.SiteVisit.VisitDate)) { _model.VisitDate = DateTime.Parse(checklistViewModel.SiteVisit.VisitDate); } _model.AreasVisited = checklistViewModel.SiteVisit.AreasVisited; _model.AreasNotVisited = checklistViewModel.SiteVisit.AreasNotVisited; } }
public void Given_a_question_answer_is_null_then_an_item_will_still_NOT_be_added_to_compliance_review_items() { var checklistViewModel = new ChecklistViewModel(); checklistViewModel.Questions.Add(CreateQuestionAnswerViewModel(UNACCEPTABLE_RESPONSE)); checklistViewModel.Questions[0].Answer = null; var target = GetTarget(); var result = target.GetViewModel(checklistViewModel); Assert.AreEqual(0, result.ComplianceReviewItems.Count); }
public void Given_a_question_has_been_answered_as_improvement_required_then_the_ActionPlanItem_status_should_equal_FurtherActionRequired() { var checklistViewModel = new ChecklistViewModel(); checklistViewModel.Questions.Add(CreateQuestionAnswerViewModel(IMPROVEMENT_REQUIRED_RESPONSE)); var target = GetTarget(); var result = target.GetViewModel(checklistViewModel); Assert.That(result.ActionPlanItems[0].Status, Is.EqualTo(ComplianceReviewItemStatus.FurtherActionRequired)); }
public void Given_a_question_has_been_answered_as_Improvement_Required_then_an_ActionPlanItem_is_created() { var checklistViewModel = new ChecklistViewModel(); checklistViewModel.Questions.Add(CreateQuestionAnswerViewModel(IMPROVEMENT_REQUIRED_RESPONSE)); var target = GetTarget(); var result = target.GetViewModel(checklistViewModel); Assert.That(result.ActionPlanItems.Count, Is.EqualTo(1)); }
public void Given_a_question_has_been_answered_as_acceptable_then_the_ComplianceReviewItem_status_should_equal_Satisfactory() { var checklistViewModel = new ChecklistViewModel(); checklistViewModel.Questions.Add(CreateQuestionAnswerViewModel(ACCEPTABLE_RESPONSE)); var target = GetTarget(); var result = target.GetViewModel(checklistViewModel); Assert.That(result.ComplianceReviewItems[0].Status, Is.EqualTo(ComplianceReviewItemStatus.Satisfactory)); }
public void Given_a_question_has_been_allocated_to_a_user_then_an_ActionPlanItem_is_created_with_allocatedTo_set_correctly() { var checklistViewModel = new ChecklistViewModel(); Guid employeeId = Guid.NewGuid(); Employee employee = new Employee() { Id = employeeId, Forename = "Benny", Surname = "Hill" }; string employeeFullName = employee.Forename + " " + employee.Surname; _employeeRepository.Setup(x => x.GetById( employeeId )) .Returns(employee); QuestionAnswerViewModel model = CreateQuestionAnswerViewModel(IMPROVEMENT_REQUIRED_RESPONSE); model.Answer.AssignedTo = new AssignedToViewModel() { Id = employeeId, NonEmployeeName = String.Empty }; checklistViewModel.Questions.Add(model); var target = GetTarget(); var result = target.GetViewModel(checklistViewModel); Assert.AreEqual( employeeFullName, result.ActionPlanItems[0].AllocatedTo); }
private void AddComplianceReviewItems(ChecklistViewModel checklistViewModel) { checklistViewModel.Questions.Where( x => ((x.Answer != null && GetSelectedResponse(x) != null && GetSelectedResponse(x).Title != "Not Applicable") || !IsQuestionAnswered(x)) ) .OrderBy(x=>x.CategoryNumber) .ThenBy(x=>x.QuestionNumber) .ToList() .ForEach(questionAnswer => { ComplianceReviewItem reviewItem = new ComplianceReviewItem() { QuestionText = questionAnswer.Question.Text, CategoryName = questionAnswer.Question.Category == null ? String.Empty : questionAnswer.Question.Category.Title, CategoryNumber = questionAnswer.CategoryNumber, QuestionNumber = questionAnswer.QuestionNumber, }; if (questionAnswer.Answer != null && GetSelectedResponse(questionAnswer) != null) { reviewItem.SupportingEvidence = questionAnswer.Answer.SupportingEvidence; reviewItem.ActionRequired = questionAnswer.Answer.ActionRequired; reviewItem.Status = ComplianceReviewItemStatus(questionAnswer); } _model.ComplianceReviewItems.Add(reviewItem); }); }
public void Given_a_question_has_been_answered_as_unacceptable_but_has_timescale_null_then_the_action_Plan_item_has_empty_Timescale_string() { var checklistViewModel = new ChecklistViewModel(); checklistViewModel.Questions.Add(CreateQuestionAnswerViewModel(UNACCEPTABLE_RESPONSE)); checklistViewModel.Questions[0].Answer.Timescale =null; var target = GetTarget(); var result = target.GetViewModel(checklistViewModel); Assert.AreEqual(String.Empty, result.ActionPlanItems[0].TargetTimescale); }
public void Given_a_question_answer_is_null_then_no_action_Plan_items_will_be_returned() { var checklistViewModel = new ChecklistViewModel(); checklistViewModel.Questions.Add(CreateQuestionAnswerViewModel(UNACCEPTABLE_RESPONSE)); checklistViewModel.Questions[0].Answer = null; var target = GetTarget(); var result = target.GetViewModel(checklistViewModel); Assert.AreEqual(0, result.ActionPlanItems.Count); }
private void ParseAllQuestions(ChecklistViewModel checklistViewModel) { // For all questions template, put all questions in Compliance review items var questions = checklistViewModel.Questions.Where( x => !x.Question.Deleted ); questions .OrderBy(x => x.CategoryNumber) .ThenBy(x => x.QuestionNumber) .ToList() .ForEach(questionAnswer => { var reviewItem = new ComplianceReviewItem(); reviewItem.QuestionText = questionAnswer.Question.Text; reviewItem.CategoryName = questionAnswer.Question.Category == null ? String.Empty : questionAnswer.Question.Category.Title; reviewItem.CategoryNumber = questionAnswer.CategoryNumber; reviewItem.QuestionNumber = questionAnswer.QuestionNumber; if (questionAnswer.Answer != null && GetSelectedResponse(questionAnswer) != null) { reviewItem.SupportingDocumentationStatus = questionAnswer.Answer.SupportingDocumentationStatus; reviewItem.SupportingDocumentationDate = questionAnswer.Answer.SupportingDocumentationDate != null ? questionAnswer.Answer.SupportingDocumentationDate.Value.ToLocalTime().ToString("dd/MM/yyyy") : null; reviewItem.SupportingEvidence = questionAnswer.Answer.SupportingEvidence; reviewItem.ActionRequired = questionAnswer.Answer.ActionRequired; reviewItem.Status = ComplianceReviewItemStatus(questionAnswer); } _model.ComplianceReviewItems.Add(reviewItem); }); }
public void Given_a_question_has_been_answered_as_unacceptable_then_the_ActionPlanItem_status_should_equal_ImmediateActionRequired() { var checklistViewModel = new ChecklistViewModel(); checklistViewModel.Questions.Add(CreateQuestionAnswerViewModel(UNACCEPTABLE_RESPONSE)); var target = GetTarget(); var result = target.GetViewModel(checklistViewModel); Assert.That(result.ActionPlanItems[0].Status, Is.EqualTo(ComplianceReviewItemStatus.ImmediateActionRequired)); }
public void Given_a_question_has_been_answered_as_Not_Applicable_then_no_ComplianceReviewItem_should_be_added() { var checklistViewModel = new ChecklistViewModel(); checklistViewModel.Questions.Add(CreateQuestionAnswerViewModel(NOT_APPLICABLE_RESPONSE)); var target = GetTarget(); var result = target.GetViewModel(checklistViewModel); Assert.AreEqual(0, result.ComplianceReviewItems.Count); }
private ChecklistViewModel CreateChecklistViewModel() { var model = new ChecklistViewModel() { Id = Guid.NewGuid(), ClientId = 55881, SiteId = 1331348, Site = new SiteViewModel() {Id = 222, Address1 = "Address", Postcode = "MA 1AA"}, CoveringLetterContent = "Letter content", Questions = new List<QuestionAnswerViewModel>(), Categories = new List<CategoryQuestionAnswerViewModel>(), CreatedOn = DateTime.Now, Status = "Draft", SiteVisit = new SiteVisitViewModel() { AreasVisited = "Areas Visited", AreasNotVisited = "Areas Not Visited", EmailAddress = "email", PersonSeen = new PersonSeenViewModel() {JobTitle = "Job", Name = "Name", Salutation = "Salutatiuon"}, SelectedImpressionType = new ImpressionTypeViewModel() {Id = Guid.NewGuid()}, VisitBy = "VisitBy", VisitDate = "10/10/2013", VisitType = "Visit Type" }, ImmediateRiskNotifications = new List<ImmediateRiskNotificationViewModel>(), Submit = false, CreatedBy = "John Smithy" }; GetQuestions(150) .ToList() .ForEach(x => model.Questions.Add(CreateQuestionAnswerViewModel(x))); return model; }