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);
            }
        }
Пример #2
0
        public ActionResult SubmitDetails(ContactUsWithDobPostcodeViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                if (SessionDataValid())
                {
                    var data   = sessionStorage.Get();
                    var result = asyncHelper.Synchronise(() => sendEmailService.SendEmailAsync(new ContactUsRequest
                    {
                        FirstName                  = viewModel.Firstname,
                        Email                      = viewModel.EmailAddress,
                        TemplateName               = TemplateName,
                        LastName                   = viewModel.Lastname,
                        Message                    = data.ContactAnAdviserFeedback?.Message,
                        TermsAndConditions         = viewModel.AcceptTermsAndConditions,
                        Postcode                   = viewModel.Postcode,
                        ContactOption              = data.ContactUsOption?.ContactOptionType.ToString(),
                        ContactAdviserQuestionType = data.ContactAnAdviserFeedback?.ContactAdviserQuestionType.ToString(),
                        DateOfBirth                = viewModel.DateOfBirth
                    }));

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

                    return(Redirect(FailurePage));
                }

                return(Redirect(ContactOptionPage));
            }

            SetupDobViewModelDefaults(viewModel);

            return(View("ContactAdvisor", viewModel));
        }
        public ActionResult Index(SendGridViewModel viewModel)
        {
            var result = asyncHelper.Synchronise(() => sendEmailService.SendEmailAsync(new ContactUsRequest
            {
                FirstName     = viewModel.FirstName,
                Email         = viewModel.EmailAddress,
                TemplateName  = viewModel.TemplateName,
                LastName      = viewModel.LastName,
                ContactOption = viewModel.ContactOption,
                ContactAdviserQuestionType = viewModel.ContactAdviserQuestionType,
                DateOfBirth          = viewModel.DateOfBirth,
                FeedbackQuestionType = viewModel.FeedbackQuestionType,
                Message            = viewModel.Message,
                IsContactable      = viewModel.IsContactable,
                Postcode           = viewModel.Postcode,
                TermsAndConditions = viewModel.AcceptTermsAndConditions
            }));

            viewModel.SendResult = JsonConvert.SerializeObject(result);

            return(View("SendResult", viewModel));
        }