public void SubmitEmail(string responseId, bool throwError, bool expectation) { //Fakes string emailAddress = "*****@*****.**"; var emailResponse = responseId == null ? null : new Notify.Models.Responses.EmailNotificationResponse { id = responseId }; //Configure calls if (throwError) { A.CallTo(() => fakeGovUkNotifyClient.SendEmail(A <string> ._, A <string> ._, A <string> ._, A <Dictionary <string, dynamic> > ._)).Throws <NotifyClientException>(); } else { A.CallTo(() => fakeGovUkNotifyClient.SendEmail(A <string> ._, A <string> ._, A <string> ._, A <Dictionary <string, dynamic> > ._)).Returns(emailResponse); } //Act var govUkNotifyService = new GovUkNotifyService(fakeApplicationLogger, fakeGovUkNotifyClient); var result = govUkNotifyService.SubmitEmail(emailAddress, new VocSurveyPersonalisation()); //Assertions result.Should().Be(expectation); A.CallTo(() => fakeGovUkNotifyClient.SendEmail(A <string> ._, A <string> .That.IsEqualTo(emailAddress), A <string> ._, A <Dictionary <string, dynamic> > ._)).MustHaveHappened(); if (throwError) { A.CallTo(() => fakeApplicationLogger.ErrorJustLogIt(A <string> ._, A <Exception> ._)).MustHaveHappened(); } }
public async Task GetServiceStatusExceptionAsync() { //Fake set up incorrectly to cause exception A.CallTo(() => fakeGovUkNotifyClient.SendEmail(A<string>._, A<string>._, A<string>._, A<Dictionary<string, dynamic>>._)).Throws<NotifyClientException>(); //Act var govUkNotifyService = new GovUkNotifyService(fakeApplicationLogger, fakeGovUkNotifyClient); var serviceStatus = await govUkNotifyService.GetCurrentStatusAsync(); //Asserts serviceStatus.Status.Should().NotBe(ServiceState.Green); }
public async Task GetServiceStatusAsync(string responseId, ServiceState expectedServiceStatus) { //Fakes var emailResponse = responseId == null ? null : new Notify.Models.Responses.EmailNotificationResponse { id = responseId }; A.CallTo(() => fakeGovUkNotifyClient.SendEmail(A <string> ._, A <string> ._, A <string> ._, A <Dictionary <string, dynamic> > ._)).Returns(emailResponse); //Act var govUkNotifyService = new GovUkNotifyService(fakeApplicationLogger, fakeGovUkNotifyClient); var serviceStatus = await govUkNotifyService.GetCurrentStatusAsync(); //Assert serviceStatus.Status.Should().Be(expectedServiceStatus); }
public async Task SendCitizenNotificationAsyncTests(string responseId, bool throwException, bool isRateLimitException, SendNotificationResponse expectation) { //Fakes var citizenEmailNotification = new Account { EMail = "*****@*****.**" }; var emailResponse = responseId == null ? null : new Notify.Models.Responses.EmailNotificationResponse { id = responseId }; //Configure calls if (throwException) { A.CallTo(() => fakeGovUkNotifyClient.SendEmail(A <string> ._, A <string> ._, A <string> ._, A <Dictionary <string, dynamic> > ._)).Throws(() => new NotifyClientException(isRateLimitException ? nameof(NotifyClientException).ToLowerInvariant() : nameof(Exception).ToLowerInvariant())); } else { A.CallTo(() => fakeGovUkNotifyClient.SendEmail(A <string> ._, A <string> ._, A <string> ._, A <Dictionary <string, dynamic> > ._)).Returns(emailResponse); } A.CallTo(() => fakeConfiguration.GetConfig <string>(A <string> ._)).Returns(isRateLimitException ? nameof(NotifyClientException).ToLowerInvariant() : "test"); //Act var govUkNotifyService = new GovUkNotifyService(fakeApplicationLogger, fakeGovUkNotifyClient, fakeConfiguration, fakeAccountsService); var result = await govUkNotifyService.SendCitizenNotificationAsync(citizenEmailNotification); //Assertions result.Should().BeEquivalentTo(expectation); A.CallTo(() => fakeGovUkNotifyClient.SendEmail(A <string> ._, A <string> .That.IsEqualTo(citizenEmailNotification.EMail), A <string> ._, A <Dictionary <string, dynamic> > ._)).MustHaveHappened(); if (throwException) { A.CallTo(() => fakeApplicationLogger.Error(A <string> ._, A <Exception> ._)).MustHaveHappened(); if (isRateLimitException) { A.CallTo(() => fakeAccountsService.OpenCircuitBreakerAsync()).MustHaveHappened(); } } }
public void ConvertTest(string key, string sourceValue, string expectedValue) { // Arrange var input = new GovUkNotifyPersonalisation { Personalisation = new Dictionary <string, string> { { key, sourceValue } } }; var expectation = new Dictionary <string, dynamic> { { key, expectedValue } }; // Act var govUkNotifyService = new GovUkNotifyService(fakeApplicationLogger, fakeGovUkNotifyClient, fakeConfiguration, fakeAccountsService); var result = govUkNotifyService.Convert(input); // Assert result.Should().BeEquivalentTo(expectation); }