Пример #1
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();
        }
        public Task <ServiceStatus> GetCurrentStatusAsync()
        {
            var serviceStatus = new ServiceStatus {
                Name = ServiceName, Status = ServiceState.Red, Notes = string.Empty
            };

            var emailAddress = "*****@*****.**";

            serviceStatus.CheckParametersUsed = $"Email used - {emailAddress}";
            var vocPersonalisation = new VocSurveyPersonalisation();

            vocPersonalisation.Personalisation.Add("jpprofile", "ServiceCheck");
            vocPersonalisation.Personalisation.Add("clientId", "ServiceCheck ClientId");
            try
            {
                var response = clientProxy.SendEmail(ConfigurationManager.AppSettings[Constants.GovUkNotifyApiKey], emailAddress, ConfigurationManager.AppSettings[Constants.GovUkNotifyTemplateId], this.Convert(vocPersonalisation));

                //Got a response back
                serviceStatus.Status = ServiceState.Amber;
                serviceStatus.Notes  = "Success Response";

                if (!string.IsNullOrEmpty(response?.id))
                {
                    serviceStatus.Status = ServiceState.Green;
                    serviceStatus.Notes  = string.Empty;
                }
            }
            catch (Exception ex)
            {
                serviceStatus.Notes = $"{Constants.ServiceStatusFailedCheckLogsMessage} - {applicationLogger.LogExceptionWithActivityId(Constants.ServiceStatusFailedLogMessage, ex)}";
            }

            return(Task.FromResult(serviceStatus));
        }
Пример #3
0
        public Task <ServiceStatus> GetCurrentStatusAsync()
        {
            var serviceStatus = new ServiceStatus {
                Name = ServiceName, Status = ServiceState.Red, CheckCorrelationId = Guid.NewGuid()
            };

            var emailAddress       = "*****@*****.**";
            var vocPersonalisation = new VocSurveyPersonalisation();

            vocPersonalisation.Personalisation.Add("jpprofile", "ServiceCheck");
            vocPersonalisation.Personalisation.Add("clientId", "ServiceCheck ClientId");
            try
            {
                var response = clientProxy.SendEmail(ConfigurationManager.AppSettings[Constants.GovUkNotifyApiKey], emailAddress, ConfigurationManager.AppSettings[Constants.GovUkNotifyTemplateId], this.Convert(vocPersonalisation));

                //Got a response back
                serviceStatus.Status = ServiceState.Amber;
                if (!string.IsNullOrEmpty(response?.id))
                {
                    serviceStatus.Status             = ServiceState.Green;
                    serviceStatus.CheckCorrelationId = Guid.Empty;
                }
                else
                {
                    applicationLogger.Warn($"{nameof(GovUkNotifyService)}.{nameof(GetCurrentStatusAsync)} : {Constants.ServiceStatusWarnLogMessage} - Correlation Id [{serviceStatus.CheckCorrelationId}] - Email used [{emailAddress}]");
                }
            }
            catch (Exception ex)
            {
                applicationLogger.ErrorJustLogIt($"{nameof(GovUkNotifyService)}.{nameof(GetCurrentStatusAsync)} : {Constants.ServiceStatusFailedLogMessage} - Correlation Id [{serviceStatus.CheckCorrelationId}] - Email used [{emailAddress}]", ex);
            }

            return(Task.FromResult(serviceStatus));
        }
 /// <summary>
 /// Submits the email.
 /// </summary>
 /// <param name="emailAddress">The email address.</param>
 /// <param name="vocPersonalisation">Stores dictionary of jpprofile and clientid</param>
 /// <returns>true or false</returns>
 public bool SubmitEmail(string emailAddress, VocSurveyPersonalisation vocPersonalisation)
 {
     try
     {
         var response = clientProxy.SendEmail(ConfigurationManager.AppSettings[Constants.GovUkNotifyApiKey], emailAddress, ConfigurationManager.AppSettings[Constants.GovUkNotifyTemplateId], this.Convert(vocPersonalisation));
         return(!string.IsNullOrEmpty(response?.id));
     }
     catch (NotifyClientException ex)
     {
         applicationLogger.ErrorJustLogIt("Failed to send VOC email", ex);
         return(false);
     }
 }
        public void GetCookieTest()
        {
            var expectation = new VocSurveyPersonalisation
            {
                Personalisation = new Dictionary <string, string>
                {
                    { Constants.LastVisitedJobProfileKey, Constants.Unknown },
                    { Constants.GoogleClientIdKey, Constants.Unknown }
                }
            };

            var webAppContext = new WebAppContext();
            var result        = webAppContext.GetVocCookie("name");

            result.Should().BeEquivalentTo(expectation);
        }
Пример #6
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();
            }
        }
        public Dictionary <string, dynamic> Convert(VocSurveyPersonalisation vocSurveyPersonalisation)
        {
            if (vocSurveyPersonalisation?.Personalisation != null)
            {
                foreach (var item in vocSurveyPersonalisation?.Personalisation?.ToArray())
                {
                    if (string.IsNullOrEmpty(item.Value) && vocSurveyPersonalisation != null)
                    {
                        vocSurveyPersonalisation.Personalisation[item.Key] = Constants.Unknown;
                    }
                }

                return(vocSurveyPersonalisation?.Personalisation
                       .ToDictionary <KeyValuePair <string, string>, string, dynamic>(
                           vocObj => vocObj.Key,
                           vocObj => vocObj.Value));
            }

            return(null);
        }
Пример #8
0
        public VocSurveyPersonalisation GetVocCookie(string cookieName)
        {
            var profile = new VocSurveyPersonalisation();
            var cookies = HttpContext.Current?.Request.Cookies;

            if (cookies != null)
            {
                var cookie = cookies.Get(cookieName)?.Value;
                if (!string.IsNullOrEmpty(cookie))
                {
                    profile.Personalisation.Add(Constants.LastVisitedJobProfileKey, HttpUtility.UrlDecode(cookie));
                }
            }

            if (!profile.Personalisation.ContainsKey(Constants.LastVisitedJobProfileKey))
            {
                profile.Personalisation.Add(Constants.LastVisitedJobProfileKey, Constants.Unknown);
            }

            profile.Personalisation.Add(Constants.GoogleClientIdKey, GetGAClientId());
            return(profile);
        }
Пример #9
0
        public void ConvertTest(string key, string sourceValue, string expectedValue)
        {
            // Arrange
            var input = new VocSurveyPersonalisation
            {
                Personalisation = new Dictionary <string, string>
                {
                    { key, sourceValue }
                }
            };

            var expectation = new Dictionary <string, dynamic>
            {
                { key, expectedValue }
            };

            // Act
            var govUkNotifyService = new GovUkNotifyService(fakeApplicationLogger, fakeGovUkNotifyClient);
            var result             = govUkNotifyService.Convert(input);

            // Assert
            result.Should().BeEquivalentTo(expectation);
        }