public AddEditQuestionViewModel Get(Guid id) { var question = _questionRepo.GetById(id); var questionViewModel = new AddEditQuestionViewModel(); questionViewModel.Id = question.Id; questionViewModel.Text = question.Title; questionViewModel.Mandatory = question.Mandatory; questionViewModel.AcceptableEnabled = question.IsAcceptableAnswerEnabled; questionViewModel.UnacceptableEnabled = question.IsUnacceptableAnswerEnabled; questionViewModel.ImprovementRequiredEnabled = question.IsImprovementRequiredAnswerEnabled; questionViewModel.NotApplicableEnabled = question.IsNotApplicableAnswerEnabled; questionViewModel.CategoryId = question.Category.Id; questionViewModel.Deleted = question.Deleted; questionViewModel.SupportingEvidence = question.SupportingEvidence; questionViewModel.ActionRequired = question.ActionRequired; questionViewModel.ImprovementRequired = question.ImprovementRequired; questionViewModel.GuidanceNotes = question.GuidanceNotes; questionViewModel.OrderNumber = question.OrderNumber; questionViewModel.Industries.IndustryIds = question.Industries.Where(x=>!x.Deleted).Select(x => x.ChecklistTemplate.Id).ToList(); questionViewModel.Industries.QuestionId = question.Id; questionViewModel.AreaOfNonCompliance = question.AreaOfNonCompliance; questionViewModel.AreaOfNonComplianceHeadingId = question.AreaOfNonComplianceHeading != null ? question.AreaOfNonComplianceHeading.Id : Guid.Empty; questionViewModel.AreaOfNonComplianceHeadings = GetAreaOfNonComplianceHeadings(); questionViewModel.IndustryTemplates = _industryRepository.GetAll().Select(x => new IndustryViewModel(){Id = x.Id, Title = x.Name, Deleted = x.Deleted}).ToList(); return questionViewModel; }
public void Given_new_question_details_When_post_question_is_called_then_question_is_created_with_correct_details() { Question question = null; _questionRepository .Setup(x => x.GetById(It.IsAny<Guid>())) .Returns(() => question); Question SavedQuestion = null; _questionRepository.Setup(x => x.SaveOrUpdate(It.IsAny<Question>())) .Callback( delegate(Question x) { SavedQuestion = x; } ); var viewModel = new AddEditQuestionViewModel(); viewModel.Id = Guid.NewGuid(); viewModel.Text = "Updated Text"; ; viewModel.CategoryId = Guid.NewGuid(); viewModel.Mandatory = true; viewModel.Deleted = true; viewModel.AcceptableEnabled = true; viewModel.UnacceptableEnabled = true; viewModel.ImprovementRequiredEnabled = true; viewModel.NotApplicableEnabled = true; viewModel.GuidanceNotes = "1231243"; viewModel.ActionRequired = "the new action required"; viewModel.SupportingEvidence = "the new supporting evidence"; viewModel.ImprovementRequired = "the new improvement required text"; viewModel.OrderNumber = 131; viewModel.GuidanceNotes = "12.415.4"; _categoryRepository .Setup(x => x.GetById(viewModel.CategoryId)) .Returns(() => new Category() { Id = viewModel.CategoryId, Title = "abc" }); var controller = GetTarget(); var response = controller.PostQuestion(viewModel); Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK)); Assert.That(SavedQuestion.Title, Is.EqualTo(viewModel.Text)); Assert.That(SavedQuestion.Category.Id, Is.EqualTo(viewModel.CategoryId)); Assert.That(SavedQuestion.Mandatory, Is.EqualTo(viewModel.Mandatory)); Assert.That(SavedQuestion.OrderNumber, Is.EqualTo(viewModel.OrderNumber)); Assert.That(SavedQuestion.Deleted, Is.EqualTo(viewModel.Deleted)); Assert.That(SavedQuestion.IsAcceptableAnswerEnabled, Is.EqualTo(viewModel.AcceptableEnabled)); Assert.That(SavedQuestion.IsImprovementRequiredAnswerEnabled, Is.EqualTo(viewModel.ImprovementRequiredEnabled)); Assert.That(SavedQuestion.IsUnacceptableAnswerEnabled, Is.EqualTo(viewModel.UnacceptableEnabled)); Assert.That(SavedQuestion.IsNotApplicableAnswerEnabled, Is.EqualTo(viewModel.NotApplicableEnabled)); Assert.That(SavedQuestion.SupportingEvidence, Is.EqualTo(viewModel.SupportingEvidence)); Assert.That(SavedQuestion.ImprovementRequired, Is.EqualTo(viewModel.ImprovementRequired)); Assert.That(SavedQuestion.ActionRequired, Is.EqualTo(viewModel.ActionRequired)); Assert.That(SavedQuestion.GuidanceNotes, Is.EqualTo(viewModel.GuidanceNotes)); }
public HttpResponseMessage PostQuestion(AddEditQuestionViewModel model) { var question = _questionRepo.GetById(model.Id); var user = _userForAuditingRepository.GetSystemUser(); var category = _categoryRepo.GetById(model.CategoryId); var areaOfNonComplianceHeading = _reportLetterStatementCategoryRepo.GetById(model.AreaOfNonComplianceHeadingId); if (question == null) { question = Question.Create(model.Id, model.Text, category, false, user); } else { question.Update(model.Text, model.Mandatory, category, model.Deleted, user); } question.Deleted = model.Deleted; question.Mandatory = model.Mandatory; question.OrderNumber = model.OrderNumber; question.SupportingEvidence = model.SupportingEvidence; question.ImprovementRequired = model.ImprovementRequired; question.ActionRequired = model.ActionRequired; question.IsAcceptableAnswerEnabled = model.AcceptableEnabled; question.IsUnacceptableAnswerEnabled = model.UnacceptableEnabled; question.IsImprovementRequiredAnswerEnabled = model.ImprovementRequiredEnabled; question.IsNotApplicableAnswerEnabled = model.NotApplicableEnabled; question.GuidanceNotes = model.GuidanceNotes; question.AreaOfNonCompliance = model.AreaOfNonCompliance; question.AreaOfNonComplianceHeading = areaOfNonComplianceHeading; foreach( Guid industryId in model.Industries.IndustryIds ) { question.AddIndustry( _industryRepository.GetById( industryId ), user); } question.Industries.Where(x => !model.Industries.IndustryIds.Contains(x.ChecklistTemplate.Id)) .ToList() .ForEach(x => question.RemoveIndustry(x.ChecklistTemplate, user)); _questionRepo.SaveOrUpdate(question); return Request.CreateResponse(HttpStatusCode.OK); }
public void Given_question_with_no_responses_When_post_question_is_called_then_responsedetails_added() { var question = GetQuestion(); question.PossibleResponses.Clear(); _questionRepository .Setup(x => x.GetById(question.Id)) .Returns(() => question); Question SavedQuestion = null; _questionRepository.Setup(x => x.SaveOrUpdate(It.IsAny<Question>())) .Callback( delegate(Question x) { SavedQuestion = x; } ); var viewModel = new AddEditQuestionViewModel(); viewModel.Id = question.Id; viewModel.Text = "Updated Text"; viewModel.CategoryId = Guid.NewGuid(); viewModel.Mandatory = true; viewModel.Deleted = true; viewModel.AcceptableEnabled = true; viewModel.UnacceptableEnabled = true; viewModel.ImprovementRequiredEnabled = true; viewModel.NotApplicableEnabled = true; viewModel.GuidanceNotes = "1231243"; _categoryRepository .Setup(x => x.GetById(viewModel.CategoryId)) .Returns(() => new Category() {Id = viewModel.CategoryId, Title = "abc"}); _userForAuditingRepository .Setup(x => x.GetSystemUser()) .Returns(new BusinessSafe.Domain.Entities.UserForAuditing {CompanyId = 1234L, Id = Guid.NewGuid()}); var controller = GetTarget(); var response = controller.PostQuestion(viewModel); Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK)); Assert.That(SavedQuestion.IsAcceptableAnswerEnabled, Is.EqualTo(viewModel.AcceptableEnabled)); Assert.That(SavedQuestion.IsImprovementRequiredAnswerEnabled, Is.EqualTo(viewModel.ImprovementRequiredEnabled)); Assert.That(SavedQuestion.IsUnacceptableAnswerEnabled, Is.EqualTo(viewModel.UnacceptableEnabled)); Assert.That(SavedQuestion.IsNotApplicableAnswerEnabled, Is.EqualTo(viewModel.NotApplicableEnabled)); }
public void Given_question_details_with_industries_When_post_question_is_called_then_industries_removed() { List<ChecklistTemplate> industries = new List<ChecklistTemplate>(); industries.Add( new ChecklistTemplate(){Id = Guid.NewGuid()}); industries.Add( new ChecklistTemplate(){Id = Guid.NewGuid()}); industries.Add( new ChecklistTemplate(){Id = Guid.NewGuid()}); var question = GetQuestion(); question.AddIndustry( industries[0], null); question.AddIndustry( industries[1], null); question.AddIndustry( industries[2], null); _questionRepository .Setup(x => x.GetById(question.Id)) .Returns(() => question); Question SavedQuestion = null; _questionRepository.Setup(x => x.SaveOrUpdate(It.IsAny<Question>())) .Callback( delegate(Question x) { SavedQuestion = x; } ); var viewModel = new AddEditQuestionViewModel(); viewModel.Id = question.Id; viewModel.Text = "Updated Text"; ; viewModel.CategoryId = Guid.NewGuid(); viewModel.Mandatory = true; viewModel.Deleted = true; viewModel.AcceptableEnabled = true; viewModel.UnacceptableEnabled = true; viewModel.ImprovementRequiredEnabled = true; viewModel.NotApplicableEnabled = true; viewModel.GuidanceNotes = "1231243"; viewModel.ActionRequired = "the new action required"; viewModel.SupportingEvidence = "the new supporting evidence"; viewModel.ImprovementRequired = "the new improvement required text"; viewModel.OrderNumber = 131; viewModel.GuidanceNotes = "12.415.4"; viewModel.Industries.IndustryIds.Add(industries[0].Id); viewModel.Industries.IndustryIds.Add(industries[2].Id); _categoryRepository .Setup(x => x.GetById(viewModel.CategoryId)) .Returns(() => new Category() { Id = viewModel.CategoryId, Title = "abc" }); var controller = GetTarget(); var response = controller.PostQuestion(viewModel); Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK)); Assert.That(SavedQuestion.Industries.Count(x => !x.Deleted) , Is.EqualTo(2)); Assert.That(SavedQuestion.Industries.Count(x => x.Deleted), Is.EqualTo(1)); }