Files
2026-03-25 14:50:13 -05:00

106 lines
4.1 KiB
C#

using LCU.API.Internal.DocumentIngestor.Configurations;
using LCU.API.Internal.DocumentIngestor.Services.MemberNotificationInfoDeterminingServices;
using LCU.API.Internal.DocumentIngestor.Services.MicroApiServices;
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.Agreements;
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.MemberAgreements;
using LCU.Library.Internal.Exceptions;
using Moq;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace LCU.API.Internal.DocumentIngestorTests.Services.MemberNotificationInfoDeterminingServices;
public class AccountNotificationInfoDeterminingServiceTest
{
private AccountNotificationInfoDeterminingService _accountNotificationInfoDeterminingService;
private Mock<ICoreApiWrapperService> _mockCoreApiWrapperService;
private ApiConfiguration _apiConfiguration;
[SetUp]
public void Setup()
{
_mockCoreApiWrapperService = new Mock<ICoreApiWrapperService>();
_apiConfiguration = new ApiConfiguration() { TimeZone = "America/Chicago" };
_accountNotificationInfoDeterminingService = new AccountNotificationInfoDeterminingService(_mockCoreApiWrapperService.Object,
_apiConfiguration);
}
[Test]
public async Task DetermineAccountOwnerNotificationInfos_Success()
{
var entityNumber = "123";
var agreeUserAccounts = new List<AgreeUserAccount>
{
new AgreeUserAccount
{
UserId = "456"
}
};
var user = new Agreement()
{
UserId = "456",
OrganizationName = "RugMart"
};
_mockCoreApiWrapperService.Setup(x => x.GetAgreeUsersByAccount(entityNumber)).ReturnsAsync(agreeUserAccounts);
_mockCoreApiWrapperService.Setup(x => x.GetAgreementByUserId(It.IsAny<string>())).ReturnsAsync(user);
var result = await _accountNotificationInfoDeterminingService.DetermineAccountOwnerNotificationInfos(entityNumber);
Assert.NotNull(result);
Assert.AreEqual(result.Count, 1);
_mockCoreApiWrapperService.Verify(x => x.GetAgreeUsersByAccount(entityNumber), Times.Once);
_mockCoreApiWrapperService.Verify(x => x.GetAgreementByUserId(It.IsAny<string>()), Times.Once);
}
[Test]
public async Task DetermineAccountOwnerNotificationInfos_Success_NoAgreeUserAccounts()
{
var entityNumber = "123";
List<AgreeUserAccount> agreeUserAccounts = null;
_mockCoreApiWrapperService.Setup(x => x.GetAgreeUsersByAccount(entityNumber)).ReturnsAsync(agreeUserAccounts);
var result = await _accountNotificationInfoDeterminingService.DetermineAccountOwnerNotificationInfos(entityNumber);
Assert.NotNull(result);
Assert.AreEqual(result.Count, 1);
_mockCoreApiWrapperService.Verify(x => x.GetAgreeUsersByAccount(entityNumber), Times.Once);
_mockCoreApiWrapperService.Verify(x => x.GetAgreementByUserId(It.IsAny<string>()), Times.Never);
}
[Test]
public void DetermineAccountOwnerNotificationInfos_MultipleAgreeUserAccounts_ExceptionThrown()
{
var entityNumber = "123";
var agreeUserAccounts = new List<AgreeUserAccount>
{
new AgreeUserAccount
{
UserId = "456"
},
new AgreeUserAccount
{
UserId = "457"
}
};
_mockCoreApiWrapperService.Setup(x => x.GetAgreeUsersByAccount(entityNumber)).ReturnsAsync(agreeUserAccounts);
Assert.ThrowsAsync<ServiceException>(async () => await _accountNotificationInfoDeterminingService
.DetermineAccountOwnerNotificationInfos(entityNumber));
_mockCoreApiWrapperService.Verify(x => x.GetAgreeUsersByAccount(entityNumber), Times.Once);
_mockCoreApiWrapperService.Verify(x => x.GetAgreementByUserId(It.IsAny<string>()), Times.Never);
}
[Test]
public void DetermineAccountOwnerNotificationInfos_Exception()
{
_mockCoreApiWrapperService.Setup(x => x.GetAgreeUsersByAccount(null)).Throws(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _accountNotificationInfoDeterminingService
.DetermineAccountOwnerNotificationInfos(null));
_mockCoreApiWrapperService.Verify(x => x.GetAgreeUsersByAccount(It.IsAny<string>()), Times.Once);
_mockCoreApiWrapperService.Verify(x => x.GetAgreementByUserId(It.IsAny<string>()), Times.Never);
}
}