Esempio n. 1
0
        public void IndexUrlNameTest()
        {
            //Setup the fakes and dummies
            var loggerFake        = A.Fake <IApplicationLogger>();
            var govUkNotify       = A.Fake <IGovUkNotify>(ops => ops.Strict());
            var fakeWebAppContext = A.Fake <IWebAppContext>(ops => ops.Strict());

            // Set up calls
            A.CallTo(() => govUkNotify.SubmitEmail(A <string> ._, null)).Returns(false);

            //Instantiate & Act
            var vocSurveyController = new VocSurveyController(govUkNotify, fakeWebAppContext, loggerFake)
            {
                EmailSentText      = nameof(VocSurveyController.EmailSentText),
                EmailNotSentText   = nameof(VocSurveyController.EmailNotSentText),
                DoNotHaveEmailText = nameof(VocSurveyController.DoNotHaveEmailText),
                AgeLimitText       = nameof(VocSurveyController.AgeLimitText),
                FormIntroText      = nameof(VocSurveyController.FormIntroText),
            };

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

            //Assert
            indexMethodCall.ShouldRenderDefaultView();
            A.CallTo(() => govUkNotify.SubmitEmail(A <string> ._, A <VocSurveyPersonalisation> ._)).MustNotHaveHappened();
        }
Esempio n. 2
0
        public void SendEmailTest(string emailAddress, object key, object value, bool returnValue)
        {
            //Setup the fakes and dummies
            var loggerFake        = A.Fake <IApplicationLogger>();
            var webAppContextFake = A.Fake <IWebAppContext>(ops => ops.Strict());
            var govUkNotifyFake   = A.Fake <IGovUkNotify>(ops => ops.Strict());

            // Create NotifyUK Dictionary
            var vocSurveyPersonalisationn = new VocSurveyPersonalisation {
                Personalisation = new Dictionary <string, string>()
            };

            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(() => webAppContextFake.GetVocCookie(Constants.VocPersonalisationCookieName)).Returns(vocSurveyPersonalisationn);
            A.CallTo(() => govUkNotifyFake.SubmitEmail(emailAddress, vocSurveyPersonalisationn)).Returns(returnValue);

            //Instantiate & Act
            var vocSurveyController = new VocSurveyController(govUkNotifyFake, webAppContextFake, loggerFake);

            //Act
            var sendEmailMethodCall = vocSurveyController.WithCallTo(c => c.SendEmail(emailAddress));

            //Assert
            sendEmailMethodCall.ShouldReturnJson().Should().BeEquivalentTo(new JsonResult {
                Data = returnValue
            });
            A.CallTo(() => webAppContextFake.GetVocCookie(Constants.VocPersonalisationCookieName)).MustHaveHappened();
            A.CallTo(() => govUkNotifyFake.SubmitEmail(emailAddress, vocSurveyPersonalisationn)).MustHaveHappened();
        }
Esempio n. 3
0
        public void IndexTest()
        {
            //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());

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

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

            //Assert
            indexMethodCall.ShouldRenderDefaultView();
            A.CallTo(() => govUkNotify.SubmitEmail(A <string> ._, A <VocSurveyPersonalisation> ._)).MustNotHaveHappened();
        }
Esempio n. 4
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();
            }
        }