コード例 #1
0
        public ActionResult Index(VocSurveyViewModel vocSurveyViewModel)
        {
            if (!string.IsNullOrEmpty(vocSurveyViewModel?.EmailAddress))
            {
                bool response        = SendByNotifyService(vocSurveyViewModel?.EmailAddress);
                var  resultViewModel = new EmailSubmissionViewModel
                {
                    ResponseMessage = response ? EmailSentText : EmailNotSentText
                };

                return(View("Response", resultViewModel));
            }

            return(ReturnSurveyViewModel());
        }
コード例 #2
0
        public void IndexSubmitEmailTest(string emailAddress, object key, object value, bool success)
        {
            //Setup the fakes and dummies
            var loggerFake    = A.Fake <IApplicationLogger>();
            var govUkNotify   = A.Fake <IGovUkNotify>(ops => ops.Strict());
            var webAppContext = A.Fake <IWebAppContext>(ops => ops.Strict());
            var emailRequest  = new VocSurveyViewModel {
                EmailAddress = emailAddress
            };
            var dummynotifyResponse = success;

            // Create NotifyUK Dictionary
            var vocSurveyPersonalisationn = new VocSurveyPersonalisation();

            for (var index = 0; index < ((IList)value).Count - 1; index++)
            {
                vocSurveyPersonalisationn.Personalisation.Add(((IList)key)[index].ToString(), ((IList)value)[index].ToString());
            }

            // Set up calls
            A.CallTo(() => webAppContext.GetVocCookie(Constants.VocPersonalisationCookieName)).Returns(vocSurveyPersonalisationn);
            A.CallTo(() => govUkNotify.SubmitEmail(A <string> ._, A <VocSurveyPersonalisation> ._)).Returns(dummynotifyResponse);

            //Instantiate
            var vocSurveyController = new VocSurveyController(govUkNotify, webAppContext, loggerFake);

            //Act
            var indexMethodCall = vocSurveyController.WithCallTo(c => c.Index(emailRequest));

            if (!string.IsNullOrEmpty(emailAddress))
            {
                //Assert
                indexMethodCall.ShouldRenderView("Response");

                A.CallTo(() => webAppContext.GetVocCookie(Constants.VocPersonalisationCookieName)).MustHaveHappened();
                A.CallTo(() => govUkNotify.SubmitEmail(emailAddress, A <VocSurveyPersonalisation> .That.IsSameAs(vocSurveyPersonalisationn))).MustHaveHappened();
            }
            else
            {
                //Assert
                indexMethodCall.ShouldRenderDefaultView();

                A.CallTo(() => webAppContext.GetVocCookie(Constants.VocPersonalisationCookieName)).MustNotHaveHappened();
                A.CallTo(() => govUkNotify.SubmitEmail(A <string> ._, A <VocSurveyPersonalisation> ._)).MustNotHaveHappened();
            }
        }
        private static VocSurveyViewModel GenerateVocSurveyViewModelDummy(
            string ageLimitText,
            string dontHaveEmailText,
            string emailSentText,
            string formIntroText,
            string emailNotSentText)
        {
            var result = new VocSurveyViewModel
            {
                AgeLimitText       = ageLimitText,
                DoNotHaveEmailText = dontHaveEmailText,
                EmailSentText      = emailSentText,
                FormIntroText      = formIntroText,
                EmailNotSentText   = emailNotSentText
            };

            return(result);
        }