Created ECNService

This commit is contained in:
Chase Tucker
2024-03-28 14:11:45 -07:00
parent c4baef8025
commit 830c8576e3
10 changed files with 525 additions and 24 deletions

View File

@ -0,0 +1,117 @@
using FabApprovalWorkerService.Clients;
using FabApprovalWorkerService.Services;
using Microsoft.Extensions.Logging;
using Moq;
using System.Net.Mail;
namespace FabApprovalWorkerServiceTests;
internal class SmtpServiceTests {
private static readonly List<MailAddress> ADDRESS_LIST = new List<MailAddress>() {
new MailAddress("fake@email.com")
};
private Mock<ILogger<SmtpService>> _mockLogger;
private Mock<ISmtpClientWrapper> _mockSmtpClient;
private SmtpService _smtpService;
[SetUp]
public void Setup() {
_mockLogger = new Mock<ILogger<SmtpService>>();
_mockSmtpClient = new Mock<ISmtpClientWrapper>();
}
[Test]
public void SmtpServiceWithNullLoggerShouldThrowException() {
Assert.Throws<ArgumentNullException>(() => new SmtpService(null, _mockSmtpClient.Object));
}
[Test]
public void SmtpServiceWithNullSmtpClientShouldThrowException() {
Assert.Throws<ArgumentNullException>(() => new SmtpService(_mockLogger.Object, null));
}
[Test]
public void SendMailWithNullRecipientsShouldThrowException() {
_smtpService = new SmtpService(_mockLogger.Object, _mockSmtpClient.Object);
Assert.ThrowsAsync<ArgumentNullException>(async Task () => {
await _smtpService.SendEmail(null, ADDRESS_LIST, "subject", "body");
});
}
[Test]
public void SendMailWithEmptyRecipientsShouldThrowException() {
_smtpService = new SmtpService(_mockLogger.Object, _mockSmtpClient.Object);
Assert.ThrowsAsync<ArgumentNullException>(async Task () => {
await _smtpService.SendEmail(new List<MailAddress> (), ADDRESS_LIST, "subject", "body");
});
}
[Test]
public void SendMailWithNullccRecipientsShouldThrowException() {
_smtpService = new SmtpService(_mockLogger.Object, _mockSmtpClient.Object);
Assert.ThrowsAsync<ArgumentNullException>(async Task () => {
await _smtpService.SendEmail(ADDRESS_LIST, null, "subject", "body");
});
}
[Test]
public void SendMailWithEmptyccRecipientsShouldThrowException() {
_smtpService = new SmtpService(_mockLogger.Object, _mockSmtpClient.Object);
Assert.ThrowsAsync<ArgumentNullException>(async Task () => {
await _smtpService.SendEmail(ADDRESS_LIST, new List<MailAddress>(), "subject", "body");
});
}
[Test]
public void SendMailWithNullSubjectShouldThrowException() {
_smtpService = new SmtpService(_mockLogger.Object, _mockSmtpClient.Object);
Assert.ThrowsAsync<ArgumentNullException>(async Task () => {
await _smtpService.SendEmail(ADDRESS_LIST, ADDRESS_LIST, null, "body");
});
}
[Test]
public void SendMailWithEmptySubjectShouldThrowException() {
_smtpService = new SmtpService(_mockLogger.Object, _mockSmtpClient.Object);
Assert.ThrowsAsync<ArgumentNullException>(async Task () => {
await _smtpService.SendEmail(ADDRESS_LIST, ADDRESS_LIST, "", "body");
});
}
[Test]
public void SendMailWithNullBodyShouldThrowException() {
_smtpService = new SmtpService(_mockLogger.Object, _mockSmtpClient.Object);
Assert.ThrowsAsync<ArgumentNullException>(async Task () => {
await _smtpService.SendEmail(ADDRESS_LIST, ADDRESS_LIST, "subject", null);
});
}
[Test]
public void SendMailWithEmptyBodyShouldThrowException() {
_smtpService = new SmtpService(_mockLogger.Object, _mockSmtpClient.Object);
Assert.ThrowsAsync<ArgumentNullException>(async Task () => {
await _smtpService.SendEmail(ADDRESS_LIST, ADDRESS_LIST, "subject", "");
});
}
[Test]
public async Task SendEmailWithValidArgsShouldSendMailThroughClient() {
_smtpService = new SmtpService(_mockLogger.Object, _mockSmtpClient.Object);
Assert.True(await _smtpService.SendEmail(ADDRESS_LIST, ADDRESS_LIST, "subject", "body"));
_mockSmtpClient.Verify(s => s.Send(It.IsAny<MailMessage>()));
}
}