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 _mockCoreApiWrapperService; private ApiConfiguration _apiConfiguration; [SetUp] public void Setup() { _mockCoreApiWrapperService = new Mock(); _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 { 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())).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()), Times.Once); } [Test] public async Task DetermineAccountOwnerNotificationInfos_Success_NoAgreeUserAccounts() { var entityNumber = "123"; List 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()), Times.Never); } [Test] public void DetermineAccountOwnerNotificationInfos_MultipleAgreeUserAccounts_ExceptionThrown() { var entityNumber = "123"; var agreeUserAccounts = new List { new AgreeUserAccount { UserId = "456" }, new AgreeUserAccount { UserId = "457" } }; _mockCoreApiWrapperService.Setup(x => x.GetAgreeUsersByAccount(entityNumber)).ReturnsAsync(agreeUserAccounts); Assert.ThrowsAsync(async () => await _accountNotificationInfoDeterminingService .DetermineAccountOwnerNotificationInfos(entityNumber)); _mockCoreApiWrapperService.Verify(x => x.GetAgreeUsersByAccount(entityNumber), Times.Once); _mockCoreApiWrapperService.Verify(x => x.GetAgreementByUserId(It.IsAny()), Times.Never); } [Test] public void DetermineAccountOwnerNotificationInfos_Exception() { _mockCoreApiWrapperService.Setup(x => x.GetAgreeUsersByAccount(null)).Throws(new Exception("Error")); Assert.ThrowsAsync(async () => await _accountNotificationInfoDeterminingService .DetermineAccountOwnerNotificationInfos(null)); _mockCoreApiWrapperService.Verify(x => x.GetAgreeUsersByAccount(It.IsAny()), Times.Once); _mockCoreApiWrapperService.Verify(x => x.GetAgreementByUserId(It.IsAny()), Times.Never); } }