示例#1
0
        public async Task ItShouldReturnAOk_When_SendAmazonEmail_SetToFalse()
        {
            var emailClient  = new HttpEmailClient(_mockLogger.Object, _emailBuilder.Object, _amazonEmailService.Object, false);
            var emailMessage = new EmailMessage("subject", "body", "*****@*****.**", "*****@*****.**", "*****@*****.**", new List <IFormFile>());

            var httpStatusCode = await emailClient.SendEmailToService(emailMessage);

            httpStatusCode.Should().Be(HttpStatusCode.OK);
            _amazonEmailService.Verify(_ => _.SendRawEmailAsync(It.IsAny <SendRawEmailRequest>(), It.IsAny <CancellationToken>()), Times.Never);
        }
示例#2
0
        public async Task ItShouldReturnA500AndLogItIfTheServiceEmailIsNullOrEmpty()
        {
            var emailClient  = new HttpEmailClient(_mockLogger.Object, _emailBuilder.Object, _amazonEmailService.Object, true);
            var emailMessage = new EmailMessage("subject", "body", "", "", "*****@*****.**", new List <IFormFile>());

            var httpStatusCode = await emailClient.SendEmailToService(emailMessage);

            httpStatusCode.Should().Be(HttpStatusCode.InternalServerError);

            LogTesting.Assert(_mockLogger, LogLevel.Error, "ToEmail can not be null or empty. No email has been sent.");
        }
示例#3
0
        public async Task ItShouldReturnABadRequestIfAmazonSesReturnsAnException()
        {
            _amazonEmailService.Setup(
                o => o.SendRawEmailAsync(It.IsAny <SendRawEmailRequest>(), It.IsAny <CancellationToken>()))
            .ThrowsAsync(new Exception("There was an error"));

            var emailClient  = new HttpEmailClient(_mockLogger.Object, _emailBuilder.Object, _amazonEmailService.Object, true);
            var emailMessage = new EmailMessage("subject", "body", "*****@*****.**", "*****@*****.**", "*****@*****.**", new List <IFormFile>());

            var httpStatusCode = await emailClient.SendEmailToService(emailMessage);

            httpStatusCode.Should().Be(HttpStatusCode.BadRequest);
            LogTesting.Assert(_mockLogger, LogLevel.Error, "An error occurred trying to send an email to Amazon SES. \nThere was an error");
        }
示例#4
0
        public async Task ItShouldReturnA500IfTheEmailServiceThrowsAnException()
        {
            _amazonEmailService.Setup(o => o.SendRawEmailAsync(It.IsAny <SendRawEmailRequest>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(new SendRawEmailResponse {
                HttpStatusCode = HttpStatusCode.InternalServerError, MessageId = "test", ResponseMetadata = new ResponseMetadata {
                    RequestId = "test"
                }
            });

            var emailClient  = new HttpEmailClient(_mockLogger.Object, _emailBuilder.Object, _amazonEmailService.Object, true);
            var emailMessage = new EmailMessage("subject", "body", "*****@*****.**", "*****@*****.**", "*****@*****.**", new List <IFormFile>());

            var httpStatusCode = await emailClient.SendEmailToService(emailMessage);

            httpStatusCode.Should().Be(HttpStatusCode.InternalServerError);
            LogTesting.Assert(_mockLogger, LogLevel.Warning, $"There was a problem sending an email, message id: test and request id: test and status code {HttpStatusCode.InternalServerError}");
        }
示例#5
0
        public async Task ItShouldReturnA200IfTheStatusCodeIsOkAndLogTheResponse()
        {
            _amazonEmailService.Setup(o => o.SendRawEmailAsync(It.IsAny <SendRawEmailRequest>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(new SendRawEmailResponse {
                HttpStatusCode = HttpStatusCode.OK, MessageId = "test", ResponseMetadata = new ResponseMetadata {
                    RequestId = "test"
                }
            });

            var emailClient  = new HttpEmailClient(_mockLogger.Object, _emailBuilder.Object, _amazonEmailService.Object, true);
            var emailMessage = new EmailMessage("subject", "body", "*****@*****.**", "*****@*****.**", "*****@*****.**", new List <IFormFile>());

            var httpStatusCode = await emailClient.SendEmailToService(emailMessage);

            httpStatusCode.Should().Be(HttpStatusCode.OK);
            LogTesting.Assert(_mockLogger, LogLevel.Information, "An email was sent to Amazon SES with message id: test and request id test");
        }