Beispiel #1
0
 private void SetupConsentViewModelDefaults(ContactUsWithConsentViewModel viewModel)
 {
     viewModel.PageTitle                  = PageTitle;
     viewModel.PageIntroduction           = NonAdviserIntroduction;
     viewModel.DoYouWantUsToContactUsText = DoYouWantUsToContactUsText;
     viewModel.TermsAndConditionsText     = TermsAndConditionsText;
     viewModel.SendButtonText             = SendButtonText;
 }
        public void SubmitTests(bool modelStateValid, bool validSubmission, bool validSession, ContactOption contactOption)
        {
            //Assign
            var postModel = new ContactUsWithConsentViewModel();

            A.CallTo(() => fakeSendEmailService.SendEmailAsync(A <ContactUsRequest> ._)).Returns(validSubmission);
            A.CallTo(() => fakeSessionStorage.Get()).Returns(validSession ? GetSessionObject(contactOption) : null);
            A.CallTo(() => fakeSessionStorage.Remove()).DoesNothing();

            var controller = new YourDetailsController(fakeApplicationLogger, fakeSendEmailService, fakeAsyncHelper, fakeContext, fakeSessionStorage)
            {
                SuccessPage   = nameof(YourDetailsController.SuccessPage),
                FailurePage   = nameof(YourDetailsController.FailurePage),
                ContactOption = contactOption
            };

            if (!modelStateValid)
            {
                controller.ModelState.AddModelError(nameof(ContactUsWithDobPostcodeViewModel.Firstname), nameof(ContactUsWithDobPostcodeViewModel.Firstname));
            }

            //Act
            var controllerResult = controller.WithCallTo(contrl => contrl.Submit(postModel));

            //Assert
            if (modelStateValid)
            {
                if (validSession)
                {
                    A.CallTo(() => fakeSessionStorage.Get()).MustHaveHappened(2, Times.Exactly);

                    A.CallTo(() => fakeSessionStorage.Remove()).MustHaveHappened();
                    A.CallTo(() => fakeSendEmailService.SendEmailAsync(A <ContactUsRequest> ._)).MustHaveHappened();

                    if (validSubmission)
                    {
                        controllerResult.ShouldRedirectTo(controller.SuccessPage);
                    }
                    else
                    {
                        controllerResult.ShouldRedirectTo(controller.FailurePage);
                    }
                }
                else
                {
                    A.CallTo(() => fakeSessionStorage.Get()).MustHaveHappened(1, Times.Exactly);

                    controllerResult.ShouldRedirectTo(controller.ContactOptionPage);
                }
            }
            else
            {
                controllerResult.ShouldRenderView("Feedback")
                .WithModel <ContactUsWithConsentViewModel>()
                .AndModelErrorFor(model => model.Firstname);
            }
        }
Beispiel #3
0
        public ActionResult Index()
        {
            if (!SessionDataValid())
            {
                return(Redirect(ContactOptionPage));
            }

            if (ContactOption == ContactOption.ContactAdviser)
            {
                var viewModel = new ContactUsWithDobPostcodeViewModel();
                SetupDobViewModelDefaults(viewModel);
                return(View("ContactAdvisor", viewModel));
            }
            else
            {
                var viewModel = new ContactUsWithConsentViewModel();
                SetupConsentViewModelDefaults(viewModel);
                return(View("Feedback", viewModel));
            }
        }
Beispiel #4
0
        public void Dfc7630YourDetailsFeedBackViewTests()
        {
            // Arrange
            var yourDetailsIndex   = new _MVC_Views_YourDetails_Feedback_cshtml();
            var contactUsViewModel = new ContactUsWithConsentViewModel
            {
                PageIntroduction           = nameof(ContactUsWithConsentViewModel.PageIntroduction),
                DoYouWantUsToContactUsText = nameof(ContactUsWithConsentViewModel.DoYouWantUsToContactUsText),
                TermsAndConditionsText     = nameof(ContactUsWithConsentViewModel.TermsAndConditionsText),
                PageTitle = nameof(ContactUsWithConsentViewModel.PageTitle)
            };

            // Act
            var htmlDocument = yourDetailsIndex.RenderAsHtml(contactUsViewModel);

            // Assert
            AssertTagInnerTextValue(htmlDocument, contactUsViewModel.PageTitle, "h1");
            AssertTagInnerTextValue(htmlDocument, contactUsViewModel.PageIntroduction, "p");
            AssertTagInnerTextValue(htmlDocument, contactUsViewModel.DoYouWantUsToContactUsText, "h2");
            AssertTagInnerTextValue(htmlDocument, contactUsViewModel.TermsAndConditionsText, "h3");
            AssertFormGroupsCounts(htmlDocument, 7);
        }
Beispiel #5
0
        public ActionResult Submit(ContactUsWithConsentViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                if (SessionDataValid())
                {
                    var sessionData = sessionStorage.Get();
                    var result      = asyncHelper.Synchronise(() => sendEmailService.SendEmailAsync(new ContactUsRequest
                    {
                        FirstName    = viewModel.Firstname,
                        Email        = viewModel.EmailAddress,
                        TemplateName = TemplateName,
                        LastName     = viewModel.Lastname,
                        Message      = ContactOption == ContactOption.Feedback
                            ? sessionData.GeneralFeedback?.Feedback
                            : sessionData.TechnicalFeedback?.Message,
                        IsContactable        = viewModel.IsContactable,
                        TermsAndConditions   = viewModel.AcceptTermsAndConditions,
                        ContactOption        = sessionData.ContactUsOption?.ContactOptionType.ToString(),
                        FeedbackQuestionType = sessionData.GeneralFeedback?.FeedbackQuestionType.ToString()
                    }));

                    sessionStorage.Remove();
                    if (result)
                    {
                        return(Redirect(SuccessPage));
                    }

                    return(Redirect(FailurePage));
                }

                return(Redirect(ContactOptionPage));
            }

            SetupConsentViewModelDefaults(viewModel);
            return(View("Feedback", viewModel));
        }