Skip to content

Commit

Permalink
Refactor some test units
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmed-Ghanam committed Dec 2, 2024
1 parent 46f13b2 commit f361657
Showing 1 changed file with 29 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@ public async Task ProcessOrder_NotificationServiceCalledOnceForEachRecipient()
{
Id = Guid.NewGuid(),
NotificationChannel = NotificationChannel.Email,
Recipients = new List<Recipient>()
{
Recipients =
[
new()
{
OrganizationNumber = "123456",
AddressInfo = [new EmailAddressPoint("[email protected]")]
OrganizationNumber = "123456",
AddressInfo = [new EmailAddressPoint("[email protected]")]
},
new()
{
OrganizationNumber = "654321",
AddressInfo = [new EmailAddressPoint("[email protected]")]
OrganizationNumber = "654321",
AddressInfo = [new EmailAddressPoint("[email protected]")]
}
}
]
};

var serviceMock = new Mock<IEmailNotificationService>();
Expand All @@ -59,28 +59,30 @@ public async Task ProcessOrder_NotificationServiceCalledOnceForEachRecipient()
public async Task ProcessOrder_ExpectedInputToNotificationService()
{
// Arrange
Guid orderId = Guid.NewGuid();
DateTime requested = DateTime.UtcNow;
Guid orderId = Guid.NewGuid();

var order = new NotificationOrder()
{
Id = orderId,
NotificationChannel = NotificationChannel.Email,
RequestedSendTime = requested,
Recipients = new List<Recipient>()
{
new(new List<IAddressPoint>() { new EmailAddressPoint("[email protected]") }, organizationNumber: "skd-orgno")
}
Recipients =
[
new([new EmailAddressPoint("[email protected]")], organizationNumber: "skd-orgno")
]
};

List<EmailAddressPoint> expectedEmailAddressPoints = [new("[email protected]")];
EmailRecipient expectedEmailRecipient = new()
{
OrganizationNumber = "skd-orgno"
};
EmailRecipient expectedEmailRecipient = new() { OrganizationNumber = "skd-orgno" };

var serviceMock = new Mock<IEmailNotificationService>();
serviceMock.Setup(s => s.CreateNotification(It.IsAny<Guid>(), It.Is<DateTime>(d => d.Equals(requested)), It.Is<List<EmailAddressPoint>>(r => AssertUtils.AreEquivalent(expectedEmailAddressPoints, r)), It.Is<EmailRecipient>(e => AssertUtils.AreEquivalent(expectedEmailRecipient, e)), It.IsAny<bool>()));
serviceMock.Setup(s => s.CreateNotification(
It.IsAny<Guid>(),
It.Is<DateTime>(d => d.Equals(requested)),
It.Is<List<EmailAddressPoint>>(r => AssertUtils.AreEquivalent(expectedEmailAddressPoints, r)),
It.Is<EmailRecipient>(e => AssertUtils.AreEquivalent(expectedEmailRecipient, e)),
It.IsAny<bool>()));

var service = GetTestService(emailService: serviceMock.Object);

Expand All @@ -101,16 +103,6 @@ public async Task ProcessOrder_NotificationServiceThrowsException_RepositoryNotC
Recipients =
[
new()
{
AddressInfo =
[
new EmailAddressPoint()
{
AddressType = AddressType.Email,
EmailAddress = "[email protected]"
}
]
}
]
};

Expand Down Expand Up @@ -179,13 +171,13 @@ public async Task ProcessOrderRetry_ServiceCalledIfRecipientNotInDatabase()
{
Id = Guid.NewGuid(),
NotificationChannel = NotificationChannel.Email,
Recipients = new List<Recipient>()
{
Recipients =
[
new(),
new(new List<IAddressPoint>() { new EmailAddressPoint("[email protected]") }, nationalIdentityNumber: "enduser-nin"),
new(new List<IAddressPoint>() { new EmailAddressPoint("[email protected]") }, organizationNumber : "skd-orgNo"),
new(new List<IAddressPoint>() { new EmailAddressPoint("[email protected]") })
}
new([new EmailAddressPoint("[email protected]")], nationalIdentityNumber: "enduser-nin"),
new([new EmailAddressPoint("[email protected]")], organizationNumber : "skd-orgNo"),
new([new EmailAddressPoint("[email protected]")])
]
};

var serviceMock = new Mock<IEmailNotificationService>();
Expand All @@ -209,10 +201,10 @@ public async Task ProcessOrderRetry_ServiceCalledIfRecipientNotInDatabase()
}

private static EmailOrderProcessingService GetTestService(
IEmailNotificationRepository? emailRepo = null,
IEmailNotificationService? emailService = null,
IContactPointService? contactPointService = null,
IKeywordsService? keywordsService = null)
IEmailNotificationRepository? emailRepo = null,
IEmailNotificationService? emailService = null,
IContactPointService? contactPointService = null,
IKeywordsService? keywordsService = null)
{
if (emailRepo == null)
{
Expand Down

0 comments on commit f361657

Please sign in to comment.