public void Given_a_checklist_then_the_answers_are_correctly_mapped_to_the_view_model() { //GIVEN var id = Guid.NewGuid(); var checklist = new Checklist(); var category = Category.Create(Guid.NewGuid(), "Category A"); var questions = new Question[] { Question.Create(Guid.NewGuid(), "Question One", category, false, new UserForAuditing()) }; var answer = ChecklistAnswer.Create(questions.First()); answer.SupportingEvidence = "this is the answer comment"; answer.ActionRequired = "this is the answer comment"; answer.Timescale = new Timescale() { Id = 123, Name = "Fred Flintstone" }; answer.Response = new QuestionResponse() {Id = Guid.NewGuid()}; answer.QaSignedOffBy = "abc"; answer.AreaOfNonCompliance = "You have 3 seconds to comply"; answer.SupportingDocumentationDate = DateTime.Now.AddDays(15); answer.SupportingDocumentationStatus = "Verified"; //checklist.UpdateQuestions(questions, new UserForAuditing()); checklist.Questions.Add(new ChecklistQuestion{ Checklist = checklist, Question = questions[0]}); checklist.Answers.Add(answer); checklistRepo.Setup(x => x.GetById(It.IsAny<Guid>())) .Returns(checklist); //when var target = new ChecklistController(dependencyFactory.Object); var result = target.GetChecklist(id); //THEN Assert.That(result.Questions.First().Answer.QuestionId, Is.EqualTo(answer.Question.Id)); Assert.That(result.Questions.First().Answer.SupportingEvidence, Is.EqualTo(answer.SupportingEvidence)); Assert.That(result.Questions.First().Answer.ActionRequired, Is.EqualTo(answer.ActionRequired)); Assert.That(result.Questions.First().Answer.SelectedResponseId, Is.EqualTo(answer.Response.Id)); Assert.That(result.Questions.First().Answer.GuidanceNotes, Is.EqualTo(answer.Response.GuidanceNotes)); Assert.That(result.Questions.First().Answer.Timescale.Id, Is.EqualTo(answer.Timescale.Id)); Assert.That(result.Questions.First().Answer.Timescale.Name, Is.EqualTo(answer.Timescale.Name)); Assert.That(result.Questions.First().Answer.QaSignedOffBy, Is.EqualTo(answer.QaSignedOffBy)); Assert.That(result.Questions.First().Answer.AreaOfNonCompliance, Is.EqualTo(answer.AreaOfNonCompliance)); Assert.That(result.Questions.First().Answer.SupportingDocumentationStatus, Is.EqualTo(answer.SupportingDocumentationStatus)); Assert.That(result.Questions.First().Answer.SupportingDocumentationDate, Is.EqualTo(answer.SupportingDocumentationDate.ToUniversalTime())); }
public void When_GetChecklist_is_called_With_Duplicate_Possible_Responses_For_Question_Database_Then_Only_Return_One_Instance_Of_Each() { //GIVEN var id = Guid.NewGuid(); var questionId = Guid.NewGuid(); var checklist = new Checklist(); var possibleResponseId = Guid.NewGuid(); var category = Category.Create(Guid.NewGuid(), "Category A"); var questions = new Question[] { Question.Create(questionId, "Question One", category, false, new UserForAuditing()), Question.Create(questionId, "Question one", category, false, new UserForAuditing()) }; var questionResponse1 = new QuestionResponse() {Id = possibleResponseId, Title = "Acceptable"}; var questionResponse2 = new QuestionResponse() {Id = possibleResponseId, Title = "Acceptable"}; questions.First().PossibleResponses.Add(questionResponse1); questions.First().PossibleResponses.Add(questionResponse2); var checklistQuestions = new ChecklistQuestion() { Id = questionId, Checklist = checklist, Question = questions.First() }; foreach (var question in questions) { checklist.Questions.Add(new ChecklistQuestion { Checklist = checklist, Question = question }); } checklist.Questions.Add(checklistQuestions); checklistRepo.Setup(x => x.GetById(It.IsAny<Guid>())) .Returns(checklist); //when var target = new ChecklistController(dependencyFactory.Object); var result = target.GetChecklist(id); //THEN Assert.That(result.Questions.First().Question.PossibleResponses.Count, Is.EqualTo(1)); }
public void Given_a_checklist_Where_assigned_to_id_is_null_and_employee_notlisted_is_not_null_then_assigned_to_should_return_non_employee_name() { //GIVEN var id = Guid.NewGuid(); var checklist = new Checklist(); var category = Category.Create(Guid.NewGuid(), "Category A"); var questions = new Question[] { Question.Create(Guid.NewGuid(), "Question One", category, false, new UserForAuditing()) }; var answer = ChecklistAnswer.Create(questions.First()); answer.AssignedTo = null; answer.EmployeeNotListed = "Benny Hill"; //checklist.UpdateQuestions(questions, new UserForAuditing()); checklist.Questions.Add(new ChecklistQuestion { Checklist = checklist, Question = questions[0] }); checklist.Answers.Add(answer); checklistRepo.Setup(x => x.GetById(It.IsAny<Guid>())) .Returns(checklist); //_favouriteChecklistRepository.Setup(x => x.Get(It.IsAny<Guid>(), It.IsAny<string>())) // .Returns(FavouriteChecklist.Create(checklist, "User")); //when var target = new ChecklistController(dependencyFactory.Object); var result = target.GetChecklist(id); //THEN Assert.AreNotEqual(null, result.Questions.First().Answer.AssignedTo); Assert.AreEqual(Guid.Empty, result.Questions.First().Answer.AssignedTo.Id); Assert.AreEqual(answer.EmployeeNotListed, result.Questions.First().Answer.AssignedTo.NonEmployeeName); }
public void Given_a_checklist_Where_assigned_to_is_a_valid_guid_and_not_empty_guid_then_assigned_to_should_return_employee_details() { //GIVEN var id = Guid.NewGuid(); var checklist = new Checklist(); var category = Category.Create(Guid.NewGuid(), "Category A"); var questions = new Question[] { Question.Create(Guid.NewGuid(), "Question One", category, false, new UserForAuditing()) }; var answer = ChecklistAnswer.Create(questions.First()); answer.AssignedTo = new Employee() { Id = Guid.NewGuid() }; answer.EmployeeNotListed = null; //checklist.UpdateQuestions(questions, new UserForAuditing()); checklist.Questions.Add(new ChecklistQuestion { Checklist = checklist, Question = questions[0] }); checklist.Answers.Add(answer); checklistRepo.Setup(x => x.GetById(It.IsAny<Guid>())) .Returns(checklist); //when var target = new ChecklistController(dependencyFactory.Object); var result = target.GetChecklist(id); //THEN Assert.AreNotEqual(null, result.Questions.First().Answer.AssignedTo); Assert.AreEqual(answer.AssignedTo.Id, result.Questions.First().Answer.AssignedTo.Id); }
public void Given_a_checklist_then_the_questions_are_correctly_mapped_to_the_view_model() { //GIVEN var id = Guid.NewGuid(); var checklist = new Checklist(); var category = Category.Create(Guid.NewGuid(), "Category A"); var questions = new Question[] { Question.Create(Guid.NewGuid(), "Question One", category, false, new UserForAuditing()) }; //checklist.UpdateQuestions(questions, new UserForAuditing()); checklist.Questions.Add(new ChecklistQuestion { Checklist = checklist, Question = questions[0] }); checklistRepo.Setup(x => x.GetById(It.IsAny<Guid>())) .Returns(checklist); //when var target = new ChecklistController(dependencyFactory.Object); var result = target.GetChecklist(id); //THEN Assert.That(result.Questions.First().Question.Id, Is.EqualTo(questions.First().Id)); Assert.That(result.Questions.First().Question.Text, Is.EqualTo(questions.First().Title)); Assert.That(result.Questions.First().Question.CategoryId, Is.EqualTo(questions.First().Category.Id)); Assert.That(result.Questions.First().Question.Category.Id, Is.EqualTo(questions.First().Category.Id)); }