private TechnicalFeedbackViewModel AddWidgetPropertyFields(TechnicalFeedbackViewModel model) { model.NextPage = NextPage; model.Title = Title; model.MessageLabel = MessageLabel; model.PageIntroduction = PageIntroduction; model.PersonalInformation = PersonalInformation; model.CharacterLimit = CharacterLimit; model.ContinueText = ContinueText; return(model); }
public ActionResult Index() { if (!context.IsContentAuthoringSite) { var sessionModel = sessionStorage.Get(); if (sessionModel is null || sessionModel.ContactUsOption?.ContactOptionType != ContactOption.Technical) { return(Redirect(ContactOptionPage)); } } var model = new TechnicalFeedbackViewModel(); return(View("Index", AddWidgetPropertyFields(model))); }
public void TechnicalViewTest() { // Arrange objects var technicalIndex = new _MVC_Views_Technical_Index_cshtml(); var technicalFeedbackViewModel = new TechnicalFeedbackViewModel() { Message = "Dummy message", Title = "Dummy Title", PageIntroduction = "Dummy Intro", PersonalInformation = "Dummy Personal", CharacterLimit = "Dummy Limit", MessageLabel = "Dummy Message Label" }; // Act var htmlDocument = technicalIndex.RenderAsHtml(technicalFeedbackViewModel); //Asserts var title = htmlDocument.DocumentNode.SelectNodes("h1").Where(d => d.GetAttributeValue("class", string.Empty).Contains("govuk-heading-xl")).FirstOrDefault(); title.InnerText.Should().Be(technicalFeedbackViewModel.Title); var pageIntroduction = htmlDocument.DocumentNode.SelectNodes("p").Where(d => d.GetAttributeValue("class", string.Empty).Contains("govuk-body-m")).FirstOrDefault(); pageIntroduction.InnerText.Should().Be(technicalFeedbackViewModel.PageIntroduction); var characterLimit = htmlDocument.DocumentNode.SelectNodes("//span").Where(d => d.GetAttributeValue("class", string.Empty).Contains("govuk-character-count__message")).FirstOrDefault(); characterLimit.InnerText.Should().Be(technicalFeedbackViewModel.CharacterLimit); var label = htmlDocument.DocumentNode.SelectNodes("//label").Where(d => d.GetAttributeValue("class", string.Empty).Contains("govuk-label")).FirstOrDefault(); label.InnerText.Should().Be(technicalFeedbackViewModel.MessageLabel); var personalInformation = htmlDocument.DocumentNode.SelectNodes("//span").Where(d => d.GetAttributeValue("class", string.Empty).Contains("govuk-hint")).FirstOrDefault(); personalInformation.InnerText.Should().Be(technicalFeedbackViewModel.PersonalInformation); var message = htmlDocument.DocumentNode.SelectNodes("//textarea").Where(d => d.GetAttributeValue("name", string.Empty).Equals("Message")).FirstOrDefault(); message.InnerText.Should().Contain(technicalFeedbackViewModel.Message); }
public void SubmitTests(bool validSubmission) { //Set up var technicalController = new TechnicalController(fakeApplicationLogger, fakeMapper, fakeWebAppContext, fakeSessionStorage); var technicalFeedbackViewModel = new TechnicalFeedbackViewModel() { Message = "Dummy message" }; var dummyErrorKey = "dummyErrorKey"; //if its not valid fake an error if (!validSubmission) { technicalController.ModelState.AddModelError(dummyErrorKey, "dummyErrorMessage"); } A.CallTo(() => fakeSessionStorage.Get()).Returns(new ContactUs()); A.CallTo(() => fakeMapper.Map(A <TechnicalFeedbackViewModel> ._, A <ContactUs> ._)).Returns(new ContactUs()); A.CallTo(() => fakeSessionStorage.Save(A <ContactUs> ._)).DoesNothing(); //Act var indexMethodCallResult = technicalController.WithCallTo(c => c.Index(technicalFeedbackViewModel)); //Assert if (!validSubmission) { indexMethodCallResult.ShouldRenderDefaultView() .WithModel <TechnicalFeedbackViewModel>(vm => { vm.CharacterLimit.Should().Be(technicalController.CharacterLimit); vm.MessageLabel.Should().Be(technicalController.MessageLabel); vm.PageIntroduction.Should().Be(technicalController.PageIntroduction); vm.PersonalInformation.Should().Be(technicalController.PersonalInformation); vm.Title.Should().Be(technicalController.Title); vm.NextPage.Should().Be(technicalController.NextPage); }).AndModelError(dummyErrorKey); } else { indexMethodCallResult.ShouldRedirectTo(technicalController.NextPage); } }
public ActionResult Index(TechnicalFeedbackViewModel model) { if (model == null) { throw new ArgumentNullException("model"); } if (ModelState.IsValid) { var mappedModel = mapper.Map(model, sessionStorage.Get()); sessionStorage.Save(mappedModel); return(Redirect(NextPage)); } model.Title = Title; //Put the non bound data fields back return(View("Index", AddWidgetPropertyFields(model))); }