167 lines
7.3 KiB
C#
167 lines
7.3 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.DocumentIngestorModels.Enums;
|
|
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 PrimaryNotificationInfoDeterminingServiceTest
|
|
{
|
|
private PrimaryNotificationInfoDeterminingService _primaryNotificationInfoDeterminingService;
|
|
private Mock<ICoreApiWrapperService> _mockCoreApiWrapperService;
|
|
private ApiConfiguration _apiConfiguration;
|
|
|
|
[SetUp]
|
|
public void Setup()
|
|
{
|
|
_mockCoreApiWrapperService = new Mock<ICoreApiWrapperService>();
|
|
_apiConfiguration = new ApiConfiguration() { TimeZone = "America/Chicago" };
|
|
_primaryNotificationInfoDeterminingService = new PrimaryNotificationInfoDeterminingService(_mockCoreApiWrapperService.Object,
|
|
_apiConfiguration);
|
|
}
|
|
|
|
[Test]
|
|
public async Task DeterminePrimaryOwnerNotificationInfos_Success_PersonNumber()
|
|
{
|
|
var entityNumber = "123";
|
|
var userIds = new List<string> { "456", "567", "678" };
|
|
var users = new List<Agreement>()
|
|
{
|
|
new()
|
|
{
|
|
UserId = userIds[0],
|
|
FirstName = "Tim"
|
|
},
|
|
new()
|
|
{
|
|
UserId = userIds[1],
|
|
FirstName = "Fred"
|
|
},
|
|
new()
|
|
{
|
|
UserId = userIds[2],
|
|
FirstName = "Randy"
|
|
}
|
|
};
|
|
|
|
_mockCoreApiWrapperService.Setup(x => x.GetAgreeUsersByPersonNumber(entityNumber)).ReturnsAsync(userIds);
|
|
_mockCoreApiWrapperService.SetupSequence(x => x.GetAgreementByUserId(It.IsAny<string>())).ReturnsAsync(users[0])
|
|
.ReturnsAsync(users[1])
|
|
.ReturnsAsync(users[2]);
|
|
|
|
var result = await _primaryNotificationInfoDeterminingService.DeterminePrimaryOwnerNotificationInfos("123", EntityTypes.Person);
|
|
|
|
Assert.NotNull(result);
|
|
Assert.AreEqual(result.Count, 3);
|
|
_mockCoreApiWrapperService.Verify(x => x.GetAgreeUsersByPersonNumber(entityNumber), Times.Once);
|
|
_mockCoreApiWrapperService.Verify(x => x.GetAgreementByUserId(It.IsAny<string>()), Times.Exactly(3));
|
|
_mockCoreApiWrapperService.Verify(x => x.GetAgreeUserByOrganizationNumber(It.IsAny<string>()), Times.Never);
|
|
}
|
|
|
|
[Test]
|
|
public async Task DeterminePrimaryOwnerNotificationInfos_Success_OrganizationNumber()
|
|
{
|
|
var entityNumber = "123";
|
|
var userIds = new List<string> { "456" };
|
|
var user = new Agreement()
|
|
{
|
|
UserId = userIds[0],
|
|
OrganizationName = "RugMart"
|
|
};
|
|
|
|
_mockCoreApiWrapperService.Setup(x => x.GetAgreeUserByOrganizationNumber(entityNumber)).ReturnsAsync(userIds[0]);
|
|
_mockCoreApiWrapperService.Setup(x => x.GetAgreementByUserId(It.IsAny<string>())).ReturnsAsync(user);
|
|
|
|
var result = await _primaryNotificationInfoDeterminingService.DeterminePrimaryOwnerNotificationInfos(entityNumber, EntityTypes.Organization);
|
|
Assert.NotNull(result);
|
|
Assert.AreEqual(result.Count, 1);
|
|
_mockCoreApiWrapperService.Verify(x => x.GetAgreeUserByOrganizationNumber(entityNumber), Times.Once);
|
|
_mockCoreApiWrapperService.Verify(x => x.GetAgreementByUserId(It.IsAny<string>()), Times.Once);
|
|
_mockCoreApiWrapperService.Verify(x => x.GetAgreeUsersByPersonNumber(It.IsAny<string>()), Times.Never);
|
|
}
|
|
|
|
[Test]
|
|
public async Task DeterminePrimaryOwnerNotificationInfos_Success_NoAgreemrnt_Organization()
|
|
{
|
|
var entityNumber = "123";
|
|
string userId = null;
|
|
|
|
_mockCoreApiWrapperService.Setup(x => x.GetAgreeUserByOrganizationNumber(entityNumber)).ReturnsAsync(userId);
|
|
|
|
var result = await _primaryNotificationInfoDeterminingService.DeterminePrimaryOwnerNotificationInfos(entityNumber, EntityTypes.Organization);
|
|
Assert.NotNull(result);
|
|
Assert.AreEqual(result.Count, 1);
|
|
_mockCoreApiWrapperService.Verify(x => x.GetAgreeUserByOrganizationNumber(entityNumber), Times.Once);
|
|
_mockCoreApiWrapperService.Verify(x => x.GetAgreementByUserId(It.IsAny<string>()), Times.Never);
|
|
_mockCoreApiWrapperService.Verify(x => x.GetAgreeUsersByPersonNumber(It.IsAny<string>()), Times.Never);
|
|
}
|
|
|
|
[Test]
|
|
public async Task DeterminePrimaryOwnerNotificationInfos_Success_NullAgreement_Person()
|
|
{
|
|
var entityNumber = "123";
|
|
var userIds = new List<string> { "456" };
|
|
Agreement user = null;
|
|
|
|
_mockCoreApiWrapperService.Setup(x => x.GetAgreeUsersByPersonNumber(entityNumber)).ReturnsAsync(userIds);
|
|
_mockCoreApiWrapperService.Setup(x => x.GetAgreementByUserId(It.IsAny<string>())).ReturnsAsync(user);
|
|
|
|
var result = await _primaryNotificationInfoDeterminingService.DeterminePrimaryOwnerNotificationInfos(entityNumber, EntityTypes.Person);
|
|
Assert.NotNull(result);
|
|
Assert.AreEqual(result.Count, 1);
|
|
_mockCoreApiWrapperService.Verify(x => x.GetAgreeUsersByPersonNumber(entityNumber), Times.Once);
|
|
_mockCoreApiWrapperService.Verify(x => x.GetAgreementByUserId(It.IsAny<string>()), Times.Once);
|
|
_mockCoreApiWrapperService.Verify(x => x.GetAgreeUserByOrganizationNumber(It.IsAny<string>()), Times.Never);
|
|
}
|
|
|
|
[Test]
|
|
public async Task DeterminePrimaryOwnerNotificationInfos_Success_NullAgreeUsers_Person()
|
|
{
|
|
var entityNumber = "123";
|
|
IEnumerable<string>? userId = null;
|
|
|
|
_mockCoreApiWrapperService.Setup(x => x.GetAgreeUsersByPersonNumber(entityNumber)).ReturnsAsync(userId);
|
|
|
|
var result = await _primaryNotificationInfoDeterminingService.DeterminePrimaryOwnerNotificationInfos(entityNumber, EntityTypes.Person);
|
|
Assert.NotNull(result);
|
|
Assert.AreEqual(result.Count, 1);
|
|
_mockCoreApiWrapperService.Verify(x => x.GetAgreeUsersByPersonNumber(entityNumber), Times.Once);
|
|
_mockCoreApiWrapperService.Verify(x => x.GetAgreementByUserId(It.IsAny<string>()), Times.Never);
|
|
_mockCoreApiWrapperService.Verify(x => x.GetAgreeUserByOrganizationNumber(It.IsAny<string>()), Times.Never);
|
|
}
|
|
|
|
[Test]
|
|
public async Task DeterminePrimaryOwnerNotificationInfos_Success_NoAgreement_Person()
|
|
{
|
|
var entityNumber = "123";
|
|
IEnumerable<string> userId = new List<string>();
|
|
|
|
_mockCoreApiWrapperService.Setup(x => x.GetAgreeUsersByPersonNumber(entityNumber)).ReturnsAsync(userId);
|
|
|
|
var result = await _primaryNotificationInfoDeterminingService.DeterminePrimaryOwnerNotificationInfos(entityNumber, EntityTypes.Person);
|
|
Assert.NotNull(result);
|
|
Assert.AreEqual(result.Count, 1);
|
|
_mockCoreApiWrapperService.Verify(x => x.GetAgreeUsersByPersonNumber(entityNumber), Times.Once);
|
|
_mockCoreApiWrapperService.Verify(x => x.GetAgreementByUserId(It.IsAny<string>()), Times.Never);
|
|
_mockCoreApiWrapperService.Verify(x => x.GetAgreeUserByOrganizationNumber(It.IsAny<string>()), Times.Never);
|
|
}
|
|
|
|
[Test]
|
|
public void DeterminePrimaryOwnerNotificationInfos_Exception()
|
|
{
|
|
_mockCoreApiWrapperService.Setup(x => x.GetAgreeUserByOrganizationNumber(null)).Throws(new Exception("Error"));
|
|
|
|
Assert.ThrowsAsync<ServiceException>(async () => await _primaryNotificationInfoDeterminingService
|
|
.DeterminePrimaryOwnerNotificationInfos(null, EntityTypes.Organization));
|
|
_mockCoreApiWrapperService.Verify(x => x.GetAgreeUserByOrganizationNumber(It.IsAny<string>()), Times.Once);
|
|
_mockCoreApiWrapperService.Verify(x => x.GetAgreementByUserId(It.IsAny<string>()), Times.Never);
|
|
_mockCoreApiWrapperService.Verify(x => x.GetAgreeUsersByPersonNumber(It.IsAny<string>()), Times.Never);
|
|
}
|
|
}
|