public void CreatePdfGet_GivenAssessmentId_PdfCreationProviderShouldBeCalled() { var assessmentId = Guid.NewGuid(); var assessment = new Assessment(); PdfDocument pdfDocumentGenerated; A.CallTo(() => _assessmentHelper.GetAssessment(assessmentId)).Returns(assessment); var model = new QuestionAnswerListViewModel(); A.CallTo(() => _questionAnswerViewModelBuilder.BuildQuestionAnswerListViewModel(A <QuestionAnswers> ._)).Returns(model); _assessmentController.CreatePdf(assessmentId, A <string> ._); A.CallTo(() => _pdfCreationProvider.CreatePdfForAssessment(assessment, out pdfDocumentGenerated)).MustHaveHappened(Repeated.Exactly.Once); }
private void AddSectionInformation(QuestionAnswerListViewModel questionAnswers) { if (questionAnswers.Items != null) { foreach (var questionAnswer in questionAnswers.Items) { if (_currentStage != questionAnswer.StageDescription) { _currentStage = questionAnswer.StageDescription; _pdfHelper.AddLine(false); _pdfHelper.AddTitle(_currentStage, false); _pdfHelper.AddLine(); } _pdfHelper.AddLine(false); _pdfHelper.AddTitle(questionAnswer.Question); _pdfHelper.AddLine(); if (string.IsNullOrEmpty(questionAnswer.Answer)) { _pdfHelper.WriteText(questionAnswer.FurtherInformation); } else { var questionAnswerText = questionAnswer.Answer; if (!string.IsNullOrWhiteSpace(questionAnswer.FurtherInformation)) { questionAnswerText += ". " + questionAnswer.FurtherInformation; } _pdfHelper.WriteText(questionAnswerText); } } } }
public QuestionAnswerListViewModel BuildQuestionAnswerListViewModel(QuestionAnswers questionAnswers) { if (questionAnswers == null) { throw new ArgumentNullException("questionAnswers"); } var questionAnswerViewModels = new List <QuestionAnswerViewModel>(); foreach (var questionAnswer in questionAnswers.Items) { var questionAnswerViewModel = Mapper.DynamicMap <QuestionAnswer, QuestionAnswerViewModel>(questionAnswer); questionAnswerViewModel.Question = questionAnswer.WorkflowQuestion.Question.Description; questionAnswerViewModel.StageDescription = questionAnswer.WorkflowQuestion.WorkflowStage.Description; questionAnswerViewModel.Answer = questionAnswer.QuestionOption.Option.Description.Contains("Single option") ? string.Empty : questionAnswer.QuestionOption.Option.Description; questionAnswerViewModel.FurtherInformation = questionAnswer.FurtherInformation ?? string.Empty; questionAnswerViewModels.Add(questionAnswerViewModel); } var viewModel = new QuestionAnswerListViewModel { Items = questionAnswerViewModels }; return(viewModel); }
public void CreatePdfForAssessment_CalledWithValidAssessment_ShouldCreatePdfContainingSectionInformation() { PdfDocument pdfDocumentCreated; var questionAnswersList = new List <QuestionAnswer> { new QuestionAnswer() { FurtherInformation = string.Empty, QuestionOption = new QuestionOption() { Question = new Question() { Description = "First Question" }, Option = new Option() { Description = "Yes" }, }, WorkflowQuestion = new WorkflowQuestion() { WorkflowStage = new WorkflowStage() { Description = "Stage 1" } } }, new QuestionAnswer() { FurtherInformation = "Further information on second question", QuestionOption = new QuestionOption() { Question = new Question() { Description = "Second Question" }, Option = new Option() { Description = "No" } }, WorkflowQuestion = new WorkflowQuestion() { WorkflowStage = new WorkflowStage() { Description = "Stage 2" } } }, new QuestionAnswer() { FurtherInformation = "Further information on third question", QuestionOption = new QuestionOption() { Question = new Question() { Description = "Third Question" }, Option = new Option() { Description = "Single option" } }, WorkflowQuestion = new WorkflowQuestion() { WorkflowStage = new WorkflowStage() { Description = "Stage 3" } } }, }; var assessment = new Assessment() { AssessmentId = Guid.NewGuid(), Stage1DecisionToBeMade = "Decision", Patient = new Patient() { FirstName = "First name", LastName = "Last name", DateOfBirth = new DateTime(1956, 1, 02), NhsNumber = 4010232137, ClinicalSystemId = "1234567890" }, AssessorName = "assessor", DateAssessmentStarted = _dateTimeProvider.Now, Role = new Role { RoleId = (int)RoleIdEnum.Assessor, Description = "A random role" }, QuestionAnswers = questionAnswersList }; var questionAnswers = new QuestionAnswers() { Items = questionAnswersList }; var viewModelList = new List <QuestionAnswerViewModel> { new QuestionAnswerViewModel() { Answer = "Yes", FurtherInformation = "", Question = "First Question", StageDescription = "Stage 1" }, new QuestionAnswerViewModel() { Answer = "No", FurtherInformation = "Further information on second question", Question = "Second Question", StageDescription = "Stage 2" }, new QuestionAnswerViewModel() { Answer = "", FurtherInformation = "Further information on third question", Question = "Third Question", StageDescription = "Stage 3" }, }; A.CallTo(() => _queryDispatcher.Dispatch <QuestionAnswersByAssessmentQuery, QuestionAnswers>(A <QuestionAnswersByAssessmentQuery> ._)).Returns(questionAnswers); var viewModels = new QuestionAnswerListViewModel() { Items = viewModelList }; A.CallTo(() => _questionAnswerViewModelBuilder.BuildQuestionAnswerListViewModel(questionAnswers)).Returns(viewModels); Assert.AreEqual(_questionAnswerViewModelBuilder.BuildQuestionAnswerListViewModel(questionAnswers), viewModels); _pdfGenerator.CreatePdfForAssessment(assessment, out pdfDocumentCreated); A.CallTo(() => _pdfHelper.AddTitle(viewModels.Items.ElementAt(0).StageDescription, false, false)).MustHaveHappened(Repeated.Exactly.Once); A.CallTo(() => _pdfHelper.AddTitle(viewModels.Items.ElementAt(0).Question, true, false)).MustHaveHappened(Repeated.Exactly.Once); A.CallTo(() => _pdfHelper.WriteText(viewModels.Items.ElementAt(0).Answer)).MustHaveHappened(Repeated.Exactly.Once); A.CallTo(() => _pdfHelper.AppendText(viewModels.Items.ElementAt(0).FurtherInformation)).MustNotHaveHappened(); A.CallTo(() => _pdfHelper.AddTitle(viewModels.Items.ElementAt(1).StageDescription, false, false)).MustHaveHappened(Repeated.Exactly.Once); A.CallTo(() => _pdfHelper.AddTitle(viewModels.Items.ElementAt(1).Question, true, false)).MustHaveHappened(Repeated.Exactly.Once); A.CallTo(() => _pdfHelper.WriteText(viewModels.Items.ElementAt(1).Answer + ". " + viewModels.Items.ElementAt(1).FurtherInformation)).MustHaveHappened(Repeated.Exactly.Once); A.CallTo(() => _pdfHelper.AddTitle(viewModels.Items.ElementAt(2).StageDescription, false, false)).MustHaveHappened(Repeated.Exactly.Once); A.CallTo(() => _pdfHelper.AddTitle(viewModels.Items.ElementAt(2).Question, true, false)).MustHaveHappened(Repeated.Exactly.Once); A.CallTo(() => _pdfHelper.WriteText(viewModels.Items.ElementAt(2).FurtherInformation)).MustHaveHappened(Repeated.Exactly.Once); }