Created ECNService
This commit is contained in:
parent
c4baef8025
commit
830c8576e3
20
FabApprovalWorkerService/Clients/SmtpClientWrapper.cs
Normal file
20
FabApprovalWorkerService/Clients/SmtpClientWrapper.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System.Net.Mail;
|
||||
|
||||
namespace FabApprovalWorkerService.Clients;
|
||||
|
||||
public interface ISmtpClientWrapper {
|
||||
void Send(MailMessage message);
|
||||
}
|
||||
|
||||
public class SmtpClientWrapper : ISmtpClientWrapper {
|
||||
private SmtpClient _client;
|
||||
|
||||
public SmtpClientWrapper(SmtpClient client) {
|
||||
_client = client ??
|
||||
throw new ArgumentNullException("SmtpClient not injected");
|
||||
}
|
||||
|
||||
public void Send(MailMessage message) {
|
||||
_client.Send(message);
|
||||
}
|
||||
}
|
10
FabApprovalWorkerService/Models/ECN.cs
Normal file
10
FabApprovalWorkerService/Models/ECN.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace FabApprovalWorkerService.Models;
|
||||
|
||||
public class ECN {
|
||||
public required int ECNNumber { get; set; }
|
||||
public bool IsTECN { get; set; } = false;
|
||||
public DateTime ExpirationDate { get; set; }
|
||||
public DateTime? ExtensionDate { get; set; }
|
||||
public required int OriginatorID { get; set; }
|
||||
public required string Title { get; set; }
|
||||
}
|
@ -1,14 +1,12 @@
|
||||
using FabApprovalWorkerService.Clients;
|
||||
using FabApprovalWorkerService.Services;
|
||||
using FabApprovalWorkerService.Workers;
|
||||
|
||||
using Microsoft.Data.Sqlite;
|
||||
|
||||
using NLog.Extensions.Logging;
|
||||
|
||||
using Quartz;
|
||||
|
||||
using System.Data;
|
||||
using Microsoft.Data.SqlClient;
|
||||
using System.Net.Mail;
|
||||
|
||||
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
@ -21,7 +19,14 @@ builder.Services.AddHttpClient();
|
||||
builder.Services.AddScoped<IDbConnectionService, DbConnectionService>();
|
||||
builder.Services.AddScoped<IMonInWorkerClient, MonInWorkerClient>();
|
||||
builder.Services.AddScoped<IDalService, DalService>();
|
||||
builder.Services.AddScoped<SmtpClient>((serviceProvider) => {
|
||||
return new SmtpClient("mailrelay-external.infineon.com");
|
||||
});
|
||||
builder.Services.AddScoped<ISmtpClientWrapper, SmtpClientWrapper>();
|
||||
builder.Services.AddScoped<ISmtpService, SmtpService>();
|
||||
|
||||
builder.Services.AddScoped<IUserService, UserService>();
|
||||
builder.Services.AddScoped<IECNService, ECNService>();
|
||||
|
||||
builder.Services.AddQuartz(q => {
|
||||
JobKey pendingOOOStatusJob = new JobKey("Pending OOO status job");
|
||||
|
78
FabApprovalWorkerService/Services/ECNService.cs
Normal file
78
FabApprovalWorkerService/Services/ECNService.cs
Normal file
@ -0,0 +1,78 @@
|
||||
using FabApprovalWorkerService.Models;
|
||||
|
||||
using System.Text;
|
||||
|
||||
namespace FabApprovalWorkerService.Services;
|
||||
|
||||
public interface IECNService {
|
||||
Task<IEnumerable<ECN>> GetExpiringTECNs();
|
||||
Task<IEnumerable<ECN>> GetExpiredTECNs();
|
||||
}
|
||||
|
||||
public class ECNService : IECNService {
|
||||
private readonly ILogger<ECNService> _logger;
|
||||
private readonly IDalService _dalService;
|
||||
|
||||
public ECNService(ILogger<ECNService> logger, IDalService dalService) {
|
||||
_logger = logger ?? throw new ArgumentNullException("ILogger not injected");
|
||||
_dalService = dalService ?? throw new ArgumentNullException("IDalService not injected");
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<ECN>> GetExpiredTECNs() {
|
||||
try {
|
||||
_logger.LogInformation("Attempting to get all TECNs expired in the last day");
|
||||
|
||||
string today = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
string yesterday = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
StringBuilder queryBuilder = new StringBuilder();
|
||||
queryBuilder.Append("select ECNNumber, IsTECN, ExpirationDate, ExtensionDate, OriginatorID, Title ");
|
||||
queryBuilder.Append($"from ECN where IsTECN = 1 and ");
|
||||
queryBuilder.Append($"ExpirationDate between '{yesterday}' ");
|
||||
queryBuilder.Append($"and '{today}'");
|
||||
|
||||
IEnumerable<ECN> expiredTecns = (await _dalService.QueryAsync<ECN>(queryBuilder.ToString()))
|
||||
.Where(e => e.ExtensionDate is null || e.ExtensionDate < DateTime.Now)
|
||||
.ToList();
|
||||
|
||||
_logger.LogInformation($"Found {expiredTecns.Count()} expired TECNs");
|
||||
|
||||
return expiredTecns;
|
||||
} catch (Exception ex) {
|
||||
StringBuilder errMsgBuilder = new();
|
||||
errMsgBuilder.Append("An exception occurred when attempting to get all TECNs expired in the last day. ");
|
||||
errMsgBuilder.Append($"Exception: {ex.Message}");
|
||||
_logger.LogError(errMsgBuilder.ToString());
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<ECN>> GetExpiringTECNs() {
|
||||
try {
|
||||
_logger.LogInformation("Attempting to get all TECNs expiring in the next five days");
|
||||
|
||||
string today = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
string fiveDaysFromToday = DateTime.Now.AddDays(5).ToString("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
StringBuilder queryBuilder = new StringBuilder();
|
||||
queryBuilder.Append("select ECNNumber, IsTECN, ExpirationDate, ExtensionDate, OriginatorID, Title ");
|
||||
queryBuilder.Append($"from ECN where IsTECN = 1 and ");
|
||||
queryBuilder.Append($"ExpirationDate between '{today}' ");
|
||||
queryBuilder.Append($"and '{fiveDaysFromToday}'");
|
||||
|
||||
IEnumerable<ECN> expiringTecns = (await _dalService.QueryAsync<ECN>(queryBuilder.ToString()))
|
||||
.Where(e => e.ExtensionDate is null || e.ExtensionDate <= DateTime.Now.AddDays(5))
|
||||
.ToList();
|
||||
|
||||
_logger.LogInformation($"Found {expiringTecns.Count()} expiring TECNs");
|
||||
|
||||
return expiringTecns;
|
||||
} catch (Exception ex) {
|
||||
StringBuilder errMsgBuilder = new();
|
||||
errMsgBuilder.Append("An exception occurred when attempting to get all TECNs expiring in the next five days. ");
|
||||
errMsgBuilder.Append($"Exception: {ex.Message}");
|
||||
_logger.LogError(errMsgBuilder.ToString());
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
71
FabApprovalWorkerService/Services/SmtpService.cs
Normal file
71
FabApprovalWorkerService/Services/SmtpService.cs
Normal file
@ -0,0 +1,71 @@
|
||||
using FabApprovalWorkerService.Clients;
|
||||
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
|
||||
using System.Net.Mail;
|
||||
|
||||
namespace FabApprovalWorkerService.Services;
|
||||
|
||||
public interface ISmtpService {
|
||||
Task<bool> SendEmail(IEnumerable<MailAddress> recipients, IEnumerable<MailAddress> ccRecipients, string subject, string body);
|
||||
}
|
||||
|
||||
public class SmtpService : ISmtpService {
|
||||
private ILogger<SmtpService> _logger;
|
||||
private ISmtpClientWrapper _smtpClient;
|
||||
|
||||
public SmtpService(ILogger<SmtpService> logger, ISmtpClientWrapper smtpClient) {
|
||||
_logger = logger ??
|
||||
throw new ArgumentNullException("ILogger not injected");
|
||||
_smtpClient = smtpClient ??
|
||||
throw new ArgumentNullException("SmtpClient not injected");
|
||||
}
|
||||
|
||||
public async Task<bool> SendEmail(IEnumerable<MailAddress> recipients,
|
||||
IEnumerable<MailAddress> ccRecipients,
|
||||
string subject,
|
||||
string body) {
|
||||
if (recipients.IsNullOrEmpty()) throw new ArgumentNullException("recipients cannot be null or empty!");
|
||||
if (ccRecipients.IsNullOrEmpty()) throw new ArgumentNullException("ccRecipients cannot be null or empty!");
|
||||
if (subject.IsNullOrEmpty()) throw new ArgumentNullException("subject cannot be null or empty!");
|
||||
if (body.IsNullOrEmpty()) throw new ArgumentNullException("body cannot be null or empty!");
|
||||
|
||||
return await Task.Run(() => {
|
||||
int maxRetries = 3;
|
||||
int backoffSeconds = 30;
|
||||
|
||||
bool messageWasSent = false;
|
||||
|
||||
try {
|
||||
int remainingRetries = maxRetries;
|
||||
while (!messageWasSent && remainingRetries > 0) {
|
||||
try {
|
||||
Task.Delay((maxRetries - remainingRetries--) * backoffSeconds * 1000);
|
||||
|
||||
_logger.LogInformation($"Attempting to send notification. Remaining retries: {remainingRetries}");
|
||||
|
||||
MailMessage msg = new MailMessage();
|
||||
msg.IsBodyHtml = true;
|
||||
msg.From = new MailAddress("MesaFabApproval@infineon.com", "Mesa Fab Approval");
|
||||
msg.Sender = new MailAddress("MesaFabApproval@infineon.com", "Mesa Fab Approval");
|
||||
foreach (MailAddress recipient in recipients) msg.To.Add(recipient);
|
||||
msg.Bcc.Add("chase.tucker@infineon.com");
|
||||
foreach (MailAddress ccRecipient in ccRecipients) msg.CC.Add(ccRecipient);
|
||||
msg.Subject = subject;
|
||||
msg.Body = body;
|
||||
|
||||
_smtpClient.Send(msg);
|
||||
|
||||
messageWasSent = true;
|
||||
} catch (Exception ex) {
|
||||
_logger.LogError($"Message not sent successfully. Exception: {ex.Message}");
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
_logger.LogError($"An exception occurred when attempting to send notification. Exception: {ex.Message}");
|
||||
}
|
||||
|
||||
return messageWasSent;
|
||||
});
|
||||
}
|
||||
}
|
@ -1,9 +1,3 @@
|
||||
{
|
||||
"ConnectionStrings": {
|
||||
"Default": "Data Source=MESTSV02EC.infineon.com\\TEST1,50572;Integrated Security=False;Initial Catalog=FabApprovalSystem;User ID=fab_approval_admin_test;Password=Fab_approval_admin_test2023!;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False; Min Pool Size=15"
|
||||
},
|
||||
"MonIn": {
|
||||
"resource": "FAB_APPROVAL_WORKER_SERVICE_MES_OP_FE_TEST",
|
||||
"workerUrl": "https://mestsa008.infineon.com:7851/"
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,12 +1,3 @@
|
||||
{
|
||||
"ConnectionStrings": {
|
||||
"Development": "Data Source=D:\\FabApprovalWorkerService\\LocalDb.db",
|
||||
"Default": "Data Source=MESTSV02EC.infineon.com\\TEST1,50572;Integrated Security=False;Initial Catalog=FabApprovalSystem;User ID=fab_approval_admin_test;Password=Fab_approval_admin_test2023!;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False; Min Pool Size=15"
|
||||
},
|
||||
"MonIn": {
|
||||
"resource": "FAB_APPROVAL_WORKER_SERVICE_MES_OP_FE",
|
||||
"workerUrl": "https://messa014.infineon.com:7851/",
|
||||
"retries": 3,
|
||||
"backoffInSeconds": 30
|
||||
}
|
||||
|
||||
}
|
||||
|
217
FabApprovalWorkerServiceTests/ECNServiceTests.cs
Normal file
217
FabApprovalWorkerServiceTests/ECNServiceTests.cs
Normal file
@ -0,0 +1,217 @@
|
||||
using FabApprovalWorkerService.Models;
|
||||
using FabApprovalWorkerService.Services;
|
||||
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
using Moq;
|
||||
|
||||
namespace FabApprovalWorkerServiceTests;
|
||||
internal class ECNServiceTests {
|
||||
Mock<ILogger<ECNService>> _mockLogger;
|
||||
Mock<IDalService> _mockDalService;
|
||||
|
||||
ECNService _ecnService;
|
||||
|
||||
[SetUp]
|
||||
public void Setup() {
|
||||
_mockLogger = new Mock<ILogger<ECNService>>();
|
||||
_mockDalService = new Mock<IDalService>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EcnServiceWithNullLoggerShouldThrowException() {
|
||||
Assert.Throws<ArgumentNullException>(() => new ECNService(null, _mockDalService.Object));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EcnServiceWithNullDalServiceShouldThrowException() {
|
||||
Assert.Throws<ArgumentNullException>(() => new ECNService(_mockLogger.Object, null));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetExpiringTECNsWithDbErrorShouldThrowException() {
|
||||
_mockDalService.Setup(d => d.QueryAsync<ECN>(It.IsAny<string>())).ThrowsAsync(new Exception());
|
||||
|
||||
_ecnService = new ECNService(_mockLogger.Object, _mockDalService.Object);
|
||||
|
||||
Assert.ThrowsAsync<Exception>(async Task () => await _ecnService.GetExpiringTECNs());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetExpiredTECNsWithDbErrorShouldThrowException() {
|
||||
_mockDalService.Setup(d => d.QueryAsync<ECN>(It.IsAny<string>())).ThrowsAsync(new Exception());
|
||||
|
||||
_ecnService = new ECNService(_mockLogger.Object, _mockDalService.Object);
|
||||
|
||||
Assert.ThrowsAsync<Exception>(async Task () => await _ecnService.GetExpiredTECNs());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetExpiringTECNsWithNoResultsFromDbShouldReturnEmpty() {
|
||||
IEnumerable<ECN> emptyEcns = new List<ECN>();
|
||||
|
||||
_mockDalService.Setup(d => d.QueryAsync<ECN>(It.IsAny<string>())).Returns(Task.FromResult(emptyEcns));
|
||||
|
||||
_ecnService = new ECNService(_mockLogger.Object, _mockDalService.Object);
|
||||
|
||||
IEnumerable<ECN> actual = await _ecnService.GetExpiringTECNs();
|
||||
|
||||
Assert.That(actual, Is.Empty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetExpiredTECNsWithNoResultsFromDbShouldReturnEmpty() {
|
||||
IEnumerable<ECN> emptyEcns = new List<ECN>();
|
||||
|
||||
_mockDalService.Setup(d => d.QueryAsync<ECN>(It.IsAny<string>())).Returns(Task.FromResult(emptyEcns));
|
||||
|
||||
_ecnService = new ECNService(_mockLogger.Object, _mockDalService.Object);
|
||||
|
||||
IEnumerable<ECN> actual = await _ecnService.GetExpiredTECNs();
|
||||
|
||||
Assert.That(actual, Is.Empty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetExpiringTECNsWithNoExtensionFromDbShouldReturnSameResults() {
|
||||
IEnumerable<ECN> ecns = new List<ECN>() {
|
||||
new ECN() {
|
||||
ECNNumber = 1,
|
||||
OriginatorID = 1,
|
||||
Title = "title1",
|
||||
IsTECN = true,
|
||||
ExpirationDate = DateTime.Now.AddDays(1)
|
||||
},
|
||||
new ECN() {
|
||||
ECNNumber = 2,
|
||||
OriginatorID = 1,
|
||||
Title = "title2",
|
||||
IsTECN = true,
|
||||
ExpirationDate = DateTime.Now.AddDays(2)
|
||||
},
|
||||
new ECN() {
|
||||
ECNNumber = 3,
|
||||
OriginatorID = 1,
|
||||
Title = "title3",
|
||||
IsTECN = true,
|
||||
ExpirationDate = DateTime.Now.AddDays(3)
|
||||
},
|
||||
};
|
||||
|
||||
_mockDalService.Setup(d => d.QueryAsync<ECN>(It.IsAny<string>())).Returns(Task.FromResult(ecns));
|
||||
|
||||
_ecnService = new ECNService(_mockLogger.Object, _mockDalService.Object);
|
||||
|
||||
IEnumerable<ECN> actual = await _ecnService.GetExpiringTECNs();
|
||||
|
||||
Assert.That(actual.Count(), Is.EqualTo(3));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetExpiredTECNsWithNoExtensionFromDbShouldReturnSameResults() {
|
||||
IEnumerable<ECN> ecns = new List<ECN>() {
|
||||
new ECN() {
|
||||
ECNNumber = 1,
|
||||
OriginatorID = 1,
|
||||
Title = "title1",
|
||||
IsTECN = true,
|
||||
ExpirationDate = DateTime.Now.AddHours(-2)
|
||||
},
|
||||
new ECN() {
|
||||
ECNNumber = 2,
|
||||
OriginatorID = 1,
|
||||
Title = "title2",
|
||||
IsTECN = true,
|
||||
ExpirationDate = DateTime.Now.AddHours(-20)
|
||||
},
|
||||
new ECN() {
|
||||
ECNNumber = 3,
|
||||
OriginatorID = 1,
|
||||
Title = "title3",
|
||||
IsTECN = true,
|
||||
ExpirationDate = DateTime.Now.AddHours(-12)
|
||||
},
|
||||
};
|
||||
|
||||
_mockDalService.Setup(d => d.QueryAsync<ECN>(It.IsAny<string>())).Returns(Task.FromResult(ecns));
|
||||
|
||||
_ecnService = new ECNService(_mockLogger.Object, _mockDalService.Object);
|
||||
|
||||
IEnumerable<ECN> actual = await _ecnService.GetExpiredTECNs();
|
||||
|
||||
Assert.That(actual.Count(), Is.EqualTo(3));
|
||||
}
|
||||
|
||||
// Test when responses include extension dates
|
||||
[Test]
|
||||
public async Task GetExpiringTECNsWithExtensionsFromDbShouldReturnSameResults() {
|
||||
IEnumerable<ECN> ecns = new List<ECN>() {
|
||||
new ECN() {
|
||||
ECNNumber = 1,
|
||||
OriginatorID = 1,
|
||||
Title = "title1",
|
||||
IsTECN = true,
|
||||
ExpirationDate = DateTime.Now.AddDays(1)
|
||||
},
|
||||
new ECN() {
|
||||
ECNNumber = 2,
|
||||
OriginatorID = 1,
|
||||
Title = "title2",
|
||||
IsTECN = true,
|
||||
ExpirationDate = DateTime.Now.AddDays(2)
|
||||
},
|
||||
new ECN() {
|
||||
ECNNumber = 3,
|
||||
OriginatorID = 1,
|
||||
Title = "title3",
|
||||
IsTECN = true,
|
||||
ExpirationDate = DateTime.Now.AddDays(3),
|
||||
ExtensionDate = DateTime.Now.AddDays(10)
|
||||
},
|
||||
};
|
||||
|
||||
_mockDalService.Setup(d => d.QueryAsync<ECN>(It.IsAny<string>())).Returns(Task.FromResult(ecns));
|
||||
|
||||
_ecnService = new ECNService(_mockLogger.Object, _mockDalService.Object);
|
||||
|
||||
IEnumerable<ECN> actual = await _ecnService.GetExpiringTECNs();
|
||||
|
||||
Assert.That(actual.Count(), Is.EqualTo(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetExpiredTECNsWithExtensionsFromDbShouldReturnSameResults() {
|
||||
IEnumerable<ECN> ecns = new List<ECN>() {
|
||||
new ECN() {
|
||||
ECNNumber = 1,
|
||||
OriginatorID = 1,
|
||||
Title = "title1",
|
||||
IsTECN = true,
|
||||
ExpirationDate = DateTime.Now.AddHours(-2)
|
||||
},
|
||||
new ECN() {
|
||||
ECNNumber = 2,
|
||||
OriginatorID = 1,
|
||||
Title = "title2",
|
||||
IsTECN = true,
|
||||
ExpirationDate = DateTime.Now.AddHours(-20)
|
||||
},
|
||||
new ECN() {
|
||||
ECNNumber = 3,
|
||||
OriginatorID = 1,
|
||||
Title = "title3",
|
||||
IsTECN = true,
|
||||
ExpirationDate = DateTime.Now.AddHours(-12),
|
||||
ExtensionDate = DateTime.Now.AddDays(10)
|
||||
},
|
||||
};
|
||||
|
||||
_mockDalService.Setup(d => d.QueryAsync<ECN>(It.IsAny<string>())).Returns(Task.FromResult(ecns));
|
||||
|
||||
_ecnService = new ECNService(_mockLogger.Object, _mockDalService.Object);
|
||||
|
||||
IEnumerable<ECN> actual = await _ecnService.GetExpiredTECNs();
|
||||
|
||||
Assert.That(actual.Count(), Is.EqualTo(2));
|
||||
}
|
||||
}
|
117
FabApprovalWorkerServiceTests/SmtpServiceTests.cs
Normal file
117
FabApprovalWorkerServiceTests/SmtpServiceTests.cs
Normal 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>()));
|
||||
}
|
||||
}
|
@ -1,5 +1,3 @@
|
||||
using Dapper.Contrib.Extensions;
|
||||
|
||||
using FabApprovalWorkerService.Models;
|
||||
using FabApprovalWorkerService.Services;
|
||||
|
||||
@ -9,7 +7,7 @@ using Moq;
|
||||
|
||||
namespace FabApprovalWorkerServiceTests;
|
||||
|
||||
public class UserServiceTests {
|
||||
internal class UserServiceTests {
|
||||
private static readonly ILogger<UserService> MOCK_LOGGER = Mock.Of<ILogger<UserService>>();
|
||||
|
||||
private static readonly IEnumerable<User> MOCK_USERS = new List<User>() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user