This commit is contained in:
Zeeshaun
2026-03-25 14:50:13 -05:00
parent 883009770f
commit b690921fd7
592 changed files with 46618 additions and 0 deletions
@@ -0,0 +1,613 @@
using LCU.API.Internal.DocumentIngestor.Services.AttributeDeterminingServices;
using LCU.API.Internal.DocumentIngestor.Services.MicroApiServices;
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.Accounts;
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.Agreements;
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.Mixed;
using LCU.Library.Internal.DocumentIngestorModels.Entities;
using LCU.Library.Internal.DocumentIngestorModels.Enums;
using Moq;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace LCU.API.Internal.DocumentIngestorTests.Services.AttributeDeterminingServices;
public class AccountOwnerDeterminingServiceTest
{
private AccountOwnerDeterminingService _accountOwnerDeterminingService;
private Mock<ICoreApiWrapperService> _mockCoreApiWrapperService;
[SetUp]
public void Setup()
{
_mockCoreApiWrapperService = new Mock<ICoreApiWrapperService>();
_accountOwnerDeterminingService = new AccountOwnerDeterminingService(_mockCoreApiWrapperService.Object);
}
[Test]
public async Task DetermineAccountOwnerAttributeForDnaDocument_PersonNumberFound_Success()
{
var fullName = "Bill B Billson";
var accountNumber = "9999";
var creationDate = new DateTime(2022, 01, 01);
var accountOwnership = new List<AccountOwnership>
{
new()
{
PersonNumber = 1,
FirstName = "Bill",
MiddleInitial = "B",
LastName = "Billson",
IsPrimaryOwner = true
}
};
_mockCoreApiWrapperService.Setup(x => x.GetOwnersByAccountNumber(accountNumber, creationDate.ToShortDateString())).ReturnsAsync(accountOwnership);
var result = await _accountOwnerDeterminingService.DetermineAccountOwnerAttribute(fullName, accountNumber, creationDate, null);
var resultPayload = result.Payload;
Assert.AreEqual("1", resultPayload.PersonNumbers?[0]);
Assert.IsEmpty(resultPayload.OrganizationNumbers);
Assert.AreEqual("9999", resultPayload.AccountNumber);
_mockCoreApiWrapperService.Verify(x => x.GetOwnersByAccountNumber(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
_mockCoreApiWrapperService.Verify(x => x.GetOwnersByPersonName(It.IsAny<string>()), Times.Never);
_mockCoreApiWrapperService.Verify(x => x.GetOwnersByOrganizationName(It.IsAny<string>()), Times.Never);
}
[Test]
public async Task DetermineAccountOwnerAttributeForDnaDocument_PersonNumberNotFound_OrganizationFound_Success()
{
var orgName = "The Big Company";
var accountNumber = "9999";
var creationDate = new DateTime(2022, 01, 01);
var accountOwnership = new List<AccountOwnership>
{
new()
{
ByOrgNbr = 2,
OrganizationName = orgName,
IsPrimaryOwner = true
}
};
_mockCoreApiWrapperService.Setup(x => x.GetOwnersByAccountNumber(accountNumber, creationDate.ToShortDateString())).ReturnsAsync(accountOwnership);
var result = await _accountOwnerDeterminingService.DetermineAccountOwnerAttribute(orgName, accountNumber, creationDate, null);
var resultPayload = result.Payload;
Assert.AreEqual("2", resultPayload.OrganizationNumbers?[0]);
Assert.IsEmpty(resultPayload.PersonNumbers);
Assert.AreEqual("9999", resultPayload.AccountNumber);
_mockCoreApiWrapperService.Verify(x => x.GetOwnersByAccountNumber(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
}
[Test]
public async Task DetermineAccountOwnerAttributeForDnaDocument_PersonNumberNotFound_OrganizationNotFound_Failure()
{
var fullName = "Bill B Billson";
var accountNumber = "9999";
var creationDate = new DateTime(2022, 01, 01);
var accountOwnership = new List<AccountOwnership>();
_mockCoreApiWrapperService.Setup(x => x.GetOwnersByAccountNumber(accountNumber, creationDate.ToShortDateString())).ReturnsAsync(accountOwnership);
var result = await _accountOwnerDeterminingService.DetermineAccountOwnerAttribute(fullName, accountNumber, creationDate, null);
var resultPayload = result.Payload;
Assert.IsEmpty(resultPayload.OrganizationNumbers);
Assert.IsEmpty(resultPayload.PersonNumbers);
Assert.AreEqual("9999", resultPayload.AccountNumber);
_mockCoreApiWrapperService.Verify(x => x.GetOwnersByAccountNumber(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
}
[Test]
public async Task DetermineAccountOwnerAttributeForDnaDocument_NoPrimaryOwner_Failure()
{
var fullName = "Bill B Billson";
var accountNumber = "";
var creationDate = new DateTime(2022, 01, 01);
var accountOwnership = new List<AccountOwnership>
{
new()
{
PersonNumber = 2,
FirstName = "Bill",
MiddleInitial = "B",
LastName = "Billson",
IsPrimaryOwner = false
},
new()
{
PersonNumber = 5,
FirstName = "Bill",
MiddleInitial = "B",
LastName = "Billson",
IsPrimaryOwner = false
}
};
_mockCoreApiWrapperService.Setup(x => x.GetOwnersByPersonName(fullName)).ReturnsAsync(accountOwnership);
var result = await _accountOwnerDeterminingService.DetermineAccountOwnerAttribute(fullName, accountNumber, creationDate, null);
var resultPayload = result.Payload;
Assert.IsFalse(result.Success);
Assert.IsEmpty(resultPayload.OrganizationNumbers);
Assert.IsEmpty(resultPayload.PersonNumbers);
Assert.AreEqual(accountNumber, resultPayload.AccountNumber);
_mockCoreApiWrapperService.Verify(x => x.GetOwnersByPersonName(It.IsAny<string>()), Times.Never);
_mockCoreApiWrapperService.Verify(x => x.GetOwnersByOrganizationName(It.IsAny<string>()), Times.Never);
_mockCoreApiWrapperService.Verify(x => x.GetOwnersByAccountNumber(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
}
[Test]
public async Task DetermineAccountOwnerAttributeForDnaDocument_TooManyOwners_Failure()
{
var fullName = "Bill B Billson";
var accountNumber = "";
var creationDate = new DateTime(2022, 01, 01);
var accountOwnership = new List<AccountOwnership>
{
new()
{
PersonNumber = 2,
FirstName = "Bill",
MiddleInitial = "B",
LastName = "Billson",
IsPrimaryOwner = true
},
new()
{
PersonNumber = 5,
FirstName = "Bill",
MiddleInitial = "B",
LastName = "Billson",
IsPrimaryOwner = true
}
};
_mockCoreApiWrapperService.Setup(x => x.GetOwnersByPersonName(fullName)).ReturnsAsync(accountOwnership);
var result = await _accountOwnerDeterminingService.DetermineAccountOwnerAttribute(fullName, accountNumber, creationDate, null);
var resultPayload = result.Payload;
Assert.IsFalse(result.Success);
Assert.IsEmpty(resultPayload.OrganizationNumbers);
Assert.IsEmpty(resultPayload.PersonNumbers);
Assert.AreEqual(accountNumber, resultPayload.AccountNumber);
_mockCoreApiWrapperService.Verify(x => x.GetOwnersByPersonName(It.IsAny<string>()), Times.Never);
_mockCoreApiWrapperService.Verify(x => x.GetOwnersByOrganizationName(It.IsAny<string>()), Times.Never);
_mockCoreApiWrapperService.Verify(x => x.GetOwnersByAccountNumber(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
}
[Test]
public async Task DeterminePrimaryOwnerAttributeForDnaDocument_EntityNameDoesNotMatch_Failure()
{
var fullName = "Bill B Billson";
var accountNumber = "9999";
var creationDate = new DateTime(2022, 01, 01);
var accountOwnership = new List<AccountOwnership>
{
new()
{
ByOrgNbr = 2,
FirstName = "Pete",
MiddleInitial = "P",
LastName = "Peterson",
IsPrimaryOwner = true
}
};
_mockCoreApiWrapperService.Setup(x => x.GetOwnersByAccountNumber(accountNumber, creationDate.ToShortDateString())).ReturnsAsync(accountOwnership);
var result = await _accountOwnerDeterminingService.DetermineAccountOwnerAttribute(fullName, accountNumber, creationDate, null);
var resultPayload = result.Payload;
Assert.IsFalse(result.Success);
Assert.AreEqual("2", resultPayload.OrganizationNumbers?[0]);
Assert.IsEmpty(resultPayload.PersonNumbers);
Assert.AreEqual("9999", resultPayload.AccountNumber);
_mockCoreApiWrapperService.Verify(x => x.GetOwnersByAccountNumber(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
}
[Test]
public async Task DetermineAccountOwnerAttributeForDnaDocument_OwnerOverridePerson_Success()
{
var fullName = "Bill B Billson";
var accountNumber = "9999";
var documentProcessingInfoId = 123;
var creationDate = new DateTime(2022, 01, 01);
var accountOwnership = new List<AccountOwnership>
{
new()
{
PersonNumber = 1,
FirstName = "Bill",
MiddleInitial = "B",
LastName = "Billson",
IsPrimaryOwner = true
}
};
var ownerOverrideRequest = new OwnerOverrideInfo()
{
DocumentProcessingInfoId = documentProcessingInfoId,
EntityId = "888888",
EntityType = EntityTypes.Person,
UserName = "Test Tester"
};
_mockCoreApiWrapperService.Setup(x => x.GetOwnersByAccountNumber(accountNumber, creationDate.ToShortDateString())).ReturnsAsync(accountOwnership);
var result = await _accountOwnerDeterminingService.DetermineAccountOwnerAttribute(fullName, accountNumber, creationDate, ownerOverrideRequest);
var resultPayload = result.Payload;
Assert.AreEqual("888888", resultPayload.PersonNumbers?[0]);
Assert.IsEmpty(resultPayload.OrganizationNumbers);
Assert.AreEqual("9999", resultPayload.AccountNumber);
_mockCoreApiWrapperService.Verify(x => x.GetOwnersByAccountNumber(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
_mockCoreApiWrapperService.Verify(x => x.GetOwnersByPersonName(It.IsAny<string>()), Times.Never);
_mockCoreApiWrapperService.Verify(x => x.GetOwnersByOrganizationName(It.IsAny<string>()), Times.Never);
}
[Test]
public async Task DetermineAccountOwnerAttributeForDnaDocument_OwnerOverrideOrganization_Success()
{
var fullName = "Bill B Billson";
var accountNumber = "9999";
var documentProcessingInfoId = 123;
var creationDate = new DateTime(2022, 01, 01);
var accountOwnership = new List<AccountOwnership>
{
new()
{
ByOrgNbr = 1,
FirstName = "Bill",
MiddleInitial = "B",
LastName = "Billson",
IsPrimaryOwner = true
}
};
var ownerOverrideRequest = new OwnerOverrideInfo()
{
DocumentProcessingInfoId = documentProcessingInfoId,
EntityId = "888888",
EntityType = EntityTypes.Organization,
UserName = "Test Tester"
};
_mockCoreApiWrapperService.Setup(x => x.GetOwnersByAccountNumber(accountNumber, creationDate.ToShortDateString())).ReturnsAsync(accountOwnership);
var result = await _accountOwnerDeterminingService.DetermineAccountOwnerAttribute(fullName, accountNumber, creationDate, ownerOverrideRequest);
var resultPayload = result.Payload;
Assert.AreEqual("888888", resultPayload.OrganizationNumbers?[0]);
Assert.IsEmpty(resultPayload.PersonNumbers);
Assert.AreEqual("9999", resultPayload.AccountNumber);
_mockCoreApiWrapperService.Verify(x => x.GetOwnersByAccountNumber(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
_mockCoreApiWrapperService.Verify(x => x.GetOwnersByPersonName(It.IsAny<string>()), Times.Never);
_mockCoreApiWrapperService.Verify(x => x.GetOwnersByOrganizationName(It.IsAny<string>()), Times.Never);
}
[Test]
public async Task DetermineAccountOwnerAttributeForDnaDocument_OwnerOverrideUnknown_Success()
{
var fullName = "Bill B Billson";
var accountNumber = "9999";
var documentProcessingInfoId = 123;
var creationDate = new DateTime(2022, 01, 01);
var accountOwnership = new List<AccountOwnership>
{
new()
{
PersonNumber = 1,
FirstName = "Bill",
MiddleInitial = "B",
LastName = "Billson",
IsPrimaryOwner = true
}
};
var ownerOverrideRequest = new OwnerOverrideInfo()
{
DocumentProcessingInfoId = documentProcessingInfoId,
EntityId = "888888",
EntityType = EntityTypes.Unknown,
UserName = "Test Tester"
};
_mockCoreApiWrapperService.Setup(x => x.GetOwnersByAccountNumber(accountNumber, creationDate.ToShortDateString())).ReturnsAsync(accountOwnership);
var result = await _accountOwnerDeterminingService.DetermineAccountOwnerAttribute(fullName, accountNumber, creationDate, ownerOverrideRequest);
var resultPayload = result.Payload;
Assert.AreEqual("1", resultPayload.PersonNumbers?[0]);
Assert.IsEmpty(resultPayload.OrganizationNumbers);
Assert.AreEqual("9999", resultPayload.AccountNumber);
_mockCoreApiWrapperService.Verify(x => x.GetOwnersByAccountNumber(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
_mockCoreApiWrapperService.Verify(x => x.GetOwnersByPersonName(It.IsAny<string>()), Times.Never);
_mockCoreApiWrapperService.Verify(x => x.GetOwnersByOrganizationName(It.IsAny<string>()), Times.Never);
}
[Test]
public async Task DetermineAccountOwnerAttributeByMemberNumberOrUserId_StartsWithM_PersonNumberFound_Success()
{
var memberNumberOrUserId = "M1234";
var accountNumber = "9999";
var docType = "MTG_NT_110_01";
var creationDate = new DateTime(2022, 01, 01);
var accountOwnership = new List<AccountOwnership>
{
new()
{
PersonNumber = 1234,
FirstName = "Bill",
MiddleInitial = "B",
LastName = "Billson",
IsPrimaryOwner = true
}
};
var personOrganization = new PersonOrganization()
{
PersonNumber = "1234",
OrganizationNumber = null
};
var agreementAccount = new AgreementAccount()
{
AccountNumber = 9999,
AccountDescription = "PREMIUM CHECKING",
MajorAccountTypeCode = "CK",
TaxReportForPersonNumber = 1234,
TaxReportForOrgNumber = null,
OvrDeliveryMethCD = "PRNT",
AccountOwner = new AgreementAccountOwner
{
AccountNumber = 9999,
AgreementNumber = 0,
UserId = null,
PersonNumber = 0
}
};
_mockCoreApiWrapperService.Setup(x => x.GetPersonOrOrganizationNumberByMemberId(It.IsAny<string>())).ReturnsAsync(personOrganization).Verifiable();
_mockCoreApiWrapperService.Setup(x => x.GetAgreementAccountByAccountId(It.IsAny<string>())).ReturnsAsync(agreementAccount);
_mockCoreApiWrapperService.Setup(x => x.GetOwnersByAccountNumber(accountNumber, creationDate.ToShortDateString())).ReturnsAsync(accountOwnership);
var result = await _accountOwnerDeterminingService.DetermineAccountOwnerAttributeByMemberNumberOrUserId(memberNumberOrUserId, accountNumber, docType, creationDate, null);
var resultPayload = result.Payload;
Assert.IsTrue(result.Success);
Assert.AreEqual("1234", resultPayload.PersonNumbers?[0]);
Assert.IsEmpty(resultPayload.OrganizationNumbers);
Assert.AreEqual("9999", resultPayload.AccountNumber);
_mockCoreApiWrapperService.Verify(x => x.GetOwnersByAccountNumber(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
_mockCoreApiWrapperService.Verify(x => x.GetAgreementByUserId(It.IsAny<string>()), Times.Never);
_mockCoreApiWrapperService.Verify(x => x.GetAgreementAccountByAccountId(It.IsAny<string>()), Times.Once);
}
[Test]
public async Task DetermineAccountOwnerAttributeByMemberNumberOrUserId_StartsWithoutM_PersonNumberFound_Success()
{
var memberNumberOrUserId = "1234";
var accountNumber = "9999";
var docType = "OPS_NT_119_01";
var creationDate = new DateTime(2022, 01, 01);
var accountOwnership = new List<AccountOwnership>
{
new()
{
PersonNumber = 1234,
FirstName = "Bill",
MiddleInitial = "B",
LastName = "Billson",
IsPrimaryOwner = true
}
};
var personOrganization = new PersonOrganization()
{
PersonNumber = "1234",
OrganizationNumber = null
};
var agreementAccount = new AgreementAccount()
{
AccountNumber = 9999,
AccountDescription = "PREMIUM CHECKING",
MajorAccountTypeCode = "CK",
TaxReportForPersonNumber = 1234,
TaxReportForOrgNumber = null,
OvrDeliveryMethCD = "PRNT",
AccountOwner = new AgreementAccountOwner
{
AccountNumber = 9999,
AgreementNumber = 0,
UserId = null,
PersonNumber = 0
}
};
_mockCoreApiWrapperService.Setup(x => x.GetPersonOrOrganizationNumberByMemberId(It.IsAny<string>())).ReturnsAsync(personOrganization).Verifiable();
_mockCoreApiWrapperService.Setup(x => x.GetAgreementAccountByAccountId(It.IsAny<string>())).ReturnsAsync(agreementAccount);
_mockCoreApiWrapperService.Setup(x => x.GetOwnersByAccountNumber(accountNumber, creationDate.ToShortDateString())).ReturnsAsync(accountOwnership);
var result = await _accountOwnerDeterminingService.DetermineAccountOwnerAttributeByMemberNumberOrUserId(memberNumberOrUserId, accountNumber, docType, creationDate, null);
var resultPayload = result.Payload;
Assert.IsTrue(result.Success);
Assert.AreEqual("1234", resultPayload.PersonNumbers?[0]);
Assert.IsEmpty(resultPayload.OrganizationNumbers);
Assert.AreEqual("9999", resultPayload.AccountNumber);
_mockCoreApiWrapperService.Verify(x => x.GetOwnersByAccountNumber(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
_mockCoreApiWrapperService.Verify(x => x.GetAgreementByUserId(It.IsAny<string>()), Times.Never);
_mockCoreApiWrapperService.Verify(x => x.GetAgreementAccountByAccountId(It.IsAny<string>()), Times.Once);
}
[Test]
public async Task DetermineAccountOwnerAttributeByMemberNumberOrUserId_PersonNumberNotFound_OrganizationNotFound_Failure()
{
var memberNumberOrUserId = "M1234";
var accountNumber = "9999";
var docType = "OPS_NT_119_01";
var creationDate = new DateTime(2022, 01, 01);
var accountOwnership = new List<AccountOwnership>
{
new()
{
PersonNumber = 1,
FirstName = "Bill",
MiddleInitial = "B",
LastName = "Billson",
IsPrimaryOwner = true
}
};
var personOrganization = new PersonOrganization()
{
PersonNumber = null,
OrganizationNumber = null
};
_mockCoreApiWrapperService.Setup(x => x.GetPersonOrOrganizationNumberByMemberId(It.IsAny<string>())).ReturnsAsync(personOrganization).Verifiable();
_mockCoreApiWrapperService.Setup(x => x.GetOwnersByAccountNumber(accountNumber, creationDate.ToShortDateString())).ReturnsAsync(accountOwnership);
var result = await _accountOwnerDeterminingService.DetermineAccountOwnerAttributeByMemberNumberOrUserId(memberNumberOrUserId, accountNumber, docType, creationDate, null);
var resultPayload = result.Payload;
Assert.IsFalse(result.Success);
_mockCoreApiWrapperService.Verify(x => x.GetOwnersByAccountNumber(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
_mockCoreApiWrapperService.Verify(x => x.GetAgreementByUserId(It.IsAny<string>()), Times.Never);
}
[Test]
public async Task DetermineAccountOwnerAttributeByMemberNumberOrUserId_AgreementNotFound_Failure()
{
var memberNumberOrUserId = "1234";
var accountNumber = "9999";
var docType = "MTG_NT_110_01";
var creationDate = new DateTime(2022, 01, 01);
var accountOwnership = new List<AccountOwnership>
{
new()
{
PersonNumber = 1,
FirstName = "Bill",
MiddleInitial = "B",
LastName = "Billson",
IsPrimaryOwner = true
}
};
_mockCoreApiWrapperService.Setup(x => x.GetOwnersByAccountNumber(accountNumber, creationDate.ToShortDateString())).ReturnsAsync(accountOwnership);
var result = await _accountOwnerDeterminingService.DetermineAccountOwnerAttributeByMemberNumberOrUserId(memberNumberOrUserId, accountNumber, docType, creationDate, null);
Assert.IsFalse(result.Success);
_mockCoreApiWrapperService.Verify(x => x.GetOwnersByAccountNumber(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
_mockCoreApiWrapperService.Verify(x => x.GetAgreementByUserId(It.IsAny<string>()), Times.Once);
_mockCoreApiWrapperService.Verify(x => x.GetAgreementAccountByAccountId(It.IsAny<string>()), Times.Never);
}
[Test]
public async Task DetermineAccountOwnerAttributeByMemberNumberOrUserId_PersonNumberDoesNotMatch_Failure()
{
var memberNumberOrUserId = "M1234";
var accountNumber = "9999";
var docType = "OPS_NT_119_01";
var creationDate = new DateTime(2022, 01, 01);
var accountOwnership = new List<AccountOwnership>
{
new()
{
PersonNumber = 1,
FirstName = "Bill",
MiddleInitial = "B",
LastName = "Billson",
IsPrimaryOwner = true
}
};
var personOrganization = new PersonOrganization()
{
PersonNumber = "2",
OrganizationNumber = null
};
var agreementAccount = new AgreementAccount()
{
AccountNumber = 9999,
AccountDescription = "PREMIUM CHECKING",
MajorAccountTypeCode = "CK",
TaxReportForPersonNumber = 1234,
TaxReportForOrgNumber = null,
OvrDeliveryMethCD = "PRNT",
AccountOwner = new AgreementAccountOwner
{
AccountNumber = 9999,
AgreementNumber = 0,
UserId = null,
PersonNumber = 0
}
};
_mockCoreApiWrapperService.Setup(x => x.GetPersonOrOrganizationNumberByMemberId(It.IsAny<string>())).ReturnsAsync(personOrganization).Verifiable();
_mockCoreApiWrapperService.Setup(x => x.GetAgreementAccountByAccountId(It.IsAny<string>())).ReturnsAsync(agreementAccount);
_mockCoreApiWrapperService.Setup(x => x.GetOwnersByAccountNumber(accountNumber, creationDate.ToShortDateString())).ReturnsAsync(accountOwnership);
var result = await _accountOwnerDeterminingService.DetermineAccountOwnerAttributeByMemberNumberOrUserId(memberNumberOrUserId, accountNumber, docType, creationDate, null);
Assert.IsFalse(result.Success);
_mockCoreApiWrapperService.Verify(x => x.GetOwnersByAccountNumber(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
_mockCoreApiWrapperService.Verify(x => x.GetAgreementByUserId(It.IsAny<string>()), Times.Never);
_mockCoreApiWrapperService.Verify(x => x.GetAgreementAccountByAccountId(It.IsAny<string>()), Times.Once);
}
[Test]
public async Task DetermineAccountOwnerAttributeByMemberNumberOrUserId_OrganizationNumberDoesNotMatch_Failure()
{
var memberNumberOrUserId = "M1234";
var accountNumber = "9999";
var docType = "OPS_NT_119_01";
var creationDate = new DateTime(2022, 01, 01);
var accountOwnership = new List<AccountOwnership>
{
new()
{
PersonNumber = 1,
FirstName = "Bill",
MiddleInitial = "B",
LastName = "Billson",
IsPrimaryOwner = true,
ByOrgNbr = 123
}
};
var personOrganization = new PersonOrganization()
{
PersonNumber = null,
OrganizationNumber = "456"
};
var agreementAccount = new AgreementAccount()
{
AccountNumber = 9999,
AccountDescription = "PREMIUM CHECKING",
MajorAccountTypeCode = "CK",
TaxReportForPersonNumber = null,
TaxReportForOrgNumber = 123,
OvrDeliveryMethCD = "PRNT",
AccountOwner = new AgreementAccountOwner
{
AccountNumber = 9999,
AgreementNumber = 0,
UserId = null,
PersonNumber = 0
}
};
_mockCoreApiWrapperService.Setup(x => x.GetPersonOrOrganizationNumberByMemberId(It.IsAny<string>())).ReturnsAsync(personOrganization).Verifiable();
_mockCoreApiWrapperService.Setup(x => x.GetAgreementAccountByAccountId(It.IsAny<string>())).ReturnsAsync(agreementAccount);
_mockCoreApiWrapperService.Setup(x => x.GetOwnersByAccountNumber(accountNumber, creationDate.ToShortDateString())).ReturnsAsync(accountOwnership);
var result = await _accountOwnerDeterminingService.DetermineAccountOwnerAttributeByMemberNumberOrUserId(memberNumberOrUserId, accountNumber, docType, creationDate, null);
Assert.IsFalse(result.Success);
_mockCoreApiWrapperService.Verify(x => x.GetOwnersByAccountNumber(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
_mockCoreApiWrapperService.Verify(x => x.GetAgreementAccountByAccountId(It.IsAny<string>()), Times.Once);
}
}
@@ -0,0 +1,957 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Linq;
using Moq;
using NUnit.Framework;
using LCU.Library.Internal.DocumentIngestorModels.Entities;
using LCU.Library.Internal.Exceptions;
using LCU.API.Internal.DocumentIngestor.Services;
using LCU.API.Internal.DocumentIngestorLib.Repositories;
using LCU.Library.Internal.DocumentIngestorModels.Enums;
using LCU.Library.Internal.DocumentIngestorModels.Models;
using LCU.Library.Internal.DocumentIngestorModels.Models.Pagination;
namespace LCU.API.Internal.DocumentIngestorTests.Services;
public class DocumentProcessingInfoServiceTest
{
private DocumentProcessingInfoService _documentProcessingInfoService;
private Mock<IUnitOfWork> _unitOfWork;
private Mock<IDocumentProcessingInfoRepository> _mockDocumentProcessingInfoRepository;
private Mock<IProcessingLogService> _mockProcessingLogService;
[SetUp]
public void Setup()
{
_unitOfWork = new Mock<IUnitOfWork>();
_mockDocumentProcessingInfoRepository = new Mock<IDocumentProcessingInfoRepository>();
_mockProcessingLogService = new Mock<IProcessingLogService>();
_documentProcessingInfoService = new DocumentProcessingInfoService(_unitOfWork.Object, _mockDocumentProcessingInfoRepository.Object, _mockProcessingLogService.Object);
}
[Test]
public async Task GetAsync_DocumentProcessingInfos_Returned()
{
var ingestorRunInfoId = Guid.NewGuid();
var id = 1;
var documentProcessingInfos = new List<DocumentProcessingInfo>()
{
new DocumentProcessingInfo()
{
DocumentProcessingInfoId = id,
IngestorRunInfoId = ingestorRunInfoId
}
};
_mockDocumentProcessingInfoRepository.Setup(x => x.FindAsync()).ReturnsAsync(documentProcessingInfos);
var result = await _documentProcessingInfoService.GetAsync();
Assert.IsNotNull(result);
Assert.AreEqual(1, result.Count());
_mockDocumentProcessingInfoRepository.Verify(x => x.FindAsync(), Times.Once);
}
[Test]
public void GetAsync_Exception()
{
_mockDocumentProcessingInfoRepository.Setup(x => x.FindAsync()).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _documentProcessingInfoService.GetAsync());
_mockDocumentProcessingInfoRepository.Verify(x => x.FindAsync(), Times.Once);
}
[Test]
public async Task GetByIdAsync_DocumentProcessingInfo_Returned()
{
var ingestorRunInfoId = Guid.NewGuid();
var id = 1;
var documentProcessingInfo = new DocumentProcessingInfo()
{
DocumentProcessingInfoId = id,
IngestorRunInfoId = ingestorRunInfoId
};
_mockDocumentProcessingInfoRepository.Setup(x => x.FindByIdAsync(id)).ReturnsAsync(documentProcessingInfo);
var result = await _documentProcessingInfoService.GetByIdAsync(id);
Assert.IsNotNull(result);
Assert.AreEqual(ingestorRunInfoId, result.IngestorRunInfoId);
Assert.AreEqual(id, result.DocumentProcessingInfoId);
_mockDocumentProcessingInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>()), Times.Once);
}
[Test]
public void GetByIdAsync_Exception()
{
var id = 1;
_mockDocumentProcessingInfoRepository.Setup(x => x.FindByIdAsync(id)).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _documentProcessingInfoService.GetByIdAsync(id));
_mockDocumentProcessingInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>()), Times.Once);
}
[Test]
public async Task GetByIngestorRunInfoIdAsync_DocumentProcessingInfos_Returned()
{
var ingestorRunInfoId = Guid.NewGuid();
var id = 1;
var documentProcessingInfos = new List<DocumentProcessingInfo>()
{
new DocumentProcessingInfo()
{
DocumentProcessingInfoId = id,
IngestorRunInfoId = ingestorRunInfoId
}
};
_mockDocumentProcessingInfoRepository.Setup(x => x.FindByIngestorRunInfoIdAsync(ingestorRunInfoId)).ReturnsAsync(documentProcessingInfos);
var result = await _documentProcessingInfoService.GetByIngestorRunInfoIdAsync(ingestorRunInfoId);
Assert.IsNotNull(result);
Assert.AreEqual(1, result.Count());
_mockDocumentProcessingInfoRepository.Verify(x => x.FindByIngestorRunInfoIdAsync(It.IsAny<Guid>()), Times.Once);
}
[Test]
public void GetByIngestorRunInfoIdAsync_Exception()
{
var ingestorRunInfoId = Guid.NewGuid();
_mockDocumentProcessingInfoRepository.Setup(x => x.FindByIngestorRunInfoIdAsync(ingestorRunInfoId)).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _documentProcessingInfoService.GetByIngestorRunInfoIdAsync(ingestorRunInfoId));
_mockDocumentProcessingInfoRepository.Verify(x => x.FindByIngestorRunInfoIdAsync(It.IsAny<Guid>()), Times.Once);
}
[Test]
public async Task SaveAsync_DocumentProcessingInfo_Returned()
{
var ingestorRunInfoId = Guid.NewGuid();
var id = 1;
var documentProcessingInfo = new DocumentProcessingInfo()
{
DocumentProcessingInfoId = id,
IngestorRunInfoId = ingestorRunInfoId
};
_mockDocumentProcessingInfoRepository.Setup(x => x.AddAsync(documentProcessingInfo)).ReturnsAsync(documentProcessingInfo);
var result = await _documentProcessingInfoService.SaveAsync(documentProcessingInfo);
Assert.IsNotNull(result);
Assert.AreEqual(ingestorRunInfoId, result.IngestorRunInfoId);
Assert.AreEqual(id, result.DocumentProcessingInfoId);
_mockDocumentProcessingInfoRepository.Verify(x => x.AddAsync(It.IsAny<DocumentProcessingInfo>()), Times.Once);
}
[Test]
public void SaveAsync_Exception()
{
var ingestorRunInfoId = Guid.NewGuid();
var id = 1;
var documentProcessingInfo = new DocumentProcessingInfo()
{
DocumentProcessingInfoId = id,
IngestorRunInfoId = ingestorRunInfoId
};
_mockDocumentProcessingInfoRepository.Setup(x => x.AddAsync(documentProcessingInfo)).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _documentProcessingInfoService.SaveAsync(documentProcessingInfo));
_mockDocumentProcessingInfoRepository.Verify(x => x.AddAsync(It.IsAny<DocumentProcessingInfo>()), Times.Once);
}
[Test]
public async Task Update_DocumentProcessingInfo_Returned()
{
var ingestorRunInfoId = Guid.NewGuid();
var id = 1;
var documentProcessingInfo = new DocumentProcessingInfo()
{
DocumentProcessingInfoId = id,
IngestorRunInfoId = ingestorRunInfoId
};
_mockDocumentProcessingInfoRepository.Setup(x => x.FindByIdAsync(id)).ReturnsAsync(documentProcessingInfo);
_mockDocumentProcessingInfoRepository.Setup(x => x.Update(documentProcessingInfo));
var result = await _documentProcessingInfoService.Update(documentProcessingInfo);
Assert.IsNotNull(result);
Assert.AreEqual(ingestorRunInfoId, result.IngestorRunInfoId);
Assert.AreEqual(id, result.DocumentProcessingInfoId);
_mockDocumentProcessingInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>()), Times.Once);
_mockDocumentProcessingInfoRepository.Verify(x => x.Update(It.IsAny<DocumentProcessingInfo>()), Times.Once);
}
[Test]
public void Update_FindByIdAsync_ThrowsException()
{
var ingestorRunInfoId = Guid.NewGuid();
var id = 1;
var documentProcessingInfo = new DocumentProcessingInfo()
{
DocumentProcessingInfoId = id,
IngestorRunInfoId = ingestorRunInfoId
};
_mockDocumentProcessingInfoRepository.Setup(x => x.FindByIdAsync(id)).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _documentProcessingInfoService.Update(documentProcessingInfo));
_mockDocumentProcessingInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>()), Times.Once);
_mockDocumentProcessingInfoRepository.Verify(x => x.Update(It.IsAny<DocumentProcessingInfo>()), Times.Never);
}
[Test]
public void Update_Update_ThrowsException()
{
var ingestorRunInfoId = Guid.NewGuid();
var id = 1;
var documentProcessingInfo = new DocumentProcessingInfo()
{
DocumentProcessingInfoId = id,
IngestorRunInfoId = ingestorRunInfoId
};
_mockDocumentProcessingInfoRepository.Setup(x => x.FindByIdAsync(id)).ReturnsAsync(documentProcessingInfo);
_mockDocumentProcessingInfoRepository.Setup(x => x.Update(documentProcessingInfo)).Throws(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _documentProcessingInfoService.Update(documentProcessingInfo));
_mockDocumentProcessingInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>()), Times.Once);
_mockDocumentProcessingInfoRepository.Verify(x => x.Update(It.IsAny<DocumentProcessingInfo>()), Times.Once);
}
[Test]
public async Task UpdateStatusAndAddLog_ById_SingleLog_Returned()
{
var ingestorRunInfoId = Guid.NewGuid();
var id = 1;
var documentProcessingInfo = new DocumentProcessingInfo()
{
DocumentProcessingInfoId = id,
IngestorRunInfoId = ingestorRunInfoId
};
_mockDocumentProcessingInfoRepository.Setup(x => x.FindByIdAsync(id)).ReturnsAsync(documentProcessingInfo);
_mockDocumentProcessingInfoRepository.Setup(x => x.Update(documentProcessingInfo));
var processingLog = new ProcessingLog()
{
DocumentProcessingInfoId = id,
LogTimeStamp = Convert.ToDateTime("1/1/2022"),
LogMessage = "Account fail",
UserName = "User"
};
_mockProcessingLogService.Setup(x => x.SaveAsync(It.IsAny<ProcessingLog>())).ReturnsAsync(processingLog);
var result = await _documentProcessingInfoService.UpdateStatusAndAddLog(id, ProcessStatusTypes.DataMappingFailure, "Account fail", "User");
Assert.IsNotNull(result);
Assert.AreEqual(ingestorRunInfoId, result.IngestorRunInfoId);
Assert.AreEqual(id, result.DocumentProcessingInfoId);
_mockDocumentProcessingInfoRepository.Verify(x => x.FindByIdAsync(id), Times.Exactly(2));
_mockDocumentProcessingInfoRepository.Verify(x => x.Update(documentProcessingInfo), Times.Once);
_mockProcessingLogService.Verify(x => x.SaveAsync(It.IsAny<ProcessingLog>()), Times.Once);
}
[Test]
public void UpdateStatusAndAddLog_ById_SingleLog_FindByIdAsync_ThrowsException()
{
var ingestorRunInfoId = Guid.NewGuid();
var id = 1;
var documentProcessingInfo = new DocumentProcessingInfo()
{
DocumentProcessingInfoId = id,
IngestorRunInfoId = ingestorRunInfoId
};
_mockDocumentProcessingInfoRepository.Setup(x => x.FindByIdAsync(id)).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _documentProcessingInfoService.UpdateStatusAndAddLog(id, ProcessStatusTypes.DataMappingFailure, "Account fail", "User"));
_mockDocumentProcessingInfoRepository.Verify(x => x.FindByIdAsync(id), Times.Once);
_mockDocumentProcessingInfoRepository.Verify(x => x.Update(documentProcessingInfo), Times.Never);
_mockProcessingLogService.Verify(x => x.SaveAsync(It.IsAny<ProcessingLog>()), Times.Never);
}
[Test]
public void UpdateStatusAndAddLog_ById_SingleLog_Update_ThrowsException()
{
var ingestorRunInfoId = Guid.NewGuid();
var id = 1;
var documentProcessingInfo = new DocumentProcessingInfo()
{
DocumentProcessingInfoId = id,
IngestorRunInfoId = ingestorRunInfoId
};
_mockDocumentProcessingInfoRepository.Setup(x => x.FindByIdAsync(id)).ReturnsAsync(documentProcessingInfo);
_mockDocumentProcessingInfoRepository.Setup(x => x.Update(documentProcessingInfo)).Throws(new Exception("Error")); ;
var processingLog = new ProcessingLog()
{
DocumentProcessingInfoId = id,
LogTimeStamp = Convert.ToDateTime("1/1/2022"),
LogMessage = "Account fail"
};
_mockProcessingLogService.Setup(x => x.SaveAsync(It.IsAny<ProcessingLog>())).ReturnsAsync(processingLog);
Assert.ThrowsAsync<ServiceException>(async () => await _documentProcessingInfoService.UpdateStatusAndAddLog(id, ProcessStatusTypes.DataMappingFailure, "Account fail", "User"));
_mockDocumentProcessingInfoRepository.Verify(x => x.FindByIdAsync(id), Times.Exactly(2));
_mockDocumentProcessingInfoRepository.Verify(x => x.Update(documentProcessingInfo), Times.Once);
_mockProcessingLogService.Verify(x => x.SaveAsync(It.IsAny<ProcessingLog>()), Times.Never);
}
[Test]
public async Task UpdateStatusAndAddLog_ById_TwoLog_Returned()
{
var ingestorRunInfoId = Guid.NewGuid();
var id = 1;
var documentProcessingInfo = new DocumentProcessingInfo()
{
DocumentProcessingInfoId = id,
IngestorRunInfoId = ingestorRunInfoId
};
_mockDocumentProcessingInfoRepository.Setup(x => x.FindByIdAsync(id)).ReturnsAsync(documentProcessingInfo);
_mockDocumentProcessingInfoRepository.Setup(x => x.Update(documentProcessingInfo));
var processingLog = new ProcessingLog()
{
DocumentProcessingInfoId = id,
LogTimeStamp = Convert.ToDateTime("1/1/2022"),
LogMessage = "Account fail",
UserName = "User"
};
_mockProcessingLogService.Setup(x => x.SaveAsync(It.IsAny<ProcessingLog>())).ReturnsAsync(processingLog);
var logMessages = new List<string>()
{
"Account fail",
"Name fail"
};
var result = await _documentProcessingInfoService.UpdateStatusAndAddLog(id, ProcessStatusTypes.DataMappingFailure, logMessages, "User");
Assert.IsNotNull(result);
Assert.AreEqual(ingestorRunInfoId, result.IngestorRunInfoId);
Assert.AreEqual(id, result.DocumentProcessingInfoId);
_mockDocumentProcessingInfoRepository.Verify(x => x.FindByIdAsync(id), Times.Exactly(2));
_mockDocumentProcessingInfoRepository.Verify(x => x.Update(documentProcessingInfo), Times.Once);
_mockProcessingLogService.Verify(x => x.SaveAsync(It.IsAny<ProcessingLog>()), Times.Exactly(2));
}
[Test]
public void UpdateStatusAndAddLog_ById_TwoLog_FindByIdAsync_ThrowsException()
{
var ingestorRunInfoId = Guid.NewGuid();
var id = 1;
var documentProcessingInfo = new DocumentProcessingInfo()
{
DocumentProcessingInfoId = id,
IngestorRunInfoId = ingestorRunInfoId
};
_mockDocumentProcessingInfoRepository.Setup(x => x.FindByIdAsync(id)).ThrowsAsync(new Exception("Error"));
var logMessages = new List<string>()
{
"Account fail",
"Name fail"
};
Assert.ThrowsAsync<ServiceException>(async () => await _documentProcessingInfoService.UpdateStatusAndAddLog(id,
ProcessStatusTypes.DataMappingFailure,
logMessages,
"User"));
_mockDocumentProcessingInfoRepository.Verify(x => x.FindByIdAsync(id), Times.Once);
_mockDocumentProcessingInfoRepository.Verify(x => x.Update(documentProcessingInfo), Times.Never);
_mockProcessingLogService.Verify(x => x.SaveAsync(It.IsAny<ProcessingLog>()), Times.Never);
}
[Test]
public void UpdateStatusAndAddLog_ById_TwoLog_Update_ThrowsException()
{
var ingestorRunInfoId = Guid.NewGuid();
var id = 1;
var documentProcessingInfo = new DocumentProcessingInfo()
{
DocumentProcessingInfoId = id,
IngestorRunInfoId = ingestorRunInfoId
};
_mockDocumentProcessingInfoRepository.Setup(x => x.FindByIdAsync(id)).ReturnsAsync(documentProcessingInfo);
_mockDocumentProcessingInfoRepository.Setup(x => x.Update(documentProcessingInfo)).Throws(new Exception("Error")); ;
var processingLog = new ProcessingLog()
{
DocumentProcessingInfoId = id,
LogTimeStamp = Convert.ToDateTime("1/1/2022"),
LogMessage = "Account fail"
};
_mockProcessingLogService.Setup(x => x.SaveAsync(It.IsAny<ProcessingLog>())).ReturnsAsync(processingLog);
var logMessages = new List<string>()
{
"Account fail",
"Name fail"
};
Assert.ThrowsAsync<ServiceException>(async () => await _documentProcessingInfoService.UpdateStatusAndAddLog(id,
ProcessStatusTypes.DataMappingFailure,
logMessages,
"User"));
_mockDocumentProcessingInfoRepository.Verify(x => x.FindByIdAsync(id), Times.Exactly(2));
_mockDocumentProcessingInfoRepository.Verify(x => x.Update(documentProcessingInfo), Times.Once);
_mockProcessingLogService.Verify(x => x.SaveAsync(It.IsAny<ProcessingLog>()), Times.Never);
}
[Test]
public async Task UpdateStatusAndAddLog_Returned()
{
var ingestorRunInfoId = Guid.NewGuid();
var id = 1;
var documentProcessingInfo = new DocumentProcessingInfo()
{
DocumentProcessingInfoId = id,
IngestorRunInfoId = ingestorRunInfoId
};
_mockDocumentProcessingInfoRepository.Setup(x => x.FindByIdAsync(id)).ReturnsAsync(documentProcessingInfo);
_mockDocumentProcessingInfoRepository.Setup(x => x.Update(documentProcessingInfo));
var processingLog = new ProcessingLog()
{
DocumentProcessingInfoId = id,
LogTimeStamp = Convert.ToDateTime("1/1/2022"),
LogMessage = "Account fail",
UserName = "User"
};
_mockProcessingLogService.Setup(x => x.SaveAsync(It.IsAny<ProcessingLog>())).ReturnsAsync(processingLog);
var result = await _documentProcessingInfoService.UpdateStatusAndAddLog(documentProcessingInfo,
ProcessStatusTypes.DataMappingFailure,
"Account fail",
"User");
Assert.IsNotNull(result);
Assert.AreEqual(ingestorRunInfoId, result.IngestorRunInfoId);
Assert.AreEqual(id, result.DocumentProcessingInfoId);
_mockDocumentProcessingInfoRepository.Verify(x => x.FindByIdAsync(id), Times.Once);
_mockDocumentProcessingInfoRepository.Verify(x => x.Update(documentProcessingInfo), Times.Once);
_mockProcessingLogService.Verify(x => x.SaveAsync(It.IsAny<ProcessingLog>()), Times.Once);
}
[Test]
public void UpdateStatusAndAddLog_FindByIdAsync_ThrowsException()
{
var ingestorRunInfoId = Guid.NewGuid();
var id = 1;
var documentProcessingInfo = new DocumentProcessingInfo()
{
DocumentProcessingInfoId = id,
IngestorRunInfoId = ingestorRunInfoId
};
_mockDocumentProcessingInfoRepository.Setup(x => x.FindByIdAsync(id)).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _documentProcessingInfoService.UpdateStatusAndAddLog(documentProcessingInfo,
ProcessStatusTypes.DataMappingFailure,
"Account fail",
"User"));
_mockDocumentProcessingInfoRepository.Verify(x => x.FindByIdAsync(id), Times.Once);
_mockDocumentProcessingInfoRepository.Verify(x => x.Update(documentProcessingInfo), Times.Never);
_mockProcessingLogService.Verify(x => x.SaveAsync(It.IsAny<ProcessingLog>()), Times.Never);
}
[Test]
public void UpdateStatusAndAddLog_Update_ThrowsException()
{
var ingestorRunInfoId = Guid.NewGuid();
var id = 1;
var documentProcessingInfo = new DocumentProcessingInfo()
{
DocumentProcessingInfoId = id,
IngestorRunInfoId = ingestorRunInfoId
};
_mockDocumentProcessingInfoRepository.Setup(x => x.FindByIdAsync(id)).ReturnsAsync(documentProcessingInfo);
_mockDocumentProcessingInfoRepository.Setup(x => x.Update(documentProcessingInfo)).Throws(new Exception("Error")); ;
var processingLog = new ProcessingLog()
{
DocumentProcessingInfoId = id,
LogTimeStamp = Convert.ToDateTime("1/1/2022"),
LogMessage = "Account fail",
UserName = "User"
};
_mockProcessingLogService.Setup(x => x.SaveAsync(It.IsAny<ProcessingLog>())).ReturnsAsync(processingLog);
Assert.ThrowsAsync<ServiceException>(async () => await _documentProcessingInfoService.UpdateStatusAndAddLog(documentProcessingInfo,
ProcessStatusTypes.DataMappingFailure,
"Account fail",
"User"));
_mockDocumentProcessingInfoRepository.Verify(x => x.FindByIdAsync(id), Times.Once);
_mockDocumentProcessingInfoRepository.Verify(x => x.Update(documentProcessingInfo), Times.Once);
_mockProcessingLogService.Verify(x => x.SaveAsync(It.IsAny<ProcessingLog>()), Times.Never);
}
[Test]
public async Task Delete_Success()
{
var ingestorRunInfoId = Guid.NewGuid();
var id = 1;
var documentProcessingInfo = new DocumentProcessingInfo()
{
DocumentProcessingInfoId = id,
IngestorRunInfoId = ingestorRunInfoId
};
_mockDocumentProcessingInfoRepository.Setup(x => x.FindByIdAsync(id)).ReturnsAsync(documentProcessingInfo);
_mockDocumentProcessingInfoRepository.Setup(x => x.Remove(documentProcessingInfo));
await _documentProcessingInfoService.Delete(id);
_mockDocumentProcessingInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>()), Times.Once);
_mockDocumentProcessingInfoRepository.Verify(x => x.Remove(It.IsAny<DocumentProcessingInfo>()), Times.Once);
}
[Test]
public void Delete_FindByIdAsync_ThrowsException()
{
var ingestorRunInfoId = Guid.NewGuid();
var id = 1;
var documentProcessingInfo = new DocumentProcessingInfo()
{
DocumentProcessingInfoId = id,
IngestorRunInfoId = ingestorRunInfoId
};
_mockDocumentProcessingInfoRepository.Setup(x => x.FindByIdAsync(id)).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _documentProcessingInfoService.Delete(id));
_mockDocumentProcessingInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>()), Times.Once);
_mockDocumentProcessingInfoRepository.Verify(x => x.Remove(It.IsAny<DocumentProcessingInfo>()), Times.Never);
}
[Test]
public void Delete_Remove_ThrowsException()
{
var ingestorRunInfoId = Guid.NewGuid();
var id = 1;
var documentProcessingInfo = new DocumentProcessingInfo()
{
DocumentProcessingInfoId = id,
IngestorRunInfoId = ingestorRunInfoId
};
_mockDocumentProcessingInfoRepository.Setup(x => x.FindByIdAsync(id)).ReturnsAsync(documentProcessingInfo);
_mockDocumentProcessingInfoRepository.Setup(x => x.Remove(documentProcessingInfo)).Throws(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _documentProcessingInfoService.Delete(id));
_mockDocumentProcessingInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>()), Times.Once);
_mockDocumentProcessingInfoRepository.Verify(x => x.Remove(It.IsAny<DocumentProcessingInfo>()), Times.Once);
}
[Test]
public async Task FilterPaged_Ok()
{
var pagedDocumentProcessingInfoResult = new PagedResult<DocumentProcessingInfo>();
var filter = new Filter()
{
Page = 1,
Limit = 2,
StatusFilters = null,
SortableFields = null,
DocBusinessName = "EAgreement"
};
_mockDocumentProcessingInfoRepository.Setup(repo => repo.FilteredListAsync(filter))
.ReturnsAsync(pagedDocumentProcessingInfoResult).Verifiable();
// Act
var result = await _documentProcessingInfoService.GetFilteredDocumentProcessingInfo(filter);
// Assert
Assert.NotNull(result);
Assert.AreEqual(pagedDocumentProcessingInfoResult, result);
}
[Test]
public async Task CountCompletedFirstPassByIngestorRunInfoIdAsync_RepositoryReturnsCount_ReturnsCount()
{
var runId = Guid.NewGuid();
var count = DateTime.Now.Millisecond;
_mockDocumentProcessingInfoRepository
.Setup(r => r.CountCompletedFirstPassByIngestorRunInfoIdAsync(runId))
.ReturnsAsync(count);
var actualCount = await _documentProcessingInfoService.CountCompletedFirstPassByIngestorRunInfoIdAsync(runId);
Assert.AreEqual(count, actualCount);
}
[Test]
public void CountCompletedFirstPassByIngestorRunInfoIdAsync_RepositoryThrows_ThrowsServiceException()
{
var runId = Guid.NewGuid();
_mockDocumentProcessingInfoRepository
.Setup(r => r.CountCompletedFirstPassByIngestorRunInfoIdAsync(runId))
.ThrowsAsync(new Exception());
Assert.ThrowsAsync<ServiceException>(() => _documentProcessingInfoService.CountCompletedFirstPassByIngestorRunInfoIdAsync(runId));
}
[Test]
public async Task SetDocumentsToEntityUnknown_Success()
{
var ids = new List<int>() { 1, 2, 3 };
var documentProcessingInfos = new List<DocumentProcessingInfo>()
{
new()
{
DocumentProcessingInfoId = ids[0],
},
new()
{
DocumentProcessingInfoId = ids[1],
},
new()
{
DocumentProcessingInfoId = ids[2],
}
};
var request = new EntityUnknownRequest()
{
UserName = "System",
DocumentProcessingInfoIds = documentProcessingInfos.Select(x => x.DocumentProcessingInfoId).ToList()
};
var processingLog = new ProcessingLog()
{
DocumentProcessingInfoId = 1,
LogMessage = "Log test",
LogTimeStamp = DateTime.Now,
UserName = "System"
};
_mockDocumentProcessingInfoRepository.Setup(x => x.FindListByIdAsync(ids)).ReturnsAsync(documentProcessingInfos);
_mockDocumentProcessingInfoRepository.SetupSequence(x => x.FindByIdAsync(It.IsAny<int>())).ReturnsAsync(documentProcessingInfos[0])
.ReturnsAsync(documentProcessingInfos[1])
.ReturnsAsync(documentProcessingInfos[2]);
_mockDocumentProcessingInfoRepository.Setup(x => x.Update(It.IsAny<DocumentProcessingInfo>()));
_mockProcessingLogService.Setup(x => x.SaveAsync(It.IsAny<ProcessingLog>())).ReturnsAsync(() => processingLog);
var result = await _documentProcessingInfoService.SetDocumentsToEntityUnknown(request);
var trueCount = result.Where(x => x.EntityUnknown).ToList().Count();
Assert.IsNotNull(result);
Assert.AreEqual(documentProcessingInfos.Count, result.Count());
Assert.AreEqual(documentProcessingInfos.Count(), trueCount);
_mockDocumentProcessingInfoRepository.Verify(x => x.FindListByIdAsync(It.IsAny<List<int>>()), Times.Once);
_mockDocumentProcessingInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>()), Times.Exactly(3));
_mockDocumentProcessingInfoRepository.Verify(x => x.Update(It.IsAny<DocumentProcessingInfo>()), Times.Exactly(3));
_mockProcessingLogService.Verify(x => x.SaveAsync(It.IsAny<ProcessingLog>()), Times.Exactly(3));
}
[Test]
public async Task SetDocumentsToEntityUnknown_ThrowsException_Failure()
{
var ids = new List<int>() { 1, 2, 3 };
var documentProcessingInfos = new List<DocumentProcessingInfo>()
{
new()
{
DocumentProcessingInfoId = ids[0],
},
new()
{
DocumentProcessingInfoId = ids[1],
},
new()
{
DocumentProcessingInfoId = ids[2],
}
};
var request = new EntityUnknownRequest()
{
UserName = "System",
DocumentProcessingInfoIds = documentProcessingInfos.Select(x => x.DocumentProcessingInfoId).ToList()
};
var processingLog = new ProcessingLog()
{
DocumentProcessingInfoId = 1,
LogMessage = "Log test",
LogTimeStamp = DateTime.Now,
UserName = "System"
};
_mockDocumentProcessingInfoRepository.Setup(x => x.FindListByIdAsync(ids)).ReturnsAsync(documentProcessingInfos);
_mockDocumentProcessingInfoRepository.SetupSequence(x => x.FindByIdAsync(It.IsAny<int>())).ReturnsAsync(documentProcessingInfos[0])
.ReturnsAsync(documentProcessingInfos[1])
.ReturnsAsync(documentProcessingInfos[2]);
_mockDocumentProcessingInfoRepository.Setup(x => x.Update(It.IsAny<DocumentProcessingInfo>()));
_mockProcessingLogService.Setup(x => x.SaveAsync(It.IsAny<ProcessingLog>())).ReturnsAsync(() => processingLog);
_mockProcessingLogService.Setup(x => x.SaveAsync(It.IsAny<ProcessingLog>())).Throws(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _documentProcessingInfoService.SetDocumentsToEntityUnknown(request));
_mockDocumentProcessingInfoRepository.Verify(x => x.FindListByIdAsync(It.IsAny<List<int>>()), Times.Once);
_mockDocumentProcessingInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>()), Times.Never);
_mockDocumentProcessingInfoRepository.Verify(x => x.Update(It.IsAny<DocumentProcessingInfo>()), Times.Never);
_mockProcessingLogService.Verify(x => x.SaveAsync(It.IsAny<ProcessingLog>()), Times.Once);
}
//
[Test]
public async Task UpdateDocumentProcessingInfoStatus_Success()
{
var documentProcessingInfoId = DateTime.Now.Millisecond;
var documentProcessingInfo = new DocumentProcessingInfo()
{
DocumentProcessingInfoId = documentProcessingInfoId,
StatusType = ProcessStatusTypes.ArchiveFailure
};
var request = new DocumentProcessingInfoStatusRequest()
{
DocumentProcessingInfoId = documentProcessingInfoId,
ProcessStatus = ProcessStatusTypes.Reprocessing,
ReasonMessage = Guid.NewGuid().ToString(),
Username = Guid.NewGuid().ToString()
};
var processingLog = new ProcessingLog()
{
DocumentProcessingInfoId = documentProcessingInfoId,
LogMessage = request.ReasonMessage,
LogTimeStamp = DateTime.Now,
UserName = request.Username
};
_mockDocumentProcessingInfoRepository.Setup(x => x.FindByIdAsync(documentProcessingInfoId)).ReturnsAsync(documentProcessingInfo);
_mockDocumentProcessingInfoRepository.Setup(x => x.Update(It.IsAny<DocumentProcessingInfo>()));
_mockProcessingLogService.Setup(x => x.SaveAsync(It.IsAny<ProcessingLog>())).ReturnsAsync(() => processingLog);
var result = await _documentProcessingInfoService.UpdateDocumentProcessingInfoStatus(request);
Assert.IsNotNull(result);
Assert.AreEqual(result?.StatusType, request.ProcessStatus);
_mockDocumentProcessingInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>()), Times.Exactly(2));
_mockDocumentProcessingInfoRepository.Verify(x => x.Update(It.IsAny<DocumentProcessingInfo>()), Times.Once);
_mockProcessingLogService.Verify(x => x.SaveAsync(It.IsAny<ProcessingLog>()), Times.Once);
}
[Test]
public async Task UpdateDocumentProcessingInfoStatus_ThrowsException_Failure()
{
var documentProcessingInfoId = DateTime.Now.Millisecond;
var documentProcessingInfo = new DocumentProcessingInfo()
{
DocumentProcessingInfoId = documentProcessingInfoId,
StatusType = ProcessStatusTypes.ArchiveFailure
};
var request = new DocumentProcessingInfoStatusRequest()
{
DocumentProcessingInfoId = documentProcessingInfoId,
ProcessStatus = ProcessStatusTypes.Reprocessing,
ReasonMessage = Guid.NewGuid().ToString(),
Username = Guid.NewGuid().ToString()
};
_mockDocumentProcessingInfoRepository.Setup(x => x.FindByIdAsync(documentProcessingInfoId)).ReturnsAsync(documentProcessingInfo);
_mockDocumentProcessingInfoRepository.Setup(x => x.Update(It.IsAny<DocumentProcessingInfo>())).Throws(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _documentProcessingInfoService.UpdateDocumentProcessingInfoStatus(request));
_mockDocumentProcessingInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>()), Times.Exactly(2));
_mockDocumentProcessingInfoRepository.Verify(x => x.Update(It.IsAny<DocumentProcessingInfo>()), Times.Once);
_mockProcessingLogService.Verify(x => x.SaveAsync(It.IsAny<ProcessingLog>()), Times.Never);
}
[Test]
public async Task UpdateDocumentProcessingInfoStatus_RejectedStatus_Failure()
{
var documentProcessingInfoId = DateTime.Now.Millisecond;
var documentProcessingInfo = new DocumentProcessingInfo()
{
DocumentProcessingInfoId = documentProcessingInfoId,
StatusType = ProcessStatusTypes.Completed
};
var request = new DocumentProcessingInfoStatusRequest()
{
DocumentProcessingInfoId = documentProcessingInfoId,
ProcessStatus = ProcessStatusTypes.Reprocessing,
ReasonMessage = Guid.NewGuid().ToString(),
Username = Guid.NewGuid().ToString()
};
_mockDocumentProcessingInfoRepository.Setup(x => x.FindByIdAsync(documentProcessingInfoId)).ReturnsAsync(documentProcessingInfo);
Assert.ThrowsAsync<ServiceException>(async () => await _documentProcessingInfoService.UpdateDocumentProcessingInfoStatus(request));
_mockDocumentProcessingInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>()), Times.Once);
_mockDocumentProcessingInfoRepository.Verify(x => x.Update(It.IsAny<DocumentProcessingInfo>()), Times.Never);
_mockProcessingLogService.Verify(x => x.SaveAsync(It.IsAny<ProcessingLog>()), Times.Never);
}
[Test]
public async Task UpdateDocumentProcessingInfoStatus_SameStatus_Failure()
{
var documentProcessingInfoId = DateTime.Now.Millisecond;
var documentProcessingInfo = new DocumentProcessingInfo()
{
DocumentProcessingInfoId = documentProcessingInfoId,
StatusType = ProcessStatusTypes.Reprocessing
};
var request = new DocumentProcessingInfoStatusRequest()
{
DocumentProcessingInfoId = documentProcessingInfoId,
ProcessStatus = ProcessStatusTypes.Reprocessing,
ReasonMessage = Guid.NewGuid().ToString(),
Username = Guid.NewGuid().ToString()
};
_mockDocumentProcessingInfoRepository.Setup(x => x.FindByIdAsync(documentProcessingInfoId)).ReturnsAsync(documentProcessingInfo);
Assert.ThrowsAsync<ServiceException>(async () => await _documentProcessingInfoService.UpdateDocumentProcessingInfoStatus(request));
_mockDocumentProcessingInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>()), Times.Once);
_mockDocumentProcessingInfoRepository.Verify(x => x.Update(It.IsAny<DocumentProcessingInfo>()), Times.Never);
_mockProcessingLogService.Verify(x => x.SaveAsync(It.IsAny<ProcessingLog>()), Times.Never);
}
[Test]
public async Task GetByDocumentIdsAsync_RepositoryReturnsInfoForId_InfoAtIdKey()
{
var ids = Enumerable.Repeat(Guid.NewGuid, 5)
.Select(f => f())
.ToArray();
var info = new DocumentProcessingInfo
{
DocumentId = ids[2]
};
_mockDocumentProcessingInfoRepository
.Setup(dpir => dpir.FindByDocumentIdsAsync(ids))
.ReturnsAsync(new[] { info });
var infoById = await _documentProcessingInfoService.GetByDocumentIdsAsync(ids);
Assert.AreSame(infoById[info.DocumentId.Value], info);
}
[Test]
public async Task GetByDocumentIdsAsync_RepositoryDoesNotReturnInfoForId_NullAtIdKey()
{
var ids = Enumerable.Repeat(Guid.NewGuid, 5)
.Select(f => f())
.ToArray();
var info = new DocumentProcessingInfo
{
DocumentId = ids[2]
};
_mockDocumentProcessingInfoRepository
.Setup(dpir => dpir.FindByDocumentIdsAsync(ids))
.ReturnsAsync(Array.Empty<DocumentProcessingInfo>());
var infoById = await _documentProcessingInfoService.GetByDocumentIdsAsync(ids);
Assert.IsNull(infoById[info.DocumentId.Value]);
}
[Test]
public async Task GetByDocumentIdsAsync_RepositoryThrowsException_ThrowsServiceException()
{
var ids = Enumerable.Repeat(Guid.NewGuid, 5)
.Select(f => f())
.ToArray();
_mockDocumentProcessingInfoRepository
.Setup(dpir => dpir.FindByDocumentIdsAsync(ids))
.ThrowsAsync(new Exception());
Assert.ThrowsAsync<ServiceException>(() => _documentProcessingInfoService.GetByDocumentIdsAsync(ids));
}
[Test]
public async Task GetByDocumentIdsAsync_AllCases_AllInputIdsInDictionaryKeys()
{
var ids = Enumerable.Repeat(Guid.NewGuid, 5)
.Select(f => f())
.ToArray();
var info = new DocumentProcessingInfo
{
DocumentId = ids[2]
};
var otherInfo = new DocumentProcessingInfo
{
DocumentId = ids[4]
};
_mockDocumentProcessingInfoRepository
.Setup(dpir => dpir.FindByDocumentIdsAsync(ids))
.ReturnsAsync(new[] { info, otherInfo });
var infoById = await _documentProcessingInfoService.GetByDocumentIdsAsync(ids);
CollectionAssert.AreEquivalent(ids, infoById.Keys);
}
[Test]
public async Task GetByProcessStatusTypeAsync_Success()
{
var processStatus = ProcessStatusTypes.Processing;
var documentProcessingInfos = GenerateDocumentProcessingInfos();
documentProcessingInfos.ForEach(x => x.StatusType.Equals(processStatus));
_mockDocumentProcessingInfoRepository.Setup(x => x.FindByProcessStatusTypeAsync(It.IsAny<ProcessStatusTypes>(), null))
.ReturnsAsync(documentProcessingInfos).Verifiable();
var result = await _documentProcessingInfoService.GetByProcessStatusTypeAsync(processStatus);
Assert.AreSame(result, documentProcessingInfos);
_mockDocumentProcessingInfoRepository.Verify(x => x.FindByProcessStatusTypeAsync(It.IsAny<ProcessStatusTypes>(), It.IsAny<bool?>()), Times.Once);
}
[Test]
public void GetByProcessStatusType_Failure_Exception()
{
_mockDocumentProcessingInfoRepository.Setup(x => x.FindByProcessStatusTypeAsync(It.IsAny<ProcessStatusTypes>(), null))
.ThrowsAsync(new Exception("Test"));
Assert.ThrowsAsync<ServiceException>(() =>
_documentProcessingInfoService.GetByProcessStatusTypeAsync(It.IsAny<ProcessStatusTypes>()));
_mockDocumentProcessingInfoRepository.Verify(x => x.FindByProcessStatusTypeAsync(It.IsAny<ProcessStatusTypes>(), It.IsAny<bool?>()), Times.Once);
}
[Test]
public async Task GetCompletedFirstPassByIngestorRunInfoIdAsync_Success()
{
var ingestorRunInfoId = Guid.NewGuid();
var documentProcessingInfos = GenerateDocumentProcessingInfos();
documentProcessingInfos.ForEach(x => x.IngestorRunInfoId = ingestorRunInfoId);
_mockDocumentProcessingInfoRepository.Setup(x => x.FindCompletedFirstPassByIngestorRunInfoIdAsync(It.IsAny<Guid>()))
.ReturnsAsync(documentProcessingInfos).Verifiable();
var result = await _documentProcessingInfoService.GetCompletedFirstPassByIngestorRunInfoIdAsync(ingestorRunInfoId);
Assert.AreSame(documentProcessingInfos, result);
_mockDocumentProcessingInfoRepository.Verify(x => x.FindCompletedFirstPassByIngestorRunInfoIdAsync(It.IsAny<Guid>()), Times.Once);
}
[Test]
public void GetCompletedFirstPassByIngestorRunInfoIdAsync_Failure_Exception()
{
_mockDocumentProcessingInfoRepository.Setup(x => x.FindCompletedFirstPassByIngestorRunInfoIdAsync(It.IsAny<Guid>()))
.ThrowsAsync(new Exception("Test"));
Assert.ThrowsAsync<ServiceException>(() =>
_documentProcessingInfoService.GetCompletedFirstPassByIngestorRunInfoIdAsync(It.IsAny<Guid>()));
_mockDocumentProcessingInfoRepository.Verify(x => x.FindCompletedFirstPassByIngestorRunInfoIdAsync(It.IsAny<Guid>()), Times.Once);
}
[Test]
public async Task SaveRangeAsync_Success()
{
var documentProcessingInfos = GenerateDocumentProcessingInfos().ToArray();
await _documentProcessingInfoService.SaveRangeAsync(documentProcessingInfos);
_mockDocumentProcessingInfoRepository.Verify(x => x.AddRangeAsync(It.IsAny<DocumentProcessingInfo[]>()), Times.Once());
_unitOfWork.Verify(x => x.CompleteAsync(), Times.Once);
}
[Test]
public void SaveRangeAsync_Failure_Exception()
{
_mockDocumentProcessingInfoRepository.Setup(x => x.AddRangeAsync(It.IsAny<DocumentProcessingInfo[]>()))
.ThrowsAsync(new Exception("Test"));
Assert.ThrowsAsync<ServiceException>(() =>
_documentProcessingInfoService.SaveRangeAsync(It.IsAny<DocumentProcessingInfo[]>()));
_mockDocumentProcessingInfoRepository.Verify(x => x.AddRangeAsync(It.IsAny<DocumentProcessingInfo[]>()), Times.Once);
_unitOfWork.Verify(x => x.CompleteAsync(), Times.Never);
}
private List<DocumentProcessingInfo> GenerateDocumentProcessingInfos()
=> new()
{
GenerateDocumentProcessingInfo(),
GenerateDocumentProcessingInfo(),
GenerateDocumentProcessingInfo()
};
private DocumentProcessingInfo GenerateDocumentProcessingInfo(Guid? documentId = null)
=> new()
{
DocumentId = documentId ?? Guid.NewGuid()
};
}
@@ -0,0 +1,608 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using NUnit.Framework;
using Moq;
using Newtonsoft.Json;
using LCU.API.Internal.DocumentIngestor.Services.AttributeDeterminingServices;
using LCU.API.Internal.DocumentIngestor.Services.DocumentProcessorServices;
using LCU.API.Internal.DocumentIngestor.Services.MicroApiServices;
using LCU.Library.DocumentType.Enums;
using LCU.Library.DocumentType.Models.Requests.Account;
using LCU.Library.DocumentType.Models.Requests.Attributes;
using LCU.Library.DocumentType.Models.Requests.PrimaryOwner;
using LCU.Library.Internal.DocumentIngestorModels.Entities;
using LCU.Library.Internal.DocumentIngestorModels.Enums;
using LCU.Library.Internal.DocumentIngestorModels.Models;
using LCU.Library.Internal.DocumentIngestorModels.Models.IndexFileDocuments;
using LCU.Library.Internal.LCUServiceFactory.Configurations;
namespace LCU.API.Internal.DocumentIngestorTests.Services.DocumentProcessorServices;
public class FosDnaDocumentProcessingServiceTest
{
private FosDnaDocumentProcessingService _fosDnaDocumentProcessingService;
private Mock<IPrimaryOwnerDeterminingService> _mockPrimaryOwnerDeterminingService;
private Mock<IAccountOwnerDeterminingService> _mockAccountOwnerDeterminingService;
private Mock<IFileOperationsApiService> _mockFileOperationsApiService;
private Mock<IDocumentTypeUploaderApiService> _mockDocumentTypeUploaderApiService;
[SetUp]
public void Setup()
{
_mockPrimaryOwnerDeterminingService = new Mock<IPrimaryOwnerDeterminingService>();
_mockAccountOwnerDeterminingService = new Mock<IAccountOwnerDeterminingService>();
_mockFileOperationsApiService = new Mock<IFileOperationsApiService>();
_mockDocumentTypeUploaderApiService = new Mock<IDocumentTypeUploaderApiService>();
var serviceFactoryConfiguration = new ServicesFactoryConfiguration
{
ServiceFactoryRegistrations = new List<ServiceFactoryRegistration>
{
new()
{
ServiceInterfaceName = "IIndexParserService",
ServiceRegistrations = new List<ServiceRegistration>
{
new()
{
ServiceName = "IndexParserService",
ServiceId = "4"
},
new()
{
ServiceName = "IndexParserService",
ServiceId = "1"
}
}
}
}
};
_fosDnaDocumentProcessingService = new FosDnaDocumentProcessingService(_mockPrimaryOwnerDeterminingService.Object,
_mockAccountOwnerDeterminingService.Object,
_mockFileOperationsApiService.Object,
_mockDocumentTypeUploaderApiService.Object,
serviceFactoryConfiguration);
}
[Test]
public async Task ProcessRequest_ProcessingRequest_Null_ProcessResult_Failure()
{
ProcessingRequest request = null;
var result = await _fosDnaDocumentProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
_mockPrimaryOwnerDeterminingService.Verify(x => x.DeterminePrimaryOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<DateTime>(),
It.IsAny<OwnerOverrideInfo>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadPrimaryOwnerDocument(It.IsAny<PrimaryOwnerDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()), Times.Never);
}
[Test]
public async Task ProcessRequest_FosDnaDocument_Null_ProcessResult_Failure()
{
var request = new ProcessingRequest
{
DocumentValuePayload = null
};
var result = await _fosDnaDocumentProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
_mockPrimaryOwnerDeterminingService.Verify(x => x.DeterminePrimaryOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<DateTime>(),
It.IsAny<OwnerOverrideInfo>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadPrimaryOwnerDocument(It.IsAny<PrimaryOwnerDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()), Times.Never);
}
[Test]
public async Task ProcessRequest_FosDnaDocument_OneValidationFailures_Failure()
{
var fosDnaDocument = new FosDnaDocument
{
AccountNumber = "0",
CreationDate = "01232005",
DocName = "Test.pdf",
DocType = "LN_NENT",
EntityName = "Bill B Billson"
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(fosDnaDocument)
};
var result = await _fosDnaDocumentProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
Assert.AreEqual(result.ProcessStatusType, ProcessStatusTypes.DataMappingFailure);
Assert.IsNull(result.EntityIsUnknown);
Assert.AreEqual(1, result.MessageStack.Count);
_mockPrimaryOwnerDeterminingService.Verify(x => x.DeterminePrimaryOwnerAttribute(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<DateTime>(),
It.IsAny<OwnerOverrideInfo>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadPrimaryOwnerDocument(It.IsAny<PrimaryOwnerDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()), Times.Never);
}
[Test]
public async Task ProcessRequest_FosDnaDocument_EntityUnknown_PsInfoChangeNotice_Failure()
{
var fosDnaDocument = new FosDnaDocument
{
AccountNumber = "0",
CreationDate = "01232005",
DocName = "Test.pdf",
DocType = "PS_INFOCHANGE_NO",
EntityName = "Bill B Billson"
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(fosDnaDocument)
};
var result = await _fosDnaDocumentProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
Assert.AreEqual(result.ProcessStatusType, ProcessStatusTypes.DataMappingFailure);
Assert.IsTrue(result.EntityIsUnknown);
Assert.AreEqual(1, result.MessageStack.Count);
_mockPrimaryOwnerDeterminingService.Verify(x => x.DeterminePrimaryOwnerAttribute(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<DateTime>(),
It.IsAny<OwnerOverrideInfo>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadPrimaryOwnerDocument(It.IsAny<PrimaryOwnerDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()), Times.Never);
}
[Test]
public async Task ProcessRequest_FosDnaDocument_ValidationFailures_Failure()
{
var fosDnaDocument = new FosDnaDocument
{
AccountNumber = "0",
CreationDate = "",
DocName = "",
DocType = "",
EntityName = ""
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(fosDnaDocument)
};
var result = await _fosDnaDocumentProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
Assert.IsNull(result.EntityIsUnknown);
Assert.AreEqual(3, result.MessageStack.Count);
_mockPrimaryOwnerDeterminingService.Verify(x => x.DeterminePrimaryOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<DateTime>(),
It.IsAny<OwnerOverrideInfo>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadPrimaryOwnerDocument(It.IsAny<PrimaryOwnerDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()), Times.Never);
}
[Test]
public async Task ProcessRequest_FosDnaDocument_NumberIsNull_Failure()
{
var fosDnaDocument = new FosDnaDocument
{
AccountNumber = "1",
CreationDate = "01232005",
DocName = "Test.pdf",
DocType = "PS_INFOCHANGE_NO",
EntityName = "Bill B Billson"
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(fosDnaDocument)
};
var primaryOwnerAttribute = ErrorCaptureResult<PrimaryOwnerAttribute>.CreateErrorPayload("Error", null);
_mockPrimaryOwnerDeterminingService.Setup(x => x.DeterminePrimaryOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<DateTime>(),
It.IsAny<OwnerOverrideInfo>())).ReturnsAsync(primaryOwnerAttribute);
var result = await _fosDnaDocumentProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
Assert.IsNull(result.EntityIsUnknown);
Assert.AreEqual(1, result.MessageStack.Count);
_mockPrimaryOwnerDeterminingService.Verify(x => x.DeterminePrimaryOwnerAttribute(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<DateTime>(),
It.IsAny<OwnerOverrideInfo>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadPrimaryOwnerDocument(It.IsAny<PrimaryOwnerDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()), Times.Never);
}
[Test]
public async Task ProcessRequest_FosDnaDocument_DataMappingFailure_CreationDate_Failure()
{
var fosDnaDocument = new FosDnaDocument
{
AccountNumber = "1",
CreationDate = "01T23T2005",
DocName = "Test.pdf",
DocType = "PS_INFOCHANGE_NO",
EntityName = "Bill B Billson"
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(fosDnaDocument)
};
var primaryOwnerAttribute = ErrorCaptureResult<PrimaryOwnerAttribute>.CreateErrorPayload("Error", null);
_mockPrimaryOwnerDeterminingService.Setup(x => x.DeterminePrimaryOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<DateTime>(),
It.IsAny<OwnerOverrideInfo>())).ReturnsAsync(primaryOwnerAttribute);
var result = await _fosDnaDocumentProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
Assert.IsNull(result.EntityIsUnknown);
Assert.AreEqual(1, result.MessageStack.Count);
Assert.AreEqual(ProcessStatusTypes.DataMappingFailure, result.ProcessStatusType);
_mockPrimaryOwnerDeterminingService.Verify(x => x.DeterminePrimaryOwnerAttribute(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<DateTime>(),
It.IsAny<OwnerOverrideInfo>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadPrimaryOwnerDocument(It.IsAny<PrimaryOwnerDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()), Times.Never);
}
[Test]
public async Task ProcessRequest_FosDnaDocumentPrimaryOwner_NumberNotNull_Upload_Success()
{
var fosDnaDocument = new FosDnaDocument
{
AccountNumber = "1",
CreationDate = "03072022",
DocName = "Test.pdf",
DocType = "PS_INFOCHANGE_NO",
EntityName = "Bill B Billson"
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(fosDnaDocument),
IngestorRequest = new IngestorRequest
{
RootPath = "\\Tester\\"
},
DocumentFileName = "test.pdf"
};
var attribute = new PrimaryOwnerAttribute
{
PersonNumber = "2"
};
var primaryOwnerAttribute = ErrorCaptureResult<PrimaryOwnerAttribute>.CreateSuccessPayload(attribute);
_mockPrimaryOwnerDeterminingService.Setup(x => x.DeterminePrimaryOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<DateTime>(),
It.IsAny<OwnerOverrideInfo>())).ReturnsAsync(primaryOwnerAttribute);
var content = new byte[1024];
_mockFileOperationsApiService.Setup(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(content);
_mockDocumentTypeUploaderApiService.Setup(x => x.UploadPrimaryOwnerDocument(It.IsAny<PrimaryOwnerDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()));
var result = await _fosDnaDocumentProcessingService.ProcessRequest(request);
Assert.IsTrue(result.Success);
Assert.IsNull(result.EntityIsUnknown);
_mockPrimaryOwnerDeterminingService.Verify(x => x.DeterminePrimaryOwnerAttribute(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<DateTime>(),
It.IsAny<OwnerOverrideInfo>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadPrimaryOwnerDocument(It.Is<PrimaryOwnerDocumentRequest>(request =>
request.PrimaryOwnerDocumentMetadata.Source == SourceTypes.FOS &&
request.PrimaryOwnerDocumentMetadata.DataSource == DataSourceTypes.DNA),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()), Times.Once);
}
[Test]
public async Task ProcessRequest_FosDnaDocumentAccountOwner_NumberNotNull_Upload_Success()
{
var fosDnaDocument = new FosDnaDocument
{
AccountNumber = "1",
CreationDate = "01232025",
DocName = "Test.pdf",
DocType = "LN_NENT",
EntityName = "Bill B Billson"
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(fosDnaDocument),
IngestorRequest = new IngestorRequest
{
RootPath = "\\Tester\\"
},
DocumentFileName = "test.pdf"
};
var attribute = new AccountAttribute
{
PersonNumbers = new List<string> { "2", "3", "4" }
};
var accountAttribute = ErrorCaptureResult<AccountAttribute>.CreateSuccessPayload(attribute);
_mockAccountOwnerDeterminingService.Setup(x => x.DetermineAccountOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<DateTime>(),
It.IsAny<OwnerOverrideInfo>())).ReturnsAsync(accountAttribute);
var content = new byte[1024];
_mockFileOperationsApiService.Setup(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(content);
_mockDocumentTypeUploaderApiService.Setup(x => x.UploadAccountDocument(It.IsAny<AccountDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()));
var result = await _fosDnaDocumentProcessingService.ProcessRequest(request);
Assert.IsTrue(result.Success);
Assert.IsNull(result.EntityIsUnknown);
_mockAccountOwnerDeterminingService.Verify(x => x.DetermineAccountOwnerAttribute(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<DateTime>(),
It.IsAny<OwnerOverrideInfo>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadAccountDocument(It.IsAny<AccountDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()), Times.Once);
}
[Test]
public async Task ProcessRequest_FosDnaDocument_NumberNotNull_GetContentBytesThrowException_Failure()
{
var fosDnaDocument = new FosDnaDocument
{
AccountNumber = "1",
CreationDate = "01232005",
DocName = "Test.pdf",
DocType = "PS_INFOCHANGE_NO",
EntityName = "Bill B Billson"
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(fosDnaDocument),
IngestorRequest = new IngestorRequest
{
RootPath = "\\Tester\\"
},
DocumentFileName = "test.pdf"
};
var attribute = new PrimaryOwnerAttribute
{
PersonNumber = "2"
};
var primaryOwnerAttribute = ErrorCaptureResult<PrimaryOwnerAttribute>.CreateSuccessPayload(attribute);
_mockPrimaryOwnerDeterminingService.Setup(x => x.DeterminePrimaryOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<DateTime>(),
It.IsAny<OwnerOverrideInfo>())).ReturnsAsync(primaryOwnerAttribute);
_mockFileOperationsApiService.Setup(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>())).ThrowsAsync(new Exception("Error"));
var result = await _fosDnaDocumentProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
Assert.IsFalse(result.EntityIsUnknown);
Assert.AreEqual(1, result.MessageStack.Count);
_mockPrimaryOwnerDeterminingService.Verify(x => x.DeterminePrimaryOwnerAttribute(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<DateTime>(),
It.IsAny<OwnerOverrideInfo>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadPrimaryOwnerDocument(It.IsAny<PrimaryOwnerDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()), Times.Never);
}
[Test]
public async Task ProcessRequest_FosDnaDocument_NumberNotNull_UploadDocumentThrowException_Failure()
{
var fosDnaDocument = new FosDnaDocument
{
AccountNumber = "1",
CreationDate = "01232005",
DocName = "Test.pdf",
DocType = "PS_INFOCHANGE_NO",
EntityName = "Bill B Billson"
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(fosDnaDocument),
IngestorRequest = new IngestorRequest
{
RootPath = "\\Tester\\"
},
DocumentFileName = "test.pdf"
};
var attribute = new PrimaryOwnerAttribute
{
PersonNumber = "2"
};
var primaryOwnerAttribute = ErrorCaptureResult<PrimaryOwnerAttribute>.CreateSuccessPayload(attribute);
_mockPrimaryOwnerDeterminingService.Setup(x => x.DeterminePrimaryOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<DateTime>(),
It.IsAny<OwnerOverrideInfo>())).ReturnsAsync(primaryOwnerAttribute);
var content = new byte[1024];
_mockFileOperationsApiService.Setup(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(content);
_mockDocumentTypeUploaderApiService.Setup(x => x.UploadPrimaryOwnerDocument(It.IsAny<PrimaryOwnerDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>())).ThrowsAsync(new Exception("Error"));
var result = await _fosDnaDocumentProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
Assert.IsFalse(result.EntityIsUnknown);
Assert.AreEqual(1, result.MessageStack.Count);
_mockPrimaryOwnerDeterminingService.Verify(x => x.DeterminePrimaryOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<DateTime>(),
It.IsAny<OwnerOverrideInfo>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadPrimaryOwnerDocument(It.IsAny<PrimaryOwnerDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()), Times.Once);
}
[Test]
public async Task ProcessRequest_FosDnaDocument_SkipAccountNumberPsInfoChangeNoticeOverride_Success()
{
var fosDnaDocument = new FosDnaDocument
{
AccountNumber = "",
CreationDate = "03072022",
DocName = "Test.pdf",
DocType = "PS_INFOCHANGE_NO",
EntityName = "Bill B Billson"
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(fosDnaDocument),
IngestorRequest = new IngestorRequest
{
RootPath = "\\Tester\\"
},
DocumentFileName = "test.pdf",
OwnerOverrideInfo = new()
{
EntityType = EntityTypes.Person,
EntityId = "123"
}
};
var attribute = new PrimaryOwnerAttribute
{
PersonNumber = "2"
};
var primaryOwnerAttribute = ErrorCaptureResult<PrimaryOwnerAttribute>.CreateSuccessPayload(attribute);
_mockPrimaryOwnerDeterminingService.Setup(x => x.DeterminePrimaryOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<DateTime>(),
It.IsAny<OwnerOverrideInfo>())).ReturnsAsync(primaryOwnerAttribute);
var content = new byte[1024];
_mockFileOperationsApiService.Setup(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(content);
_mockDocumentTypeUploaderApiService.Setup(x => x.UploadPrimaryOwnerDocument(It.IsAny<PrimaryOwnerDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()));
var result = await _fosDnaDocumentProcessingService.ProcessRequest(request);
Assert.IsTrue(result.Success);
Assert.IsNull(result.EntityIsUnknown);
_mockPrimaryOwnerDeterminingService.Verify(x => x.DeterminePrimaryOwnerAttribute(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<DateTime>(),
It.IsAny<OwnerOverrideInfo>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadPrimaryOwnerDocument(It.Is<PrimaryOwnerDocumentRequest>(request =>
request.PrimaryOwnerDocumentMetadata.Source == SourceTypes.FOS &&
request.PrimaryOwnerDocumentMetadata.DataSource == DataSourceTypes.DNA),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()), Times.Once);
}
[Test]
public async Task ProcessRequest_FosDnaDocument_SkipAccountNumberPsInfoChangeNoticeOverride_Failure()
{
var fosDnaDocument = new FosDnaDocument
{
AccountNumber = "",
CreationDate = "03072022",
DocName = "Test.pdf",
DocType = "LN_NENT",
EntityName = "Bill B Billson"
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(fosDnaDocument),
IngestorRequest = new IngestorRequest
{
RootPath = "\\Tester\\"
},
DocumentFileName = "test.pdf",
OwnerOverrideInfo = new()
{
EntityType = EntityTypes.Person,
EntityId = "123"
}
};
var result = await _fosDnaDocumentProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
Assert.IsNull(result.EntityIsUnknown);
_mockPrimaryOwnerDeterminingService.Verify(x => x.DeterminePrimaryOwnerAttribute(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<DateTime>(),
It.IsAny<OwnerOverrideInfo>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadAccountDocument(It.IsAny<AccountDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()), Times.Never);
}
[Test]
public async Task ProcessRequest_FosDnaDocument_GetValueFromName_ExceptionThrown_Failure()
{
var fosDnaDocument = new FosDnaDocument
{
AccountNumber = "1",
CreationDate = "01232005",
DocName = "Test.pdf",
DocType = Guid.NewGuid().ToString(),
EntityName = "Bill B Billson"
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(fosDnaDocument),
IngestorRequest = new IngestorRequest
{
RootPath = "\\Tester\\"
},
DocumentFileName = "test.pdf"
};
var attribute = new PrimaryOwnerAttribute
{
PersonNumber = "2"
};
var primaryOwnerAttribute = ErrorCaptureResult<PrimaryOwnerAttribute>.CreateSuccessPayload(attribute);
_mockPrimaryOwnerDeterminingService.Setup(x => x.DeterminePrimaryOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<DateTime>(),
It.IsAny<OwnerOverrideInfo>())).ReturnsAsync(primaryOwnerAttribute);
var content = new byte[1024];
_mockFileOperationsApiService.Setup(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(content);
var result = await _fosDnaDocumentProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
Assert.IsFalse(result.EntityIsUnknown);
Assert.AreEqual(1, result.MessageStack.Count);
_mockPrimaryOwnerDeterminingService.Verify(x => x.DeterminePrimaryOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<DateTime>(),
It.IsAny<OwnerOverrideInfo>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadPrimaryOwnerDocument(It.IsAny<PrimaryOwnerDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()), Times.Never);
}
}
@@ -0,0 +1,426 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using NUnit.Framework;
using Moq;
using Newtonsoft.Json;
using LCU.Library.DocumentType.Enums;
using LCU.Library.DocumentType.Models.Requests.Account;
using LCU.Library.DocumentType.Models.Requests.Attributes;
using LCU.Library.Internal.DocumentIngestorModels.Entities;
using LCU.Library.Internal.DocumentIngestorModels.Models;
using LCU.Library.Internal.DocumentIngestorModels.Models.IndexFileDocuments;
using LCU.API.Internal.DocumentIngestor.Services.AttributeDeterminingServices;
using LCU.API.Internal.DocumentIngestor.Services.DocumentProcessorServices;
using LCU.API.Internal.DocumentIngestor.Services.MicroApiServices;
using LCU.Library.Internal.LCUServiceFactory.Configurations;
namespace LCU.API.Internal.DocumentIngestorTests.Services.DocumentProcessorServices;
public class FosLoanStatementProcessingServiceTest
{
private FosLoanStatementProcessingService _fosLoanStatementProcessingService;
private Mock<IAccountOwnerDeterminingService> _mockAccountOwnerDeterminingService;
private Mock<IFileOperationsApiService> _mockFileOperationsApiService;
private Mock<IDocumentTypeUploaderApiService> _mockDocumentTypeUploaderApiService;
[SetUp]
public void Setup()
{
_mockAccountOwnerDeterminingService = new Mock<IAccountOwnerDeterminingService>();
_mockFileOperationsApiService = new Mock<IFileOperationsApiService>();
_mockDocumentTypeUploaderApiService = new Mock<IDocumentTypeUploaderApiService>();
var serviceFactoryConfiguration = new ServicesFactoryConfiguration
{
ServiceFactoryRegistrations = new List<ServiceFactoryRegistration>
{
new()
{
ServiceInterfaceName = "IIndexParserService",
ServiceRegistrations = new List<ServiceRegistration>
{
new()
{
ServiceName = "IndexParserService",
ServiceId = "4"
},
new()
{
ServiceName = "IndexParserService",
ServiceId = "3"
}
}
}
}
};
_fosLoanStatementProcessingService = new FosLoanStatementProcessingService(_mockAccountOwnerDeterminingService.Object,
_mockFileOperationsApiService.Object,
_mockDocumentTypeUploaderApiService.Object,
serviceFactoryConfiguration);
}
[Test]
public async Task ProcessRequest_ProcessingRequest_Null_ProcessResult_Failure()
{
ProcessingRequest request = null;
var result = await _fosLoanStatementProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadAccountDocument(It.IsAny<AccountDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()), Times.Never);
}
[Test]
public async Task ProcessRequest_FosLoanStatement_Null_ProcessResult_Failure()
{
var request = new ProcessingRequest
{
DocumentValuePayload = null
};
var result = await _fosLoanStatementProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
Assert.IsFalse(result.EntityIsUnknown);
_mockAccountOwnerDeterminingService.Verify(x => x.DetermineAccountOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<DateTime>(),
It.IsAny<OwnerOverrideInfo>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadAccountDocument(It.IsAny<AccountDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()), Times.Never);
}
[Test]
public async Task ProcessRequest_FosLoanStatement_OneValidationFailures_Failure()
{
var FosLoanStatement = new FosLoanStatement
{
AccountNumber = "0",
CreationDate = "20230401",
DocName = "test.pdf",
EmailAddress = "[email protected]",
EntityName = "Test Tester",
StartingPage = "2",
NumberOfPages = "3",
DocType = "Mortgage Statement"
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(FosLoanStatement)
};
var result = await _fosLoanStatementProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
Assert.IsNull(result.EntityIsUnknown);
Assert.AreEqual(1, result.MessageStack.Count);
_mockAccountOwnerDeterminingService.Verify(x => x.DetermineAccountOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<DateTime>(),
It.IsAny<OwnerOverrideInfo>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()),
Times.Never);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadAccountDocument(It.IsAny<AccountDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()), Times.Never);
}
[Test]
public async Task ProcessRequest_FosLoanStatement_FiveValidationFailures_Failure()
{
var FosLoanStatement = new FosLoanStatement
{
AccountNumber = "0",
CreationDate = "20230401",
DocName = "test.pdf",
EmailAddress = "[email protected]",
EntityName = "Test Tester",
StartingPage = "2",
NumberOfPages = "3",
DocType = "Mortgage Statement"
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(FosLoanStatement)
};
var result = await _fosLoanStatementProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
Assert.IsNull(result.EntityIsUnknown);
Assert.AreEqual(1, result.MessageStack.Count);
_mockAccountOwnerDeterminingService.Verify(x => x.DetermineAccountOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<DateTime>(),
It.IsAny<OwnerOverrideInfo>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()),
Times.Never);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadAccountDocument(It.IsAny<AccountDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()), Times.Never);
}
[Test]
public async Task ProcessRequest_FosLoanStatement_NumberIsNull_Failure()
{
var FosLoanStatement = new FosLoanStatement
{
AccountNumber = "111111",
CreationDate = "20230401",
DocName = "test.pdf",
EmailAddress = "[email protected]",
EntityName = "Test Tester",
StartingPage = "2",
NumberOfPages = "3",
DocType = "Mortgage Statement"
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(FosLoanStatement)
};
AccountAttribute attribute = null;
var accountAttribute = ErrorCaptureResult<AccountAttribute>.CreateSuccessPayload(attribute);
_mockAccountOwnerDeterminingService.Setup(x => x.DetermineAccountOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<DateTime>(),
It.IsAny<OwnerOverrideInfo>())).ReturnsAsync(accountAttribute);
var result = await _fosLoanStatementProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
Assert.IsFalse(result.EntityIsUnknown);
Assert.AreEqual(1, result.MessageStack.Count);
_mockAccountOwnerDeterminingService.Verify(x => x.DetermineAccountOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<DateTime>(),
It.IsAny<OwnerOverrideInfo>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()),
Times.Never);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadAccountDocument(It.IsAny<AccountDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()), Times.Never);
}
[Test]
public async Task ProcessRequest_FosLoanStatement_NumberNotNull_Upload_Success()
{
var FosLoanStatement = new FosLoanStatement
{
AccountNumber = "111111",
CreationDate = "20230401",
DocName = "test.pdf",
EmailAddress = "[email protected]",
EntityName = "Test Tester",
StartingPage = "2",
NumberOfPages = "3",
DocType = "Mortgage Statement"
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(FosLoanStatement),
IngestorRequest = new IngestorRequest
{
RootPath = "\\Tester\\"
},
DocumentFileName = "test.pdf"
};
var attribute = new AccountAttribute
{
PersonNumbers = new List<string> { "2", "3", "4" }
};
var accountAttribute = ErrorCaptureResult<AccountAttribute>.CreateSuccessPayload(attribute);
_mockAccountOwnerDeterminingService.Setup(x => x.DetermineAccountOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<DateTime>(),
It.IsAny<OwnerOverrideInfo>())).ReturnsAsync(accountAttribute);
byte[] content = new byte[1024];
_mockFileOperationsApiService.Setup(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()))
.ReturnsAsync(content);
_mockDocumentTypeUploaderApiService.Setup(x => x.UploadAccountDocument(It.IsAny<AccountDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()));
var result = await _fosLoanStatementProcessingService.ProcessRequest(request);
Assert.IsTrue(result.Success);
Assert.IsNull(result.EntityIsUnknown);
_mockAccountOwnerDeterminingService.Verify(x => x.DetermineAccountOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<DateTime>(),
It.IsAny<OwnerOverrideInfo>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()),
Times.Once);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadAccountDocument(It.Is<AccountDocumentRequest>(request =>
request.AccountDocumentMetadata.Source == SourceTypes.FOS &&
request.AccountDocumentMetadata.DataSource == DataSourceTypes.DNA),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()), Times.Once);
}
[Test]
public async Task ProcessRequest_FosLoanStatement_NumberNotNull_GetContentBtyesThrowException_Failure()
{
var FosLoanStatement = new FosLoanStatement
{
AccountNumber = "111111",
CreationDate = "20230401",
DocName = "test.pdf",
EmailAddress = "[email protected]",
EntityName = "Test Tester",
StartingPage = "2",
NumberOfPages = "3",
DocType = "Mortgage Statement"
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(FosLoanStatement),
IngestorRequest = new IngestorRequest
{
RootPath = "\\Tester\\"
},
DocumentFileName = "test.pdf"
};
var attribute = new AccountAttribute
{
PersonNumbers = new List<string> { "2", "3", "4" }
};
var accountAttribute = ErrorCaptureResult<AccountAttribute>.CreateSuccessPayload(attribute);
_mockAccountOwnerDeterminingService.Setup(x => x.DetermineAccountOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<DateTime>(),
It.IsAny<OwnerOverrideInfo>())).ReturnsAsync(accountAttribute);
_mockFileOperationsApiService.Setup(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()))
.ThrowsAsync(new Exception("Error"));
var result = await _fosLoanStatementProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
Assert.IsFalse(result.EntityIsUnknown);
Assert.AreEqual(1, result.MessageStack.Count);
_mockAccountOwnerDeterminingService.Verify(x => x.DetermineAccountOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<DateTime>(),
It.IsAny<OwnerOverrideInfo>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()),
Times.Once);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadAccountDocument(It.IsAny<AccountDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()), Times.Never);
}
[Test]
public async Task ProcessRequest_FosLoanStatement_NumberNotNull_UploadDocumentThrowException_Failure()
{
var FosLoanStatement = new FosLoanStatement
{
AccountNumber = "111111",
CreationDate = "20230401",
DocName = "test.pdf",
EmailAddress = "[email protected]",
EntityName = "Test Tester",
StartingPage = "2",
NumberOfPages = "3",
DocType = "Mortgage Statement"
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(FosLoanStatement),
IngestorRequest = new IngestorRequest
{
RootPath = "\\Tester\\"
},
DocumentFileName = "test.pdf"
};
var attribute = new AccountAttribute
{
PersonNumbers = new List<string> { "2", "3", "4" }
};
var accountAttribute = ErrorCaptureResult<AccountAttribute>.CreateSuccessPayload(attribute);
_mockAccountOwnerDeterminingService.Setup(x => x.DetermineAccountOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<DateTime>(),
It.IsAny<OwnerOverrideInfo>())).ReturnsAsync(accountAttribute);
byte[] content = new byte[1024];
_mockFileOperationsApiService.Setup(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(content);
_mockDocumentTypeUploaderApiService.Setup(x => x.UploadAccountDocument(It.IsAny<AccountDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>())).ThrowsAsync(new Exception("Error"));
var result = await _fosLoanStatementProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
Assert.IsFalse(result.EntityIsUnknown);
Assert.AreEqual(1, result.MessageStack.Count);
_mockAccountOwnerDeterminingService.Verify(x => x.DetermineAccountOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<DateTime>(),
It.IsAny<OwnerOverrideInfo>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadAccountDocument(It.IsAny<AccountDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()),
Times.Once);
}
[Test]
public async Task ProcessRequest_FosLoanStatement_GetValueFromName_ExceptionThrown_Failure()
{
var FosLoanStatement = new FosLoanStatement
{
AccountNumber = "111111",
CreationDate = "20230401",
DocName = "test.pdf",
EmailAddress = "[email protected]",
EntityName = "Test Tester",
StartingPage = "2",
NumberOfPages = "3",
DocType = Guid.NewGuid().ToString()
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(FosLoanStatement),
IngestorRequest = new IngestorRequest
{
RootPath = "\\Tester\\"
},
DocumentFileName = "test.pdf"
};
var attribute = new AccountAttribute
{
PersonNumbers = new List<string> { "2", "3", "4" }
};
var accountAttribute = ErrorCaptureResult<AccountAttribute>.CreateSuccessPayload(attribute);
_mockAccountOwnerDeterminingService.Setup(x => x.DetermineAccountOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<DateTime>(),
It.IsAny<OwnerOverrideInfo>())).ReturnsAsync(accountAttribute);
byte[] content = new byte[1024];
_mockFileOperationsApiService.Setup(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()))
.ReturnsAsync(content);
var result = await _fosLoanStatementProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
Assert.IsFalse(result.EntityIsUnknown);
Assert.AreEqual(1, result.MessageStack.Count);
_mockAccountOwnerDeterminingService.Verify(x => x.DetermineAccountOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<DateTime>(),
It.IsAny<OwnerOverrideInfo>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()),
Times.Never);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadAccountDocument(It.IsAny<AccountDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()), Times.Never);
}
}
@@ -0,0 +1,473 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using NUnit.Framework;
using Moq;
using Newtonsoft.Json;
using LCU.API.Internal.DocumentIngestor.Services.AttributeDeterminingServices;
using LCU.API.Internal.DocumentIngestor.Services.DocumentProcessorServices;
using LCU.API.Internal.DocumentIngestor.Services.MicroApiServices;
using LCU.Library.DocumentType.Enums;
using LCU.Library.DocumentType.Models.Requests.Attributes;
using LCU.Library.DocumentType.Models.Requests.PrimaryOwner;
using LCU.Library.DocumentType.Models.Requests.Generic;
using LCU.Library.Internal.DocumentIngestorModels.Entities;
using LCU.Library.Internal.DocumentIngestorModels.Models;
using LCU.Library.Internal.DocumentIngestorModels.Models.IndexFileDocuments;
using LCU.Library.Internal.LCUServiceFactory.Configurations;
namespace LCU.API.Internal.DocumentIngestorTests.Services.DocumentProcessorServices;
public class FosTaxStatementProcessingServiceTest
{
private FosTaxStatementProcessingService _fosTaxStatementProcessingService;
private Mock<IPrimaryOwnerDeterminingService> _mockPrimaryOwnerDeterminingService;
private Mock<IFileOperationsApiService> _mockFileOperationsApiService;
private Mock<IDocumentTypeUploaderApiService> _mockDocumentTypeUploaderApiService;
[SetUp]
public void Setup()
{
_mockPrimaryOwnerDeterminingService = new Mock<IPrimaryOwnerDeterminingService>();
_mockFileOperationsApiService = new Mock<IFileOperationsApiService>();
_mockDocumentTypeUploaderApiService = new Mock<IDocumentTypeUploaderApiService>();
var serviceFactoryConfiguration = new ServicesFactoryConfiguration
{
ServiceFactoryRegistrations = new List<ServiceFactoryRegistration>
{
new()
{
ServiceInterfaceName = "IIndexParserService",
ServiceRegistrations = new List<ServiceRegistration>
{
new()
{
ServiceName = "IndexParserService",
ServiceId = "4"
},
new()
{
ServiceName = "IndexParserService",
ServiceId = "0"
}
}
}
}
};
_fosTaxStatementProcessingService = new FosTaxStatementProcessingService(_mockPrimaryOwnerDeterminingService.Object,
_mockFileOperationsApiService.Object,
_mockDocumentTypeUploaderApiService.Object,
serviceFactoryConfiguration);
}
[Test]
public async Task ProcessRequest_ProcessingRequest_Null_ProcessResult_Failure()
{
ProcessingRequest request = null;
var result = await _fosTaxStatementProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
_mockPrimaryOwnerDeterminingService.Verify(x => x.DeterminePrimaryOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(), It.IsAny<string>(),
It.IsAny<OwnerOverrideInfo>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()),
Times.Never);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadPrimaryOwnerDocument(It.IsAny<PrimaryOwnerDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()), Times.Never);
_mockDocumentTypeUploaderApiService.Verify(
x => x.UploadGenericDocument(It.IsAny<GenericDocumentRequest>(), It.IsAny<ProcessingRequest>(), It.IsAny<ProcessResult>()), Times.Never);
}
[Test]
public async Task ProcessRequest_FosTaxStatementDocument_Null_ProcessResult_Failure()
{
var request = new ProcessingRequest
{
DocumentValuePayload = null
};
var result = await _fosTaxStatementProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
Assert.IsFalse(result.EntityIsUnknown);
_mockPrimaryOwnerDeterminingService.Verify(x => x.DeterminePrimaryOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(), It.IsAny<string>(),
It.IsAny<OwnerOverrideInfo>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()),
Times.Never);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadPrimaryOwnerDocument(It.IsAny<PrimaryOwnerDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()), Times.Never);
_mockDocumentTypeUploaderApiService.Verify(
x => x.UploadGenericDocument(It.IsAny<GenericDocumentRequest>(), It.IsAny<ProcessingRequest>(), It.IsAny<ProcessResult>()), Times.Never);
}
[Test]
public async Task ProcessRequest_FosTaxStatementDocument_OneValidationFailures_Failure()
{
var fosTaxStatementDocument = new FosTaxStatementDocument
{
AccountNumber = "0",
FileName = "test",
FullName = "test",
PDF = "test",
PrimaryTIN = "1"
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(fosTaxStatementDocument)
};
var result = await _fosTaxStatementProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
Assert.IsNull(result.EntityIsUnknown);
Assert.AreEqual(1, result.MessageStack.Count);
_mockPrimaryOwnerDeterminingService.Verify(x => x.DeterminePrimaryOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(), It.IsAny<string>(),
It.IsAny<OwnerOverrideInfo>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()),
Times.Never);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadPrimaryOwnerDocument(It.IsAny<PrimaryOwnerDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()), Times.Never);
_mockDocumentTypeUploaderApiService.Verify(
x => x.UploadGenericDocument(It.IsAny<GenericDocumentRequest>(), It.IsAny<ProcessingRequest>(), It.IsAny<ProcessResult>()), Times.Never);
}
[Test]
public async Task ProcessRequest_FosTaxStatementDocument_FiveValidationFailures_Failure()
{
var fosTaxStatementDocument = new FosTaxStatementDocument
{
AccountNumber = "0",
FileName = "",
FullName = "",
PDF = "",
PrimaryTIN = ""
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(fosTaxStatementDocument)
};
var result = await _fosTaxStatementProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
Assert.IsNull(result.EntityIsUnknown);
Assert.AreEqual(5, result.MessageStack.Count);
_mockPrimaryOwnerDeterminingService.Verify(x => x.DeterminePrimaryOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(), It.IsAny<string>(),
It.IsAny<OwnerOverrideInfo>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()),
Times.Never);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadPrimaryOwnerDocument(It.IsAny<PrimaryOwnerDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()), Times.Never);
_mockDocumentTypeUploaderApiService.Verify(
x => x.UploadGenericDocument(It.IsAny<GenericDocumentRequest>(), It.IsAny<ProcessingRequest>(), It.IsAny<ProcessResult>()), Times.Never);
}
[Test]
public async Task ProcessRequest_FosTaxStatementDocument_NumberIsNull_Failure()
{
var fosTaxStatementDocument = new FosTaxStatementDocument
{
AccountNumber = "1",
FileName = "1099-INT",
FullName = "test",
PDF = "test",
PrimaryTIN = "11"
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(fosTaxStatementDocument)
};
var primaryOwnerAttribute =
ErrorCaptureResult<PrimaryOwnerAttribute>.CreateErrorPayload("Error from unit test", null);
_mockPrimaryOwnerDeterminingService.Setup(x => x.DeterminePrimaryOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<OwnerOverrideInfo>())).ReturnsAsync(primaryOwnerAttribute);
var result = await _fosTaxStatementProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
Assert.IsNull(result.EntityIsUnknown);
Assert.AreEqual(1, result.MessageStack.Count);
_mockPrimaryOwnerDeterminingService.Verify(x => x.DeterminePrimaryOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(), It.IsAny<string>(),
It.IsAny<OwnerOverrideInfo>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()),
Times.Never);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadPrimaryOwnerDocument(It.IsAny<PrimaryOwnerDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()), Times.Never);
_mockDocumentTypeUploaderApiService.Verify(
x => x.UploadGenericDocument(It.IsAny<GenericDocumentRequest>(), It.IsAny<ProcessingRequest>(), It.IsAny<ProcessResult>()), Times.Never);
}
[Test]
public async Task ProcessRequest_FosTaxStatementDocument_NumberNotNull_Upload_Success()
{
var fosTaxStatementDocument = new FosTaxStatementDocument
{
AccountNumber = "1",
FileName = "1099-INT",
FullName = "test",
PDF = "test",
PrimaryTIN = "11"
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(fosTaxStatementDocument),
IngestorRequest = new IngestorRequest
{
RootPath = "\\Tester\\"
},
DocumentFileName = "test.pdf"
};
var attribute = new PrimaryOwnerAttribute
{
PersonNumber = "2"
};
var primaryOwnerAttribute = ErrorCaptureResult<PrimaryOwnerAttribute>.CreateSuccessPayload(attribute);
_mockPrimaryOwnerDeterminingService.Setup(x => x.DeterminePrimaryOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<OwnerOverrideInfo>())).ReturnsAsync(primaryOwnerAttribute);
var content = new byte[1024];
_mockFileOperationsApiService.Setup(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()))
.ReturnsAsync(content);
_mockDocumentTypeUploaderApiService.Setup(x => x.UploadPrimaryOwnerDocument(It.IsAny<PrimaryOwnerDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()));
var result = await _fosTaxStatementProcessingService.ProcessRequest(request);
Assert.IsTrue(result.Success);
_mockPrimaryOwnerDeterminingService.Verify(x => x.DeterminePrimaryOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<OwnerOverrideInfo>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
_mockDocumentTypeUploaderApiService.Verify(x =>
x.UploadPrimaryOwnerDocument(It.Is<PrimaryOwnerDocumentRequest>(request =>
request.PrimaryOwnerDocumentMetadata.Source == SourceTypes.FOS &&
request.PrimaryOwnerDocumentMetadata.DataSource == DataSourceTypes.DNA),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()), Times.Once);
}
[Test]
public async Task ProcessRequest_FosTaxStatementDocument_GenericDocument_NumberNotNull_Upload_Success()
{
var fosTaxStatementDocument = new FosTaxStatementDocument
{
AccountNumber = "1",
FileName = "1099-MISC",
FullName = "test",
PDF = "test",
PrimaryTIN = "11"
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(fosTaxStatementDocument),
IngestorRequest = new IngestorRequest
{
RootPath = "\\Tester\\"
},
DocumentFileName = "test.pdf"
};
var attribute = new GenericDocumentAttribute
{
EntityName = "test"
};
var genericAttribute = ErrorCaptureResult<GenericDocumentAttribute>.CreateSuccessPayload(attribute);
var content = new byte[1024];
_mockFileOperationsApiService.Setup(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()))
.ReturnsAsync(content);
var documentTypeArchiveDeleteInfo = new DocumentTypeArchiveDeleteInfo
{
DocumentTypeName = "OneThousandNinetyNineMiscelanneous",
ArchiveDays = 2000,
DeleteDays = 4000
};
_mockDocumentTypeUploaderApiService.Setup(x =>
x.UploadGenericDocument(It.IsAny<GenericDocumentRequest>(), It.IsAny<ProcessingRequest>(), It.IsAny<ProcessResult>()));
var result = await _fosTaxStatementProcessingService.ProcessRequest(request);
Assert.IsTrue(result.Success);
Assert.IsNull(result.EntityIsUnknown);
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()),
Times.Once);
_mockDocumentTypeUploaderApiService.Verify(
x => x.UploadGenericDocument(It.Is<GenericDocumentRequest>(request =>
request.GenericDocumentMetadata.Source == SourceTypes.FOS &&
request.GenericDocumentMetadata.DataSource == DataSourceTypes.DNA),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()), Times.Once);
}
[Test]
public async Task ProcessRequest_FosTaxStatementDocument_NumberNotNull_GetContentBytesThrowException_Failure()
{
var fosTaxStatementDocument = new FosTaxStatementDocument
{
AccountNumber = "1",
FileName = "1099-INT",
FullName = "test",
PDF = "test",
PrimaryTIN = "11"
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(fosTaxStatementDocument),
IngestorRequest = new IngestorRequest
{
RootPath = "\\Tester\\"
},
DocumentFileName = "test.pdf"
};
var attribute = new PrimaryOwnerAttribute
{
PersonNumber = "2"
};
var primaryOwnerAttribute = ErrorCaptureResult<PrimaryOwnerAttribute>.CreateSuccessPayload(attribute);
_mockPrimaryOwnerDeterminingService.Setup(x => x.DeterminePrimaryOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<OwnerOverrideInfo>())).ReturnsAsync(primaryOwnerAttribute);
_mockFileOperationsApiService.Setup(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()))
.ThrowsAsync(new Exception("Error"));
var result = await _fosTaxStatementProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
Assert.IsFalse(result.EntityIsUnknown);
Assert.AreEqual(1, result.MessageStack.Count);
_mockPrimaryOwnerDeterminingService.Verify(x => x.DeterminePrimaryOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<OwnerOverrideInfo>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()),
Times.Once);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadPrimaryOwnerDocument(It.IsAny<PrimaryOwnerDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()), Times.Never);
_mockDocumentTypeUploaderApiService.Verify(
x => x.UploadGenericDocument(It.IsAny<GenericDocumentRequest>(), It.IsAny<ProcessingRequest>(), It.IsAny<ProcessResult>()), Times.Never);
}
[Test]
public async Task ProcessRequest_FosTaxStatementDocument_NumberNotNull_UploadDocumentThrowException_Failure()
{
var fosTaxStatementDocument = new FosTaxStatementDocument
{
AccountNumber = "1",
FileName = "1099-INT",
FullName = "test",
PDF = "test",
PrimaryTIN = "11"
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(fosTaxStatementDocument),
IngestorRequest = new IngestorRequest
{
RootPath = "\\Tester\\"
},
DocumentFileName = "test.pdf"
};
var attribute = new PrimaryOwnerAttribute
{
PersonNumber = "2"
};
var primaryOwnerAttribute = ErrorCaptureResult<PrimaryOwnerAttribute>.CreateSuccessPayload(attribute);
_mockPrimaryOwnerDeterminingService.Setup(x => x.DeterminePrimaryOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<OwnerOverrideInfo>())).ReturnsAsync(primaryOwnerAttribute);
var content = new byte[1024];
_mockFileOperationsApiService.Setup(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()))
.ReturnsAsync(content);
_mockDocumentTypeUploaderApiService.Setup(x => x.UploadPrimaryOwnerDocument(It.IsAny<PrimaryOwnerDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()))
.ThrowsAsync(new Exception("Error"));
var result = await _fosTaxStatementProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
Assert.IsFalse(result.EntityIsUnknown);
Assert.AreEqual(1, result.MessageStack.Count);
_mockPrimaryOwnerDeterminingService.Verify(x => x.DeterminePrimaryOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<OwnerOverrideInfo>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadPrimaryOwnerDocument(It.IsAny<PrimaryOwnerDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()), Times.Once);
}
[Test]
public async Task ProcessRequest_FosTaxStatementDocument_GetCreatedDateFromDocumentType_Success()
{
var createdDate = DateTime.Now.Date;
var fosTaxStatementDocument = new FosTaxStatementDocument
{
AccountNumber = "1",
FileName = "1099-INT",
FullName = "test",
TaxYear = 2021,
PDF = "test",
PrimaryTIN = "11"
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(fosTaxStatementDocument),
IngestorRequest = new IngestorRequest
{
RootPath = "\\Tester\\"
},
DocumentFileName = "test.pdf"
};
var attribute = new PrimaryOwnerAttribute
{
PersonNumber = "2"
};
var primaryOwnerAttribute = ErrorCaptureResult<PrimaryOwnerAttribute>.CreateSuccessPayload(attribute);
_mockPrimaryOwnerDeterminingService.Setup(x => x.DeterminePrimaryOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(), It.IsAny<string>(),
It.IsAny<OwnerOverrideInfo>())).ReturnsAsync(primaryOwnerAttribute);
var content = new byte[1024];
_mockFileOperationsApiService.Setup(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()))
.ReturnsAsync(content);
var builtRequest = await _fosTaxStatementProcessingService.BuildUploadRequest(request, fosTaxStatementDocument, attribute);
Assert.AreEqual(createdDate, builtRequest.PrimaryOwnerDocumentMetadata.CreatedDate);
_mockDocumentTypeUploaderApiService.Setup(x => x.UploadPrimaryOwnerDocument(It.IsAny<PrimaryOwnerDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()));
var result = await _fosTaxStatementProcessingService.ProcessRequest(request);
Assert.IsTrue(result.Success);
Assert.IsNull(result.EntityIsUnknown);
_mockPrimaryOwnerDeterminingService.Verify(x => x.DeterminePrimaryOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(), It.IsAny<string>(),
It.IsAny<OwnerOverrideInfo>()), Times.Once);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadPrimaryOwnerDocument(It.IsAny<PrimaryOwnerDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()), Times.Once);
}
}
@@ -0,0 +1,166 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using NUnit.Framework;
using Moq;
using Newtonsoft.Json;
using LCU.API.Internal.DocumentIngestor.Services.AttributeDeterminingServices;
using LCU.API.Internal.DocumentIngestor.Services.DocumentProcessorServices;
using LCU.API.Internal.DocumentIngestor.Services.MicroApiServices;
using LCU.Library.DocumentType.Models.Requests.Attributes;
using LCU.Library.DocumentType.Models.Requests.PrimaryOwner;
using LCU.Library.Internal.DocumentIngestorModels.Entities;
using LCU.Library.Internal.DocumentIngestorModels.Models;
using LCU.Library.Internal.DocumentIngestorModels.Models.IndexFileDocuments;
using LCU.Library.DocumentType.Models.Requests.Account;
using LCU.Library.Internal.LCUServiceFactory.Configurations;
namespace LCU.API.Internal.DocumentIngestorTests.Services.DocumentProcessorServices;
public class OsgDnaNoticeSplitProcessingServiceTest
{
private OsgDnaNoticeSplitProcessingService _osgDnaNoticeSplitProcessingService;
private Mock<IAccountOwnerDeterminingService> _mockAccountOwnerDeterminingService;
private Mock<IFileOperationsApiService> _mockFileOperationsApiService;
private Mock<IDocumentTypeUploaderApiService> _mockDocumentTypeUploaderApiService;
[SetUp]
public void Setup()
{
_mockAccountOwnerDeterminingService = new Mock<IAccountOwnerDeterminingService>();
_mockFileOperationsApiService = new Mock<IFileOperationsApiService>();
_mockDocumentTypeUploaderApiService = new Mock<IDocumentTypeUploaderApiService>();
var serviceFactoryConfiguration = new ServicesFactoryConfiguration
{
ServiceFactoryRegistrations = new List<ServiceFactoryRegistration>
{
new()
{
ServiceInterfaceName = "IIndexParserService",
ServiceRegistrations = new List<ServiceRegistration>
{
new()
{
ServiceName = "IndexParserService",
ServiceId = "4"
},
new()
{
ServiceName = "IndexParserService",
ServiceId = "9"
}
}
}
}
};
_osgDnaNoticeSplitProcessingService = new OsgDnaNoticeSplitProcessingService(_mockFileOperationsApiService.Object,
_mockDocumentTypeUploaderApiService.Object,
_mockAccountOwnerDeterminingService.Object,
serviceFactoryConfiguration);
}
[Test]
public async Task ProcessRequest_ProcessingRequest_Null_ProcessResult_Failure()
{
ProcessingRequest request = null;
var result = await _osgDnaNoticeSplitProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
_mockAccountOwnerDeterminingService.Verify(x => x.DetermineAccountOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(), DateTime.Now,
It.IsAny<OwnerOverrideInfo>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()),
Times.Never);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadAccountDocument(It.IsAny<AccountDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()), Times.Never);
}
[Test]
public async Task ProcessRequest_OsgDnaNoticeSplitStatementDocument_Null_ProcessResult_Failure()
{
var request = new ProcessingRequest
{
DocumentValuePayload = null
};
var result = await _osgDnaNoticeSplitProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
Assert.IsFalse(result.EntityIsUnknown);
_mockAccountOwnerDeterminingService.Verify(x => x.DetermineAccountOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(), DateTime.Now,
It.IsAny<OwnerOverrideInfo>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()),
Times.Never);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadAccountDocument(It.IsAny<AccountDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()), Times.Never);
}
[Test]
public async Task ProcessRequest_OsgDnaNoticeSplitDocument_FiveValidationFailures_Failure()
{
var osgDnaNoticeSplitDocument = new OsgDnaNoticeSplit
{
AccountNumber = "0",
NoticeName = "",
RecipientName = "",
PdfName = "",
MemberNumber = ""
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(osgDnaNoticeSplitDocument)
};
var result = await _osgDnaNoticeSplitProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
Assert.IsNull(result.EntityIsUnknown);
Assert.AreEqual(4, result.MessageStack.Count);
_mockAccountOwnerDeterminingService.Verify(x => x.DetermineAccountOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(), DateTime.Now,
It.IsAny<OwnerOverrideInfo>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()),
Times.Never);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadAccountDocument(It.IsAny<AccountDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()), Times.Never);
}
[Test]
public async Task ProcessRequest_OsgDnaNoticeSplitDocument_NumberIsNull_Failure()
{
var osgDnaNoticeSplitDocument = new OsgDnaNoticeSplit
{
AccountNumber = "1",
NoticeName = "1099-INT",
RecipientName = "test",
PdfName = "test",
MemberNumber = "11",
CreationDate = DateTime.Now.Date.ToString("MMddyyyy")
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(osgDnaNoticeSplitDocument)
};
var primaryOwnerAttribute =
ErrorCaptureResult<PrimaryOwnerAttribute>.CreateErrorPayload("Error from unit test", null);
_mockAccountOwnerDeterminingService.Verify(x => x.DetermineAccountOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(), DateTime.Now,
It.IsAny<OwnerOverrideInfo>()), Times.Never);
var result = await _osgDnaNoticeSplitProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
Assert.IsFalse(result.EntityIsUnknown);
Assert.AreEqual(1, result.MessageStack.Count);
_mockAccountOwnerDeterminingService.Verify(x => x.DetermineAccountOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(), DateTime.Now,
It.IsAny<OwnerOverrideInfo>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()),
Times.Never);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadAccountDocument(It.IsAny<AccountDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()), Times.Never);
}
}
@@ -0,0 +1,467 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using LCU.API.Internal.DocumentIngestor.Services.AttributeDeterminingServices;
using LCU.API.Internal.DocumentIngestor.Services.DocumentProcessorServices;
using LCU.API.Internal.DocumentIngestor.Services.MicroApiServices;
using LCU.Library.DocumentType.Enums;
using LCU.Library.DocumentType.Models.Requests.Account;
using LCU.Library.DocumentType.Models.Requests.Attributes;
using LCU.Library.Internal.DocumentIngestorModels.Entities;
using LCU.Library.Internal.DocumentIngestorModels.Enums;
using LCU.Library.Internal.DocumentIngestorModels.Models;
using LCU.Library.Internal.DocumentIngestorModels.Models.IndexFileDocuments;
using LCU.Library.Internal.LCUServiceFactory.Configurations;
using Moq;
using Newtonsoft.Json;
using NUnit.Framework;
namespace LCU.API.Internal.DocumentIngestorTests.Services.DocumentProcessorServices;
public class OsgDnaNoticesProcessingServiceTest
{
private OsgDnaNoticesProcessingService _osgDnaNoticesProcessingService;
private Mock<IAccountOwnerDeterminingService> _mockAccountOwnerDeterminingService;
private Mock<IFileOperationsApiService> _mockFileOperationsApiService;
private Mock<IDocumentTypeUploaderApiService> _mockDocumentTypeUploaderApiService;
private Mock<IPrimaryOwnerDeterminingService> _mockPrimaryOwnerDeterminingService;
[SetUp]
public void Setup()
{
_mockAccountOwnerDeterminingService = new Mock<IAccountOwnerDeterminingService>();
_mockPrimaryOwnerDeterminingService = new Mock<IPrimaryOwnerDeterminingService>();
_mockFileOperationsApiService = new Mock<IFileOperationsApiService>();
_mockDocumentTypeUploaderApiService = new Mock<IDocumentTypeUploaderApiService>();
var serviceFactoryConfiguration = new ServicesFactoryConfiguration
{
ServiceFactoryRegistrations = new List<ServiceFactoryRegistration>
{
new()
{
ServiceInterfaceName = "IIndexParserService",
ServiceRegistrations = new List<ServiceRegistration>
{
new()
{
ServiceName = "IndexParserService",
ServiceId = "4"
},
new()
{
ServiceName = "IndexParserService",
ServiceId = "1"
}
}
}
}
};
_osgDnaNoticesProcessingService = new OsgDnaNoticesProcessingService(_mockPrimaryOwnerDeterminingService.Object,
_mockFileOperationsApiService.Object,
_mockDocumentTypeUploaderApiService.Object,
_mockAccountOwnerDeterminingService.Object,
serviceFactoryConfiguration);
}
[Test]
public async Task ProcessRequest_ProcessingRequest_Null_ProcessResult_Failure()
{
ProcessingRequest request = null;
var result = await _osgDnaNoticesProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
Assert.IsFalse(result.EntityIsUnknown);
_mockFileOperationsApiService.Verify(
x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()),
Times.Never
);
_mockDocumentTypeUploaderApiService.Verify(
x => x.UploadAccountDocument(It.IsAny<AccountDocumentRequest>(), It.IsAny<ProcessingRequest>(), It.IsAny<ProcessResult>()),
Times.Never
);
}
[Test]
public async Task ProcessRequest_OsgDnaNotices_Null_ProcessResult_Failure()
{
var request = new ProcessingRequest
{
DocumentValuePayload = null
};
var result = await _osgDnaNoticesProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
Assert.IsFalse(result.EntityIsUnknown);
_mockAccountOwnerDeterminingService.Verify(
x => x.DetermineAccountOwnerAttribute(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<DateTime>(), It.IsAny<OwnerOverrideInfo>()),
Times.Never
);
_mockFileOperationsApiService.Verify(
x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()),
Times.Never
);
_mockDocumentTypeUploaderApiService.Verify(
x => x.UploadAccountDocument(It.IsAny<AccountDocumentRequest>(), It.IsAny<ProcessingRequest>(), It.IsAny<ProcessResult>()),
Times.Never
);
}
[Test]
public async Task ProcessRequest_OsgDnaNotices_OneValidationFailures_Failure()
{
var OsgDnaNotices = new OsgDnaNoticesDocument
{
DocType = "MTG_NT_110_01",
AccountNumber = "1",
MemberNumberOrUserId = "2",
CreationDate = "2",
StartingPage = "1",
NumberOfPages = "3"
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(OsgDnaNotices)
};
var result = await _osgDnaNoticesProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
Assert.IsNull(result.EntityIsUnknown);
Assert.AreEqual(result.ProcessStatusType, ProcessStatusTypes.DataMappingFailure);
Assert.AreEqual(1, result.MessageStack.Count);
_mockAccountOwnerDeterminingService.Verify(
x => x.DetermineAccountOwnerAttribute(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<DateTime>(), It.IsAny<OwnerOverrideInfo>()),
Times.Never
);
_mockFileOperationsApiService.Verify(
x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()),
Times.Never
);
_mockDocumentTypeUploaderApiService.Verify(
x => x.UploadAccountDocument(It.IsAny<AccountDocumentRequest>(), It.IsAny<ProcessingRequest>(), It.IsAny<ProcessResult>()),
Times.Never
);
}
[Test]
public async Task ProcessRequest_OsgDnaNotices_ValidationFailures_Failure()
{
var OsgDnaNotices = new OsgDnaNoticesDocument
{
DocType = "MTG_NT_110_01",
AccountNumber = "0",
MemberNumberOrUserId = "2",
CreationDate = "20220823",
StartingPage = "1",
NumberOfPages = "3"
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(OsgDnaNotices)
};
var result = await _osgDnaNoticesProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
Assert.IsNull(result.EntityIsUnknown);
Assert.AreEqual(result.ProcessStatusType, ProcessStatusTypes.DataMappingFailure);
Assert.AreEqual(1, result.MessageStack.Count);
_mockAccountOwnerDeterminingService.Verify(
x => x.DetermineAccountOwnerAttributeByMemberNumberOrUserId(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<DateTime>(), It.IsAny<OwnerOverrideInfo>()),
Times.Never
);
_mockFileOperationsApiService.Verify(
x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()),
Times.Never
);
_mockDocumentTypeUploaderApiService.Verify(
x => x.UploadAccountDocument(It.IsAny<AccountDocumentRequest>(), It.IsAny<ProcessingRequest>(), It.IsAny<ProcessResult>()),
Times.Never
);
}
[Test]
public async Task ProcessRequest_OsgDnaNotices_NumberIsNull_Failure()
{
var OsgDnaNotices = new OsgDnaNoticesDocument
{
DocType = "MTG_NT_110_01",
AccountNumber = "1",
MemberNumberOrUserId = "2",
CreationDate = "20220823",
StartingPage = "1",
NumberOfPages = "3"
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(OsgDnaNotices)
};
AccountAttribute attribute = null;
var accountAttribute = ErrorCaptureResult<AccountAttribute>.CreateSuccessPayload(attribute);
_mockAccountOwnerDeterminingService.Setup(x => x.DetermineAccountOwnerAttributeByMemberNumberOrUserId(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<DateTime>(),
It.IsAny<OwnerOverrideInfo>())).ReturnsAsync(accountAttribute);
var result = await _osgDnaNoticesProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
Assert.IsFalse(result.EntityIsUnknown);
Assert.AreEqual(1, result.MessageStack.Count);
_mockAccountOwnerDeterminingService.Verify(
x => x.DetermineAccountOwnerAttributeByMemberNumberOrUserId(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<DateTime>(), It.IsAny<OwnerOverrideInfo>()),
Times.Once
);
_mockFileOperationsApiService.Verify(
x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()),
Times.Never
);
_mockDocumentTypeUploaderApiService.Verify(
x => x.UploadAccountDocument(It.IsAny<AccountDocumentRequest>(), It.IsAny<ProcessingRequest>(), It.IsAny<ProcessResult>()),
Times.Never
);
}
[Test]
public async Task ProcessRequest_OsgDnaNotices_NumberNotNull_Upload_Success()
{
var OsgDnaNotices = new OsgDnaNoticesDocument
{
DocType = "MTG_NT_110_01",
AccountNumber = "1",
MemberNumberOrUserId = "2",
CreationDate = "20220823",
StartingPage = "1",
NumberOfPages = "3"
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(OsgDnaNotices),
IngestorRequest = new IngestorRequest
{
RootPath = "\\Tester\\"
},
DocumentFileName = "test.pdf"
};
var attribute = new AccountAttribute
{
PersonNumbers = new List<string> { "2", "3", "4" }
};
var accountAttribute = ErrorCaptureResult<AccountAttribute>.CreateSuccessPayload(attribute);
_mockAccountOwnerDeterminingService.Setup(x => x.DetermineAccountOwnerAttributeByMemberNumberOrUserId(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<DateTime>(),
It.IsAny<OwnerOverrideInfo>())).ReturnsAsync(accountAttribute);
byte[] content = new byte[1024];
_mockFileOperationsApiService.Setup(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()))
.ReturnsAsync(content);
var documentTypeArchiveDeleteInfo = new DocumentTypeArchiveDeleteInfo
{
DocumentTypeName = "MTG_NT_110_01",
ArchiveDays = 2000,
DeleteDays = 4000
};
_mockDocumentTypeUploaderApiService.Setup(x => x.UploadAccountDocument(It.IsAny<AccountDocumentRequest>(), It.IsAny<ProcessingRequest>(), It.IsAny<ProcessResult>()));
var result = await _osgDnaNoticesProcessingService.ProcessRequest(request);
Assert.IsTrue(result.Success);
Assert.IsNull(result.EntityIsUnknown);
_mockAccountOwnerDeterminingService.Verify(
x => x.DetermineAccountOwnerAttributeByMemberNumberOrUserId(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<DateTime>(), It.IsAny<OwnerOverrideInfo>()),
Times.Once
);
_mockFileOperationsApiService.Verify(
x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()),
Times.Once
);
_mockDocumentTypeUploaderApiService.Verify(
x => x.UploadAccountDocument(It.Is<AccountDocumentRequest>(request =>
request.AccountDocumentMetadata.Source == SourceTypes.OSG &&
request.AccountDocumentMetadata.DataSource == DataSourceTypes.DNA),
It.IsAny<ProcessingRequest>(), It.IsAny<ProcessResult>()),
Times.Once
);
}
[Test]
public async Task ProcessRequest_OsgDnaNotices_NumberNotNull_GetContentBtyesThrowException_Failure()
{
var OsgDnaNotices = new OsgDnaNoticesDocument
{
DocType = "MTG_NT_110_01",
AccountNumber = "1",
MemberNumberOrUserId = "2",
CreationDate = "20220823",
StartingPage = "1",
NumberOfPages = "3"
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(OsgDnaNotices),
IngestorRequest = new IngestorRequest
{
RootPath = "\\Tester\\"
},
DocumentFileName = "test.pdf"
};
var attribute = new AccountAttribute
{
PersonNumbers = new List<string> { "2", "3", "4" }
};
var accountAttribute = ErrorCaptureResult<AccountAttribute>.CreateSuccessPayload(attribute);
_mockAccountOwnerDeterminingService.Setup(x => x.DetermineAccountOwnerAttributeByMemberNumberOrUserId(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(), It.IsAny<DateTime>(),
It.IsAny<OwnerOverrideInfo>())).ReturnsAsync(accountAttribute);
_mockFileOperationsApiService.Setup(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()))
.ThrowsAsync(new Exception("Error"));
var result = await _osgDnaNoticesProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
Assert.IsFalse(result.EntityIsUnknown);
Assert.AreEqual(1, result.MessageStack.Count);
_mockAccountOwnerDeterminingService.Verify(
x => x.DetermineAccountOwnerAttributeByMemberNumberOrUserId(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<DateTime>(), It.IsAny<OwnerOverrideInfo>()),
Times.Once
);
_mockFileOperationsApiService.Verify(
x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()),
Times.Once
);
_mockDocumentTypeUploaderApiService.Verify(
x => x.UploadAccountDocument(It.IsAny<AccountDocumentRequest>(), It.IsAny<ProcessingRequest>(), It.IsAny<ProcessResult>()),
Times.Never
);
}
[Test]
public async Task ProcessRequest_OsgDnaNotices_NumberNotNull_UploadDocumentThrowException_Failure()
{
var OsgDnaNotices = new OsgDnaNoticesDocument
{
DocType = "MTG_NT_110_01",
AccountNumber = "1",
MemberNumberOrUserId = "2",
CreationDate = "20220823",
StartingPage = "1",
NumberOfPages = "3"
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(OsgDnaNotices),
IngestorRequest = new IngestorRequest
{
RootPath = "\\Tester\\"
},
DocumentFileName = "test.pdf"
};
var attribute = new AccountAttribute
{
PersonNumbers = new List<string> { "2", "3", "4" }
};
var accountAttribute = ErrorCaptureResult<AccountAttribute>.CreateSuccessPayload(attribute);
_mockAccountOwnerDeterminingService.Setup(x => x.DetermineAccountOwnerAttributeByMemberNumberOrUserId(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(), It.IsAny<DateTime>(),
It.IsAny<OwnerOverrideInfo>())).ReturnsAsync(accountAttribute);
byte[] content = new byte[1024];
_mockFileOperationsApiService.Setup(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()))
.ReturnsAsync(content);
_mockDocumentTypeUploaderApiService.Setup(x => x.UploadAccountDocument(It.IsAny<AccountDocumentRequest>(), It.IsAny<ProcessingRequest>(), It.IsAny<ProcessResult>()))
.ThrowsAsync(new Exception("Error"));
var result = await _osgDnaNoticesProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
Assert.IsFalse(result.EntityIsUnknown);
Assert.AreEqual(1, result.MessageStack.Count);
_mockAccountOwnerDeterminingService.Verify(
x => x.DetermineAccountOwnerAttributeByMemberNumberOrUserId(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<DateTime>(), It.IsAny<OwnerOverrideInfo>()),
Times.Once
);
_mockFileOperationsApiService.Verify(
x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()),
Times.Once
);
_mockDocumentTypeUploaderApiService.Verify(
x => x.UploadAccountDocument(It.IsAny<AccountDocumentRequest>(), It.IsAny<ProcessingRequest>(), It.IsAny<ProcessResult>()),
Times.Once
);
}
[Test]
public async Task ProcessRequest_OsgDnaNotices_GetValueFromName_ExceptionThrown_Failure()
{
var OsgDnaNotices = new OsgDnaNoticesDocument
{
DocType = Guid.NewGuid().ToString(),
AccountNumber = "1",
MemberNumberOrUserId = "2",
CreationDate = "20220823",
StartingPage = "1",
NumberOfPages = "3"
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(OsgDnaNotices),
IngestorRequest = new IngestorRequest
{
RootPath = "\\Tester\\"
},
DocumentFileName = "test.pdf"
};
var attribute = new AccountAttribute
{
PersonNumbers = new List<string> { "2", "3", "4" }
};
var accountAttribute = ErrorCaptureResult<AccountAttribute>.CreateSuccessPayload(attribute);
_mockAccountOwnerDeterminingService.Setup(x => x.DetermineAccountOwnerAttributeByMemberNumberOrUserId(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(), It.IsAny<DateTime>(),
It.IsAny<OwnerOverrideInfo>())).ReturnsAsync(accountAttribute);
byte[] content = new byte[1024];
_mockFileOperationsApiService.Setup(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()))
.ReturnsAsync(content);
var result = await _osgDnaNoticesProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
Assert.IsFalse(result.EntityIsUnknown);
Assert.AreEqual(1, result.MessageStack.Count);
_mockAccountOwnerDeterminingService.Verify(
x => x.DetermineAccountOwnerAttributeByMemberNumberOrUserId(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<DateTime>(), It.IsAny<OwnerOverrideInfo>()),
Times.Never
);
_mockFileOperationsApiService.Verify(
x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()),
Times.Never
);
_mockDocumentTypeUploaderApiService.Verify(
x => x.UploadAccountDocument(It.IsAny<AccountDocumentRequest>(), It.IsAny<ProcessingRequest>(), It.IsAny<ProcessResult>()),
Times.Never
);
}
}
@@ -0,0 +1,485 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using LCU.API.Internal.DocumentIngestor.Services.AttributeDeterminingServices;
using LCU.API.Internal.DocumentIngestor.Services.DocumentProcessorServices;
using LCU.API.Internal.DocumentIngestor.Services.MicroApiServices;
using LCU.Library.DocumentType.Enums;
using LCU.Library.DocumentType.Models.Requests.Attributes;
using LCU.Library.DocumentType.Models.Requests.PrimaryOwner;
using LCU.Library.Internal.DocumentIngestorModels.Entities;
using LCU.Library.Internal.DocumentIngestorModels.Enums;
using LCU.Library.Internal.DocumentIngestorModels.Models;
using LCU.Library.Internal.DocumentIngestorModels.Models.IndexFileDocuments;
using LCU.Library.Internal.LCUServiceFactory.Configurations;
using Moq;
using Newtonsoft.Json;
using NUnit.Framework;
namespace LCU.API.Internal.DocumentIngestorTests.Services.DocumentProcessorServices;
public class OsgHistoricalDocumentProcessingServiceTest
{
private OsgHistoricalDocumentProcessingService _osgHistoricalDocumentProcessingService;
private Mock<IFileOperationsApiService> _mockFileOperationsApiService;
private Mock<IDocumentTypeUploaderApiService> _mockDocumentTypeUploaderApiService;
private Mock<IPrimaryOwnerDeterminingService> _mockPrimaryOwnerDeterminingService;
[SetUp]
public void Setup()
{
_mockPrimaryOwnerDeterminingService = new Mock<IPrimaryOwnerDeterminingService>();
_mockFileOperationsApiService = new Mock<IFileOperationsApiService>();
_mockDocumentTypeUploaderApiService = new Mock<IDocumentTypeUploaderApiService>();
var serviceFactoryConfiguration = new ServicesFactoryConfiguration
{
ServiceFactoryRegistrations = new List<ServiceFactoryRegistration>
{
new()
{
ServiceInterfaceName = "IIndexParserService",
ServiceRegistrations = new List<ServiceRegistration>
{
new()
{
ServiceName = "IndexParserService",
ServiceId = "4"
},
new()
{
ServiceName = "IndexParserService",
ServiceId = "6"
}
}
}
}
};
_osgHistoricalDocumentProcessingService = new OsgHistoricalDocumentProcessingService(_mockPrimaryOwnerDeterminingService.Object,
_mockFileOperationsApiService.Object,
_mockDocumentTypeUploaderApiService.Object,
serviceFactoryConfiguration);
}
[Test]
public async Task ProcessRequest_ProcessingRequest_Null_ProcessResult_Failure()
{
ProcessingRequest request = null;
var result = await _osgHistoricalDocumentProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
_mockFileOperationsApiService.Verify(
x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()),
Times.Never
);
_mockDocumentTypeUploaderApiService.Verify(
x => x.UploadPrimaryOwnerDocument(It.IsAny<PrimaryOwnerDocumentRequest>(), It.IsAny<ProcessingRequest>(), It.IsAny<ProcessResult>()),
Times.Never
);
}
[Test]
public async Task ProcessRequest_OsgHistoricalDocument_Null_ProcessResult_Failure()
{
var request = new ProcessingRequest
{
DocumentValuePayload = null
};
var result = await _osgHistoricalDocumentProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
Assert.IsFalse(result.EntityIsUnknown);
_mockPrimaryOwnerDeterminingService.Verify(
x => x.DeterminePrimaryOwnerAttributeByMemberNumberOrUserId(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<OwnerOverrideInfo>()),
Times.Never
);
_mockFileOperationsApiService.Verify(
x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()),
Times.Never
);
_mockDocumentTypeUploaderApiService.Verify(
x => x.UploadPrimaryOwnerDocument(It.IsAny<PrimaryOwnerDocumentRequest>(), It.IsAny<ProcessingRequest>(), It.IsAny<ProcessResult>()),
Times.Never
);
}
[Test]
public async Task ProcessRequest_OsgHistoricalDocument_OneValidationFailures_Failure()
{
var OsgHistoricalDocument = new OsgHistoricalDocument
{
DocType = "MM_STMXT",
EntityName = "",
MemberNumberOrUserId = "2",
CreationDate = "20220823",
StartingPage = "1",
NumberOfPages = "3"
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(OsgHistoricalDocument)
};
var result = await _osgHistoricalDocumentProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
Assert.IsNull(result.EntityIsUnknown);
Assert.AreEqual(1, result.MessageStack.Count);
_mockPrimaryOwnerDeterminingService.Verify(
x => x.DeterminePrimaryOwnerAttributeByMemberNumberOrUserId(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<OwnerOverrideInfo>()),
Times.Never
);
_mockFileOperationsApiService.Verify(
x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()),
Times.Never
);
_mockDocumentTypeUploaderApiService.Verify(
x => x.UploadPrimaryOwnerDocument(It.IsAny<PrimaryOwnerDocumentRequest>(), It.IsAny<ProcessingRequest>(), It.IsAny<ProcessResult>()),
Times.Never
);
}
[Test]
public async Task ProcessRequest_OsgHistoricalDocument_ValidationFailures_Failure()
{
var OsgHistoricalDocument = new OsgHistoricalDocument
{
DocType = "MTG_NT_110_01",
EntityName = "Jan Jim",
MemberNumberOrUserId = "2",
CreationDate = "20220823",
StartingPage = "1",
NumberOfPages = "3"
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(OsgHistoricalDocument)
};
var result = await _osgHistoricalDocumentProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
Assert.IsFalse(result.EntityIsUnknown);
Assert.AreEqual(1, result.MessageStack.Count);
_mockPrimaryOwnerDeterminingService.Verify(
x => x.DeterminePrimaryOwnerAttributeByMemberNumberOrUserId(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<OwnerOverrideInfo>()),
Times.Never
);
_mockFileOperationsApiService.Verify(
x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()),
Times.Never
);
_mockDocumentTypeUploaderApiService.Verify(
x => x.UploadPrimaryOwnerDocument(It.IsAny<PrimaryOwnerDocumentRequest>(), It.IsAny<ProcessingRequest>(), It.IsAny<ProcessResult>()),
Times.Never
);
}
[Test]
public async Task ProcessRequest_OsgHistoricalDocument_DataMappingFailure_CreationDate_Failure()
{
var OsgHistoricalDocument = new OsgHistoricalDocument
{
DocType = "MTG_NT_110_01",
EntityName = "Jan Jim",
MemberNumberOrUserId = "2",
CreationDate = "2022T08T23",
StartingPage = "1",
NumberOfPages = "3"
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(OsgHistoricalDocument)
};
var result = await _osgHistoricalDocumentProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
Assert.IsNull(result.EntityIsUnknown);
Assert.AreEqual(1, result.MessageStack.Count);
Assert.AreEqual(ProcessStatusTypes.DataMappingFailure, result.ProcessStatusType);
_mockPrimaryOwnerDeterminingService.Verify(
x => x.DeterminePrimaryOwnerAttributeByMemberNumberOrUserId(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<OwnerOverrideInfo>()),
Times.Never
);
_mockFileOperationsApiService.Verify(
x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()),
Times.Never
);
_mockDocumentTypeUploaderApiService.Verify(
x => x.UploadPrimaryOwnerDocument(It.IsAny<PrimaryOwnerDocumentRequest>(), It.IsAny<ProcessingRequest>(), It.IsAny<ProcessResult>()),
Times.Never
);
}
[Test]
public async Task ProcessRequest_OsgHistoricalDocument_NumberIsNull_Failure()
{
var OsgHistoricalDocument = new OsgHistoricalDocument
{
DocType = "MM_STMXT",
EntityName = "John James",
MemberNumberOrUserId = "2",
CreationDate = "20220823",
StartingPage = "1",
NumberOfPages = "3"
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(OsgHistoricalDocument)
};
PrimaryOwnerAttribute attribute = null;
var accountAttribute = ErrorCaptureResult<PrimaryOwnerAttribute>.CreateSuccessPayload(attribute);
_mockPrimaryOwnerDeterminingService.Setup(x => x.DeterminePrimaryOwnerAttributeByMemberNumberOrUserId(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<DateTime>(),
It.IsAny<OwnerOverrideInfo>())).ReturnsAsync(accountAttribute);
var result = await _osgHistoricalDocumentProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
Assert.IsFalse(result.EntityIsUnknown);
Assert.AreEqual(1, result.MessageStack.Count);
_mockPrimaryOwnerDeterminingService.Verify(
x => x.DeterminePrimaryOwnerAttributeByMemberNumberOrUserId(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<OwnerOverrideInfo>()),
Times.Once
);
_mockFileOperationsApiService.Verify(
x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()),
Times.Never
);
_mockDocumentTypeUploaderApiService.Verify(
x => x.UploadPrimaryOwnerDocument(It.IsAny<PrimaryOwnerDocumentRequest>(), It.IsAny<ProcessingRequest>(), It.IsAny<ProcessResult>()),
Times.Never
);
}
[Test]
public async Task ProcessRequest_OsgHistoricalDocument_NumberNotNull_Upload_Success()
{
var OsgHistoricalDocument = new OsgHistoricalDocument
{
DocType = "MM_STMXT",
EntityName = "Jane Smith",
MemberNumberOrUserId = "2",
CreationDate = "20220823",
StartingPage = "1",
NumberOfPages = "3"
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(OsgHistoricalDocument),
IngestorRequest = new IngestorRequest
{
RootPath = "\\Tester\\"
},
DocumentFileName = "test.pdf"
};
var attribute = new PrimaryOwnerAttribute()
{
PersonNumber = "2"
};
var accountAttribute = ErrorCaptureResult<PrimaryOwnerAttribute>.CreateSuccessPayload(attribute);
_mockPrimaryOwnerDeterminingService.Setup(x => x.DeterminePrimaryOwnerAttributeByMemberNumberOrUserId(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<OwnerOverrideInfo>())).ReturnsAsync(accountAttribute);
byte[] content = new byte[1024];
_mockFileOperationsApiService.Setup(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()))
.ReturnsAsync(content);
_mockDocumentTypeUploaderApiService.Setup(x => x.UploadPrimaryOwnerDocument(It.IsAny<PrimaryOwnerDocumentRequest>(), It.IsAny<ProcessingRequest>(), It.IsAny<ProcessResult>()));
var result = await _osgHistoricalDocumentProcessingService.ProcessRequest(request);
Assert.IsTrue(result.Success);
Assert.IsNull(result.EntityIsUnknown);
_mockPrimaryOwnerDeterminingService.Verify(
x => x.DeterminePrimaryOwnerAttributeByMemberNumberOrUserId(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<OwnerOverrideInfo>()),
Times.Once
);
_mockFileOperationsApiService.Verify(
x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()),
Times.Once
);
_mockDocumentTypeUploaderApiService.Verify(
x => x.UploadPrimaryOwnerDocument(It.Is<PrimaryOwnerDocumentRequest>(request =>
request.PrimaryOwnerDocumentMetadata.Source == SourceTypes.OSG &&
request.PrimaryOwnerDocumentMetadata.DataSource == DataSourceTypes.DNA),
It.IsAny<ProcessingRequest>(), It.IsAny<ProcessResult>()),
Times.Once
);
}
[Test]
public async Task ProcessRequest_OsgHistoricalDocument_NumberNotNull_GetContentBtyesThrowException_Failure()
{
var OsgHistoricalDocument = new OsgHistoricalDocument
{
DocType = "MM_STMXT",
EntityName = "John Smith",
MemberNumberOrUserId = "2",
CreationDate = "20220823",
StartingPage = "1",
NumberOfPages = "3"
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(OsgHistoricalDocument),
IngestorRequest = new IngestorRequest
{
RootPath = "\\Tester\\"
},
DocumentFileName = "test.pdf"
};
var attribute = new PrimaryOwnerAttribute()
{
PersonNumber = "2"
};
var accountAttribute = ErrorCaptureResult<PrimaryOwnerAttribute>.CreateSuccessPayload(attribute);
_mockPrimaryOwnerDeterminingService.Setup(x => x.DeterminePrimaryOwnerAttributeByMemberNumberOrUserId(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<OwnerOverrideInfo>())).ReturnsAsync(accountAttribute);
_mockFileOperationsApiService.Setup(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()))
.ThrowsAsync(new Exception("Error"));
var result = await _osgHistoricalDocumentProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
Assert.IsFalse(result.EntityIsUnknown);
Assert.AreEqual(1, result.MessageStack.Count);
_mockPrimaryOwnerDeterminingService.Verify(
x => x.DeterminePrimaryOwnerAttributeByMemberNumberOrUserId(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<OwnerOverrideInfo>()),
Times.Once
);
_mockFileOperationsApiService.Verify(
x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()),
Times.Once
);
_mockDocumentTypeUploaderApiService.Verify(
x => x.UploadPrimaryOwnerDocument(It.IsAny<PrimaryOwnerDocumentRequest>(), It.IsAny<ProcessingRequest>(), It.IsAny<ProcessResult>()),
Times.Never
);
}
[Test]
public async Task ProcessRequest_OsgHistoricalDocument_NumberNotNull_UploadDocumentThrowException_Failure()
{
var OsgHistoricalDocument = new OsgHistoricalDocument
{
DocType = "MM_STMXT",
EntityName = "Jan Smith",
MemberNumberOrUserId = "2",
CreationDate = "20220823",
StartingPage = "1",
NumberOfPages = "3"
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(OsgHistoricalDocument),
IngestorRequest = new IngestorRequest
{
RootPath = "\\Tester\\"
},
DocumentFileName = "test.pdf"
};
var attribute = new PrimaryOwnerAttribute
{
PersonNumber = "2"
};
var accountAttribute = ErrorCaptureResult<PrimaryOwnerAttribute>.CreateSuccessPayload(attribute);
_mockPrimaryOwnerDeterminingService.Setup(x => x.DeterminePrimaryOwnerAttributeByMemberNumberOrUserId(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<OwnerOverrideInfo>())).ReturnsAsync(accountAttribute);
byte[] content = new byte[1024];
_mockFileOperationsApiService.Setup(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()))
.ReturnsAsync(content);
_mockDocumentTypeUploaderApiService.Setup(x => x.UploadPrimaryOwnerDocument(It.IsAny<PrimaryOwnerDocumentRequest>(), It.IsAny<ProcessingRequest>(), It.IsAny<ProcessResult>()))
.ThrowsAsync(new Exception("Error"));
var result = await _osgHistoricalDocumentProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
Assert.IsFalse(result.EntityIsUnknown);
Assert.AreEqual(1, result.MessageStack.Count);
_mockPrimaryOwnerDeterminingService.Verify(
x => x.DeterminePrimaryOwnerAttributeByMemberNumberOrUserId(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<OwnerOverrideInfo>()),
Times.Once
);
_mockFileOperationsApiService.Verify(
x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()),
Times.Once
);
_mockDocumentTypeUploaderApiService.Verify(
x => x.UploadPrimaryOwnerDocument(It.IsAny<PrimaryOwnerDocumentRequest>(), It.IsAny<ProcessingRequest>(), It.IsAny<ProcessResult>()),
Times.Once
);
}
[Test]
public async Task ProcessRequest_OsgHistoricalDocument_GetValueFromName_ExceptionThrown_Failure()
{
var OsgHistoricalDocument = new OsgHistoricalDocument
{
DocType = Guid.NewGuid().ToString(),
EntityName = "John Jim",
MemberNumberOrUserId = "2",
CreationDate = "20220823",
StartingPage = "1",
NumberOfPages = "3"
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(OsgHistoricalDocument),
IngestorRequest = new IngestorRequest
{
RootPath = "\\Tester\\"
},
DocumentFileName = "test.pdf"
};
var attribute = new PrimaryOwnerAttribute
{
PersonNumber = "2",
};
var accountAttribute = ErrorCaptureResult<PrimaryOwnerAttribute>.CreateSuccessPayload(attribute);
_mockPrimaryOwnerDeterminingService.Setup(x => x.DeterminePrimaryOwnerAttributeByMemberNumberOrUserId(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<OwnerOverrideInfo>())).ReturnsAsync(accountAttribute);
byte[] content = new byte[1024];
_mockFileOperationsApiService.Setup(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()))
.ReturnsAsync(content);
var result = await _osgHistoricalDocumentProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
Assert.IsFalse(result.EntityIsUnknown);
Assert.AreEqual(1, result.MessageStack.Count);
_mockPrimaryOwnerDeterminingService.Verify(
x => x.DeterminePrimaryOwnerAttributeByMemberNumberOrUserId(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<OwnerOverrideInfo>()),
Times.Never
);
_mockFileOperationsApiService.Verify(
x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()),
Times.Never
);
_mockDocumentTypeUploaderApiService.Verify(
x => x.UploadPrimaryOwnerDocument(It.IsAny<PrimaryOwnerDocumentRequest>(), It.IsAny<ProcessingRequest>(), It.IsAny<ProcessResult>()),
Times.Never
);
}
}
@@ -0,0 +1,478 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using NUnit.Framework;
using Moq;
using Newtonsoft.Json;
using LCU.API.Internal.DocumentIngestor.Services.AttributeDeterminingServices;
using LCU.API.Internal.DocumentIngestor.Services.DocumentProcessorServices;
using LCU.API.Internal.DocumentIngestor.Services.MicroApiServices;
using LCU.Library.DocumentType.Enums;
using LCU.Library.DocumentType.Models.Requests.Attributes;
using LCU.Library.DocumentType.Models.Requests.PrimaryOwner;
using LCU.Library.DocumentType.Models.Requests.Generic;
using LCU.Library.Internal.DocumentIngestorModels.Entities;
using LCU.Library.Internal.DocumentIngestorModels.Models;
using LCU.Library.Internal.DocumentIngestorModels.Models.IndexFileDocuments;
using LCU.Library.Internal.LCUServiceFactory.Configurations;
namespace LCU.API.Internal.DocumentIngestorTests.Services.DocumentProcessorServices;
public class OsgTaxStatementProcessingServiceTest
{
private OsgTaxStatementProcessingService _osgTaxStatementProcessingService;
private Mock<IPrimaryOwnerDeterminingService> _mockPrimaryOwnerDeterminingService;
private Mock<IFileOperationsApiService> _mockFileOperationsApiService;
private Mock<IDocumentTypeUploaderApiService> _mockDocumentTypeUploaderApiService;
[SetUp]
public void Setup()
{
_mockPrimaryOwnerDeterminingService = new Mock<IPrimaryOwnerDeterminingService>();
_mockFileOperationsApiService = new Mock<IFileOperationsApiService>();
_mockDocumentTypeUploaderApiService = new Mock<IDocumentTypeUploaderApiService>();
var serviceFactoryConfiguration = new ServicesFactoryConfiguration
{
ServiceFactoryRegistrations = new List<ServiceFactoryRegistration>
{
new()
{
ServiceInterfaceName = "IIndexParserService",
ServiceRegistrations = new List<ServiceRegistration>
{
new()
{
ServiceName = "IndexParserService",
ServiceId = "8"
},
new()
{
ServiceName = "IndexParserService",
ServiceId = "1"
}
}
}
}
};
_osgTaxStatementProcessingService = new OsgTaxStatementProcessingService(_mockPrimaryOwnerDeterminingService.Object,
_mockFileOperationsApiService.Object,
_mockDocumentTypeUploaderApiService.Object,
serviceFactoryConfiguration);
}
[Test]
public async Task ProcessRequest_ProcessingRequest_Null_ProcessResult_Failure()
{
ProcessingRequest request = null;
var result = await _osgTaxStatementProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
_mockPrimaryOwnerDeterminingService.Verify(x => x.DeterminePrimaryOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(), It.IsAny<string>(),
It.IsAny<OwnerOverrideInfo>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()),
Times.Never);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadPrimaryOwnerDocument(It.IsAny<PrimaryOwnerDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()), Times.Never);
_mockDocumentTypeUploaderApiService.Verify(
x => x.UploadGenericDocument(It.IsAny<GenericDocumentRequest>(), It.IsAny<ProcessingRequest>(), It.IsAny<ProcessResult>()), Times.Never);
}
[Test]
public async Task ProcessRequest_OsgTaxStatementDocument_Null_ProcessResult_Failure()
{
var request = new ProcessingRequest
{
DocumentValuePayload = null
};
var result = await _osgTaxStatementProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
Assert.IsFalse(result.EntityIsUnknown);
_mockPrimaryOwnerDeterminingService.Verify(x => x.DeterminePrimaryOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(), It.IsAny<string>(),
It.IsAny<OwnerOverrideInfo>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()),
Times.Never);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadPrimaryOwnerDocument(It.IsAny<PrimaryOwnerDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()), Times.Never);
_mockDocumentTypeUploaderApiService.Verify(
x => x.UploadGenericDocument(It.IsAny<GenericDocumentRequest>(), It.IsAny<ProcessingRequest>(), It.IsAny<ProcessResult>()), Times.Never);
}
[Test]
public async Task ProcessRequest_OsgTaxStatementDocument_OneValidationFailures_Failure()
{
var osgTaxStatementDocument = new OsgTaxStatement
{
AccountNumber = "0",
NoticeName = "test",
RecipientName = "test",
PdfName = "test",
SSN = "1"
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(osgTaxStatementDocument)
};
var result = await _osgTaxStatementProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
Assert.IsNull(result.EntityIsUnknown);
Assert.AreEqual(1, result.MessageStack.Count);
_mockPrimaryOwnerDeterminingService.Verify(x => x.DeterminePrimaryOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(), It.IsAny<string>(),
It.IsAny<OwnerOverrideInfo>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()),
Times.Never);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadPrimaryOwnerDocument(It.IsAny<PrimaryOwnerDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()), Times.Never);
_mockDocumentTypeUploaderApiService.Verify(
x => x.UploadGenericDocument(It.IsAny<GenericDocumentRequest>(), It.IsAny<ProcessingRequest>(), It.IsAny<ProcessResult>()), Times.Never);
}
[Test]
public async Task ProcessRequest_OsgTaxStatementDocument_FiveValidationFailures_Failure()
{
var osgTaxStatementDocument = new OsgTaxStatement
{
AccountNumber = "0",
NoticeName = "",
RecipientName = "",
PdfName = "",
SSN = ""
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(osgTaxStatementDocument)
};
var result = await _osgTaxStatementProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
Assert.IsNull(result.EntityIsUnknown);
Assert.AreEqual(5, result.MessageStack.Count);
_mockPrimaryOwnerDeterminingService.Verify(x => x.DeterminePrimaryOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(), It.IsAny<string>(),
It.IsAny<OwnerOverrideInfo>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()),
Times.Never);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadPrimaryOwnerDocument(It.IsAny<PrimaryOwnerDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()), Times.Never);
_mockDocumentTypeUploaderApiService.Verify(
x => x.UploadGenericDocument(It.IsAny<GenericDocumentRequest>(), It.IsAny<ProcessingRequest>(), It.IsAny<ProcessResult>()), Times.Never);
}
[Test]
public async Task ProcessRequest_OsgTaxStatementDocument_NumberIsNull_Failure()
{
var osgTaxStatementDocument = new OsgTaxStatement
{
AccountNumber = "1",
NoticeName = "1099-INT",
RecipientName = "test",
PdfName = "test",
SSN = "11",
CreationDate = DateTime.Now.Date.ToString("MMddyyyy")
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(osgTaxStatementDocument)
};
var primaryOwnerAttribute =
ErrorCaptureResult<PrimaryOwnerAttribute>.CreateErrorPayload("Error from unit test", null);
_mockPrimaryOwnerDeterminingService.Setup(x => x.DeterminePrimaryOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<OwnerOverrideInfo>())).ReturnsAsync(primaryOwnerAttribute);
var result = await _osgTaxStatementProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
Assert.IsNull(result.EntityIsUnknown);
Assert.AreEqual(1, result.MessageStack.Count);
_mockPrimaryOwnerDeterminingService.Verify(x => x.DeterminePrimaryOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(), It.IsAny<string>(),
It.IsAny<OwnerOverrideInfo>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()),
Times.Never);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadPrimaryOwnerDocument(It.IsAny<PrimaryOwnerDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()), Times.Never);
_mockDocumentTypeUploaderApiService.Verify(
x => x.UploadGenericDocument(It.IsAny<GenericDocumentRequest>(), It.IsAny<ProcessingRequest>(), It.IsAny<ProcessResult>()), Times.Never);
}
[Test]
public async Task ProcessRequest_OsgTaxStatementDocument_NumberNotNull_Upload_Success()
{
var osgTaxStatementDocument = new OsgTaxStatement
{
AccountNumber = "1",
NoticeName = "1099-INT",
RecipientName = "test",
PdfName = "test",
SSN = "11",
CreationDate = DateTime.Now.Date.ToString("MMddyyyy")
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(osgTaxStatementDocument),
IngestorRequest = new IngestorRequest
{
RootPath = "\\Tester\\"
},
DocumentFileName = "test.pdf"
};
var attribute = new PrimaryOwnerAttribute
{
PersonNumber = "2"
};
var primaryOwnerAttribute = ErrorCaptureResult<PrimaryOwnerAttribute>.CreateSuccessPayload(attribute);
_mockPrimaryOwnerDeterminingService.Setup(x => x.DeterminePrimaryOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<OwnerOverrideInfo>())).ReturnsAsync(primaryOwnerAttribute);
var content = new byte[1024];
_mockFileOperationsApiService.Setup(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()))
.ReturnsAsync(content);
_mockDocumentTypeUploaderApiService.Setup(x => x.UploadPrimaryOwnerDocument(It.IsAny<PrimaryOwnerDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()));
var result = await _osgTaxStatementProcessingService.ProcessRequest(request);
Assert.IsTrue(result.Success);
_mockPrimaryOwnerDeterminingService.Verify(x => x.DeterminePrimaryOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<OwnerOverrideInfo>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
_mockDocumentTypeUploaderApiService.Verify(x =>
x.UploadPrimaryOwnerDocument(It.Is<PrimaryOwnerDocumentRequest>(request =>
request.PrimaryOwnerDocumentMetadata.Source == SourceTypes.OSG &&
request.PrimaryOwnerDocumentMetadata.DataSource == DataSourceTypes.DNA),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()), Times.Once);
}
[Test]
public async Task ProcessRequest_OsgTaxStatementDocument_GenericDocument_NumberNotNull_Upload_Success()
{
var osgTaxStatementDocument = new OsgTaxStatement
{
AccountNumber = "1",
NoticeName = "1099-MISC",
RecipientName = "test",
PdfName = "test",
SSN = "11",
CreationDate = DateTime.Now.Date.ToString("MMddyyyy")
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(osgTaxStatementDocument),
IngestorRequest = new IngestorRequest
{
RootPath = "\\Tester\\"
},
DocumentFileName = "test.pdf"
};
var attribute = new GenericDocumentAttribute
{
EntityName = "test"
};
var genericAttribute = ErrorCaptureResult<GenericDocumentAttribute>.CreateSuccessPayload(attribute);
var content = new byte[1024];
_mockFileOperationsApiService.Setup(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()))
.ReturnsAsync(content);
var documentTypeArchiveDeleteInfo = new DocumentTypeArchiveDeleteInfo
{
DocumentTypeName = "OneThousandNinetyNineMiscelanneous",
ArchiveDays = 2000,
DeleteDays = 4000
};
_mockDocumentTypeUploaderApiService.Setup(x =>
x.UploadGenericDocument(It.IsAny<GenericDocumentRequest>(), It.IsAny<ProcessingRequest>(), It.IsAny<ProcessResult>()));
var result = await _osgTaxStatementProcessingService.ProcessRequest(request);
Assert.IsTrue(result.Success);
Assert.IsNull(result.EntityIsUnknown);
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()),
Times.Once);
_mockDocumentTypeUploaderApiService.Verify(
x => x.UploadGenericDocument(It.Is<GenericDocumentRequest>(request =>
request.GenericDocumentMetadata.Source == SourceTypes.OSG &&
request.GenericDocumentMetadata.DataSource == DataSourceTypes.DNA),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()), Times.Once);
}
[Test]
public async Task ProcessRequest_OsgTaxStatementDocument_NumberNotNull_GetContentBytesThrowException_Failure()
{
var osgTaxStatementDocument = new OsgTaxStatement
{
AccountNumber = "1",
NoticeName = "1099-INT",
RecipientName = "test",
PdfName = "test",
SSN = "11",
CreationDate = DateTime.Now.Date.ToString("MMddyyyy")
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(osgTaxStatementDocument),
IngestorRequest = new IngestorRequest
{
RootPath = "\\Tester\\"
},
DocumentFileName = "test.pdf"
};
var attribute = new PrimaryOwnerAttribute
{
PersonNumber = "2"
};
var primaryOwnerAttribute = ErrorCaptureResult<PrimaryOwnerAttribute>.CreateSuccessPayload(attribute);
_mockPrimaryOwnerDeterminingService.Setup(x => x.DeterminePrimaryOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<OwnerOverrideInfo>())).ReturnsAsync(primaryOwnerAttribute);
_mockFileOperationsApiService.Setup(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()))
.ThrowsAsync(new Exception("Error"));
var result = await _osgTaxStatementProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
Assert.IsFalse(result.EntityIsUnknown);
Assert.AreEqual(1, result.MessageStack.Count);
_mockPrimaryOwnerDeterminingService.Verify(x => x.DeterminePrimaryOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<OwnerOverrideInfo>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()),
Times.Once);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadPrimaryOwnerDocument(It.IsAny<PrimaryOwnerDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()), Times.Never);
_mockDocumentTypeUploaderApiService.Verify(
x => x.UploadGenericDocument(It.IsAny<GenericDocumentRequest>(), It.IsAny<ProcessingRequest>(), It.IsAny<ProcessResult>()), Times.Never);
}
[Test]
public async Task ProcessRequest_OsgTaxStatementDocument_NumberNotNull_UploadDocumentThrowException_Failure()
{
var osgTaxStatementDocument = new OsgTaxStatement
{
AccountNumber = "1",
NoticeName = "1099-INT",
RecipientName = "test",
PdfName = "test",
SSN = "11",
CreationDate = DateTime.Now.Date.ToString("MMddyyyy")
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(osgTaxStatementDocument),
IngestorRequest = new IngestorRequest
{
RootPath = "\\Tester\\"
},
DocumentFileName = "test.pdf"
};
var attribute = new PrimaryOwnerAttribute
{
PersonNumber = "2"
};
var primaryOwnerAttribute = ErrorCaptureResult<PrimaryOwnerAttribute>.CreateSuccessPayload(attribute);
_mockPrimaryOwnerDeterminingService.Setup(x => x.DeterminePrimaryOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<OwnerOverrideInfo>())).ReturnsAsync(primaryOwnerAttribute);
var content = new byte[1024];
_mockFileOperationsApiService.Setup(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()))
.ReturnsAsync(content);
_mockDocumentTypeUploaderApiService.Setup(x => x.UploadPrimaryOwnerDocument(It.IsAny<PrimaryOwnerDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()))
.ThrowsAsync(new Exception("Error"));
var result = await _osgTaxStatementProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
Assert.IsFalse(result.EntityIsUnknown);
Assert.AreEqual(1, result.MessageStack.Count);
_mockPrimaryOwnerDeterminingService.Verify(x => x.DeterminePrimaryOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<OwnerOverrideInfo>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadPrimaryOwnerDocument(It.IsAny<PrimaryOwnerDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()), Times.Once);
}
[Test]
public async Task ProcessRequest_OsgTaxStatementDocument_GetCreatedDateFromDocumentType_Success()
{
var createdDate = DateTime.Now.Date;
var osgTaxStatementDocument = new OsgTaxStatement
{
AccountNumber = "1",
NoticeName = "1099-INT",
RecipientName = "test",
CreationDate = DateTime.Now.Date.ToString("MMddyyyy"),
PdfName = "test",
SSN = "11"
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(osgTaxStatementDocument),
IngestorRequest = new IngestorRequest
{
RootPath = "\\Tester\\"
},
DocumentFileName = "test.pdf"
};
var attribute = new PrimaryOwnerAttribute
{
PersonNumber = "2"
};
var primaryOwnerAttribute = ErrorCaptureResult<PrimaryOwnerAttribute>.CreateSuccessPayload(attribute);
_mockPrimaryOwnerDeterminingService.Setup(x => x.DeterminePrimaryOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(), It.IsAny<string>(),
It.IsAny<OwnerOverrideInfo>())).ReturnsAsync(primaryOwnerAttribute);
var content = new byte[1024];
_mockFileOperationsApiService.Setup(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()))
.ReturnsAsync(content);
var builtRequest = await _osgTaxStatementProcessingService.BuildUploadRequest(request, osgTaxStatementDocument, attribute, DateTime.Now.Date);
Assert.AreEqual(createdDate, builtRequest.PrimaryOwnerDocumentMetadata.CreatedDate);
_mockDocumentTypeUploaderApiService.Setup(x => x.UploadPrimaryOwnerDocument(It.IsAny<PrimaryOwnerDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()));
var result = await _osgTaxStatementProcessingService.ProcessRequest(request);
Assert.IsTrue(result.Success);
Assert.IsNull(result.EntityIsUnknown);
_mockPrimaryOwnerDeterminingService.Verify(x => x.DeterminePrimaryOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(), It.IsAny<string>(),
It.IsAny<OwnerOverrideInfo>()), Times.Once);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadPrimaryOwnerDocument(It.IsAny<PrimaryOwnerDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()), Times.Once);
}
}
@@ -0,0 +1,242 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using LCU.API.Internal.DocumentIngestor.Services.DocumentProcessorServices;
using LCU.API.Internal.DocumentIngestor.Services.MicroApiServices;
using LCU.Library.DocumentType.Enums;
using LCU.Library.DocumentType.Models.Requests.Generic;
using LCU.Library.Internal.DocumentIngestorModels.Models;
using LCU.Library.Internal.DocumentIngestorModels.Models.IndexFileDocuments;
using LCU.Library.Internal.LCUServiceFactory.Configurations;
using Moq;
using Newtonsoft.Json;
using NUnit.Framework;
namespace LCU.API.Internal.DocumentIngestorTests.Services.DocumentProcessorServices;
public class XdiActionNoticeDocumentProcessingServiceTest
{
private XdiActionNoticesProcessingService _xdiActionNoticesProcessingService;
private Mock<IFileOperationsApiService> _mockFileOperationsApiService;
private Mock<IDocumentTypeUploaderApiService> _mockDocumentTypeUploaderApiService;
[SetUp]
public void Setup()
{
_mockFileOperationsApiService = new Mock<IFileOperationsApiService>();
_mockDocumentTypeUploaderApiService = new Mock<IDocumentTypeUploaderApiService>();
var serviceFactoryConfiguration = new ServicesFactoryConfiguration
{
ServiceFactoryRegistrations = new List<ServiceFactoryRegistration>
{
new()
{
ServiceInterfaceName = "IIndexParserService",
ServiceRegistrations = new List<ServiceRegistration>
{
new()
{
ServiceName = "IndexParserService",
ServiceId = "4"
},
new()
{
ServiceName = "IndexParserService",
ServiceId = "5"
}
}
}
}
};;
_xdiActionNoticesProcessingService = new XdiActionNoticesProcessingService(_mockFileOperationsApiService.Object,
_mockDocumentTypeUploaderApiService.Object,
serviceFactoryConfiguration);
}
[Test]
public async Task ProcessRequest_XdiDnaActionNotice_Upload_Success()
{
var xdiActionNoticesDocument = new XdiActionNoticesDocument
{
CreationDate = "01/23/2025",
DocumentName = "Test.pdf",
DocumentType = "ACTion_Consumer Loan Tattle Tale Notice",
PageCount = 2,
EntityName = "Bill B Billson"
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(xdiActionNoticesDocument),
IngestorRequest = new IngestorRequest
{
RootPath = "\\Tester\\"
},
DocumentFileName = "test.pdf"
};
var content = new byte[1024];
_mockFileOperationsApiService.Setup(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()))
.ReturnsAsync(content);
_mockDocumentTypeUploaderApiService.Setup(x => x.UploadGenericDocument(It.IsAny<GenericDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()));
var result = await _xdiActionNoticesProcessingService.ProcessRequest(request);
Assert.IsTrue(result.Success);
Assert.IsNull(result.EntityIsUnknown);
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()),
Times.Once);
_mockDocumentTypeUploaderApiService.Verify(
x => x.UploadGenericDocument(It.Is<GenericDocumentRequest>(request =>
request.GenericDocumentMetadata.Source == SourceTypes.XDI &&
request.GenericDocumentMetadata.DataSource == DataSourceTypes.ACTION), request, result), Times.Once);
}
[Test]
public async Task ProcessRequest_XdiActionNoticeDocument_RequestNull_ThrowsException_Failure()
{
var result = await _xdiActionNoticesProcessingService.ProcessRequest(null);
Assert.IsFalse(result.Success);
Assert.IsFalse(result.EntityIsUnknown);
Assert.AreEqual(1, result.MessageStack.Count);
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()),
Times.Never);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadGenericDocument(It.IsAny<GenericDocumentRequest>(), It.IsAny<ProcessingRequest>(), It.IsAny<ProcessResult>()),
Times.Never);
}
[Test]
public async Task ProcessRequest_XdiActionNoticeDocument_PayloadNull_ThrowsException_Failure()
{
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(null),
IngestorRequest = new IngestorRequest
{
RootPath = "\\Tester\\"
},
DocumentFileName = "test.pdf"
};
var result = await _xdiActionNoticesProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
Assert.IsFalse(result.EntityIsUnknown);
Assert.AreEqual(1, result.MessageStack.Count);
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()),
Times.Never);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadGenericDocument(It.IsAny<GenericDocumentRequest>(), It.IsAny<ProcessingRequest>(), It.IsAny<ProcessResult>()),
Times.Never);
}
[Test]
public async Task ProcessRequest_XdiActionNoticeDocument_NumberNotNull_GetContentBytesThrowException_Failure()
{
var xdiActionNoticesDocument = new XdiActionNoticesDocument
{
CreationDate = "01/23/2025",
DocumentName = "Test.pdf",
DocumentType = "ACTion_Consumer Loan Tattle Tale Notice",
PageCount = 2,
EntityName = "Bill B Billson"
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(xdiActionNoticesDocument),
IngestorRequest = new IngestorRequest
{
RootPath = "\\Tester\\"
},
DocumentFileName = "test.pdf"
};
_mockFileOperationsApiService.Setup(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()))
.ThrowsAsync(new Exception("Error"));
var result = await _xdiActionNoticesProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
Assert.IsFalse(result.EntityIsUnknown);
Assert.AreEqual(1, result.MessageStack.Count);
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()),
Times.Once);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadGenericDocument(It.IsAny<GenericDocumentRequest>(), It.IsAny<ProcessingRequest>(), It.IsAny<ProcessResult>()),
Times.Never);
}
[Test]
public async Task ProcessRequest_XdiActionNoticeDocument_NumberNotNull_UploadDocumentThrowException_Failure()
{
var xdiActionNoticesDocument = new XdiActionNoticesDocument
{
CreationDate = "01/23/2025",
DocumentName = "Test.pdf",
DocumentType = "ACTion_Consumer Loan Tattle Tale Notice",
PageCount = 2,
EntityName = "Bill B Billson"
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(xdiActionNoticesDocument),
IngestorRequest = new IngestorRequest
{
RootPath = "\\Tester\\"
},
DocumentFileName = "test.pdf"
};
var content = new byte[1024];
_mockFileOperationsApiService.Setup(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()))
.ReturnsAsync(content);
_mockDocumentTypeUploaderApiService.Setup(x => x.UploadGenericDocument(It.IsAny<GenericDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()))
.ThrowsAsync(new Exception("Error"));
var result = await _xdiActionNoticesProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
Assert.IsFalse(result.EntityIsUnknown);
Assert.AreEqual(1, result.MessageStack.Count);
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()),
Times.Once);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadGenericDocument(It.IsAny<GenericDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()), Times.Once);
}
[Test]
public async Task ProcessRequest_XdiActionNoticeDocument_GetValueFromName_ExceptionThrown_Failure()
{
var xdiActionNoticesDocument = new XdiActionNoticesDocument
{
CreationDate = "01/23/2025",
DocumentName = "Test.pdf",
DocumentType = "ACTion_Consumer Loan Tattle Tale Notice Incorrect",
PageCount = 2,
EntityName = "Bill B Billson"
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(xdiActionNoticesDocument),
IngestorRequest = new IngestorRequest
{
RootPath = "\\Tester\\"
},
DocumentFileName = "test.pdf"
};
var result = await _xdiActionNoticesProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
Assert.IsFalse(result.EntityIsUnknown);
Assert.AreEqual(1, result.MessageStack.Count);
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()),
Times.Never);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadGenericDocument(It.IsAny<GenericDocumentRequest>(), request, result),
Times.Never);
}
}
@@ -0,0 +1,343 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using NUnit.Framework;
using Moq;
using Newtonsoft.Json;
using LCU.Library.DocumentType.Enums;
using LCU.Library.DocumentType.Models.Requests.Account;
using LCU.Library.DocumentType.Models.Requests.Attributes;
using LCU.Library.Internal.DocumentIngestorModels.Entities;
using LCU.Library.Internal.DocumentIngestorModels.Models;
using LCU.Library.Internal.DocumentIngestorModels.Models.IndexFileDocuments;
using LCU.API.Internal.DocumentIngestor.Services.AttributeDeterminingServices;
using LCU.API.Internal.DocumentIngestor.Services.DocumentProcessorServices;
using LCU.API.Internal.DocumentIngestor.Services.MicroApiServices;
using LCU.Library.Internal.DocumentIngestorModels.Enums;
using LCU.Library.Internal.LCUServiceFactory.Configurations;
namespace LCU.API.Internal.DocumentIngestorTests.Services.DocumentProcessorServices;
public class XdiDnaNoticeDocumentProcessingServiceTest
{
private XdiDnaNoticeDocumentProcessingService _xdiDnaNoticeDocumentProcessingService;
private Mock<IAccountOwnerDeterminingService> _mockAccountOwnerDeterminingService;
private Mock<IFileOperationsApiService> _mockFileOperationsApiService;
private Mock<IDocumentTypeUploaderApiService> _mockDocumentTypeUploaderApiService;
[SetUp]
public void Setup()
{
_mockAccountOwnerDeterminingService = new Mock<IAccountOwnerDeterminingService>();
_mockFileOperationsApiService = new Mock<IFileOperationsApiService>();
_mockDocumentTypeUploaderApiService = new Mock<IDocumentTypeUploaderApiService>();
var serviceFactoryConfiguration = new ServicesFactoryConfiguration
{
ServiceFactoryRegistrations = new List<ServiceFactoryRegistration>
{
new()
{
ServiceInterfaceName = "IIndexParserService",
ServiceRegistrations = new List<ServiceRegistration>
{
new()
{
ServiceName = "IndexParserService",
ServiceId = "4"
},
new()
{
ServiceName = "IndexParserService",
ServiceId = "2"
}
}
}
}
};
_xdiDnaNoticeDocumentProcessingService = new XdiDnaNoticeDocumentProcessingService(_mockAccountOwnerDeterminingService.Object,
_mockFileOperationsApiService.Object,
_mockDocumentTypeUploaderApiService.Object,
serviceFactoryConfiguration);
}
[Test]
public async Task ProcessRequest_XdiDnaNoticeDocumentAccountOwner_NumberNotNull_Upload_Success()
{
var xdiDnaDocument = new XdiDnaNoticesDocument
{
AccountNumber = "1",
CreationDate = "01/23/2025",
PDF = "Test.pdf",
DocumentType = "DNA_22 Day Past Due Letter",
PageCount = 2,
EntityName = "Bill B Billson"
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(xdiDnaDocument),
IngestorRequest = new IngestorRequest
{
RootPath = "\\Tester\\"
},
DocumentFileName = "test.pdf"
};
var attribute = new AccountAttribute
{
PersonNumbers = new List<string> { "2", "3", "4" }
};
var accountAttribute = ErrorCaptureResult<AccountAttribute>.CreateSuccessPayload(attribute);
_mockAccountOwnerDeterminingService.Setup(x => x.DetermineAccountOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<DateTime>(),
It.IsAny<OwnerOverrideInfo>())).ReturnsAsync(accountAttribute);
var content = new byte[1024];
_mockFileOperationsApiService.Setup(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(content);
_mockDocumentTypeUploaderApiService.Setup(x => x.UploadAccountDocument(It.IsAny<AccountDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()));
var result = await _xdiDnaNoticeDocumentProcessingService.ProcessRequest(request);
Assert.IsTrue(result.Success);
Assert.IsNull(result.EntityIsUnknown);
_mockAccountOwnerDeterminingService.Verify(x => x.DetermineAccountOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<DateTime>(),
It.IsAny<OwnerOverrideInfo>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadAccountDocument(It.Is<AccountDocumentRequest>(request =>
request.AccountDocumentMetadata.Source == SourceTypes.XDI &&
request.AccountDocumentMetadata.DataSource == DataSourceTypes.DNA),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()), Times.Once);
}
[Test]
public async Task ProcessRequest_XdiDnaNoticeDocument_AccountOwnerNotDetermined_Failure()
{
var xdiDnaNoticeDocument = new XdiDnaNoticesDocument
{
AccountNumber = "1",
CreationDate = "01/23/2025",
PDF = "Test.pdf",
DocumentType = "DNA_32 Day Past Due Letter",
EntityName = "Bill B Billson"
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(xdiDnaNoticeDocument),
IngestorRequest = new IngestorRequest
{
RootPath = "\\Tester\\"
},
DocumentFileName = "test.pdf"
};
var attribute = new AccountAttribute
{
PersonNumbers = new List<string> { "2", "3", "4" }
};
var accountAttribute = ErrorCaptureResult<AccountAttribute>.CreateErrorPayload("Error from test", attribute);
_mockAccountOwnerDeterminingService.Setup(x => x.DetermineAccountOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<DateTime>(),
It.IsAny<OwnerOverrideInfo>())).ReturnsAsync(accountAttribute);
var result = await _xdiDnaNoticeDocumentProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
Assert.IsNull(result.EntityIsUnknown);
Assert.AreEqual(1, result.MessageStack.Count);
Assert.AreEqual(ProcessStatusTypes.DataMappingFailure, result.ProcessStatusType);
_mockAccountOwnerDeterminingService.Verify(x => x.DetermineAccountOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<DateTime>(),
It.IsAny<OwnerOverrideInfo>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadAccountDocument(It.IsAny<AccountDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()), Times.Never);
}
[Test]
public async Task ProcessRequest_XdiDnaNoticeDocument_NumberNotNull_GetContentBytesThrowException_Failure()
{
var xdiDnaNoticeDocument = new XdiDnaNoticesDocument
{
AccountNumber = "1",
CreationDate = "01/23/2025",
PDF = "Test.pdf",
DocumentType = "DNA_32 Day Past Due Letter",
EntityName = "Bill B Billson"
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(xdiDnaNoticeDocument),
IngestorRequest = new IngestorRequest
{
RootPath = "\\Tester\\"
},
DocumentFileName = "test.pdf"
};
var attribute = new AccountAttribute
{
PersonNumbers = new List<string> { "2", "3", "4" }
};
var accountAttribute = ErrorCaptureResult<AccountAttribute>.CreateSuccessPayload(attribute);
_mockAccountOwnerDeterminingService.Setup(x => x.DetermineAccountOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<DateTime>(),
It.IsAny<OwnerOverrideInfo>())).ReturnsAsync(accountAttribute);
_mockFileOperationsApiService.Setup(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()))
.ThrowsAsync(new Exception("Error"));
var result = await _xdiDnaNoticeDocumentProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
Assert.IsFalse(result.EntityIsUnknown);
Assert.AreEqual(1, result.MessageStack.Count);
_mockAccountOwnerDeterminingService.Verify(x => x.DetermineAccountOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<DateTime>(),
It.IsAny<OwnerOverrideInfo>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadAccountDocument(It.IsAny<AccountDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()), Times.Never);
}
[Test]
public async Task ProcessRequest_XdiDnaNoticeDocument_NumberNotNull_UploadDocumentThrowException_Failure()
{
var xdiDnaNoticeDocument = new XdiDnaNoticesDocument
{
AccountNumber = "1",
CreationDate = "01/23/2025",
PDF = "Test.pdf",
DocumentType = "ThirtyTwoDayPastDueLetter",
EntityName = "Bill B Billson"
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(xdiDnaNoticeDocument),
IngestorRequest = new IngestorRequest
{
RootPath = "\\Tester\\"
},
DocumentFileName = "test.pdf"
};
var attribute = new AccountAttribute
{
PersonNumbers = new List<string> { "2", "3", "4" }
};
var accountOwnerAttribute = ErrorCaptureResult<AccountAttribute>.CreateSuccessPayload(attribute);
_mockAccountOwnerDeterminingService.Setup(x => x.DetermineAccountOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(), It.IsAny<DateTime>(),
It.IsAny<OwnerOverrideInfo>())).ReturnsAsync(accountOwnerAttribute);
var content = new byte[1024];
_mockFileOperationsApiService.Setup(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()))
.ReturnsAsync(content);
_mockDocumentTypeUploaderApiService.Setup(x => x.UploadAccountDocument(It.IsAny<AccountDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()))
.ThrowsAsync(new Exception("Error"));
var result = await _xdiDnaNoticeDocumentProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
Assert.IsFalse(result.EntityIsUnknown);
Assert.AreEqual(1, result.MessageStack.Count);
_mockAccountOwnerDeterminingService.Verify(x => x.DetermineAccountOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<DateTime>(),
It.IsAny<OwnerOverrideInfo>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()),
Times.Once);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadAccountDocument(It.IsAny<AccountDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()), Times.Once);
}
[Test]
public async Task ProcessRequest_XdiDnaNoticeDocument_GetValueFromName_ExceptionThrown_Failure()
{
var xdiDnaDocument = new XdiDnaNoticesDocument
{
AccountNumber = "1",
CreationDate = "01/23/2005",
PDF = "Test.pdf",
DocumentType = "DNA_32 Day Past Due Letter Incorrect",
EntityName = "Test Entity"
};
var request = new ProcessingRequest
{
DocumentValuePayload = JsonConvert.SerializeObject(xdiDnaDocument),
IngestorRequest = new IngestorRequest
{
RootPath = "\\Tester\\"
},
DocumentFileName = "test.pdf"
};
var result = await _xdiDnaNoticeDocumentProcessingService.ProcessRequest(request);
Assert.IsFalse(result.Success);
Assert.IsFalse(result.EntityIsUnknown);
Assert.AreEqual(1, result.MessageStack.Count);
_mockAccountOwnerDeterminingService.Verify(x => x.DetermineAccountOwnerAttribute(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<DateTime>(),
It.IsAny<OwnerOverrideInfo>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadAccountDocument(It.IsAny<AccountDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()), Times.Never);
}
[Test]
public async Task ProcessRequest_ValidDate_ParsesDateCorrectly()
{
var date = DateTime.Now;
DateTime? parsedCreationTime = null;
var request = new ProcessingRequest
{
DocumentValuePayload = @"{
""CreationDate"":""" + $"{date:MM/dd/yyyy}" + @""",
""AccountNumber"":""10"",
""LoanNumber"":""1"",
""EntityName"":""1"",
""PageCount"":1,
""DocumentType"":""" + typeof(AccountDocumentTypes).GetFields().First(f => f.GetCustomAttribute<DisplayAttribute>() is not null).GetCustomAttribute<DisplayAttribute>().Name + @""",
""PDF"":""1""
}"
};
_mockAccountOwnerDeterminingService
.Setup(aods => aods.DetermineAccountOwnerAttribute(It.IsAny<string>(), It.IsAny<string>(),
It.IsAny<DateTime>(), It.IsAny<OwnerOverrideInfo>()))
.Callback<string, string, DateTime, OwnerOverrideInfo>((_, _, creationTime, _) => parsedCreationTime = creationTime);
await _xdiDnaNoticeDocumentProcessingService.ProcessRequest(request);
Assert.IsNotNull(parsedCreationTime);
Assert.AreEqual(date.Month, parsedCreationTime.Value.Month);
Assert.AreEqual(date.Day, parsedCreationTime.Value.Day);
Assert.AreEqual(date.Year, parsedCreationTime.Value.Year);
}
}
@@ -0,0 +1,537 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Serilog;
using Serilog.Events;
using Moq;
using NUnit.Framework;
using LCU.API.Internal.DocumentIngestor.Configurations;
using LCU.API.Internal.DocumentIngestor.Services;
using LCU.API.Internal.DocumentIngestor.Services.QueueServices;
using LCU.Library.Internal.DocumentIngestorModels.Entities;
using LCU.Library.Internal.DocumentIngestorModels.Enums;
using LCU.Library.Internal.DocumentIngestorModels.Models;
using LCU.Library.Internal.Exceptions;
using Newtonsoft.Json;
namespace LCU.API.Internal.DocumentIngestorTests.Services;
public class DocumentReprocessingServiceTest
{
private DocumentReprocessingService _documentReprocessingService;
private Mock<IIngestorRunInfoService> _mockIngestorRunInfoService;
private Mock<IDocumentProcessingInfoService> _mockDocumentProcessingInfoService;
private Mock<IQueueDocumentProcessingService> _mockQueueDocumentProcessing;
private Mock<IOwnerOverrideInfoService> _mockOwnerOverrideInfoService;
private ApiConfiguration _apiConfiguration;
private readonly Mock<ILogger> _logger = new();
private readonly ILogger _originalLogger = Log.Logger;
[SetUp]
public void Setup()
{
Log.Logger = _logger.Object;
_mockIngestorRunInfoService = new Mock<IIngestorRunInfoService>();
_mockDocumentProcessingInfoService = new Mock<IDocumentProcessingInfoService>();
_mockQueueDocumentProcessing = new Mock<IQueueDocumentProcessingService>();
_mockOwnerOverrideInfoService = new Mock<IOwnerOverrideInfoService>();
_apiConfiguration = new ApiConfiguration();
_documentReprocessingService = new DocumentReprocessingService(_mockIngestorRunInfoService.Object,
_mockDocumentProcessingInfoService.Object,
_mockOwnerOverrideInfoService.Object,
_mockQueueDocumentProcessing.Object,
_apiConfiguration);
}
[TearDown]
public void TearDown()
{
Log.Logger = _originalLogger;
}
[Test]
public async Task QueueReprocessDocumentByDocumentProcessingInfoId_Success()
{
var documentProcessingInfoId = 1;
var userName = "Test Tester";
var ingestorRunInfoId = new Guid();
var documentProcessingInfo = new DocumentProcessingInfo()
{
DocumentProcessingInfoId = documentProcessingInfoId,
DocumentFileName = "TestDoc",
DocumentValuePayload = "{jsonblah: hello}",
IngestorRunInfoId = ingestorRunInfoId,
CreatedDate = new DateTime(2022, 01, 01),
StatusType = ProcessStatusTypes.ArchiveFailure
};
var ingestorRunInfo = new IngestorRunInfo()
{
IndexFileName = "Test.txt",
IndexFilePath = "\\\\Test\\Test\\",
IngestorType = IngestorTypes.FosLoanStatement
};
_mockDocumentProcessingInfoService.Setup(x => x.GetByIdAsync(documentProcessingInfoId)).ReturnsAsync(documentProcessingInfo);
_mockIngestorRunInfoService.Setup(x => x.GetByIdAsync(ingestorRunInfoId)).ReturnsAsync(ingestorRunInfo);
await _documentReprocessingService.QueueReprocessDocumentByDocumentProcessingInfoId(documentProcessingInfoId, userName);
_mockDocumentProcessingInfoService.Verify(x => x.GetByIdAsync(documentProcessingInfoId), Times.Once);
_mockIngestorRunInfoService.Verify(x => x.GetByIdAsync(It.IsAny<Guid>()), Times.Once);
_mockDocumentProcessingInfoService.Verify(x => x.UpdateStatusAndAddLog(It.IsAny<int>(),
It.IsAny<ProcessStatusTypes>(),
It.IsAny<string>(),
It.IsAny<string>(),
null), Times.Once);
_mockQueueDocumentProcessing.Verify(x => x.QueueDocumentProcessingRequest(It.IsAny<ProcessingRequest>()), Times.Once);
}
[Test]
public void QueueReprocessDocumentByDocumentProcessingInfoId_Failure_Exception()
{
var id = 1;
var userName = "Test Tester";
var ingestorRequest = new IngestorRequest()
{
RootPath = "\\Test\\Test"
};
var request = new ProcessingRequest()
{
DocumentFileName = "000001Test.pdf",
IngestorRequest = ingestorRequest
};
_mockQueueDocumentProcessing.Setup(x => x.QueueDocumentProcessingRequest(request)).ThrowsAsync(new Exception("Test Error"));
Assert.ThrowsAsync<ArgumentNullException>(async () => await _documentReprocessingService
.QueueReprocessDocumentByDocumentProcessingInfoId(id, userName));
_mockDocumentProcessingInfoService.Verify(x => x.GetByIdAsync(id), Times.Once);
_mockQueueDocumentProcessing.Verify(x => x.QueueDocumentProcessingRequest(It.IsAny<ProcessingRequest>()), Times.Never);
}
[Test]
public void QueueReprocessDocumentByDocumentProcessingInfoId_Failure_ArgumentNullException()
{
var id = 1;
var userName = "Test Tester";
_mockDocumentProcessingInfoService.Setup(x => x.GetByIdAsync(id)).ThrowsAsync(new ArgumentNullException("Test Error"));
Assert.ThrowsAsync<ArgumentNullException>(async () => await _documentReprocessingService
.QueueReprocessDocumentByDocumentProcessingInfoId(id, userName));
_mockDocumentProcessingInfoService.Verify(x => x.GetByIdAsync(id), Times.Once);
_mockIngestorRunInfoService.Verify(x => x.GetByIdAsync(It.IsAny<Guid>()), Times.Never);
_mockDocumentProcessingInfoService.Verify(x => x.UpdateStatusAndAddLog(It.IsAny<int>(),
It.IsAny<ProcessStatusTypes>(),
It.IsAny<string>(),
It.IsAny<string>(),
false), Times.Never);
_mockQueueDocumentProcessing.Verify(x => x.QueueDocumentProcessingRequest(It.IsAny<ProcessingRequest>()), Times.Never);
}
private OwnerOverrideInfo OverrideFactory()
{
var info = new OwnerOverrideInfo
{
UserName = Guid.NewGuid().ToString(),
EntityId = Guid.NewGuid().ToString(),
EntityType = Random<EntityTypes>(),
DocumentProcessingInfoId = DateTime.Now.Millisecond
};
_mockOwnerOverrideInfoService
.Setup(s => s.GetByDocumentProcessingInfoIdAsync(info.DocumentProcessingInfoId))
.ReturnsAsync(new[] { info });
return info;
}
[Test]
public async Task QueueOverrideDocumentByDocumentProcessingInfoId_AllCases_SavesOwnerOverrides()
{
var ownerOverride = OverrideFactory();
try
{
await _documentReprocessingService.QueueOverrideDocumentByDocumentProcessingInfoId(ownerOverride);
}
catch { }
_mockOwnerOverrideInfoService.Verify(s => s.SaveAsync(ownerOverride), Times.Once);
}
[Test]
public void QueueOverrideDocumentByDocumentProcessingInfoId_OverrideSaveThrowsException_LogsAndThrowsServiceException()
{
var ownerOverride = OverrideFactory();
var saveException = new Exception();
var loggedErrors = new List<string>();
_mockOwnerOverrideInfoService
.Setup(s => s.SaveAsync(ownerOverride))
.ThrowsAsync(saveException);
_logger
.Setup(l => l.Write(LogEventLevel.Error, saveException, It.IsAny<string>()))
.Callback<LogEventLevel, Exception, string>((_, _, log) => loggedErrors.Add(log));
var thrownException = Assert.ThrowsAsync<ServiceException>(() => _documentReprocessingService.QueueOverrideDocumentByDocumentProcessingInfoId(ownerOverride));
StringAssert.Contains(ownerOverride.DocumentProcessingInfoId.ToString(), thrownException!.Message);
Assert.AreEqual(1, loggedErrors.Count);
var errorLog = loggedErrors.Single();
StringAssert.Contains(ownerOverride.DocumentProcessingInfoId.ToString(), errorLog);
StringAssert.Contains(ownerOverride.EntityId, errorLog);
StringAssert.Contains(ownerOverride.EntityType.ToString(), errorLog);
}
[Test]
public async Task QueueOverrideDocumentByDocumentProcessingInfoId_OverrideSaveThrowsException_DoesNotRequeue()
{
var ownerOverride = OverrideFactory();
_mockOwnerOverrideInfoService
.Setup(s => s.SaveAsync(ownerOverride))
.ThrowsAsync(new Exception());
try
{
await _documentReprocessingService.QueueOverrideDocumentByDocumentProcessingInfoId(ownerOverride);
}
catch { }
_mockQueueDocumentProcessing.Verify(p => p.QueueDocumentProcessingRequest(It.IsAny<ProcessingRequest>()), Times.Never);
}
[Test]
public void QueueOverrideDocumentByDocumentProcessingInfoId_FetchedDocumentInfoNull_LogsAndThrowsArgumentNull()
{
var ownerOverride = SetupSave(OverrideFactory());
var loggedErrors = new List<(Exception exception, string log)>();
_logger
.Setup(l => l.Write(LogEventLevel.Error, It.IsAny<Exception>(), It.IsAny<string>()))
.Callback<LogEventLevel, Exception, string>((_, exception, log) => loggedErrors.Add((exception, log)));
_mockDocumentProcessingInfoService
.Setup(s => s.GetByIdAsync(ownerOverride.DocumentProcessingInfoId))
.ReturnsAsync((DocumentProcessingInfo)null);
var thrownException = Assert.ThrowsAsync<ArgumentNullException>(() => _documentReprocessingService.QueueOverrideDocumentByDocumentProcessingInfoId(ownerOverride));
Assert.AreEqual(1, loggedErrors.Count);
var (loggedException, log) = loggedErrors.Single();
Assert.AreSame(loggedException, thrownException);
StringAssert.Contains(ownerOverride.DocumentProcessingInfoId.ToString(), log);
}
[Test]
public async Task QueueOverrideDocumentByDocumentProcessingInfoId_FetchedDocumentInfoNull_DoesNotRequeue()
{
var ownerOverride = SetupSave(OverrideFactory());
_mockDocumentProcessingInfoService
.Setup(s => s.GetByIdAsync(ownerOverride.DocumentProcessingInfoId))
.ReturnsAsync((DocumentProcessingInfo)null);
try
{
await _documentReprocessingService.QueueOverrideDocumentByDocumentProcessingInfoId(ownerOverride);
}
catch { }
_mockQueueDocumentProcessing.Verify(p => p.QueueDocumentProcessingRequest(It.IsAny<ProcessingRequest>()), Times.Never);
}
[Test]
public void QueueOverrideDocumentByDocumentProcessingInfoId_FetchedIngestorRunNull_LogsAndThrowsArgumentNull()
{
var ownerOverride = SetupSave(OverrideFactory());
var info = SetupGetDocumentProcessingInfo(ownerOverride);
var loggedErrors = new List<(Exception exception, string log)>();
_logger
.Setup(l => l.Write(LogEventLevel.Error, It.IsAny<Exception>(), It.IsAny<string>()))
.Callback<LogEventLevel, Exception, string>((_, exception, log) => loggedErrors.Add((exception, log)));
_mockIngestorRunInfoService
.Setup(s => s.GetByIdAsync(info.IngestorRunInfoId))
.ReturnsAsync((IngestorRunInfo)null);
var thrownException = Assert.ThrowsAsync<ArgumentNullException>(() => _documentReprocessingService.QueueOverrideDocumentByDocumentProcessingInfoId(ownerOverride));
Assert.AreEqual(1, loggedErrors.Count);
var (loggedException, log) = loggedErrors.Single();
Assert.AreSame(loggedException, thrownException);
StringAssert.Contains(ownerOverride.DocumentProcessingInfoId.ToString(), log);
}
[Test]
public async Task QueueOverrideDocumentByDocumentProcessingInfoId_FetchedIngestorRunNull_DoesNotRequeue()
{
var ownerOverride = SetupSave(OverrideFactory());
var info = SetupGetDocumentProcessingInfo(ownerOverride);
_mockIngestorRunInfoService
.Setup(s => s.GetByIdAsync(info.IngestorRunInfoId))
.ReturnsAsync((IngestorRunInfo)null);
try
{
await _documentReprocessingService.QueueOverrideDocumentByDocumentProcessingInfoId(ownerOverride);
}
catch { }
_mockQueueDocumentProcessing.Verify(p => p.QueueDocumentProcessingRequest(It.IsAny<ProcessingRequest>()), Times.Never);
}
[Test]
public async Task QueueOverrideDocumentByDocumentProcessingInfoId_SaveSucceeds_UpdatesStatusAndLogs()
{
var ownerOverride = SetupSave(OverrideFactory());
var documentInfo = SetupGetDocumentProcessingInfo(ownerOverride);
SetupGetIngestorRunInfo(documentInfo);
await _documentReprocessingService.QueueOverrideDocumentByDocumentProcessingInfoId(ownerOverride);
_mockDocumentProcessingInfoService.Verify
(
s => s.UpdateStatusAndAddLog
(
ownerOverride.DocumentProcessingInfoId,
ProcessStatusTypes.Reprocessing,
It.Is<string>(s => s.Contains(ownerOverride.UserName) && s.Contains(JsonConvert.SerializeObject(ownerOverride))),
ownerOverride.UserName,
It.IsAny<bool?>()
),
Times.Once
);
}
[Test]
public void QueueOverrideDocumentByDocumentProcessingInfoId_UpdateStatusThrowsException_LogsAndThrowsServiceException()
{
var ownerOverride = SetupSave(OverrideFactory());
var documentInfo = SetupGetDocumentProcessingInfo(ownerOverride);
SetupGetIngestorRunInfo(documentInfo);
var exceptionToThrow = new Exception();
var loggedErrors = new List<string>();
_logger
.Setup(l => l.Write(LogEventLevel.Error, It.IsAny<Exception>(), It.IsAny<string>()))
.Callback<LogEventLevel, Exception, string>((_, _, log) => loggedErrors.Add(log));
_mockDocumentProcessingInfoService
.Setup
(
s => s.UpdateStatusAndAddLog
(
ownerOverride.DocumentProcessingInfoId,
ProcessStatusTypes.Reprocessing,
It.Is<string>(s =>
s.Contains(ownerOverride.UserName) && s.Contains(JsonConvert.SerializeObject(ownerOverride))),
ownerOverride.UserName,
null
)
)
.ThrowsAsync(exceptionToThrow);
var thrownException = Assert.ThrowsAsync<ServiceException>(() => _documentReprocessingService.QueueOverrideDocumentByDocumentProcessingInfoId(ownerOverride));
StringAssert.Contains(ownerOverride.DocumentProcessingInfoId.ToString(), thrownException!.Message);
Assert.AreEqual(1, loggedErrors.Count);
var errorLog = loggedErrors.Single();
StringAssert.Contains(ownerOverride.DocumentProcessingInfoId.ToString(), errorLog);
StringAssert.Contains(ownerOverride.EntityId, errorLog);
StringAssert.Contains(ownerOverride.EntityType.ToString(), errorLog);
}
[Test]
public async Task QueueOverrideDocumentByDocumentProcessingInfoId_UpdateStatusThrowsException_DoesNotRequeue()
{
var ownerOverride = SetupSave(OverrideFactory());
var documentInfo = SetupGetDocumentProcessingInfo(ownerOverride);
SetupGetIngestorRunInfo(documentInfo);
_mockDocumentProcessingInfoService
.Setup
(
s => s.UpdateStatusAndAddLog
(
ownerOverride.DocumentProcessingInfoId,
ProcessStatusTypes.Reprocessing,
It.Is<string>(s =>
s.Contains(ownerOverride.UserName) && s.Contains(JsonConvert.SerializeObject(ownerOverride))),
ownerOverride.UserName,
null
)
)
.ThrowsAsync(new Exception());
try
{
await _documentReprocessingService.QueueOverrideDocumentByDocumentProcessingInfoId(ownerOverride);
}
catch { }
_mockQueueDocumentProcessing.Verify(p => p.QueueDocumentProcessingRequest(It.IsAny<ProcessingRequest>()), Times.Never);
}
[Test]
public async Task QueueOverrideDocumentByDocumentProcessingInfoId_SaveSucceeds_RequeuesProcessing()
{
var ownerOverride = SetupSave(OverrideFactory());
var documentInfo = SetupGetDocumentProcessingInfo(ownerOverride);
var ingestorInfo = SetupGetIngestorRunInfo(documentInfo);
var requeuedRequests = new List<ProcessingRequest>();
_mockQueueDocumentProcessing
.Setup(p => p.QueueDocumentProcessingRequest(It.IsAny<ProcessingRequest>()))
.Callback<ProcessingRequest>(requeuedRequests.Add);
await _documentReprocessingService.QueueOverrideDocumentByDocumentProcessingInfoId(ownerOverride);
Assert.AreEqual(1, requeuedRequests.Count);
var requeued = requeuedRequests.Single();
Assert.AreEqual(requeued.DocumentProcessingInfoId, ownerOverride.DocumentProcessingInfoId);
Assert.AreEqual(requeued.IngestorRunInfoId, documentInfo.IngestorRunInfoId);
Assert.AreEqual(requeued.DocumentFileName, documentInfo.DocumentFileName);
Assert.AreEqual(requeued.DocumentValuePayload, documentInfo.DocumentValuePayload);
Assert.AreEqual(requeued.IngestorRequest.IngestorType, ingestorInfo.IngestorType);
Assert.AreEqual(requeued.IngestorRequest.RootPath, ingestorInfo.IndexFilePath + "\\");
Assert.AreEqual(requeued.IngestorRequest.IndexFileName, ingestorInfo.IndexFileName);
Assert.AreSame(requeued.OwnerOverrideInfo, ownerOverride);
}
[Test]
public void QueueOverrideDocumentByDocumentProcessingInfoId_RequeueThrowsException_LogsAndThrowsServiceException()
{
var ownerOverride = SetupSave(OverrideFactory());
var documentInfo = SetupGetDocumentProcessingInfo(ownerOverride);
SetupGetIngestorRunInfo(documentInfo);
var exceptionToThrow = new Exception();
var loggedErrors = new List<string>();
_logger
.Setup(l => l.Write(LogEventLevel.Error, It.IsAny<Exception>(), It.IsAny<string>()))
.Callback<LogEventLevel, Exception, string>((_, _, log) => loggedErrors.Add(log));
_mockQueueDocumentProcessing
.Setup(p => p.QueueDocumentProcessingRequest(It.IsAny<ProcessingRequest>()))
.Throws(exceptionToThrow);
var thrownException = Assert.ThrowsAsync<ServiceException>(() => _documentReprocessingService.QueueOverrideDocumentByDocumentProcessingInfoId(ownerOverride));
StringAssert.Contains(ownerOverride.DocumentProcessingInfoId.ToString(), thrownException!.Message);
Assert.AreEqual(1, loggedErrors.Count);
var errorLog = loggedErrors.Single();
StringAssert.Contains(ownerOverride.DocumentProcessingInfoId.ToString(), errorLog);
StringAssert.Contains(ownerOverride.EntityId, errorLog);
StringAssert.Contains(ownerOverride.EntityType.ToString(), errorLog);
}
[Test]
public void QueueReprocessAllCriticalFailures_InfoServiceThrowsArgumentNull_ThrowsServiceException()
{
var processStatus = ProcessStatusTypes.CriticalFailure;
_mockDocumentProcessingInfoService
.Setup(s => s.GetByProcessStatusTypeAsync(processStatus, null))
.ThrowsAsync(new ArgumentNullException());
Assert.ThrowsAsync<ServiceException>(() => _documentReprocessingService.QueueReprocessAllCriticalFailures(Guid.NewGuid().ToString()));
}
[Test]
public async Task QueueReprocessAllCriticalFailures_InfoServiceThrows_ThrowsServiceException()
{
var processStatus = ProcessStatusTypes.CriticalFailure;
_mockDocumentProcessingInfoService
.Setup(s => s.GetByProcessStatusTypeAsync(processStatus, null))
.ThrowsAsync(new Exception());
Assert.ThrowsAsync<ServiceException>(() => _documentReprocessingService.QueueReprocessAllCriticalFailures(Guid.NewGuid().ToString()));
}
[Test]
public async Task QueueReprocessAllCriticalFailures_InfoServiceReturnsMoreThanLimit_RequeuesUpToLimit()
{
var processStatus = ProcessStatusTypes.CriticalFailure;
var username = Guid.NewGuid().ToString();
var criticalFailures = Enumerable
.Repeat(() => SetupGetDocumentProcessingInfo(OverrideFactory()), 16)
.Select(f => f())
.ToArray();
foreach (var info in criticalFailures) SetupGetIngestorRunInfo(info);
_apiConfiguration.CriticalFailureReprocessLimit = criticalFailures.Length / 2;
_mockDocumentProcessingInfoService
.Setup(s => s.GetByProcessStatusTypeAsync(processStatus, null))
.ReturnsAsync(criticalFailures);
await _documentReprocessingService.QueueReprocessAllCriticalFailures(username);
_mockDocumentProcessingInfoService
.Verify
(
s => s.UpdateStatusAndAddLog
(
It.Is<int>(id => criticalFailures.Any(f => f.DocumentProcessingInfoId == id)),
ProcessStatusTypes.Reprocessing,
It.IsAny<string>(),
username,
null
),
Times.Exactly(_apiConfiguration.CriticalFailureReprocessLimit)
);
_mockQueueDocumentProcessing
.Verify
(
dp => dp.QueueDocumentProcessingRequest
(
It.Is<ProcessingRequest>(r => criticalFailures.Any(f => f.DocumentProcessingInfoId == r.DocumentProcessingInfoId))
),
Times.Exactly(_apiConfiguration.CriticalFailureReprocessLimit)
);
}
private OwnerOverrideInfo SetupSave(OwnerOverrideInfo ownerOverride)
{
_mockOwnerOverrideInfoService
.Setup(s => s.SaveAsync(ownerOverride))
.ReturnsAsync(ownerOverride);
return ownerOverride;
}
private DocumentProcessingInfo SetupGetDocumentProcessingInfo(OwnerOverrideInfo ownerOverride)
{
var info = new DocumentProcessingInfo
{
IngestorRunInfoId = Guid.NewGuid(),
CreatedDate = DateTime.Now,
DocumentValuePayload = Guid.NewGuid().ToString(),
StatusType = Random<ProcessStatusTypes>(),
DocumentFileName = Guid.NewGuid().ToString(),
ProcessCount = DateTime.Now.Millisecond,
DocumentType = Guid.NewGuid().ToString(),
DocumentBusinessName = Guid.NewGuid().ToString(),
DocumentProcessingInfoId = ownerOverride.DocumentProcessingInfoId
};
_mockDocumentProcessingInfoService
.Setup(s => s.GetByIdAsync(ownerOverride.DocumentProcessingInfoId))
.ReturnsAsync(info);
return info;
}
private IngestorRunInfo SetupGetIngestorRunInfo(DocumentProcessingInfo ownerOverride)
{
var info = new IngestorRunInfo
{
IngestorRunInfoId = Guid.NewGuid(),
StartTimeStamp = DateTime.Now,
IngestorType = Random<IngestorTypes>(),
IndexFileName = Guid.NewGuid().ToString(),
IndexFilePath = Guid.NewGuid().ToString(),
IndexTotal = DateTime.Now.Millisecond
};
_mockIngestorRunInfoService
.Setup(s => s.GetByIdAsync(ownerOverride.IngestorRunInfoId))
.ReturnsAsync(info);
return info;
}
private static T Random<T>() where T : struct, Enum => Enum.GetValues<T>()[DateTime.Now.Millisecond % (Enum.GetValues<T>().Length - 1)];
}
@@ -0,0 +1,289 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Linq;
using Moq;
using NUnit.Framework;
using LCU.Library.Internal.DocumentIngestorModels.Entities;
using LCU.Library.Internal.Exceptions;
using LCU.API.Internal.DocumentIngestor.Services;
using LCU.API.Internal.DocumentIngestorLib.Repositories;
using LCU.Library.DocumentType.Enums;
namespace LCU.API.Internal.DocumentIngestorTests.Services;
public class DocumentTypeArchiveDeleteInfoServiceTest
{
private DocumentTypeArchiveDeleteInfoService _documentTypeArchiveDeleteInfoService;
private Mock<IUnitOfWork> _unitOfWork;
private Mock<IDocumentTypeArchiveDeleteInfoRepository> _mockDocumentTypeArchiveDeleteInfoRepository;
[SetUp]
public void Setup()
{
_unitOfWork = new Mock<IUnitOfWork>();
_mockDocumentTypeArchiveDeleteInfoRepository = new Mock<IDocumentTypeArchiveDeleteInfoRepository>();
_documentTypeArchiveDeleteInfoService = new DocumentTypeArchiveDeleteInfoService(_unitOfWork.Object, _mockDocumentTypeArchiveDeleteInfoRepository.Object);
}
[Test]
public async Task GetAsync_DocumentTypeArchiveDeleteInfos_Returned()
{
var processingLogs = new List<DocumentTypeArchiveDeleteInfo>()
{
new DocumentTypeArchiveDeleteInfo()
{
DocumentTypeName = "Test"
}
};
_mockDocumentTypeArchiveDeleteInfoRepository.Setup(x => x.FindAsync()).ReturnsAsync(processingLogs);
var result = await _documentTypeArchiveDeleteInfoService.GetAsync();
Assert.IsNotNull(result);
Assert.AreEqual(1, result.Count());
_mockDocumentTypeArchiveDeleteInfoRepository.Verify(x => x.FindAsync(), Times.Once);
}
[Test]
public void GetAsync_Exception()
{
_mockDocumentTypeArchiveDeleteInfoRepository.Setup(x => x.FindAsync()).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _documentTypeArchiveDeleteInfoService.GetAsync());
_mockDocumentTypeArchiveDeleteInfoRepository.Verify(x => x.FindAsync(), Times.Once);
}
[Test]
public async Task GetByDocumentTypeNameAsync_ByEnum_DocumentTypeArchiveDeleteInfo_Returned()
{
var documentType = PrimaryOwnerDocumentTypes.OneThousandNinetyNineInt;
var documentTypeName = "OneThousandNinetyNineInt";
var archiveDays = 200;
var deleteDays = 3000;
var documentTypeArchiveDeleteInfo = new DocumentTypeArchiveDeleteInfo()
{
DocumentTypeName = documentTypeName,
ArchiveDays = archiveDays,
DeleteDays = deleteDays
};
_mockDocumentTypeArchiveDeleteInfoRepository.Setup(x => x.FindByDocumentTypeNameAsync(documentTypeName)).ReturnsAsync(documentTypeArchiveDeleteInfo);
var result = await _documentTypeArchiveDeleteInfoService.GetByDocumentTypeNameAsync(documentType);
Assert.IsNotNull(result);
Assert.AreEqual(documentTypeName, result.DocumentTypeName);
Assert.AreEqual(archiveDays, result.ArchiveDays);
Assert.AreEqual(deleteDays, result.DeleteDays);
_mockDocumentTypeArchiveDeleteInfoRepository.Verify(x => x.FindByDocumentTypeNameAsync(documentTypeName), Times.Once);
}
[Test]
public void GetByDocumentTypeNameAsync_ByEnum_Exception()
{
var documentType = PrimaryOwnerDocumentTypes.OneThousandNinetyNineInt;
var documentTypeName = "OneThousandNinetyNineInt";
_mockDocumentTypeArchiveDeleteInfoRepository.Setup(x => x.FindByDocumentTypeNameAsync(documentTypeName)).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _documentTypeArchiveDeleteInfoService.GetByDocumentTypeNameAsync(documentType));
_mockDocumentTypeArchiveDeleteInfoRepository.Verify(x => x.FindByDocumentTypeNameAsync(documentTypeName), Times.Once);
}
[Test]
public async Task GetByDocumentTypeNameAsync_DocumentTypeArchiveDeleteInfo_Returned()
{
var documentType = "Test";
var archiveDays = 200;
var deleteDays = 3000;
var documentTypeArchiveDeleteInfo = new DocumentTypeArchiveDeleteInfo()
{
DocumentTypeName = documentType,
ArchiveDays = archiveDays,
DeleteDays = deleteDays
};
_mockDocumentTypeArchiveDeleteInfoRepository.Setup(x => x.FindByDocumentTypeNameAsync(documentType)).ReturnsAsync(documentTypeArchiveDeleteInfo);
var result = await _documentTypeArchiveDeleteInfoService.GetByDocumentTypeNameAsync(documentType);
Assert.IsNotNull(result);
Assert.AreEqual(documentType, result.DocumentTypeName);
Assert.AreEqual(archiveDays, result.ArchiveDays);
Assert.AreEqual(deleteDays, result.DeleteDays);
_mockDocumentTypeArchiveDeleteInfoRepository.Verify(x => x.FindByDocumentTypeNameAsync(documentType), Times.Once);
}
[Test]
public void GetByDocumentTypeNameAsync_Exception()
{
var documentType = "Test";
_mockDocumentTypeArchiveDeleteInfoRepository.Setup(x => x.FindByDocumentTypeNameAsync(documentType)).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _documentTypeArchiveDeleteInfoService.GetByDocumentTypeNameAsync(documentType));
_mockDocumentTypeArchiveDeleteInfoRepository.Verify(x => x.FindByDocumentTypeNameAsync(documentType), Times.Once);
}
[Test]
public async Task SaveAsync_ProcessingLog_Returned()
{
var documentType = "Test";
var archiveDays = 200;
var deleteDays = 3000;
var documentTypeArchiveDeleteInfo = new DocumentTypeArchiveDeleteInfo()
{
DocumentTypeName = documentType,
ArchiveDays = archiveDays,
DeleteDays = deleteDays
};
_mockDocumentTypeArchiveDeleteInfoRepository.Setup(x => x.AddAsync(documentTypeArchiveDeleteInfo)).ReturnsAsync(documentTypeArchiveDeleteInfo);
var result = await _documentTypeArchiveDeleteInfoService.SaveAsync(documentTypeArchiveDeleteInfo);
Assert.IsNotNull(result);
Assert.AreEqual(documentType, result.DocumentTypeName);
Assert.AreEqual(archiveDays, result.ArchiveDays);
Assert.AreEqual(deleteDays, result.DeleteDays);
_mockDocumentTypeArchiveDeleteInfoRepository.Verify(x => x.AddAsync(It.IsAny<DocumentTypeArchiveDeleteInfo>()), Times.Once);
}
[Test]
public void SaveAsync_Exception()
{
var documentType = "Test";
var archiveDays = 200;
var deleteDays = 3000;
var documentTypeArchiveDeleteInfo = new DocumentTypeArchiveDeleteInfo()
{
DocumentTypeName = documentType,
ArchiveDays = archiveDays,
DeleteDays = deleteDays
};
_mockDocumentTypeArchiveDeleteInfoRepository.Setup(x => x.AddAsync(documentTypeArchiveDeleteInfo)).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _documentTypeArchiveDeleteInfoService.SaveAsync(documentTypeArchiveDeleteInfo));
_mockDocumentTypeArchiveDeleteInfoRepository.Verify(x => x.AddAsync(It.IsAny<DocumentTypeArchiveDeleteInfo>()), Times.Once);
}
[Test]
public async Task Update_DocumentTypeArchiveDeleteInfo_Returned()
{
var documentType = "Test";
var archiveDays = 200;
var deleteDays = 3000;
var existingDocumentTypeArchiveDeleteInfo = new DocumentTypeArchiveDeleteInfo()
{
DocumentTypeName = documentType,
ArchiveDays = archiveDays,
DeleteDays = deleteDays
};
var documentTypeArchiveDeleteInfo = new DocumentTypeArchiveDeleteInfo()
{
DocumentTypeName = documentType,
ArchiveDays = archiveDays,
DeleteDays = 4000
};
_mockDocumentTypeArchiveDeleteInfoRepository.Setup(x => x.FindByDocumentTypeNameAsync(documentType)).ReturnsAsync(existingDocumentTypeArchiveDeleteInfo);
_mockDocumentTypeArchiveDeleteInfoRepository.Setup(x => x.Update(documentTypeArchiveDeleteInfo));
var result = await _documentTypeArchiveDeleteInfoService.Update(documentTypeArchiveDeleteInfo);
Assert.IsNotNull(result);
Assert.AreEqual(documentType, result.DocumentTypeName);
Assert.AreEqual(archiveDays, result.ArchiveDays);
Assert.AreEqual(4000, result.DeleteDays);
_mockDocumentTypeArchiveDeleteInfoRepository.Verify(x => x.FindByDocumentTypeNameAsync(It.IsAny<string>()), Times.Once);
_mockDocumentTypeArchiveDeleteInfoRepository.Verify(x => x.Update(It.IsAny<DocumentTypeArchiveDeleteInfo>()), Times.Once);
}
[Test]
public void Update_FindByIdAsync_ThrowsException()
{
var documentType = "Test";
var archiveDays = 200;
var documentTypeArchiveDeleteInfo = new DocumentTypeArchiveDeleteInfo()
{
DocumentTypeName = documentType,
ArchiveDays = archiveDays,
DeleteDays = 4000
};
_mockDocumentTypeArchiveDeleteInfoRepository.Setup(x => x.FindByDocumentTypeNameAsync(documentType)).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _documentTypeArchiveDeleteInfoService.Update(documentTypeArchiveDeleteInfo));
_mockDocumentTypeArchiveDeleteInfoRepository.Verify(x => x.FindByDocumentTypeNameAsync(It.IsAny<string>()), Times.Once);
_mockDocumentTypeArchiveDeleteInfoRepository.Verify(x => x.Update(It.IsAny<DocumentTypeArchiveDeleteInfo>()), Times.Never);
}
[Test]
public void Update_Update_ThrowsException()
{
var documentType = "Test";
var archiveDays = 200;
var deleteDays = 3000;
var existingDocumentTypeArchiveDeleteInfo = new DocumentTypeArchiveDeleteInfo()
{
DocumentTypeName = documentType,
ArchiveDays = archiveDays,
DeleteDays = deleteDays
};
var documentTypeArchiveDeleteInfo = new DocumentTypeArchiveDeleteInfo()
{
DocumentTypeName = documentType,
ArchiveDays = archiveDays,
DeleteDays = 4000
};
_mockDocumentTypeArchiveDeleteInfoRepository.Setup(x => x.FindByDocumentTypeNameAsync(documentType)).ReturnsAsync(existingDocumentTypeArchiveDeleteInfo);
_mockDocumentTypeArchiveDeleteInfoRepository.Setup(x => x.Update(existingDocumentTypeArchiveDeleteInfo)).Throws(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _documentTypeArchiveDeleteInfoService.Update(documentTypeArchiveDeleteInfo));
_mockDocumentTypeArchiveDeleteInfoRepository.Verify(x => x.FindByDocumentTypeNameAsync(It.IsAny<string>()), Times.Once);
_mockDocumentTypeArchiveDeleteInfoRepository.Verify(x => x.Update(It.IsAny<DocumentTypeArchiveDeleteInfo>()), Times.Once);
}
[Test]
public async Task Delete_Success()
{
var documentType = "Test";
var archiveDays = 200;
var deleteDays = 3000;
var existingDocumentTypeArchiveDeleteInfo = new DocumentTypeArchiveDeleteInfo()
{
DocumentTypeName = documentType,
ArchiveDays = archiveDays,
DeleteDays = deleteDays
};
_mockDocumentTypeArchiveDeleteInfoRepository.Setup(x => x.FindByDocumentTypeNameAsync(documentType)).ReturnsAsync(existingDocumentTypeArchiveDeleteInfo);
_mockDocumentTypeArchiveDeleteInfoRepository.Setup(x => x.Remove(existingDocumentTypeArchiveDeleteInfo));
await _documentTypeArchiveDeleteInfoService.Delete(documentType);
_mockDocumentTypeArchiveDeleteInfoRepository.Verify(x => x.FindByDocumentTypeNameAsync(documentType), Times.Once);
_mockDocumentTypeArchiveDeleteInfoRepository.Verify(x => x.Remove(It.IsAny<DocumentTypeArchiveDeleteInfo>()), Times.Once);
}
[Test]
public void Delete_FindByIdAsync_ThrowsException()
{
var documentType = "Test";
var archiveDays = 200;
var deleteDays = 3000;
var existingDocumentTypeArchiveDeleteInfo = new DocumentTypeArchiveDeleteInfo()
{
DocumentTypeName = documentType,
ArchiveDays = archiveDays,
DeleteDays = deleteDays
};
_mockDocumentTypeArchiveDeleteInfoRepository.Setup(x => x.FindByDocumentTypeNameAsync(documentType)).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _documentTypeArchiveDeleteInfoService.Delete(documentType));
_mockDocumentTypeArchiveDeleteInfoRepository.Verify(x => x.FindByDocumentTypeNameAsync(documentType), Times.Once);
_mockDocumentTypeArchiveDeleteInfoRepository.Verify(x => x.Remove(It.IsAny<DocumentTypeArchiveDeleteInfo>()), Times.Never);
}
[Test]
public void Delete_Remove_ThrowsException()
{
var documentType = "Test";
var archiveDays = 200;
var deleteDays = 3000;
var existingDocumentTypeArchiveDeleteInfo = new DocumentTypeArchiveDeleteInfo()
{
DocumentTypeName = documentType,
ArchiveDays = archiveDays,
DeleteDays = deleteDays
};
_mockDocumentTypeArchiveDeleteInfoRepository.Setup(x => x.FindByDocumentTypeNameAsync(documentType)).ReturnsAsync(existingDocumentTypeArchiveDeleteInfo);
_mockDocumentTypeArchiveDeleteInfoRepository.Setup(x => x.Remove(existingDocumentTypeArchiveDeleteInfo)).Throws(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _documentTypeArchiveDeleteInfoService.Delete(documentType));
_mockDocumentTypeArchiveDeleteInfoRepository.Verify(x => x.FindByDocumentTypeNameAsync(documentType), Times.Once);
_mockDocumentTypeArchiveDeleteInfoRepository.Verify(x => x.Remove(It.IsAny<DocumentTypeArchiveDeleteInfo>()), Times.Once);
}
}
@@ -0,0 +1,132 @@
using System;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using Moq;
using NUnit.Framework;
using LCU.API.Internal.DocumentIngestor.Services.MicroApiServices;
using LCU.API.Internal.DocumentIngestor.Services.IndexParserServices;
using LCU.Library.Internal.DocumentIngestorModels.Models;
using LCU.Library.Internal.DocumentIngestorModels.Enums;
using LCU.Library.Internal.DocumentIngestorModels.Models.IndexFileDocuments;
using LCU.Library.Internal.LCUServiceFactory.Configurations;
namespace LCU.API.Internal.DocumentIngestorTests.Services.IndexParserServices;
public class FosDnaDocumentIndexServiceTest
{
private FosDnaDocumentIndexService _fosDnaDocumentIndexService;
private Mock<IFileOperationsApiService> _mockFileOperationsApiService;
[SetUp]
public void Setup()
{
_mockFileOperationsApiService = new Mock<IFileOperationsApiService>();
var serviceFactoryConfiguration = new ServicesFactoryConfiguration
{
ServiceFactoryRegistrations = new List<ServiceFactoryRegistration>
{
new()
{
ServiceInterfaceName = "IIndexParserService",
ServiceRegistrations = new List<ServiceRegistration>
{
new()
{
ServiceName = "IndexParserService",
ServiceId = "4"
},
new()
{
ServiceName = "IndexParserService",
ServiceId = "1"
}
}
}
}
};
_fosDnaDocumentIndexService = new FosDnaDocumentIndexService(_mockFileOperationsApiService.Object, serviceFactoryConfiguration);
}
[Test]
public async Task HandleIndexRequest_IngestorRequest_Null_IngestorResult_Failure()
{
IngestorRequest request = null;
var result = await _fosDnaDocumentIndexService.HandleIndexRequest(request);
Assert.IsTrue(result.FatalFailure);
_mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Never);
}
[Test]
public async Task HandleIndexRequest_IngestorRequest_Success()
{
var request = new IngestorRequest
{
RootPath = "\\Test\\",
IndexFileName = "Test.csv"
};
const string fileContent = "\"220299012291\",\"CURTIS M, MACIK\",\"03072022\",\"LN_NENT\",\"03f6bd41-7aae-4160-8a16-06583f75916c.pdf\"";
_mockFileOperationsApiService.Setup(x => x.GetFileContent(It.IsAny<string>())).ReturnsAsync(fileContent);
var result = await _fosDnaDocumentIndexService.HandleIndexRequest(request);
Assert.IsFalse(result.FatalFailure);
Assert.AreEqual(1, result.ProcessingRequests.Count);
_mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Once);
var firstPayloadObject = result.ProcessingRequests.First().DocumentValuePayload;
var fosDnaDocumentRecord = JsonSerializer.Deserialize<FosDnaDocument>(firstPayloadObject);
Assert.NotNull(fosDnaDocumentRecord);
Assert.AreEqual("220299012291", fosDnaDocumentRecord.AccountNumber);
Assert.AreEqual("03f6bd41-7aae-4160-8a16-06583f75916c.pdf", fosDnaDocumentRecord.DocName);
Assert.AreEqual("LN_NENT", fosDnaDocumentRecord.DocType);
Assert.AreEqual("CURTIS M, MACIK", fosDnaDocumentRecord.EntityName);
Assert.AreEqual("03072022", fosDnaDocumentRecord.CreationDate);
}
[Test]
public async Task HandleIndexRequest_IngestorRequest_GetFileContent_ThrowsException_Failure()
{
var request = new IngestorRequest
{
RootPath = "\\Test\\",
IndexFileName = "Test.csv"
};
_mockFileOperationsApiService.Setup(x => x.GetFileContent(It.IsAny<string>())).ThrowsAsync(new Exception("Error"));
var result = await _fosDnaDocumentIndexService.HandleIndexRequest(request);
Assert.IsTrue(result.FatalFailure);
_mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Once);
}
[Test]
public void PrepareRunInfoAndProcessRequests_IngestorRunInfo_ProcessRequests_Created()
{
var request = new IngestorRequest
{
RootPath = "\\Test\\",
IndexFileName = "Test.csv",
IngestorType = IngestorTypes.FosTaxStatement,
};
var documentMetaData = new List<FosDnaDocument>
{
new()
{
AccountNumber = "1",
DocType = "1099-INT",
EntityName = "tester",
DocName = "test.pdf",
CreationDate = "01022003"
}
};
var ingestorResult = new IngestorResult();
var result = _fosDnaDocumentIndexService.PrepareRunInfoAndProcessRequests(request, documentMetaData, ingestorResult);
Assert.IsFalse(result.FatalFailure);
Assert.AreEqual(1, result.ProcessingRequests.Count);
Assert.AreEqual("Test.csv", result.IngestorRunInfo.IndexFileName);
Assert.AreEqual(IngestorTypes.FosTaxStatement, result.IngestorRunInfo.IngestorType);
Assert.AreEqual("\\Test\\", result.IngestorRunInfo.IndexFilePath);
}
}
@@ -0,0 +1,153 @@
using System;
using System.Threading.Tasks;
using System.Collections.Generic;
using Moq;
using NUnit.Framework;
using LCU.API.Internal.DocumentIngestor.Services.MicroApiServices;
using LCU.API.Internal.DocumentIngestor.Services.IndexParserServices;
using LCU.Library.Internal.DocumentIngestorModels.Models;
using LCU.Library.Internal.DocumentIngestorModels.Enums;
using LCU.Library.Internal.DocumentIngestorModels.Models.IndexFileDocuments;
using LCU.Library.Internal.FileOperationsModels.Models;
using LCU.Library.Internal.FileOperationsModels.Models.NameSettings;
using LCU.Library.Internal.LCUServiceFactory.Configurations;
namespace LCU.API.Internal.DocumentIngestorTests.Services.IndexParserServices;
public class FosLoanStatementIndexServiceTest
{
private FosLoanStatementIndexService _fosLoanStatementIndexService;
private Mock<IFileOperationsApiService> _mockFileOperationsApiService;
[SetUp]
public void Setup()
{
_mockFileOperationsApiService = new Mock<IFileOperationsApiService>();
var serviceFactoryConfiguration = new ServicesFactoryConfiguration
{
ServiceFactoryRegistrations = new List<ServiceFactoryRegistration>
{
new()
{
ServiceInterfaceName = "IIndexParserService",
ServiceRegistrations = new List<ServiceRegistration>
{
new()
{
ServiceName = "IndexParserService",
ServiceId = "4"
},
new()
{
ServiceName = "IndexParserService",
ServiceId = "3"
}
}
}
}
};
_fosLoanStatementIndexService = new FosLoanStatementIndexService(_mockFileOperationsApiService.Object,
serviceFactoryConfiguration);
}
[Test]
public async Task HandleIndexRequest_IngestorRequest_Null_IngestorResult_Failure()
{
IngestorRequest request = null;
var result = await _fosLoanStatementIndexService.HandleIndexRequest(request);
Assert.IsTrue(result.FatalFailure);
_mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Never);
}
[Test]
public async Task HandleIndexRequest_IngestorRequest_Success()
{
var rootPath = "\\Test\\";
var request = new IngestorRequest()
{
RootPath = rootPath,
IndexFileName = "NAU123456789.91.21.txt",
IngestorType = IngestorTypes.FosLoanStatement
};
var fileContent = "\"Mortgage Statement\"|\"11111111111111111111111\"|\"11\"|\"N\"|\"1111\"" +
"|\"Test, Tester\"|\"[email protected]\"|\"111111111\"|\"2\"|\"4\"|\"test.pdf\"\n" +
"\"Loan Statement\"|\"11111111111111111111111\"|\"11\"|\"N\"|\"1111\"" +
"|\"Tester Testing\"|\"[email protected]\"|\"111111111\"|\"1\"|\"3\"|\"tester.pdf\"";
var requestResponse = new RequestResponse()
{
IsSuccessful = true
};
var dynamicFileRequest = new DynamicFileListRequest()
{
Path = rootPath,
Filename = "replaceTag.pdf",
DynamicFileSettings = new DynamicNameSetting()
{
RegexSettings = new List<RegexSetting>()
{
new RegexSetting()
{
Tag = "replaceTag",
Regex = ".*"
}
}
}
};
_mockFileOperationsApiService.Setup(x => x.GetFileContent(It.IsAny<string>())).ReturnsAsync(fileContent);
var result = await _fosLoanStatementIndexService.HandleIndexRequest(request);
Assert.IsFalse(result.FatalFailure);
Assert.AreEqual(2, result.ProcessingRequests.Count);
_mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Once);
}
[Test]
public async Task HandleIndexRequest_IngestorRequest_GetFileContent_ThrowsException_Failure()
{
var request = new IngestorRequest()
{
RootPath = "\\Test\\",
IndexFileName = "Test.csv",
IngestorType = IngestorTypes.FosLoanStatement
};
_mockFileOperationsApiService.Setup(x => x.GetFileContent(It.IsAny<string>())).ThrowsAsync(new Exception("Error"));
var result = await _fosLoanStatementIndexService.HandleIndexRequest(request);
Assert.IsTrue(result.FatalFailure);
_mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Once);
}
[Test]
public void PrepareRunInfoAndProcessRequests_IngestorRunInfo_ProcessRequests_Created()
{
var request = new IngestorRequest()
{
RootPath = "\\Test\\",
IndexFileName = "Test.csv",
IngestorType = IngestorTypes.FosLoanStatement
};
var documentMetaData = new List<FosLoanStatement>()
{
new FosLoanStatement()
{
AccountNumber = "111111",
CreationDate = "04012023",
DocName = "test.pdf",
EmailAddress = "[email protected]",
EntityName = "Test Tester",
StartingPage = "2",
NumberOfPages = "3",
DocType = "Mortgage Statement"
}
};
var ingestorResult = new IngestorResult();
var result = _fosLoanStatementIndexService.PrepareRunInfoAndProcessRequests(request, documentMetaData, ingestorResult);
Assert.IsFalse(result.FatalFailure);
Assert.AreEqual(1, result.ProcessingRequests.Count);
Assert.AreEqual("Test.csv", result.IngestorRunInfo.IndexFileName);
Assert.AreEqual(IngestorTypes.FosLoanStatement, result.IngestorRunInfo.IngestorType);
Assert.AreEqual("\\Test\\", result.IngestorRunInfo.IndexFilePath);
}
}
@@ -0,0 +1,122 @@
using System;
using System.Threading.Tasks;
using System.Collections.Generic;
using Moq;
using NUnit.Framework;
using LCU.API.Internal.DocumentIngestor.Services.MicroApiServices;
using LCU.API.Internal.DocumentIngestor.Services.IndexParserServices;
using LCU.Library.Internal.DocumentIngestorModels.Models;
using LCU.Library.Internal.DocumentIngestorModels.Enums;
using LCU.Library.Internal.DocumentIngestorModels.Models.IndexFileDocuments;
using LCU.Library.Internal.LCUServiceFactory.Configurations;
namespace LCU.API.Internal.DocumentIngestorTests.Services.IndexParserServices;
public class FosTaxStatementIndexServiceTest
{
private FosTaxStatementIndexService _fosTaxStatementIndexService;
private Mock<IFileOperationsApiService> _mockFileOperationsApiService;
[SetUp]
public void Setup()
{
_mockFileOperationsApiService = new Mock<IFileOperationsApiService>();
var serviceFactoryConfiguration = new ServicesFactoryConfiguration
{
ServiceFactoryRegistrations = new List<ServiceFactoryRegistration>
{
new()
{
ServiceInterfaceName = "IIndexParserService",
ServiceRegistrations = new List<ServiceRegistration>
{
new()
{
ServiceName = "IndexParserService",
ServiceId = "4"
},
new()
{
ServiceName = "IndexParserService",
ServiceId = "0"
}
}
}
}
};
_fosTaxStatementIndexService = new FosTaxStatementIndexService(_mockFileOperationsApiService.Object,
serviceFactoryConfiguration);
}
[Test]
public async Task HandleIndexRequest_IngestorRequest_Null_IngestorResult_Failure()
{
IngestorRequest request = null;
var result = await _fosTaxStatementIndexService.HandleIndexRequest(request);
Assert.IsTrue(result.FatalFailure);
_mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Never);
}
[Test]
public async Task HandleIndexRequest_IngestorRequest_Success()
{
var request = new IngestorRequest()
{
RootPath = "\\Test\\",
IndexFileName = "Test.csv"
};
var fileContent = "1099 - INT,999999999,Test Tester T,2012,12345674,0000000001.pdf";
_mockFileOperationsApiService.Setup(x => x.GetFileContent(It.IsAny<string>())).ReturnsAsync(fileContent);
var result = await _fosTaxStatementIndexService.HandleIndexRequest(request);
Assert.IsFalse(result.FatalFailure);
Assert.AreEqual(1, result.ProcessingRequests.Count);
_mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Once);
}
[Test]
public async Task HandleIndexRequest_IngestorRequest_GetFileContent_ThrowsException_Failure()
{
var request = new IngestorRequest()
{
RootPath = "\\Test\\",
IndexFileName = "Test.csv"
};
_mockFileOperationsApiService.Setup(x => x.GetFileContent(It.IsAny<string>())).ThrowsAsync(new Exception("Error"));
var result = await _fosTaxStatementIndexService.HandleIndexRequest(request);
Assert.IsTrue(result.FatalFailure);
_mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Once);
}
[Test]
public void PrepareRunInfoAndProcessRequests_IngestorRunInfo_ProcessRequests_Created()
{
var request = new IngestorRequest()
{
RootPath = "\\Test\\",
IndexFileName = "Test.csv",
IngestorType = IngestorTypes.FosTaxStatement
};
var documentMetaData = new List<FosTaxStatementDocument>()
{
new FosTaxStatementDocument()
{
AccountNumber = "1",
FileName = "1099-INT",
PrimaryTIN = "1",
FullName = "tester",
PDF = "test.pdf"
}
};
var ingestorResult = new IngestorResult();
var result = _fosTaxStatementIndexService.PrepareRunInfoAndProcessRequests(request, documentMetaData, ingestorResult);
Assert.IsFalse(result.FatalFailure);
Assert.AreEqual(1, result.ProcessingRequests.Count);
Assert.AreEqual("Test.csv", result.IngestorRunInfo.IndexFileName);
Assert.AreEqual(IngestorTypes.FosTaxStatement, result.IngestorRunInfo.IngestorType);
Assert.AreEqual("\\Test\\", result.IngestorRunInfo.IndexFilePath);
}
}
@@ -0,0 +1,123 @@
using System;
using System.Threading.Tasks;
using System.Collections.Generic;
using Moq;
using NUnit.Framework;
using LCU.API.Internal.DocumentIngestor.Services.MicroApiServices;
using LCU.API.Internal.DocumentIngestor.Services.IndexParserServices;
using LCU.Library.Internal.DocumentIngestorModels.Models;
using LCU.Library.Internal.DocumentIngestorModels.Enums;
using LCU.Library.Internal.DocumentIngestorModels.Models.IndexFileDocuments;
using LCU.API.Internal.DocumentIngestor.Services.DocumentProcessorServices;
using LCU.Library.Internal.LCUServiceFactory.Configurations;
namespace LCU.API.Internal.DocumentIngestorTests.Services.IndexParserServices;
public class OsgDnaNoticeSplitIndexServiceTest
{
private OsgDnaNoticeSplitIndexService _osgDnaNoticeSplitIndexService;
private Mock<IFileOperationsApiService> _mockFileOperationsApiService;
[SetUp]
public void Setup()
{
_mockFileOperationsApiService = new Mock<IFileOperationsApiService>();
var serviceFactoryConfiguration = new ServicesFactoryConfiguration
{
ServiceFactoryRegistrations = new List<ServiceFactoryRegistration>
{
new()
{
ServiceInterfaceName = "IIndexParserService",
ServiceRegistrations = new List<ServiceRegistration>
{
new()
{
ServiceName = "IndexParserService",
ServiceId = "4"
},
new()
{
ServiceName = "IndexParserService",
ServiceId = "9"
}
}
}
}
};
_osgDnaNoticeSplitIndexService = new OsgDnaNoticeSplitIndexService(_mockFileOperationsApiService.Object,
serviceFactoryConfiguration);
}
[Test]
public async Task HandleIndexRequest_IngestorRequest_Null_IngestorResult_Failure()
{
IngestorRequest request = null;
var result = await _osgDnaNoticeSplitIndexService.HandleIndexRequest(request);
Assert.IsTrue(result.FatalFailure);
_mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Never);
}
[Test]
public async Task HandleIndexRequest_IngestorRequest_Success()
{
var request = new IngestorRequest()
{
RootPath = "\\Test\\",
IndexFileName = "Test.csv"
};
var fileContent = "1|OPS_NT_129|1234567890||111111|Test Tester||OD Government Funds Notice||02242025|1804777185.pdf";
_mockFileOperationsApiService.Setup(x => x.GetFileContent(It.IsAny<string>())).ReturnsAsync(fileContent);
var result = await _osgDnaNoticeSplitIndexService.HandleIndexRequest(request);
Assert.IsFalse(result.FatalFailure);
Assert.AreEqual(1, result.ProcessingRequests.Count);
_mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Once);
}
[Test]
public async Task HandleIndexRequest_IngestorRequest_GetFileContent_ThrowsException_Failure()
{
var request = new IngestorRequest()
{
RootPath = "\\Test\\",
IndexFileName = "Test.csv"
};
_mockFileOperationsApiService.Setup(x => x.GetFileContent(It.IsAny<string>())).ThrowsAsync(new Exception("Error"));
var result = await _osgDnaNoticeSplitIndexService.HandleIndexRequest(request);
Assert.IsTrue(result.FatalFailure);
_mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Once);
}
[Test]
public void PrepareRunInfoAndProcessRequests_IngestorRunInfo_ProcessRequests_Created()
{
var request = new IngestorRequest()
{
RootPath = "\\Test\\",
IndexFileName = "Test.csv",
IngestorType = IngestorTypes.OsgDnaNoticeSplit
};
var documentMetaData = new List<OsgDnaNoticeSplit>()
{
new OsgDnaNoticeSplit()
{
AccountNumber = "1",
NoticeName = "OPS_NT_129",
MemberNumber = "1",
RecipientName = "tester",
PdfName = "test.pdf"
}
};
var ingestorResult = new IngestorResult();
var result = _osgDnaNoticeSplitIndexService.PrepareRunInfoAndProcessRequests(request, documentMetaData, ingestorResult);
Assert.IsFalse(result.FatalFailure);
Assert.AreEqual(1, result.ProcessingRequests.Count);
Assert.AreEqual("Test.csv", result.IngestorRunInfo.IndexFileName);
Assert.AreEqual(IngestorTypes.OsgDnaNoticeSplit, result.IngestorRunInfo.IngestorType);
Assert.AreEqual("\\Test\\", result.IngestorRunInfo.IndexFilePath);
}
}
@@ -0,0 +1,153 @@
using System;
using System.Threading.Tasks;
using System.Collections.Generic;
using Moq;
using NUnit.Framework;
using LCU.API.Internal.DocumentIngestor.Services.MicroApiServices;
using LCU.API.Internal.DocumentIngestor.Services.IndexParserServices;
using LCU.Library.Internal.DocumentIngestorModels.Models;
using LCU.Library.Internal.DocumentIngestorModels.Enums;
using LCU.Library.Internal.DocumentIngestorModels.Models.IndexFileDocuments;
using LCU.Library.Internal.FileOperationsModels.Models;
using LCU.Library.Internal.FileOperationsModels.Models.NameSettings;
using LCU.Library.Internal.LCUServiceFactory.Configurations;
namespace LCU.API.Internal.DocumentIngestorTests.Services.IndexParserServices;
public class OsgDnaNoticesIndexServiceTest
{
private OsgDnaNoticesIndexService _osgDnaNoticesIndexService;
private Mock<IFileOperationsApiService> _mockFileOperationsApiService;
[SetUp]
public void Setup()
{
_mockFileOperationsApiService = new Mock<IFileOperationsApiService>();
var serviceFactoryConfiguration = new ServicesFactoryConfiguration
{
ServiceFactoryRegistrations = new List<ServiceFactoryRegistration>
{
new()
{
ServiceInterfaceName = "IIndexParserService",
ServiceRegistrations = new List<ServiceRegistration>
{
new()
{
ServiceName = "IndexParserService",
ServiceId = "4"
},
new()
{
ServiceName = "IndexParserService",
ServiceId = "1"
}
}
}
}
};
_osgDnaNoticesIndexService = new OsgDnaNoticesIndexService(_mockFileOperationsApiService.Object,
serviceFactoryConfiguration);
}
[Test]
public async Task HandleIndexRequest_IngestorRequest_Null_IngestorResult_Failure()
{
IngestorRequest request = null;
var result = await _osgDnaNoticesIndexService.HandleIndexRequest(request);
Assert.IsTrue(result.FatalFailure);
_mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Never);
}
[Test]
public async Task HandleIndexRequest_IngestorRequest_Success()
{
var rootPath = "\\Test\\";
var request = new IngestorRequest()
{
RootPath = rootPath,
IndexFileName = "PDFXREF.TXT",
IngestorType = IngestorTypes.OsgDnaNoticesDocument
};
var fileContent = "00000001|LCL_LT_114_03|5651830147|5651830|20220823|1|1\n" +
"00000002|LVI_LT_105_03|19619353841|8996218227|20220823|2|1\n";
var requestResponse = new RequestResponse()
{
IsSuccessful = true
};
var dynamicFileRequest = new DynamicFileListRequest()
{
Path = rootPath,
Filename = "replaceTag.pdf",
DynamicFileSettings = new DynamicNameSetting()
{
RegexSettings = new List<RegexSetting>()
{
new RegexSetting()
{
Tag = "replaceTag",
Regex = ".*"
}
}
}
};
_mockFileOperationsApiService.Setup(x => x.GetFileContent(It.IsAny<string>())).ReturnsAsync(fileContent);
var result = await _osgDnaNoticesIndexService.HandleIndexRequest(request);
Assert.IsFalse(result.FatalFailure);
Assert.AreEqual(2, result.ProcessingRequests.Count);
_mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Once);
}
[Test]
public async Task HandleIndexRequest_IngestorRequest_GetFileContent_ThrowsException_Failure()
{
var request = new IngestorRequest()
{
RootPath = "\\Test\\",
IndexFileName = "PDFXREF.TXT",
IngestorType = IngestorTypes.OsgDnaNoticesDocument
};
_mockFileOperationsApiService.Setup(x => x.GetFileContent(It.IsAny<string>())).ThrowsAsync(new Exception("Error"));
var result = await _osgDnaNoticesIndexService.HandleIndexRequest(request);
Assert.IsTrue(result.FatalFailure);
_mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Once);
}
[Test]
public void PrepareRunInfoAndProcessRequests_IngestorRunInfo_ProcessRequests_Created()
{
var request = new IngestorRequest()
{
RootPath = "\\Test\\",
IndexFileName = "PDFXREF.TXT",
IngestorType = IngestorTypes.OsgDnaNoticesDocument
};
var documentMetaData = new List<OsgDnaNoticesDocument>()
{
new OsgDnaNoticesDocument()
{
DocType = "TestDocType",
AccountNumber = "1",
MemberNumberOrUserId = "2",
CreationDate = "20220823",
StartingPage = "1",
NumberOfPages = "3"
}
};
var ingestorResult = new IngestorResult();
var result = _osgDnaNoticesIndexService.PrepareRunInfoAndProcessRequests(request, documentMetaData, ingestorResult);
Assert.IsFalse(result.FatalFailure);
Assert.AreEqual(1, result.ProcessingRequests.Count);
Assert.AreEqual("PDFXREF.TXT", result.IngestorRunInfo.IndexFileName);
Assert.AreEqual(IngestorTypes.OsgDnaNoticesDocument, result.IngestorRunInfo.IngestorType);
Assert.AreEqual("\\Test\\", result.IngestorRunInfo.IndexFilePath);
}
}
@@ -0,0 +1,153 @@
using System;
using System.Threading.Tasks;
using System.Collections.Generic;
using Moq;
using NUnit.Framework;
using LCU.API.Internal.DocumentIngestor.Services.MicroApiServices;
using LCU.API.Internal.DocumentIngestor.Services.IndexParserServices;
using LCU.Library.Internal.DocumentIngestorModels.Models;
using LCU.Library.Internal.DocumentIngestorModels.Enums;
using LCU.Library.Internal.DocumentIngestorModels.Models.IndexFileDocuments;
using LCU.Library.Internal.FileOperationsModels.Models;
using LCU.Library.Internal.FileOperationsModels.Models.NameSettings;
using LCU.Library.Internal.LCUServiceFactory.Configurations;
namespace LCU.API.Internal.DocumentIngestorTests.Services.IndexParserServices;
public class OsgHistoricalDocumentIndexServiceTest
{
private OsgHistoricalDocumentIndexService _osgHistoricalDocumentIndexService;
private Mock<IFileOperationsApiService> _mockFileOperationsApiService;
[SetUp]
public void Setup()
{
_mockFileOperationsApiService = new Mock<IFileOperationsApiService>();
var serviceFactoryConfiguration = new ServicesFactoryConfiguration
{
ServiceFactoryRegistrations = new List<ServiceFactoryRegistration>
{
new()
{
ServiceInterfaceName = "IIndexParserService",
ServiceRegistrations = new List<ServiceRegistration>
{
new()
{
ServiceName = "IndexParserService",
ServiceId = "4"
},
new()
{
ServiceName = "IndexParserService",
ServiceId = "6"
}
}
}
}
};
_osgHistoricalDocumentIndexService = new OsgHistoricalDocumentIndexService(_mockFileOperationsApiService.Object,
serviceFactoryConfiguration);
}
[Test]
public async Task HandleIndexRequest_IngestorRequest_Null_IngestorResult_Failure()
{
IngestorRequest request = null;
var result = await _osgHistoricalDocumentIndexService.HandleIndexRequest(request);
Assert.IsTrue(result.FatalFailure);
_mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Never);
}
[Test]
public async Task HandleIndexRequest_IngestorRequest_Success()
{
var rootPath = "\\Test\\";
var request = new IngestorRequest()
{
RootPath = rootPath,
IndexFileName = "PDFXREF.TXT",
IngestorType = IngestorTypes.OsgDnaNoticesDocument
};
var fileContent = "00000001|LCL_LT_114_03|5651830147|5651830|20220823|1|1\n" +
"00000002|LVI_LT_105_03|19619353841|8996218227|20220823|2|1\n";
var requestResponse = new RequestResponse()
{
IsSuccessful = true
};
var dynamicFileRequest = new DynamicFileListRequest()
{
Path = rootPath,
Filename = "replaceTag.pdf",
DynamicFileSettings = new DynamicNameSetting()
{
RegexSettings = new List<RegexSetting>()
{
new RegexSetting()
{
Tag = "replaceTag",
Regex = ".*"
}
}
}
};
_mockFileOperationsApiService.Setup(x => x.GetFileContent(It.IsAny<string>())).ReturnsAsync(fileContent);
var result = await _osgHistoricalDocumentIndexService.HandleIndexRequest(request);
Assert.IsFalse(result.FatalFailure);
Assert.AreEqual(2, result.ProcessingRequests.Count);
_mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Once);
}
[Test]
public async Task HandleIndexRequest_IngestorRequest_GetFileContent_ThrowsException_Failure()
{
var request = new IngestorRequest()
{
RootPath = "\\Test\\",
IndexFileName = "PDFXREF.TXT",
IngestorType = IngestorTypes.OsgHistoricalDocument
};
_mockFileOperationsApiService.Setup(x => x.GetFileContent(It.IsAny<string>())).ThrowsAsync(new Exception("Error"));
var result = await _osgHistoricalDocumentIndexService.HandleIndexRequest(request);
Assert.IsTrue(result.FatalFailure);
_mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Once);
}
[Test]
public void PrepareRunInfoAndProcessRequests_IngestorRunInfo_ProcessRequests_Created()
{
var request = new IngestorRequest()
{
RootPath = "\\Test\\",
IndexFileName = "PDFXREF.TXT",
IngestorType = IngestorTypes.OsgHistoricalDocument
};
var documentMetaData = new List<OsgHistoricalDocument>()
{
new OsgHistoricalDocument()
{
DocType = "TestDocType",
EntityName = "John Jim",
MemberNumberOrUserId = "2",
CreationDate = "20220823",
StartingPage = "1",
NumberOfPages = "3"
}
};
var ingestorResult = new IngestorResult();
var result = _osgHistoricalDocumentIndexService.PrepareRunInfoAndProcessRequests(request, documentMetaData, ingestorResult);
Assert.IsFalse(result.FatalFailure);
Assert.AreEqual(1, result.ProcessingRequests.Count);
Assert.AreEqual("PDFXREF.TXT", result.IngestorRunInfo.IndexFileName);
Assert.AreEqual(IngestorTypes.OsgHistoricalDocument, result.IngestorRunInfo.IngestorType);
Assert.AreEqual("\\Test\\", result.IngestorRunInfo.IndexFilePath);
}
}
@@ -0,0 +1,123 @@
using System;
using System.Threading.Tasks;
using System.Collections.Generic;
using Moq;
using NUnit.Framework;
using LCU.API.Internal.DocumentIngestor.Services.MicroApiServices;
using LCU.API.Internal.DocumentIngestor.Services.IndexParserServices;
using LCU.Library.Internal.DocumentIngestorModels.Models;
using LCU.Library.Internal.DocumentIngestorModels.Enums;
using LCU.Library.Internal.DocumentIngestorModels.Models.IndexFileDocuments;
using LCU.API.Internal.DocumentIngestor.Services.DocumentProcessorServices;
using LCU.Library.Internal.LCUServiceFactory.Configurations;
namespace LCU.API.Internal.DocumentIngestorTests.Services.IndexParserServices;
public class OsgTaxStatementIndexServiceTest
{
private OsgTaxStatementIndexService _osgTaxStatementIndexService;
private Mock<IFileOperationsApiService> _mockFileOperationsApiService;
[SetUp]
public void Setup()
{
_mockFileOperationsApiService = new Mock<IFileOperationsApiService>();
var serviceFactoryConfiguration = new ServicesFactoryConfiguration
{
ServiceFactoryRegistrations = new List<ServiceFactoryRegistration>
{
new()
{
ServiceInterfaceName = "IIndexParserService",
ServiceRegistrations = new List<ServiceRegistration>
{
new()
{
ServiceName = "IndexParserService",
ServiceId = "4"
},
new()
{
ServiceName = "IndexParserService",
ServiceId = "8"
}
}
}
}
};
_osgTaxStatementIndexService = new OsgTaxStatementIndexService(_mockFileOperationsApiService.Object,
serviceFactoryConfiguration);
}
[Test]
public async Task HandleIndexRequest_IngestorRequest_Null_IngestorResult_Failure()
{
IngestorRequest request = null;
var result = await _osgTaxStatementIndexService.HandleIndexRequest(request);
Assert.IsTrue(result.FatalFailure);
_mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Never);
}
[Test]
public async Task HandleIndexRequest_IngestorRequest_Success()
{
var request = new IngestorRequest()
{
RootPath = "\\Test\\",
IndexFileName = "Test.csv"
};
var fileContent = "1||1281|||Test Name Tester|111-11-1111|1098||12162024|TAXFORM_1098_Test Name Tester_1281.PDF";
_mockFileOperationsApiService.Setup(x => x.GetFileContent(It.IsAny<string>())).ReturnsAsync(fileContent);
var result = await _osgTaxStatementIndexService.HandleIndexRequest(request);
Assert.IsFalse(result.FatalFailure);
Assert.AreEqual(1, result.ProcessingRequests.Count);
_mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Once);
}
[Test]
public async Task HandleIndexRequest_IngestorRequest_GetFileContent_ThrowsException_Failure()
{
var request = new IngestorRequest()
{
RootPath = "\\Test\\",
IndexFileName = "Test.csv"
};
_mockFileOperationsApiService.Setup(x => x.GetFileContent(It.IsAny<string>())).ThrowsAsync(new Exception("Error"));
var result = await _osgTaxStatementIndexService.HandleIndexRequest(request);
Assert.IsTrue(result.FatalFailure);
_mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Once);
}
[Test]
public void PrepareRunInfoAndProcessRequests_IngestorRunInfo_ProcessRequests_Created()
{
var request = new IngestorRequest()
{
RootPath = "\\Test\\",
IndexFileName = "Test.csv",
IngestorType = IngestorTypes.OsgTaxStatement
};
var documentMetaData = new List<OsgTaxStatement>()
{
new OsgTaxStatement()
{
AccountNumber = "1",
NoticeName = "1099-INT",
SSN = "1",
RecipientName = "tester",
PdfName = "test.pdf"
}
};
var ingestorResult = new IngestorResult();
var result = _osgTaxStatementIndexService.PrepareRunInfoAndProcessRequests(request, documentMetaData, ingestorResult);
Assert.IsFalse(result.FatalFailure);
Assert.AreEqual(1, result.ProcessingRequests.Count);
Assert.AreEqual("Test.csv", result.IngestorRunInfo.IndexFileName);
Assert.AreEqual(IngestorTypes.OsgTaxStatement, result.IngestorRunInfo.IngestorType);
Assert.AreEqual("\\Test\\", result.IngestorRunInfo.IndexFilePath);
}
}
@@ -0,0 +1,112 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Linq;
using System.Text.Json;
using Moq;
using NUnit.Framework;
using LCU.API.Internal.DocumentIngestor.Services.MicroApiServices;
using LCU.API.Internal.DocumentIngestor.Services.IndexParserServices;
using LCU.Library.Internal.DocumentIngestorModels.Models;
using LCU.Library.Internal.DocumentIngestorModels.Enums;
using LCU.Library.Internal.DocumentIngestorModels.Models.IndexFileDocuments;
using LCU.Library.Internal.LCUServiceFactory.Configurations;
namespace LCU.API.Internal.DocumentIngestorTests.Services.IndexParserServices;
public class XdiActionNoticeDocumentIndexServiceTest
{
private XdiActionNoticeDocumentIndexService _xdiActionNoticeDocumentIndexService;
private Mock<IFileOperationsApiService> _mockFileOperationsApiService;
[SetUp]
public void Setup()
{
_mockFileOperationsApiService = new Mock<IFileOperationsApiService>();
var serviceFactoryConfiguration = new ServicesFactoryConfiguration
{
ServiceFactoryRegistrations = new List<ServiceFactoryRegistration>
{
new()
{
ServiceInterfaceName = "IIndexParserService",
ServiceRegistrations = new List<ServiceRegistration>
{
new()
{
ServiceName = "IndexParserService",
ServiceId = "5"
},
new()
{
ServiceName = "IndexParserService",
ServiceId = "1"
}
}
}
}
};
_xdiActionNoticeDocumentIndexService = new XdiActionNoticeDocumentIndexService(_mockFileOperationsApiService.Object,
serviceFactoryConfiguration);
}
[Test]
public async Task HandleIndexRequest_IngestorRequest_Null_IngestorResult_Failure()
{
IngestorRequest request = null;
var result = await _xdiActionNoticeDocumentIndexService.HandleIndexRequest(request);
Assert.IsTrue(result.FatalFailure);
_mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Never);
}
[Test]
public async Task HandleIndexRequest_IngestorRequest_Success()
{
var request = new IngestorRequest
{
RootPath = "\\Test\\",
IndexFileName = "Test.csv",
IngestorType = IngestorTypes.XdiActionNotice
};
const string fileContent = "08/08/2022|0001853948|00|PRUDENCIANO RAMOS|1|ACTion_Declined Loan Letter|ACTion_Declined Loan Letter|10270_20220808144204_00000023.PDF";
_mockFileOperationsApiService.Setup(x => x.GetFileContent(It.IsAny<string>())).ReturnsAsync(fileContent);
var result = await _xdiActionNoticeDocumentIndexService.HandleIndexRequest(request);
Assert.IsFalse(result.FatalFailure);
Assert.AreEqual(1, result.ProcessingRequests.Count);
_mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Once);
var firstPayloadObject = result.ProcessingRequests.First().DocumentValuePayload;
var xdiActionDocumentRecord = JsonSerializer.Deserialize<XdiActionNoticesDocument>(firstPayloadObject);
Assert.NotNull(xdiActionDocumentRecord);
Assert.AreEqual("10270_20220808144204_00000023.PDF", xdiActionDocumentRecord.DocumentName);
Assert.AreEqual(1, xdiActionDocumentRecord.PageCount);
Assert.AreEqual("ACTion_Declined Loan Letter", xdiActionDocumentRecord.DocumentType);
Assert.AreEqual("PRUDENCIANO RAMOS", xdiActionDocumentRecord.EntityName);
Assert.AreEqual("08/08/2022", xdiActionDocumentRecord.CreationDate);
Assert.AreEqual(1, result.ProcessingRequests.Count);
var initialRunInfo = result.IngestorRunInfo;
Assert.AreEqual(request.IndexFileName, initialRunInfo.IndexFileName);
Assert.AreEqual(request.RootPath, initialRunInfo.IndexFilePath);
Assert.AreEqual(IngestorTypes.XdiActionNotice, initialRunInfo.IngestorType);
Assert.AreEqual(DateTime.Now.Date, initialRunInfo.StartTimeStamp.Date);
Assert.AreEqual("\\Test\\", initialRunInfo.IndexFilePath);
}
[Test]
public async Task HandleIndexRequest_IngestorRequest_GetFileContent_ThrowsException_Failure()
{
var request = new IngestorRequest
{
RootPath = "\\Test\\",
IndexFileName = "Test.csv"
};
_mockFileOperationsApiService.Setup(x => x.GetFileContent(It.IsAny<string>())).ThrowsAsync(new Exception("Error"));
var result = await _xdiActionNoticeDocumentIndexService.HandleIndexRequest(request);
Assert.IsTrue(result.FatalFailure);
_mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Once);
}
}
@@ -0,0 +1,112 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Linq;
using System.Text.Json;
using Moq;
using NUnit.Framework;
using LCU.API.Internal.DocumentIngestor.Services.MicroApiServices;
using LCU.API.Internal.DocumentIngestor.Services.IndexParserServices;
using LCU.Library.Internal.DocumentIngestorModels.Models;
using LCU.Library.Internal.DocumentIngestorModels.Enums;
using LCU.Library.Internal.DocumentIngestorModels.Models.IndexFileDocuments;
using LCU.Library.Internal.LCUServiceFactory.Configurations;
namespace LCU.API.Internal.DocumentIngestorTests.Services.IndexParserServices;
public class XdiDnaNoticeDocumentIndexServiceTest
{
private XdiDnaNoticeDocumentIndexService _xdiDnaNoticeDocumentIndexService;
private Mock<IFileOperationsApiService> _mockFileOperationsApiService;
[SetUp]
public void Setup()
{
_mockFileOperationsApiService = new Mock<IFileOperationsApiService>();
var serviceFactoryConfiguration = new ServicesFactoryConfiguration
{
ServiceFactoryRegistrations = new List<ServiceFactoryRegistration>
{
new()
{
ServiceInterfaceName = "IIndexParserService",
ServiceRegistrations = new List<ServiceRegistration>
{
new()
{
ServiceName = "IndexParserService",
ServiceId = "4"
},
new()
{
ServiceName = "IndexParserService",
ServiceId = "2"
}
}
}
}
};
_xdiDnaNoticeDocumentIndexService = new XdiDnaNoticeDocumentIndexService(_mockFileOperationsApiService.Object, serviceFactoryConfiguration);
}
[Test]
public async Task HandleIndexRequest_IngestorRequest_Null_IngestorResult_Failure()
{
IngestorRequest request = null;
var result = await _xdiDnaNoticeDocumentIndexService.HandleIndexRequest(request);
Assert.IsTrue(result.FatalFailure);
_mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Never);
}
[Test]
public async Task HandleIndexRequest_IngestorRequest_Success()
{
var request = new IngestorRequest
{
RootPath = "\\Test\\",
IndexFileName = "Test.csv",
IngestorType = IngestorTypes.XdiDnaNotice
};
const string fileContent = "05/12/2022|1748070144|00|Zachary Ps Buth|2|22 Day Past Due Letter|22 Day Past Due Letter|10270_20220512234318_00000011.PDF";
_mockFileOperationsApiService.Setup(x => x.GetFileContent(It.IsAny<string>())).ReturnsAsync(fileContent);
var result = await _xdiDnaNoticeDocumentIndexService.HandleIndexRequest(request);
Assert.IsFalse(result.FatalFailure);
Assert.AreEqual(1, result.ProcessingRequests.Count);
_mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Once);
var firstPayloadObject = result.ProcessingRequests.First().DocumentValuePayload;
var xdiDnaDocumentRecord = JsonSerializer.Deserialize<XdiDnaNoticesDocument>(firstPayloadObject);
Assert.NotNull(xdiDnaDocumentRecord);
Assert.AreEqual("1748070144", xdiDnaDocumentRecord.AccountNumber);
Assert.AreEqual("10270_20220512234318_00000011.PDF", xdiDnaDocumentRecord.PDF);
Assert.AreEqual(2, xdiDnaDocumentRecord.PageCount);
Assert.AreEqual("22 Day Past Due Letter", xdiDnaDocumentRecord.DocumentType);
Assert.AreEqual("Zachary Ps Buth", xdiDnaDocumentRecord.EntityName);
Assert.AreEqual("05/12/2022", xdiDnaDocumentRecord.CreationDate);
Assert.AreEqual(1, result.ProcessingRequests.Count);
var initialRunInfo = result.IngestorRunInfo;
Assert.AreEqual(request.IndexFileName, initialRunInfo.IndexFileName);
Assert.AreEqual(request.RootPath, initialRunInfo.IndexFilePath);
Assert.AreEqual(IngestorTypes.XdiDnaNotice, initialRunInfo.IngestorType);
Assert.AreEqual(DateTime.Now.Date, initialRunInfo.StartTimeStamp.Date);
Assert.AreEqual("\\Test\\", initialRunInfo.IndexFilePath);
}
[Test]
public async Task HandleIndexRequest_IngestorRequest_GetFileContent_ThrowsException_Failure()
{
var request = new IngestorRequest
{
RootPath = "\\Test\\",
IndexFileName = "Test.csv"
};
_mockFileOperationsApiService.Setup(x => x.GetFileContent(It.IsAny<string>())).ThrowsAsync(new Exception("Error"));
var result = await _xdiDnaNoticeDocumentIndexService.HandleIndexRequest(request);
Assert.IsTrue(result.FatalFailure);
_mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Once);
}
}
@@ -0,0 +1,173 @@
using System;
using Moq;
using NUnit.Framework;
using LCU.Library.Internal.DocumentIngestorModels.Models;
using LCU.API.Internal.DocumentIngestor.Services.IngestionOperationServices;
using LCU.Api.Internal.DispatcherSharedLib.Utilities;
using LCU.API.Internal.DocumentIngestor.Services.MicroApiServices;
using LCU.API.Internal.DocumentIngestor.Configurations;
using LCU.Library.Internal.DispatcherModels.Models;
using LCU.Library.Internal.Exceptions;
using System.Collections.Generic;
using System.Threading.Tasks;
using LCU.Library.Internal.DispatcherModels.Entities;
using LCU.Library.Internal.DocumentIngestorModels.Enums;
using LCU.Api.Internal.DispatcherSharedLib.BuilderServices;
using LCU.Library.Internal.DispatcherModels.Enums;
using LCU.Library.Internal.FileOperationsModels.Models;
namespace LCU.API.Internal.DocumentIngestorTests.Services.IngestionOperationServices;
public class BatchIngestionServiceTest
{
private BatchIngestionService _batchIngestionService;
private ApiConfiguration _apiConfiguration;
private DispatcherJobCreationConfiguration _dispatcherJobCreationConfiguration;
private Mock<IFileOperationsApiService> _mockFileOperationsApiService;
private Mock<IRequestBuilderService> _mockDispatcherRequestBuilder;
[SetUp]
public void Setup()
{
_apiConfiguration = new ApiConfiguration
{
TimeZone = "America/Chicago"
};
_dispatcherJobCreationConfiguration = new DispatcherJobCreationConfiguration
{
DocumentIngestorDispatcherErrorRecipients = new List<string>
{
"[email protected]"
},
JobTags = new List<JobTag>
{
new JobTag
{
JobTagId = 0,
JobId = 0,
TagId = 1
}
}
};
_mockFileOperationsApiService = new Mock<IFileOperationsApiService>();
_mockDispatcherRequestBuilder = new Mock<IRequestBuilderService>();
_batchIngestionService = new BatchIngestionService
(
_apiConfiguration,
_dispatcherJobCreationConfiguration,
_mockFileOperationsApiService.Object,
_mockDispatcherRequestBuilder.Object
);
}
[Test]
public void HandleBatchIngestion_ArgumentNullException_RequestNull()
{
BatchIngestionRequest request = null;
Assert.ThrowsAsync<ArgumentNullException>(async () => await _batchIngestionService.HandleBatchIngestion(request));
_mockDispatcherRequestBuilder.Verify(x => x.CreateJob(It.IsAny<JobDetails>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.BuildDynamicDirectoryList(It.IsAny<DynamicDirectoryListRequest>()), Times.Never);
_mockDispatcherRequestBuilder.Verify(x => x.AddWorkItem(It.IsAny<CreateDirectoryRequest>(), It.IsAny<WorkItemDetails>(), ActionType.CreateDirectory), Times.Never);
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>()), Times.Never);
_mockDispatcherRequestBuilder.Verify(x => x.AddWorkItem(It.IsAny<IngestorRequest>(), It.IsAny<WorkItemDetails>(), ActionType.DocumentIngestor), Times.Never);
_mockDispatcherRequestBuilder.Verify(x => x.SendDispatcherRequest(null), Times.Never);
}
[Test]
public void HandleBatchIngestion_ServiceException_BuildDynamicDirectoryList_ThrowsException()
{
var request = new BatchIngestionRequest
{
RootBasePath = "\\\\Tester\\path",
ParentDynamicDirectory = "TestParentDynamicDirectory",
IngestorType = IngestorTypes.FosTaxStatement
};
_mockFileOperationsApiService.Setup(x => x.BuildDynamicDirectoryList(It.IsAny<DynamicDirectoryListRequest>())).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _batchIngestionService.HandleBatchIngestion(request));
_mockDispatcherRequestBuilder.Verify(x => x.CreateJob(It.IsAny<JobDetails>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.BuildDynamicDirectoryList(It.IsAny<DynamicDirectoryListRequest>()), Times.Once);
_mockDispatcherRequestBuilder.Verify(x => x.AddWorkItem(It.IsAny<CreateDirectoryRequest>(), It.IsAny<WorkItemDetails>(), ActionType.CreateDirectory), Times.Never);
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>()), Times.Never);
_mockDispatcherRequestBuilder.Verify(x => x.AddWorkItem(It.IsAny<IngestorRequest>(), It.IsAny<WorkItemDetails>(), ActionType.DocumentIngestor), Times.Never);
_mockDispatcherRequestBuilder.Verify(x => x.SendDispatcherRequest(null), Times.Never);
}
[Test]
public async Task HandleBatchIngestion_BuildDynamicFileList_ThrowsException()
{
var request = new BatchIngestionRequest
{
RootBasePath = "\\\\Tester\\path",
ParentDynamicDirectory = "TestParentDynamicDirectory",
IngestorType = IngestorTypes.FosTaxStatement
};
var dynamicDirectoryListResult = new List<string>
{
"TestParentDynamicDirectory1",
"TestParentDynamicDirectory2"
};
_mockFileOperationsApiService.Setup(x => x.BuildDynamicDirectoryList(It.IsAny<DynamicDirectoryListRequest>())).ReturnsAsync(dynamicDirectoryListResult);
_mockDispatcherRequestBuilder.Setup(x => x.CreateJob(It.IsAny<JobDetails>()));
_mockFileOperationsApiService.Setup(x => x.BuildDynamicFile(It.IsAny<DynamicFileListRequest>())).ThrowsAsync(new Exception("Error"));
await _batchIngestionService.HandleBatchIngestion(request);
_mockFileOperationsApiService.Verify(x => x.BuildDynamicDirectoryList(It.IsAny<DynamicDirectoryListRequest>()), Times.Once);
_mockDispatcherRequestBuilder.Verify(x => x.CreateJob(It.IsAny<JobDetails>()), Times.Exactly(2));
_mockDispatcherRequestBuilder.Verify(x => x.AddWorkItem(It.IsAny<CreateDirectoryRequest>(), It.IsAny<WorkItemDetails>(), ActionType.CreateDirectory), Times.Exactly(2));
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFile(It.IsAny<DynamicFileListRequest>()), Times.Exactly(2));
_mockDispatcherRequestBuilder.Verify(x => x.AddWorkItem(It.IsAny<IngestorRequest>(), It.IsAny<WorkItemDetails>(), ActionType.DocumentIngestor), Times.Never);
_mockDispatcherRequestBuilder.Verify(x => x.SendDispatcherRequest(null), Times.Never);
}
[Test]
public async Task HandleBatchIngestion_Success()
{
var request = new BatchIngestionRequest
{
RootBasePath = "\\\\Tester\\path",
ParentDynamicDirectory = "TestParentDynamicDirectory",
DynamicIndexFileName = "TestIndexFile",
IngestorType = IngestorTypes.FosTaxStatement,
IngestionDate = Convert.ToDateTime("1/1/2022")
};
var dynamicDirectoryListResult = new List<string>
{
"TestParentDynamicDirectory1",
"TestParentDynamicDirectory2"
};
_mockFileOperationsApiService.Setup(x => x.BuildDynamicDirectoryList(It.IsAny<DynamicDirectoryListRequest>())).ReturnsAsync(dynamicDirectoryListResult);
_mockDispatcherRequestBuilder.Setup(x => x.CreateJob(It.IsAny<JobDetails>()));
var dynamicFileListRequest1 = new DynamicFileListRequest
{
Path = "\\\\Tester\\path\\01012022\\TestParentDynamicDirectory1\\",
Filename = "TestIndexFile",
DynamicFileSettings = null
};
var dynamicFileResult1 = "TestIndexFile1";
_mockFileOperationsApiService.Setup(x => x.BuildDynamicFile(It.Is<DynamicFileListRequest>(x => x.Path == dynamicFileListRequest1.Path))).ReturnsAsync(dynamicFileResult1);
var dynamicFileListRequest2 = new DynamicFileListRequest
{
Path = "\\\\Tester\\path\\01012022\\TestParentDynamicDirectory2\\",
Filename = "TestIndexFile",
DynamicFileSettings = null
};
var dynamicFileResult2 = "TestIndexFile2";
_mockFileOperationsApiService.Setup(x => x.BuildDynamicFile(It.Is<DynamicFileListRequest>(x => x.Path == dynamicFileListRequest2.Path))).ReturnsAsync(dynamicFileResult2);
await _batchIngestionService.HandleBatchIngestion(request);
_mockFileOperationsApiService.Verify(x => x.BuildDynamicDirectoryList(It.IsAny<DynamicDirectoryListRequest>()), Times.Once);
_mockDispatcherRequestBuilder.Verify(x => x.CreateJob(It.IsAny<JobDetails>()), Times.Exactly(2));
_mockDispatcherRequestBuilder.Verify(x => x.AddWorkItem(It.IsAny<CreateDirectoryRequest>(), It.IsAny<WorkItemDetails>(), ActionType.CreateDirectory), Times.Exactly(2));
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFile(It.IsAny<DynamicFileListRequest>()), Times.Exactly(2));
_mockDispatcherRequestBuilder.Verify(x => x.AddWorkItem(It.IsAny<IngestorRequest>(), It.IsAny<WorkItemDetails>(), ActionType.DocumentIngestor), Times.Exactly(2));
_mockDispatcherRequestBuilder.Verify(x => x.SendDispatcherRequest(null), Times.Exactly(2));
}
}
@@ -0,0 +1,242 @@
using System;
using System.Threading.Tasks;
using System.Collections.Generic;
using Moq;
using NUnit.Framework;
using Newtonsoft.Json;
using LCU.API.Internal.DocumentIngestor.Services;
using LCU.API.Internal.DocumentIngestor.Services.IngestionOperationServices;
using LCU.API.Internal.DocumentIngestor.Services.QueueServices;
using LCU.Library.Internal.DocumentIngestorModels.Models;
using LCU.Library.Internal.ApiResponse.Models;
using LCU.Library.Internal.DocumentIngestorModels.Constants;
using LCU.Library.Internal.DocumentIngestorModels.Entities;
using LCU.Library.Internal.Exceptions;
using LCU.Library.Internal.DocumentIngestorModels.Enums;
namespace LCU.API.Internal.DocumentIngestorTests.Services.IngestionOperationServices;
public class CompletionServiceTest
{
private CompletionService _completionService;
private Mock<IIngestorRunInfoService> _mockIngestorRunInfoService;
private Mock<IDocumentProcessingInfoService> _mockDocumentProcessingInfoService;
private readonly Mock<IResponseQueue> _responseQueue = new();
[SetUp]
public void Setup()
{
_mockIngestorRunInfoService = new Mock<IIngestorRunInfoService>();
_mockDocumentProcessingInfoService = new Mock<IDocumentProcessingInfoService>();
_completionService = new CompletionService(_mockIngestorRunInfoService.Object, _mockDocumentProcessingInfoService.Object, _responseQueue.Object);
}
[Test]
public void HandleCompletion_Exception_ResponseNull()
{
Response request = null;
Assert.ThrowsAsync<ArgumentNullException>(async () => await _completionService.HandleCompletion(null));
_mockDocumentProcessingInfoService.Verify(x => x.UpdateStatusAndAddLog(It.IsAny<int>(),
It.IsAny<ProcessStatusTypes>(),
It.IsAny<List<string>>(),
It.IsAny<string>(),
It.IsAny<bool?>()), Times.Never);
}
[Test]
public void HandleCompletion_Exception_RequestNull()
{
var request = new Response();
Assert.ThrowsAsync<ArgumentNullException>(async () => await _completionService.HandleCompletion(new List<Response>() { request }));
_mockDocumentProcessingInfoService.Verify(x => x.UpdateStatusAndAddLog(It.IsAny<int>(),
It.IsAny<ProcessStatusTypes>(),
It.IsAny<List<string>>(),
It.IsAny<string>(),
It.IsAny<bool?>()), Times.Never);
}
[Test]
public async Task HandleCompletion_Update_Success_Complete()
{
var documentProcessInfo = new DocumentProcessingInfo()
{
DocumentProcessingInfoId = 1,
IngestorRunInfoId = Guid.NewGuid(),
DocumentValuePayload = "{test}",
StatusType = ProcessStatusTypes.Completed
};
var ingestorRunInfo = new IngestorRunInfo()
{
IngestorRunInfoId = documentProcessInfo.IngestorRunInfoId,
IndexFilePath = "\\Test\\",
IndexTotal = 1
};
_mockIngestorRunInfoService.Setup(service =>
service.GetListByIdAsync(It.IsAny<List<Guid>>())).ReturnsAsync(new List<IngestorRunInfo>() { ingestorRunInfo });
var processResult = new ProcessResult()
{
Success = true,
AttemptToArchive = false,
};
var processingRequest = new ProcessingRequest()
{
IngestorRunInfoId = documentProcessInfo.IngestorRunInfoId
};
var completionRequest = new CompletionRequest()
{
ProcessingRequest = processingRequest,
ProcessResult = processResult
};
var response = new Response()
{
Successful = true,
ResponsePayload = JsonConvert.SerializeObject(completionRequest)
};
var completionProcessingData = new CompletionProcessingData()
{
DocumentProcessingInfo = documentProcessInfo,
CompletionRequest = completionRequest
};
_mockDocumentProcessingInfoService.Setup(service => service.UpdateProcessCountAndStatusAndAddLog(
It.IsAny<List<CompletionRequest>>()))
.ReturnsAsync(new List<CompletionProcessingData>() { completionProcessingData});
_mockDocumentProcessingInfoService.Setup(service => service.GetCompletedFirstPassByIngestorRunInfoIdAsync(
It.IsAny<Guid>())).ReturnsAsync(
new List<DocumentProcessingInfo>() { documentProcessInfo });
await _completionService.HandleCompletion(new List<Response>() { response });
_mockDocumentProcessingInfoService.Verify(x => x.UpdateProcessCountAndStatusAndAddLog(It.IsAny<List<CompletionRequest>>()), Times.Once);
_mockIngestorRunInfoService.Verify(x => x.GetListByIdAsync(It.IsAny<List<Guid>>()), Times.Once);
_mockDocumentProcessingInfoService.Verify(x => x.GetCompletedFirstPassByIngestorRunInfoIdAsync(It.IsAny<Guid>()), Times.Once);
_mockIngestorRunInfoService.Verify(x => x.Update(It.IsAny<IngestorRunInfo>()), Times.Once);
}
[Test]
public async Task HandleCompletion_Update_Success_Incomplete()
{
var documentProcessInfo = new DocumentProcessingInfo()
{
DocumentProcessingInfoId = 1,
IngestorRunInfoId = Guid.NewGuid(),
DocumentValuePayload = "{test}",
StatusType = ProcessStatusTypes.Completed
};
var ingestorRunInfo = new IngestorRunInfo()
{
IngestorRunInfoId = documentProcessInfo.IngestorRunInfoId,
IndexFilePath = "\\Test\\",
IndexTotal = 5
};
_mockIngestorRunInfoService.Setup(service =>
service.GetListByIdAsync(It.IsAny<List<Guid>>())).ReturnsAsync(new List<IngestorRunInfo>() { ingestorRunInfo });
var processResult = new ProcessResult()
{
Success = true,
AttemptToArchive = false,
};
var processingRequest = new ProcessingRequest()
{
IngestorRunInfoId = documentProcessInfo.IngestorRunInfoId
};
var completionRequest = new CompletionRequest()
{
ProcessingRequest = processingRequest,
ProcessResult = processResult
};
var response = new Response()
{
Successful = true,
ResponsePayload = JsonConvert.SerializeObject(completionRequest)
};
var completionProcessingData = new CompletionProcessingData()
{
DocumentProcessingInfo = documentProcessInfo,
CompletionRequest = completionRequest
};
_mockDocumentProcessingInfoService.Setup(service => service.UpdateProcessCountAndStatusAndAddLog(
It.IsAny<List<CompletionRequest>>()))
.ReturnsAsync(new List<CompletionProcessingData>() { completionProcessingData });
_mockDocumentProcessingInfoService.Setup(service => service.GetCompletedFirstPassByIngestorRunInfoIdAsync(
It.IsAny<Guid>())).ReturnsAsync(
new List<DocumentProcessingInfo>() { documentProcessInfo });
await _completionService.HandleCompletion(new List<Response>() { response });
_mockDocumentProcessingInfoService.Verify(x => x.UpdateProcessCountAndStatusAndAddLog(It.IsAny<List<CompletionRequest>>()), Times.Once);
_mockIngestorRunInfoService.Verify(x => x.GetListByIdAsync(It.IsAny<List<Guid>>()), Times.Once);
_mockDocumentProcessingInfoService.Verify(x => x.GetCompletedFirstPassByIngestorRunInfoIdAsync(It.IsAny<Guid>()), Times.Never);
_mockIngestorRunInfoService.Verify(x => x.Update(It.IsAny<IngestorRunInfo>()), Times.Once);
}
[Test]
public void HandleCompletion_UpdateRunInfoStatusById_ThrowsException()
{
var documentProcessInfo = new DocumentProcessingInfo()
{
DocumentProcessingInfoId = 1,
IngestorRunInfoId = Guid.NewGuid(),
DocumentValuePayload = "{test}",
StatusType = ProcessStatusTypes.Completed
};
var ingestorRunInfo = new IngestorRunInfo()
{
IngestorRunInfoId = new Guid(),
IndexFilePath = "\\Test\\",
IndexTotal = 1
};
var processResult = new ProcessResult()
{
Success = true,
AttemptToArchive = false,
};
var processingRequest = new ProcessingRequest()
{
IngestorRunInfoId = documentProcessInfo.IngestorRunInfoId
};
var completionRequest = new CompletionRequest()
{
ProcessingRequest = processingRequest,
ProcessResult = processResult
};
var response = new Response()
{
Successful = true,
ResponsePayload = JsonConvert.SerializeObject(completionRequest)
};
var completionProcessingData = new CompletionProcessingData()
{
DocumentProcessingInfo = documentProcessInfo,
CompletionRequest = completionRequest
};
_mockDocumentProcessingInfoService.Setup(service => service.UpdateProcessCountAndStatusAndAddLog(
It.IsAny<List<CompletionRequest>>()))
.ReturnsAsync(new List<CompletionProcessingData>() { completionProcessingData });
_mockIngestorRunInfoService.Setup(x => x.GetListByIdAsync(It.IsAny<List<Guid>>())).ThrowsAsync(new Exception("Test Exception"));
Assert.ThrowsAsync<ServiceException>(async () => await _completionService.HandleCompletion(new List<Response>() { response }));
_mockDocumentProcessingInfoService.Verify(x => x.UpdateProcessCountAndStatusAndAddLog(It.IsAny<List<CompletionRequest>>()), Times.Once);
_mockIngestorRunInfoService.Verify(x => x.Update(It.IsAny<IngestorRunInfo>()), Times.Never);
}
}
@@ -0,0 +1,196 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Moq;
using NUnit.Framework;
using LCU.API.Internal.DocumentIngestor.Services.IngestionOperationServices;
using LCU.Library.Internal.DocumentIngestorModels.Models;
using LCU.API.Internal.DocumentIngestor.Services.MicroApiServices;
using LCU.API.Internal.DocumentIngestor.Services.QueueServices;
using LCU.API.Internal.DocumentIngestor.Services.DocumentProcessorServices;
using LCU.API.Internal.DocumentIngestor.Configurations;
using LCU.API.Internal.DocumentIngestor.Services.IndexParserServices;
using LCU.Library.Internal.DocumentIngestorModels.Enums;
using LCU.Library.Internal.DocumentIngestorModels.Models.IndexFileDocuments;
using LCU.Library.Internal.FileOperationsModels.Models;
using LCU.Library.Internal.LCUServiceFactory.Services;
namespace LCU.API.Internal.DocumentIngestorTests.Services.IngestionOperationServices;
public class DocumentProcessorServiceTest
{
private DocumentProcessorService _documentProcessorService;
private ApiConfiguration _apiConfiguration;
private Mock<IQueueDocumentProcessingService> _mockQueueDocumentProcessingService;
private Mock<IQueueCompletionService> _mockQueueCompletionService;
private Mock<IFileOperationsApiService> _mockFileOperationsApiService;
private Mock<ILcuServiceFactory<IDocumentProcessingService>> _mockLcuServiceFactory;
private IDictionary<Type, object> _handlerServicesByType;
[SetUp]
public void Setup()
{
_apiConfiguration = new ApiConfiguration
{
DocumentProcessingReQueueCountLimit = 1
};
_mockQueueDocumentProcessingService = new Mock<IQueueDocumentProcessingService>();
_mockQueueCompletionService = new Mock<IQueueCompletionService>();
_mockFileOperationsApiService = new Mock<IFileOperationsApiService>();
_mockLcuServiceFactory = new Mock<ILcuServiceFactory<IDocumentProcessingService>>();
_documentProcessorService = new DocumentProcessorService(_apiConfiguration,
_mockQueueDocumentProcessingService.Object,
_mockQueueCompletionService.Object,
_mockFileOperationsApiService.Object,
_mockLcuServiceFactory.Object);
}
[Test]
public void HandleIngestion_Exception_RequestNull()
{
ProcessingRequest request = null;
Assert.ThrowsAsync<ArgumentNullException>(async () => await _documentProcessorService.HandleProcessing(request));
_mockFileOperationsApiService.Verify(x => x.ValidateFileExistsAndNotArchived(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
_mockQueueCompletionService.Verify(x => x.QueueCompletionRequest(It.IsAny<ProcessingRequest>(), It.IsAny<ProcessResult>()), Times.Never);
_mockLcuServiceFactory.Verify(x => x.GetService(It.IsAny<IngestorTypes>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.DirectMoveFile(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()), Times.Never);
}
[Test]
public async Task HandleIngestion_DocumentDoesNotNeedProcessing_Update_Return()
{
var filePath = "\\Test\\Test\\000001Test.pdf";
var archiveFilePath = "\\Test\\Test\\Archived\\000001Test.pdf";
_mockFileOperationsApiService.Setup(service => service.ValidateFileExistsAndNotArchived(filePath, archiveFilePath))
.ReturnsAsync(false);
var ingestorRequest = new IngestorRequest
{
RootPath = "\\Test\\Test"
};
var request = new ProcessingRequest()
{
DocumentFileName = "000001Test.pdf",
IngestorRequest = ingestorRequest
};
await _documentProcessorService.HandleProcessing(request);
_mockFileOperationsApiService.Verify(x => x.ValidateFileExistsAndNotArchived(filePath,
archiveFilePath), Times.Once);
_mockQueueCompletionService.Verify(x => x.QueueCompletionRequest(request, It.Is<ProcessResult>(y => y.Success == true
&& y.AttemptToArchive == false
&& y.MessageStack.Count == 1
&& y.ProcessStatusType == ProcessStatusTypes.Completed)
), Times.Once);
_mockLcuServiceFactory.Verify(x => x.GetService(It.IsAny<IngestorTypes>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.DirectMoveFile(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()), Times.Never);
}
[Test]
public async Task HandlePostProcessingFailure_ProcessResult_SuccessFalse_QueueDocumentProcessing()
{
var request = new ProcessingRequest
{
IngestorRequest = new()
{
IngestorType = IngestorTypes.FosLoanStatement
},
RetryCount = 0
};
var result = new ProcessResult
{
Success = false,
ProcessStatusType = ProcessStatusTypes.CriticalFailure
};
await _documentProcessorService.HandlePostProcessingFailure(request, result);
_mockQueueDocumentProcessingService.Verify(x => x.QueueDocumentProcessingRequest(It.IsAny<ProcessingRequest>()), Times.Once);
_mockQueueCompletionService.Verify(x => x.QueueCompletionRequest(It.IsAny<ProcessingRequest>(), It.IsAny<ProcessResult>()), Times.Never);
}
[Test]
public async Task HandlePostProcessingFailure_ProcessResult_SuccessFalse_QueueCompletion()
{
var request = new ProcessingRequest
{
RetryCount = 1
};
var result = new ProcessResult
{
Success = false,
ProcessStatusType = ProcessStatusTypes.CriticalFailure
};
await _documentProcessorService.HandlePostProcessingFailure(request, result);
_mockQueueDocumentProcessingService.Verify(x => x.QueueDocumentProcessingRequest(It.IsAny<ProcessingRequest>()), Times.Never);
_mockQueueCompletionService.Verify(x => x.QueueCompletionRequest(It.IsAny<ProcessingRequest>(), It.IsAny<ProcessResult>()), Times.Once);
}
[TestCase(IngestorTypes.FosTaxStatement, typeof(IDocumentProcessingService))]
[TestCase(IngestorTypes.FosDnaDocument, typeof(IDocumentProcessingService))]
[TestCase(IngestorTypes.FosLoanStatement, typeof(IDocumentProcessingService))]
[TestCase(IngestorTypes.XdiDnaNotice, typeof(IDocumentProcessingService))]
[TestCase(IngestorTypes.OsgDnaNoticesDocument, typeof(IDocumentProcessingService))]
[TestCase(IngestorTypes.XdiActionNotice, typeof(IDocumentProcessingService))]
[TestCase(IngestorTypes.OsgHistoricalDocument, typeof(IDocumentProcessingService))]
[Test]
public async Task HandleProcessing_ByTypedRequest_HandledByMatchingServiceAndArchived(IngestorTypes type, Type handlerType)
{
var request = new ProcessingRequest
{
IngestorRequest = new IngestorRequest
{
IngestorType = type,
RootPath = Guid.NewGuid().ToString(),
},
DocumentFileName = Guid.NewGuid().ToString()
};
var result = new ProcessResult
{
Success = true
};
var documentProcessorService = new Mock<IDocumentProcessingService>();
_mockLcuServiceFactory.Setup(x => x.GetService(request.IngestorRequest.IngestorType)).Returns(documentProcessorService.Object);
documentProcessorService.Setup(x => x.ProcessRequest(request)).ReturnsAsync(result);
_mockFileOperationsApiService
.Setup
(
fs => fs.ValidateFileExistsAndNotArchived
(
request.IngestorRequest.RootPath + request.DocumentFileName,
request.IngestorRequest.ArchivePath + request.DocumentFileName
)
)
.ReturnsAsync(true);
_mockFileOperationsApiService
.Setup(fs => fs.DirectMoveFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
.ReturnsAsync(new RequestResponse { IsSuccessful = true });
await _documentProcessorService.HandleProcessing(request);
_mockLcuServiceFactory.Verify(x => x.GetService(request.IngestorRequest.IngestorType), Times.Once);
_mockFileOperationsApiService
.Verify
(
s => s.DirectMoveFile
(
request.IngestorRequest.RootPath,
request.DocumentFileName,
request.IngestorRequest.ArchivePath
),
Times.Once
);
}
}
@@ -0,0 +1,633 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Moq;
using NUnit.Framework;
using LCU.Library.Internal.DocumentIngestorModels.Entities;
using LCU.Library.Internal.DocumentIngestorModels.Enums;
using LCU.Library.Internal.DocumentIngestorModels.Models;
using LCU.Library.Internal.Exceptions;
using LCU.API.Internal.DocumentIngestor.Services.QueueServices;
using LCU.API.Internal.DocumentIngestor.Services;
using LCU.API.Internal.DocumentIngestor.Services.IndexParserServices;
using LCU.API.Internal.DocumentIngestor.Services.IngestionOperationServices;
using LCU.API.Internal.DocumentIngestor.Services.MicroApiServices;
using LCU.Library.Internal.LCUServiceFactory.Services;
namespace LCU.API.Internal.DocumentIngestorTests.Services.IngestionOperationServices;
public class IndexServiceTest
{
private IndexService _indexService;
private Mock<IQueueDocumentProcessingService> _mockQueueDocumentProcessing;
private Mock<IIngestorRunInfoService> _mockIngestorRunInfoService;
private Mock<IDocumentProcessingInfoService> _mockDocumentProcessingInfoService;
private Mock<IDocumentTypeRetrieverService> _mockDocumentTypeRetrieverService;
private Mock<ILcuServiceFactory<IIndexParserService>> _mockLcuServiceFactory;
private IDictionary<Type, object> _handlerServicesByType;
[SetUp]
public void Setup()
{
_mockQueueDocumentProcessing = new Mock<IQueueDocumentProcessingService>();
_mockIngestorRunInfoService = new Mock<IIngestorRunInfoService>();
_mockDocumentProcessingInfoService = new Mock<IDocumentProcessingInfoService>();
_mockDocumentTypeRetrieverService = new Mock<IDocumentTypeRetrieverService>();
_mockLcuServiceFactory = new Mock<ILcuServiceFactory<IIndexParserService>>();
_indexService = new IndexService(_mockQueueDocumentProcessing.Object,
_mockIngestorRunInfoService.Object,
_mockDocumentProcessingInfoService.Object,
_mockDocumentTypeRetrieverService.Object,
_mockLcuServiceFactory.Object);
}
[Test]
public void HandleIngestion_Exception_RequestNull()
{
IngestorRequest request = null;
Assert.ThrowsAsync<ArgumentNullException>(async () => await _indexService.HandleIngestion(request));
_mockLcuServiceFactory.Verify(x => x.GetService(It.IsAny<string>()), Times.Never);
_mockIngestorRunInfoService.Verify(x => x.SaveAsync(It.IsAny<IngestorRunInfo>()), Times.Never);
_mockDocumentProcessingInfoService.Verify(x => x.SaveAsync(It.IsAny<DocumentProcessingInfo>()), Times.Never);
_mockQueueDocumentProcessing.Verify(x => x.QueueDocumentProcessingRequest(It.IsAny<ProcessingRequest>()), Times.Never);
_mockDocumentProcessingInfoService.Verify(x => x.UpdateStatusAndAddLog(It.IsAny<DocumentProcessingInfo>(),
It.IsAny<ProcessStatusTypes>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<bool?>()), Times.Never);
}
[Test]
public void HandleIngestion_Exception_Result_FatalFailure()
{
var request = new IngestorRequest()
{
IngestorType = IngestorTypes.FosTaxStatement,
RootPath = "\\test\\test",
IndexFileName = "TestIndex.csv"
};
var result = new IngestorResult(true, "fail");
var indexParsingService = new Mock<IIndexParserService>();
_mockLcuServiceFactory.Setup(x => x.GetService(request.IngestorType)).Returns(indexParsingService.Object);
indexParsingService.Setup(x => x.HandleIndexRequest(request)).ReturnsAsync(result);
Assert.ThrowsAsync<ServiceException>(async () => await _indexService.HandleIngestion(request));
indexParsingService.Verify(x => x.HandleIndexRequest(request), Times.Once);
_mockIngestorRunInfoService.Verify(x => x.SaveAsync(It.IsAny<IngestorRunInfo>()), Times.Never);
_mockDocumentProcessingInfoService.Verify(x => x.SaveAsync(It.IsAny<DocumentProcessingInfo>()), Times.Never);
_mockQueueDocumentProcessing.Verify(x => x.QueueDocumentProcessingRequest(It.IsAny<ProcessingRequest>()), Times.Never);
_mockDocumentProcessingInfoService.Verify(x => x.UpdateStatusAndAddLog(It.IsAny<DocumentProcessingInfo>(),
It.IsAny<ProcessStatusTypes>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<bool?>()), Times.Never);
}
[Test]
public void HandleIngestion_Exception_FosTaxStatementIndexService_ExceptionThrown()
{
var request = new IngestorRequest()
{
IngestorType = IngestorTypes.FosTaxStatement,
RootPath = "\\test\\test",
IndexFileName = "TestIndex.csv"
};
var ingestorRunInfo = new IngestorRunInfo()
{
IngestorRunInfoId = new Guid(),
IndexFilePath = "\\test\\test\\TestIndex.csv",
IndexTotal = 1
};
var indexParsingService = new Mock<IIndexParserService>();
_mockLcuServiceFactory.Setup(x => x.GetService(request.IngestorType)).Returns(indexParsingService.Object);
indexParsingService.Setup(x => x.HandleIndexRequest(request)).Throws(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _indexService.HandleIngestion(request));
indexParsingService.Verify(x => x.HandleIndexRequest(request), Times.Once);
_mockIngestorRunInfoService.Verify(x => x.SaveAsync(It.IsAny<IngestorRunInfo>()), Times.Never);
_mockDocumentProcessingInfoService.Verify(x => x.SaveAsync(It.IsAny<DocumentProcessingInfo>()), Times.Never);
_mockQueueDocumentProcessing.Verify(x => x.QueueDocumentProcessingRequest(It.IsAny<ProcessingRequest>()), Times.Never);
_mockDocumentProcessingInfoService.Verify(x => x.UpdateStatusAndAddLog(It.IsAny<DocumentProcessingInfo>(),
It.IsAny<ProcessStatusTypes>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<bool?>()), Times.Never);
}
[Test]
public void HandleIngestion_Exception_FosDnaDocumentIndexService_ExceptionThrown()
{
var request = new IngestorRequest()
{
IngestorType = IngestorTypes.FosDnaDocument,
RootPath = "\\test\\test",
IndexFileName = "TestIndex.csv"
};
var ingestorRunInfo = new IngestorRunInfo()
{
IngestorRunInfoId = new Guid(),
IndexFilePath = "\\test\\test\\TestIndex.csv",
IndexTotal = 1
};
var indexParsingService = new Mock<IIndexParserService>();
_mockLcuServiceFactory.Setup(x => x.GetService(request.IngestorType)).Returns(indexParsingService.Object);
indexParsingService.Setup(x => x.HandleIndexRequest(request)).Throws(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _indexService.HandleIngestion(request));
indexParsingService.Verify(x => x.HandleIndexRequest(request), Times.Once);
_mockIngestorRunInfoService.Verify(x => x.SaveAsync(It.IsAny<IngestorRunInfo>()), Times.Never);
_mockDocumentProcessingInfoService.Verify(x => x.SaveAsync(It.IsAny<DocumentProcessingInfo>()), Times.Never);
_mockQueueDocumentProcessing.Verify(x => x.QueueDocumentProcessingRequest(It.IsAny<ProcessingRequest>()), Times.Never);
_mockDocumentProcessingInfoService.Verify(x => x.UpdateStatusAndAddLog(It.IsAny<DocumentProcessingInfo>(),
It.IsAny<ProcessStatusTypes>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<bool?>()), Times.Never);
}
[Test]
public async Task HandleIngestion_Success_ThreeProcessRequest_Queued()
{
var request = new IngestorRequest()
{
IngestorType = IngestorTypes.FosTaxStatement,
RootPath = "\\test\\test",
IndexFileName = "TestIndex.csv"
};
var guid = new Guid();
var ingestorRunInfo = new IngestorRunInfo()
{
IngestorRunInfoId = guid,
IndexFilePath = "\\test\\test\\TestIndex.csv",
IndexTotal = 1
};
var result = new IngestorResult();
result.ProcessingRequests = new List<ProcessingRequest>()
{
new ProcessingRequest()
{
IngestorRunInfoId = guid,
IngestorRequest = request,
DocumentFileName = "Test1.pdf",
DocumentValuePayload = "{jsonblah: hello1}",
DocumentTypeDisplayName = "OneThousandNinetyNineInt"
},
new ProcessingRequest()
{
IngestorRunInfoId = guid,
IngestorRequest = request,
DocumentFileName = "Test2.pdf",
DocumentValuePayload = "{jsonblah: hello2}",
DocumentTypeDisplayName = "OneThousandNinetyNineInt"
},
new ProcessingRequest()
{
IngestorRunInfoId = guid,
IngestorRequest = request,
DocumentFileName = "Test3.pdf",
DocumentValuePayload = "{jsonblah: hello3}",
DocumentTypeDisplayName = "OneThousandNinetyNineInt"
}
};
result.IngestorRunInfo = new IngestorRunInfo(Guid.NewGuid(),
Convert.ToDateTime("1/1/2022"),
IngestorTypes.FosTaxStatement,
"\\test\\test\\",
"Test.csv",
1);
var documentCodeDetailInfo = new DocumentCodeDetailInfo()
{
DocumentBusinessName = "TestStatement",
DocumentType = "TestDocumentType"
};
var indexParsingService = new Mock<IIndexParserService>();
_mockLcuServiceFactory.Setup(x => x.GetService(request.IngestorType)).Returns(indexParsingService.Object);
indexParsingService.Setup(x => x.HandleIndexRequest(request)).ReturnsAsync(result);
_mockDocumentTypeRetrieverService.Setup(x => x.GetDocumentCodeDetailByDisplayName(It.IsAny<string>()))
.ReturnsAsync(documentCodeDetailInfo);
_mockIngestorRunInfoService.Setup(x => x.SaveAsync(It.IsAny<IngestorRunInfo>())).ReturnsAsync(result.IngestorRunInfo);
var documentProcessingInfos = new List<DocumentProcessingInfo>()
{
new()
{
IngestorRunInfoId = guid,
DocumentProcessingInfoId = 1,
DocumentFileName = "Test1.pdf",
DocumentValuePayload = "{jsonblah: hello1}"
},
new()
{
IngestorRunInfoId = guid,
DocumentProcessingInfoId = 2,
DocumentFileName = "Test2.pdf",
DocumentValuePayload = "{jsonblah: hello2}",
},
new()
{
IngestorRunInfoId = guid,
DocumentProcessingInfoId = 3,
DocumentFileName = "Test3.pdf",
DocumentValuePayload = "{jsonblah: hello3}",
}
};
_mockDocumentProcessingInfoService.Setup(x => x.GetByIngestorRunInfoIdAsync(It.IsAny<Guid>())).ReturnsAsync(documentProcessingInfos);
_mockDocumentProcessingInfoService.Setup(x => x.SaveRangeAsync(It.IsAny<DocumentProcessingInfo[]>()));
await _indexService.HandleIngestion(request);
indexParsingService.Verify(x => x.HandleIndexRequest(request), Times.Once);
_mockDocumentTypeRetrieverService.Verify(x => x.GetDocumentCodeDetailByDisplayName(It.IsAny<string>()), Times.Exactly(1));
_mockIngestorRunInfoService.Verify(x => x.SaveAsync(It.IsAny<IngestorRunInfo>()), Times.Once);
_mockDocumentProcessingInfoService.Verify(x => x.SaveRangeAsync(It.IsAny<DocumentProcessingInfo[]>()), Times.Exactly(1));
_mockQueueDocumentProcessing.Verify(x => x.QueueDocumentProcessingRequest(It.IsAny<ProcessingRequest>()), Times.Exactly(3));
_mockDocumentProcessingInfoService.Verify(x => x.UpdateStatusAndAddLog(It.IsAny<DocumentProcessingInfo>(),
It.IsAny<ProcessStatusTypes>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<bool?>()), Times.Never);
}
[Test]
public async Task HandleIngestion_ExceptionThrown_OnQueue()
{
var request = new IngestorRequest()
{
IngestorType = IngestorTypes.FosTaxStatement,
RootPath = "\\test\\test",
IndexFileName = "TestIndex.csv"
};
var guid = Guid.NewGuid();
var ingestorRunInfo = new IngestorRunInfo()
{
IngestorRunInfoId = guid,
IndexFilePath = "\\test\\test\\TestIndex.csv",
IndexTotal = 1
};
var result = new IngestorResult();
var processRequest1 = new ProcessingRequest()
{
IngestorRunInfoId = guid,
IngestorRequest = request,
DocumentFileName = "Test1.pdf",
DocumentValuePayload = "{jsonblah: hello1}",
DocumentTypeDisplayName = "OneThousandNinetyNineInt"
};
var processRequest2 = new ProcessingRequest()
{
IngestorRunInfoId = guid,
IngestorRequest = request,
DocumentFileName = "Test2.pdf",
DocumentValuePayload = "{jsonblah: hello2}",
DocumentTypeDisplayName = "OneThousandNinetyNineInt"
};
var processRequest3 = new ProcessingRequest()
{
IngestorRunInfoId = guid,
IngestorRequest = request,
DocumentFileName = "Test3.pdf",
DocumentValuePayload = "{jsonblah: hello3}",
DocumentTypeDisplayName = "OneThousandNinetyNineInt"
};
result.ProcessingRequests = new List<ProcessingRequest>()
{
processRequest1,
processRequest2,
processRequest3
};
result.IngestorRunInfo = new IngestorRunInfo(guid,
Convert.ToDateTime("1/1/2022"),
IngestorTypes.FosTaxStatement,
"\\test\\test\\",
"Test.csv",
1);
var documentCodeDetailInfo = new DocumentCodeDetailInfo()
{
DocumentBusinessName = "TestStatement",
DocumentType = "TestDocumentType"
};
var documentProcessingInfos = new List<DocumentProcessingInfo>()
{
new()
{
IngestorRunInfoId = guid,
DocumentProcessingInfoId = 1,
DocumentFileName = "Test1.pdf",
DocumentValuePayload = "{jsonblah: hello1}"
},
new()
{
IngestorRunInfoId = guid,
DocumentProcessingInfoId = 2,
DocumentFileName = "Test2.pdf",
DocumentValuePayload = "{jsonblah: hello2}",
},
new()
{
IngestorRunInfoId = guid,
DocumentProcessingInfoId = 3,
DocumentFileName = "Test3.pdf",
DocumentValuePayload = "{jsonblah: hello3}",
}
};
var indexParsingService = new Mock<IIndexParserService>();
_mockLcuServiceFactory.Setup(x => x.GetService(request.IngestorType)).Returns(indexParsingService.Object);
indexParsingService.Setup(x => x.HandleIndexRequest(request)).ReturnsAsync(result);
_mockDocumentTypeRetrieverService.Setup(x => x.GetDocumentCodeDetailByDisplayName(It.IsAny<string>())).ReturnsAsync(documentCodeDetailInfo);
_mockDocumentProcessingInfoService.Setup(x => x.SaveRangeAsync(It.IsAny<DocumentProcessingInfo[]>()));
_mockDocumentProcessingInfoService.Setup(x => x.GetByIngestorRunInfoIdAsync(It.IsAny<Guid>()))
.ReturnsAsync(documentProcessingInfos);
_mockIngestorRunInfoService.Setup(x => x.SaveAsync(It.IsAny<IngestorRunInfo>())).ReturnsAsync(result.IngestorRunInfo);
var documentProcessingInfo1 = new DocumentProcessingInfo()
{
DocumentProcessingInfoId = 1,
IngestorRunInfoId = guid,
StatusType = ProcessStatusTypes.Processing,
DocumentValuePayload = "{jsonblah: hello1}",
DocumentBusinessName = "1099-INT (interest income) (Tax)",
DocumentType = "Statement"
};
_mockQueueDocumentProcessing.Setup(x => x.QueueDocumentProcessingRequest(processRequest1)).ThrowsAsync(new Exception("Error"));
var documentProcessingInfoUpdated1 = new DocumentProcessingInfo()
{
DocumentProcessingInfoId = 1,
IngestorRunInfoId = guid,
DocumentValuePayload = "{jsonblah: hello1}",
StatusType = ProcessStatusTypes.CriticalFailure,
DocumentBusinessName = "1099-INT (interest income) (Tax)",
DocumentType = "Statement"
};
_mockDocumentProcessingInfoService.Setup(x => x.UpdateStatusAndAddLog(It.IsAny<DocumentProcessingInfo>(),
It.IsAny<ProcessStatusTypes>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<bool?>())).ReturnsAsync(documentProcessingInfoUpdated1);
var documentProcessingInfo2 = new DocumentProcessingInfo()
{
DocumentProcessingInfoId = 2,
IngestorRunInfoId = guid,
StatusType = ProcessStatusTypes.Processing,
DocumentValuePayload = "{jsonblah: hello2}",
DocumentBusinessName = "1099-INT (interest income) (Tax)",
DocumentType = "Statement"
};
_mockQueueDocumentProcessing.Setup(x => x.QueueDocumentProcessingRequest(processRequest2)).ThrowsAsync(new Exception("Error"));
var documentProcessingInfoUpdated2 = new DocumentProcessingInfo()
{
DocumentProcessingInfoId = 2,
IngestorRunInfoId = guid,
DocumentValuePayload = "{jsonblah: hello2}",
StatusType = ProcessStatusTypes.CriticalFailure,
DocumentBusinessName = "1099-INT (interest income) (Tax)",
DocumentType = "Statement"
};
_mockDocumentProcessingInfoService.Setup(x => x.UpdateStatusAndAddLog(It.IsAny<DocumentProcessingInfo>(),
It.IsAny<ProcessStatusTypes>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<bool?>())).ReturnsAsync(documentProcessingInfoUpdated2);
var documentProcessingInfo3 = new DocumentProcessingInfo()
{
DocumentProcessingInfoId = 2,
IngestorRunInfoId = guid,
StatusType = ProcessStatusTypes.Processing,
DocumentValuePayload = "{jsonblah: hello3}",
DocumentBusinessName = "1099-INT (interest income) (Tax)",
DocumentType = "Statement"
};
_mockQueueDocumentProcessing.Setup(x => x.QueueDocumentProcessingRequest(processRequest3)).ThrowsAsync(new Exception("Error"));
var documentProcessingInfoUpdated3 = new DocumentProcessingInfo()
{
DocumentProcessingInfoId = 3,
IngestorRunInfoId = guid,
DocumentValuePayload = "{jsonblah: hello3}",
StatusType = ProcessStatusTypes.CriticalFailure,
DocumentBusinessName = "1099-INT (interest income) (Tax)",
DocumentType = "Statement"
};
_mockDocumentProcessingInfoService.Setup(x => x.UpdateStatusAndAddLog(It.IsAny<DocumentProcessingInfo>(),
It.IsAny<ProcessStatusTypes>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<bool?>())).ReturnsAsync(documentProcessingInfoUpdated3);
await _indexService.HandleIngestion(request);
indexParsingService.Verify(x => x.HandleIndexRequest(request), Times.Once);
_mockDocumentTypeRetrieverService.Verify(x => x.GetDocumentCodeDetailByDisplayName(It.IsAny<string>()), Times.Once);
_mockIngestorRunInfoService.Verify(x => x.SaveAsync(It.IsAny<IngestorRunInfo>()), Times.Once);
_mockDocumentProcessingInfoService.Verify(x => x.SaveRangeAsync(It.IsAny<DocumentProcessingInfo[]>()), Times.Once);
_mockQueueDocumentProcessing.Verify(x => x.QueueDocumentProcessingRequest(It.IsAny<ProcessingRequest>()), Times.Exactly(3));
_mockDocumentProcessingInfoService.Verify(x => x.UpdateStatusAndAddLog(It.IsAny<DocumentProcessingInfo>(),
It.IsAny<ProcessStatusTypes>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<bool?>()), Times.Exactly(3));
}
[Test]
public void HandleIngestion_ExceptionThrown_DocumentProcessingInfo_SaveRangeAsync()
{
var request = new IngestorRequest()
{
IngestorType = IngestorTypes.FosTaxStatement,
RootPath = "\\test\\test",
IndexFileName = "TestIndex.csv"
};
var guid = new Guid();
var ingestorRunInfo = new IngestorRunInfo()
{
IngestorRunInfoId = guid,
IndexFilePath = "\\test\\test\\TestIndex.csv",
IndexTotal = 1
};
var result = new IngestorResult();
var processRequest1 = new ProcessingRequest()
{
IngestorRunInfoId = guid,
IngestorRequest = request,
DocumentFileName = "Test1.pdf",
DocumentValuePayload = "{jsonblah: hello1}",
DocumentTypeDisplayName = "1099-INT"
};
result.ProcessingRequests = new List<ProcessingRequest>()
{
processRequest1,
new ProcessingRequest()
{
IngestorRunInfoId = guid,
IngestorRequest = request,
DocumentFileName = "Test2.pdf",
DocumentValuePayload = "{jsonblah: hello2}",
DocumentTypeDisplayName = "1099-INT"
},
new ProcessingRequest()
{
IngestorRunInfoId = guid,
IngestorRequest = request,
DocumentFileName = "Test3.pdf",
DocumentValuePayload = "{jsonblah: hello3}",
DocumentTypeDisplayName = "1099-INT"
}
};
result.IngestorRunInfo = new IngestorRunInfo(Guid.NewGuid(),
Convert.ToDateTime("1/1/2022"),
IngestorTypes.FosTaxStatement,
"\\test\\test\\",
"Test.csv",
1);
var documentCodeDetailInfo = new DocumentCodeDetailInfo()
{
DocumentBusinessName = "TestStatement",
DocumentType = "TestDocumentType"
};
var indexParsingService = new Mock<IIndexParserService>();
_mockLcuServiceFactory.Setup(x => x.GetService(request.IngestorType)).Returns(indexParsingService.Object);
indexParsingService.Setup(x => x.HandleIndexRequest(request)).ReturnsAsync(result);
_mockDocumentTypeRetrieverService.Setup(x => x.GetDocumentCodeDetailByDisplayName(It.IsAny<string>()))
.ReturnsAsync(documentCodeDetailInfo);
_mockIngestorRunInfoService.Setup(x => x.SaveAsync(It.IsAny<IngestorRunInfo>())).ReturnsAsync(result.IngestorRunInfo);
var documentProcessingInfo = new DocumentProcessingInfo()
{
DocumentProcessingInfoId = 1,
IngestorRunInfoId = Guid.NewGuid(),
DocumentValuePayload = "{Test}",
DocumentBusinessName = "1099-INT (interest income) (Tax)",
DocumentType = "Statement"
};
_mockDocumentProcessingInfoService.Setup(x => x.SaveRangeAsync(It.IsAny<DocumentProcessingInfo[]>())).Throws(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _indexService.HandleIngestion(request));
indexParsingService.Verify(x => x.HandleIndexRequest(request), Times.Once);
_mockDocumentTypeRetrieverService.Verify(x => x.GetDocumentCodeDetailByDisplayName(It.IsAny<string>()), Times.Once);
_mockIngestorRunInfoService.Verify(x => x.SaveAsync(It.IsAny<IngestorRunInfo>()), Times.Once);
_mockDocumentProcessingInfoService.Verify(x => x.SaveRangeAsync(It.IsAny<DocumentProcessingInfo[]>()), Times.Once);
_mockQueueDocumentProcessing.Verify(x => x.QueueDocumentProcessingRequest(It.IsAny<ProcessingRequest>()), Times.Never);
_mockDocumentProcessingInfoService.Verify(x => x.UpdateStatusAndAddLog(It.IsAny<DocumentProcessingInfo>(),
It.IsAny<ProcessStatusTypes>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<bool?>()), Times.Never);
}
[Test]
public void HandleIngestion_ExceptionThrown_OnIngestorRunInfoSave()
{
var request = new IngestorRequest()
{
IngestorType = IngestorTypes.FosTaxStatement,
RootPath = "\\test\\test",
IndexFileName = "TestIndex.csv"
};
var guid = new Guid();
var ingestorRunInfo = new IngestorRunInfo()
{
IngestorRunInfoId = guid,
IndexFilePath = "\\test\\test\\TestIndex.csv",
IndexTotal = 1
};
var result = new IngestorResult();
var processRequest1 = new ProcessingRequest()
{
IngestorRunInfoId = guid,
IngestorRequest = request,
DocumentFileName = "Test1.pdf",
DocumentValuePayload = "{jsonblah: hello1}"
};
result.ProcessingRequests = new List<ProcessingRequest>()
{
processRequest1,
new ProcessingRequest()
{
IngestorRunInfoId = guid,
IngestorRequest = request,
DocumentFileName = "Test2.pdf",
DocumentValuePayload = "{jsonblah: hello2}"
},
new ProcessingRequest()
{
IngestorRunInfoId = guid,
IngestorRequest = request,
DocumentFileName = "Test3.pdf",
DocumentValuePayload = "{jsonblah: hello3}"
}
};
result.IngestorRunInfo = new IngestorRunInfo(Guid.NewGuid(),
Convert.ToDateTime("1/1/2022"),
IngestorTypes.FosTaxStatement,
"\\test\\test\\",
"Test.csv",
1);
var indexParsingService = new Mock<IIndexParserService>();
_mockLcuServiceFactory.Setup(x => x.GetService(request.IngestorType)).Returns(indexParsingService.Object);
_mockIngestorRunInfoService.Setup(x => x.SaveAsync(It.IsAny<IngestorRunInfo>())).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _indexService.HandleIngestion(request));
indexParsingService.Verify(x => x.HandleIndexRequest(request), Times.Once);
_mockIngestorRunInfoService.Verify(x => x.SaveAsync(It.IsAny<IngestorRunInfo>()), Times.Never);
_mockDocumentProcessingInfoService.Verify(x => x.SaveAsync(It.IsAny<DocumentProcessingInfo>()), Times.Never);
_mockQueueDocumentProcessing.Verify(x => x.QueueDocumentProcessingRequest(It.IsAny<ProcessingRequest>()), Times.Never);
_mockDocumentProcessingInfoService.Verify(x => x.UpdateStatusAndAddLog(It.IsAny<DocumentProcessingInfo>(),
It.IsAny<ProcessStatusTypes>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<bool?>()), Times.Never);
}
[TestCase(IngestorTypes.FosTaxStatement, typeof(IIndexParserService))]
[TestCase(IngestorTypes.FosDnaDocument, typeof(IIndexParserService))]
[TestCase(IngestorTypes.FosLoanStatement, typeof(IIndexParserService))]
[TestCase(IngestorTypes.XdiDnaNotice, typeof(IIndexParserService))]
[TestCase(IngestorTypes.OsgDnaNoticesDocument, typeof(IIndexParserService))]
[TestCase(IngestorTypes.XdiActionNotice, typeof(IIndexParserService))]
[TestCase(IngestorTypes.OsgHistoricalDocument, typeof(IIndexParserService))]
public async Task PerformIngestor_ByTypedRequest_HandledByMatchingService(IngestorTypes type, Type handlerType)
{
var request = new IngestorRequest
{
IngestorType = type
};
var expectedResult = new IngestorResult();
var indexParsingService = new Mock<IIndexParserService>();
_mockLcuServiceFactory.Setup(x => x.GetService(request.IngestorType)).Returns(indexParsingService.Object);
indexParsingService.Setup(x => x.HandleIndexRequest(request)).ReturnsAsync(expectedResult);
var result = await _indexService.PerformIngestor(request);
Assert.AreSame(expectedResult, result);
}
}
@@ -0,0 +1,731 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Moq;
using NUnit.Framework;
using LCU.API.Internal.DocumentIngestor.Services.IngestionOperationServices;
using LCU.API.Internal.DocumentIngestor.Services.MicroApiServices;
using LCU.API.Internal.DocumentIngestor.Services;
using LCU.Library.Internal.DocumentIngestorModels.Entities;
using LCU.Library.Internal.DocumentIngestorModels.Enums;
using LCU.Library.Internal.DocumentIngestorModels.Models;
using LCU.Library.Internal.Exceptions;
using LCU.Library.Internal.FileOperationsModels.Models;
namespace LCU.API.Internal.DocumentIngestorTests.Services.IngestionOperationServices;
public class IngestionFolderCleanUpTest
{
private IngestionFolderCleanUpService _ingestionFolderCleanUpService;
private Mock<IFileOperationsApiService> _mockFileOperationsApiService;
private Mock<IIngestorRunInfoService> _mockIngestorRunInfoService;
private Mock<IDocumentProcessingInfoService> _mockDocumentProcessingInfoService;
[SetUp]
public void Setup()
{
_mockFileOperationsApiService = new Mock<IFileOperationsApiService>();
_mockIngestorRunInfoService = new Mock<IIngestorRunInfoService>();
_mockDocumentProcessingInfoService = new Mock<IDocumentProcessingInfoService>();
_ingestionFolderCleanUpService = new IngestionFolderCleanUpService
(
_mockFileOperationsApiService.Object,
_mockIngestorRunInfoService.Object,
_mockDocumentProcessingInfoService.Object
);
}
[Test]
public async Task HandleIngestionFolderCleanUp_Success()
{
var now = DateTime.Now.ToString("yyyyMMdd");
// Arrange
var request = new IngestionFolderCleanUpRequest()
{
ArchiveDate = new DateTime(2023, 03, 30),
ArchiveRootPath = "\\\\zeus\\some\\path\\",
IngestionEndedDate = new DateTime(2023, 3, 30)
};
var ingestorRunInfos = new List<IngestorRunInfo>()
{
new ()
{
IngestorRunInfoId = Guid.NewGuid(),
IngestorType = IngestorTypes.FosDnaDocument,
IndexTotal = 5,
IndexFilePath = $"Path1\\{now}\\Path1\\",
IndexFileName = "Filename",
StartTimeStamp = new DateTime(2023, 03, 27),
EndTimeStamp = new DateTime(2023, 03, 27),
ArchiveTimeStamp = null,
},
new ()
{
IngestorRunInfoId = Guid.NewGuid(),
IngestorType = IngestorTypes.FosDnaDocument,
IndexTotal = 5,
IndexFilePath = $"Path2\\{now}\\Path2\\",
IndexFileName = "Filename",
StartTimeStamp = new DateTime(2023, 03, 28),
EndTimeStamp = new DateTime(2023, 03, 28),
ArchiveTimeStamp = null,
},
new ()
{
IngestorRunInfoId = Guid.NewGuid(),
IngestorType = IngestorTypes.FosDnaDocument,
IndexTotal = 5,
IndexFilePath = $"Path3\\{now}\\Path3\\",
IndexFileName = "Filename",
StartTimeStamp = new DateTime(2023, 03, 29),
EndTimeStamp = new DateTime(2023, 03, 29),
ArchiveTimeStamp = null,
}
};
var docProcessingInfoFiles = new List<string>()
{
"Filename1.pdf",
"Filename2.pdf",
"Filename3.pdf",
"Filename4.pdf",
"Filename5.pdf"
};
var successfulRequestResponse = new RequestResponse()
{
IsSuccessful = true,
MessageStack = null,
ReturnResponse = null
};
_mockIngestorRunInfoService.Setup(x => x.FindByIngestionEndDateNotArchived(It.IsAny<DateTime>()))
.Returns(ingestorRunInfos).Verifiable();
_mockIngestorRunInfoService.Setup(x => x.Update(It.IsAny<IngestorRunInfo>())).Verifiable();
_mockDocumentProcessingInfoService.Setup(x => x.CountCompletedByIngestorRunInfoIdAsync(It.IsAny<Guid>()))
.ReturnsAsync(docProcessingInfoFiles.Count).Verifiable();
_mockFileOperationsApiService.Setup(x => x.BuildDynamicFileList(It.Is<DynamicFileListRequest>(d => d.Filename.Equals("{ArchiveFiles}")))).ReturnsAsync(docProcessingInfoFiles).Verifiable();
_mockFileOperationsApiService.Setup(x => x.BuildDynamicFileList(It.Is<DynamicFileListRequest>(d => d.Filename.Equals("{ZipFileRegex}")))).ReturnsAsync(new List<string>() { "" }).Verifiable();
_mockFileOperationsApiService.Setup(x => x.DirectCreateDirectory(It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(successfulRequestResponse).Verifiable();
_mockFileOperationsApiService.Setup(x => x.DirectDeleteDirectory(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>())).ReturnsAsync(successfulRequestResponse).Verifiable();
_mockFileOperationsApiService.Setup(x => x.DirectMoveFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).Verifiable();
// Act
await _ingestionFolderCleanUpService.HandleIngestionFolderCleanUp(request);
// Assert
_mockIngestorRunInfoService.Verify(x => x.FindByIngestionEndDateNotArchived(It.IsAny<DateTime>()), Times.Once);
_mockIngestorRunInfoService.Verify(x => x.Update(It.IsAny<IngestorRunInfo>()), Times.Exactly(ingestorRunInfos.Count));
_mockDocumentProcessingInfoService.Verify(x => x.CountCompletedByIngestorRunInfoIdAsync(It.IsAny<Guid>()), Times.Exactly(ingestorRunInfos.Count));
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFileList(It.Is<DynamicFileListRequest>(d => d.Filename.Equals("{ArchiveFiles}"))), Times.Exactly(ingestorRunInfos.Count));
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFileList(It.Is<DynamicFileListRequest>(d => d.Filename.Equals("{ZipFileRegex}"))), Times.Exactly(ingestorRunInfos.Count));
_mockFileOperationsApiService.Verify(x => x.DirectCreateDirectory(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.DirectDeleteDirectory(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>()), Times.Exactly(ingestorRunInfos.Count));
_mockFileOperationsApiService.Verify(x => x.DirectMoveFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Exactly(ingestorRunInfos.Count));
}
[Test]
public async Task HandleIngestionFolderCleanUp_DocumentProcessingInfoCount_IndexTotal_Mismatch()
{
// Arrange
var request = new IngestionFolderCleanUpRequest()
{
ArchiveDate = new DateTime(2023, 03, 30),
ArchiveRootPath = "\\\\zeus\\some\\path\\",
IngestionEndedDate = new DateTime(2023, 3, 30)
};
var ingestorRunInfos = new List<IngestorRunInfo>()
{
new ()
{
IngestorRunInfoId = Guid.NewGuid(),
IngestorType = IngestorTypes.FosDnaDocument,
IndexTotal = 5,
IndexFilePath = $"Path1\\{DateTime.Now:yyyyMMdd}\\Path1\\",
IndexFileName = "Filename",
StartTimeStamp = new DateTime(2023, 03, 27),
EndTimeStamp = new DateTime(2023, 03, 27),
ArchiveTimeStamp = null,
}
};
var docProcessingInfoFiles = new List<string>()
{
"Filename1.pdf",
"Filename2.pdf",
"Filename3.pdf",
};
_mockIngestorRunInfoService.Setup(x => x.FindByIngestionEndDateNotArchived(It.IsAny<DateTime>()))
.Returns(ingestorRunInfos).Verifiable();
_mockDocumentProcessingInfoService.Setup(x => x.CountCompletedByIngestorRunInfoIdAsync(It.IsAny<Guid>()))
.ReturnsAsync(docProcessingInfoFiles.Count).Verifiable();
// Act
await _ingestionFolderCleanUpService.HandleIngestionFolderCleanUp(request);
// Assert
_mockIngestorRunInfoService.Verify(x => x.FindByIngestionEndDateNotArchived(It.IsAny<DateTime>()), Times.Once);
_mockIngestorRunInfoService.Verify(x => x.Update(It.IsAny<IngestorRunInfo>()), Times.Never);
_mockDocumentProcessingInfoService.Verify(x => x.CountCompletedByIngestorRunInfoIdAsync(It.IsAny<Guid>()), Times.Exactly(ingestorRunInfos.Count));
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.DirectCreateDirectory(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.DirectDeleteDirectory(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.DirectMoveFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Never);
}
[Test]
public async Task HandleIngestionFolderCleanUp_ArchivedFileCount_IndexTotal_Mismatch()
{
// Arrange
var request = new IngestionFolderCleanUpRequest()
{
ArchiveDate = new DateTime(2023, 03, 30),
ArchiveRootPath = "\\\\zeus\\some\\path\\",
IngestionEndedDate = new DateTime(2023, 3, 30)
};
var ingestorRunInfos = new List<IngestorRunInfo>()
{
new ()
{
IngestorRunInfoId = Guid.NewGuid(),
IngestorType = IngestorTypes.FosDnaDocument,
IndexTotal = 5,
IndexFilePath = $"Path1\\{DateTime.Now:yyyyMMdd}\\Path1\\",
IndexFileName = "Filename",
StartTimeStamp = new DateTime(2023, 03, 27),
EndTimeStamp = new DateTime(2023, 03, 27),
ArchiveTimeStamp = null,
},
};
var docProcessingInfoFiles = new List<string>()
{
"Filename1.pdf",
"Filename2.pdf",
"Filename3.pdf"
};
var successfulRequestResponse = new RequestResponse()
{
IsSuccessful = true,
MessageStack = null,
ReturnResponse = null
};
_mockIngestorRunInfoService.Setup(x => x.FindByIngestionEndDateNotArchived(It.IsAny<DateTime>()))
.Returns(ingestorRunInfos).Verifiable();
_mockDocumentProcessingInfoService.Setup(x => x.CountCompletedByIngestorRunInfoIdAsync(It.IsAny<Guid>()))
.ReturnsAsync(5).Verifiable();
_mockFileOperationsApiService.Setup(x => x.BuildDynamicFileList(It.Is<DynamicFileListRequest>(d => d.Filename.Equals("{ArchiveFiles}")))).ReturnsAsync(docProcessingInfoFiles).Verifiable();
// Act
await _ingestionFolderCleanUpService.HandleIngestionFolderCleanUp(request);
// Assert
_mockIngestorRunInfoService.Verify(x => x.FindByIngestionEndDateNotArchived(It.IsAny<DateTime>()), Times.Once);
_mockIngestorRunInfoService.Verify(x => x.Update(It.IsAny<IngestorRunInfo>()), Times.Never);
_mockDocumentProcessingInfoService.Verify(x => x.CountCompletedByIngestorRunInfoIdAsync(It.IsAny<Guid>()), Times.Exactly(ingestorRunInfos.Count));
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFileList(It.Is<DynamicFileListRequest>(d => d.Filename.Equals("{ArchiveFiles}"))), Times.Exactly(ingestorRunInfos.Count));
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFileList(It.Is<DynamicFileListRequest>(d => d.Filename.Equals("{ZipFileRegex}"))), Times.Never);
_mockFileOperationsApiService.Verify(x => x.DirectCreateDirectory(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.DirectDeleteDirectory(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.DirectMoveFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Never);
}
[Test]
public async Task HandleIngestionFolderCleanUp_ZipFile_NotFound()
{
// Arrange
var request = new IngestionFolderCleanUpRequest()
{
ArchiveDate = new DateTime(2023, 03, 30),
ArchiveRootPath = "\\\\zeus\\some\\path\\",
IngestionEndedDate = new DateTime(2023, 3, 30)
};
var ingestorRunInfos = new List<IngestorRunInfo>()
{
new ()
{
IngestorRunInfoId = Guid.NewGuid(),
IngestorType = IngestorTypes.FosDnaDocument,
IndexTotal = 5,
IndexFilePath = $"Path1\\{DateTime.Now.ToString("yyyyMMdd")}\\Path1\\",
IndexFileName = "Filename",
StartTimeStamp = new DateTime(2023, 03, 27),
EndTimeStamp = new DateTime(2023, 03, 27),
ArchiveTimeStamp = null,
},
};
var docProcessingInfoFiles = new List<string>()
{
"Filename1.pdf",
"Filename2.pdf",
"Filename3.pdf",
"Filename4.pdf",
"Filename5.pdf"
};
_mockIngestorRunInfoService.Setup(x => x.FindByIngestionEndDateNotArchived(It.IsAny<DateTime>()))
.Returns(ingestorRunInfos).Verifiable();
_mockDocumentProcessingInfoService.Setup(x => x.CountCompletedByIngestorRunInfoIdAsync(It.IsAny<Guid>()))
.ReturnsAsync(docProcessingInfoFiles.Count).Verifiable();
_mockFileOperationsApiService.Setup(x => x.BuildDynamicFileList(It.Is<DynamicFileListRequest>(d => d.Filename.Equals("{ArchiveFiles}")))).ReturnsAsync(docProcessingInfoFiles).Verifiable();
_mockFileOperationsApiService.Setup(x => x.BuildDynamicFileList(It.Is<DynamicFileListRequest>(d => d.Filename.Equals("{ZipFileRegex}")))).ReturnsAsync(new List<string>()).Verifiable();
// Act
await _ingestionFolderCleanUpService.HandleIngestionFolderCleanUp(request);
// Assert
_mockIngestorRunInfoService.Verify(x => x.FindByIngestionEndDateNotArchived(It.IsAny<DateTime>()), Times.Once);
_mockIngestorRunInfoService.Verify(x => x.Update(It.IsAny<IngestorRunInfo>()), Times.Never);
_mockDocumentProcessingInfoService.Verify(x => x.CountCompletedByIngestorRunInfoIdAsync(It.IsAny<Guid>()), Times.Exactly(ingestorRunInfos.Count));
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFileList(It.Is<DynamicFileListRequest>(d => d.Filename.Equals("{ArchiveFiles}"))), Times.Exactly(ingestorRunInfos.Count));
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFileList(It.Is<DynamicFileListRequest>(d => d.Filename.Equals("{ZipFileRegex}"))), Times.Exactly(ingestorRunInfos.Count));
_mockFileOperationsApiService.Verify(x => x.DirectCreateDirectory(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.DirectDeleteDirectory(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.DirectMoveFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Never);
}
[Test]
public async Task HandleIngestionFolderCleanUp_CreateArchiveDirectory_Exception()
{
var now = DateTime.Now.ToString("yyyyMMdd");
// Arrange
var request = new IngestionFolderCleanUpRequest()
{
ArchiveDate = new DateTime(2023, 03, 30),
ArchiveRootPath = $"\\\\zeus\\some\\path\\{now}\\",
IngestionEndedDate = new DateTime(2023, 3, 30)
};
var ingestorRunInfos = new List<IngestorRunInfo>()
{
new ()
{
IngestorRunInfoId = Guid.NewGuid(),
IngestorType = IngestorTypes.FosDnaDocument,
IndexTotal = 5,
IndexFilePath = $"Path1\\{now}\\Path1\\",
IndexFileName = "Filename",
StartTimeStamp = new DateTime(2023, 03, 27),
EndTimeStamp = new DateTime(2023, 03, 27),
ArchiveTimeStamp = null,
},
new ()
{
IngestorRunInfoId = Guid.NewGuid(),
IngestorType = IngestorTypes.FosDnaDocument,
IndexTotal = 5,
IndexFilePath = $"Path2\\{now}\\Path2\\",
IndexFileName = "Filename",
StartTimeStamp = new DateTime(2023, 03, 28),
EndTimeStamp = new DateTime(2023, 03, 28),
ArchiveTimeStamp = null,
},
};
var docProcessingInfoFiles = new List<string>()
{
"Filename1.pdf",
"Filename2.pdf",
"Filename3.pdf",
"Filename4.pdf",
"Filename5.pdf"
};
var successfulRequestResponse = new RequestResponse()
{
IsSuccessful = true,
MessageStack = null,
ReturnResponse = null
};
_mockIngestorRunInfoService.Setup(x => x.FindByIngestionEndDateNotArchived(It.IsAny<DateTime>()))
.Returns(ingestorRunInfos).Verifiable();
_mockDocumentProcessingInfoService.Setup(x => x.CountCompletedByIngestorRunInfoIdAsync(It.IsAny<Guid>()))
.ReturnsAsync(docProcessingInfoFiles.Count).Verifiable();
_mockFileOperationsApiService.Setup(x => x.BuildDynamicFileList(It.Is<DynamicFileListRequest>(d => d.Filename.Equals("{ArchiveFiles}")))).ReturnsAsync(docProcessingInfoFiles).Verifiable();
_mockFileOperationsApiService.Setup(x => x.BuildDynamicFileList(It.Is<DynamicFileListRequest>(d => d.Filename.Equals("{ZipFileRegex}")))).ReturnsAsync(new List<string>() { "" }).Verifiable();
_mockFileOperationsApiService.Setup(x => x.DirectCreateDirectory(It.IsAny<string>(), It.IsAny<string>())).ThrowsAsync(new ServiceException("Exception from test")).Verifiable();
// Act
Assert.ThrowsAsync<ServiceException>(async () => await _ingestionFolderCleanUpService.HandleIngestionFolderCleanUp(request));
// Assert
_mockIngestorRunInfoService.Verify(x => x.FindByIngestionEndDateNotArchived(It.IsAny<DateTime>()), Times.Once);
_mockIngestorRunInfoService.Verify(x => x.Update(It.IsAny<IngestorRunInfo>()), Times.Never);
_mockDocumentProcessingInfoService.Verify(x => x.CountCompletedByIngestorRunInfoIdAsync(It.IsAny<Guid>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFileList(It.Is<DynamicFileListRequest>(d => d.Filename.Equals("{ArchiveFiles}"))), Times.Once);
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFileList(It.Is<DynamicFileListRequest>(d => d.Filename.Equals("{ZipFileRegex}"))), Times.Once);
_mockFileOperationsApiService.Verify(x => x.DirectCreateDirectory(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.DirectDeleteDirectory(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.DirectMoveFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Never);
}
[Test]
public async Task HandleIngestionFolderCleanUp_MoveZipFile_Exception()
{
var now = DateTime.Now.ToString("yyyyMMdd");
// Arrange
var request = new IngestionFolderCleanUpRequest()
{
ArchiveDate = new DateTime(2023, 03, 30),
ArchiveRootPath = "\\\\zeus\\some\\path\\",
IngestionEndedDate = new DateTime(2023, 3, 30)
};
var ingestorRunInfos = new List<IngestorRunInfo>()
{
new ()
{
IngestorRunInfoId = Guid.NewGuid(),
IngestorType = IngestorTypes.FosDnaDocument,
IndexTotal = 5,
IndexFilePath = $"Path1\\{now}\\Path1\\",
IndexFileName = "Filename",
StartTimeStamp = new DateTime(2023, 03, 27),
EndTimeStamp = new DateTime(2023, 03, 27),
ArchiveTimeStamp = null,
},
new ()
{
IngestorRunInfoId = Guid.NewGuid(),
IngestorType = IngestorTypes.FosDnaDocument,
IndexTotal = 5,
IndexFilePath = $"Path2\\{now}\\Path2\\",
IndexFileName = "Filename",
StartTimeStamp = new DateTime(2023, 03, 28),
EndTimeStamp = new DateTime(2023, 03, 28),
ArchiveTimeStamp = null,
},
new ()
{
IngestorRunInfoId = Guid.NewGuid(),
IngestorType = IngestorTypes.FosDnaDocument,
IndexTotal = 5,
IndexFilePath = $"Path3\\{now}\\Path3\\",
IndexFileName = "Filename",
StartTimeStamp = new DateTime(2023, 03, 29),
EndTimeStamp = new DateTime(2023, 03, 29),
ArchiveTimeStamp = null,
}
};
var docProcessingInfoFiles = new List<string>()
{
"Filename1.pdf",
"Filename2.pdf",
"Filename3.pdf",
"Filename4.pdf",
"Filename5.pdf"
};
var successfulRequestResponse = new RequestResponse()
{
IsSuccessful = true,
MessageStack = null,
ReturnResponse = null
};
_mockIngestorRunInfoService.Setup(x => x.FindByIngestionEndDateNotArchived(It.IsAny<DateTime>()))
.Returns(ingestorRunInfos).Verifiable();
_mockIngestorRunInfoService.Setup(x => x.Update(It.IsAny<IngestorRunInfo>())).Verifiable();
_mockDocumentProcessingInfoService.Setup(x => x.CountCompletedByIngestorRunInfoIdAsync(It.IsAny<Guid>()))
.ReturnsAsync(docProcessingInfoFiles.Count).Verifiable();
_mockFileOperationsApiService.Setup(x => x.BuildDynamicFileList(It.Is<DynamicFileListRequest>(d => d.Filename.Equals("{ArchiveFiles}")))).ReturnsAsync(docProcessingInfoFiles).Verifiable();
_mockFileOperationsApiService.Setup(x => x.BuildDynamicFileList(It.Is<DynamicFileListRequest>(d => d.Filename.Equals("{ZipFileRegex}")))).ReturnsAsync(new List<string>() { "" }).Verifiable();
_mockFileOperationsApiService.Setup(x => x.DirectCreateDirectory(It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(successfulRequestResponse).Verifiable();
_mockFileOperationsApiService.Setup(x => x.DirectDeleteDirectory(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>())).ReturnsAsync(successfulRequestResponse).Verifiable();
_mockFileOperationsApiService.Setup(x => x.DirectMoveFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).ThrowsAsync(new ServiceException("Exception from test")).Verifiable();
// Act
await _ingestionFolderCleanUpService.HandleIngestionFolderCleanUp(request);
// Assert
_mockIngestorRunInfoService.Verify(x => x.FindByIngestionEndDateNotArchived(It.IsAny<DateTime>()), Times.Once);
_mockIngestorRunInfoService.Verify(x => x.Update(It.IsAny<IngestorRunInfo>()), Times.Exactly(ingestorRunInfos.Count));
_mockDocumentProcessingInfoService.Verify(x => x.CountCompletedByIngestorRunInfoIdAsync(It.IsAny<Guid>()), Times.Exactly(ingestorRunInfos.Count));
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFileList(It.Is<DynamicFileListRequest>(d => d.Filename.Equals("{ArchiveFiles}"))), Times.Exactly(ingestorRunInfos.Count));
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFileList(It.Is<DynamicFileListRequest>(d => d.Filename.Equals("{ZipFileRegex}"))), Times.Exactly(ingestorRunInfos.Count));
_mockFileOperationsApiService.Verify(x => x.DirectCreateDirectory(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.DirectDeleteDirectory(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>()), Times.Exactly(ingestorRunInfos.Count));
_mockFileOperationsApiService.Verify(x => x.DirectMoveFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Exactly(ingestorRunInfos.Count));
}
[Test]
public async Task HandleIngestionFolderCleanUp_BuildDynamicFileList_Failure()
{
var now = DateTime.Now.ToString("yyyyMMdd");
// Arrange
var request = new IngestionFolderCleanUpRequest()
{
ArchiveDate = new DateTime(2023, 03, 30),
ArchiveRootPath = "\\\\zeus\\some\\path\\",
IngestionEndedDate = new DateTime(2023, 3, 30)
};
var ingestorRunInfos = new List<IngestorRunInfo>()
{
new ()
{
IngestorRunInfoId = Guid.NewGuid(),
IngestorType = IngestorTypes.FosDnaDocument,
IndexTotal = 5,
IndexFilePath = $"Path1\\{now}\\Path1\\",
IndexFileName = "Filename",
StartTimeStamp = new DateTime(2023, 03, 27),
EndTimeStamp = new DateTime(2023, 03, 27),
ArchiveTimeStamp = null,
},
new ()
{
IngestorRunInfoId = Guid.NewGuid(),
IngestorType = IngestorTypes.FosDnaDocument,
IndexTotal = 5,
IndexFilePath = $"Path2\\{now}\\Path2\\",
IndexFileName = "Filename",
StartTimeStamp = new DateTime(2023, 03, 28),
EndTimeStamp = new DateTime(2023, 03, 28),
ArchiveTimeStamp = null,
},
new ()
{
IngestorRunInfoId = Guid.NewGuid(),
IngestorType = IngestorTypes.FosDnaDocument,
IndexTotal = 5,
IndexFilePath = $"Path3\\{now}\\Path3\\",
IndexFileName = "Filename",
StartTimeStamp = new DateTime(2023, 03, 29),
EndTimeStamp = new DateTime(2023, 03, 29),
ArchiveTimeStamp = null,
}
};
var docProcessingInfoFiles = new List<string>()
{
"Filename1.pdf",
"Filename2.pdf",
"Filename3.pdf",
"Filename4.pdf",
"Filename5.pdf"
};
_mockIngestorRunInfoService.Setup(x => x.FindByIngestionEndDateNotArchived(It.IsAny<DateTime>()))
.Returns(ingestorRunInfos).Verifiable();
_mockIngestorRunInfoService.Setup(x => x.Update(It.IsAny<IngestorRunInfo>())).Verifiable();
_mockDocumentProcessingInfoService.Setup(x => x.CountCompletedByIngestorRunInfoIdAsync(It.IsAny<Guid>()))
.ReturnsAsync(docProcessingInfoFiles.Count).Verifiable();
_mockFileOperationsApiService.Setup(x => x.BuildDynamicFileList(It.Is<DynamicFileListRequest>(d => d.Filename.Equals("{ArchiveFiles}")))).ReturnsAsync(docProcessingInfoFiles).Verifiable();
_mockFileOperationsApiService.Setup(x => x.BuildDynamicFileList(It.Is<DynamicFileListRequest>(d => d.Filename.Equals("{ZipFileRegex}")))).ThrowsAsync(new ServiceException("Exception from test")).Verifiable();
// Act
await _ingestionFolderCleanUpService.HandleIngestionFolderCleanUp(request);
// Assert
_mockIngestorRunInfoService.Verify(x => x.FindByIngestionEndDateNotArchived(It.IsAny<DateTime>()), Times.Once);
_mockDocumentProcessingInfoService.Verify(x => x.CountCompletedByIngestorRunInfoIdAsync(It.IsAny<Guid>()), Times.Exactly(ingestorRunInfos.Count));
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFileList(It.Is<DynamicFileListRequest>(d => d.Filename.Equals("{ArchiveFiles}"))), Times.Exactly(ingestorRunInfos.Count));
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFileList(It.Is<DynamicFileListRequest>(d => d.Filename.Equals("{ZipFileRegex}"))), Times.Exactly(ingestorRunInfos.Count));
_mockFileOperationsApiService.Verify(x => x.DirectCreateDirectory(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.DirectDeleteDirectory(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.DirectMoveFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Never);
_mockIngestorRunInfoService.Verify(x => x.Update(It.IsAny<IngestorRunInfo>()), Times.Never);
}
[Test]
public async Task HandleIngestionFolderCleanUp_IncorrectFilePathFormat_Failure()
{
// Arrange
var request = new IngestionFolderCleanUpRequest()
{
ArchiveDate = new DateTime(2023, 03, 30),
ArchiveRootPath = "\\\\zeus\\some\\path\\",
IngestionEndedDate = new DateTime(2023, 3, 30)
};
var ingestorRunInfos = new List<IngestorRunInfo>()
{
new ()
{
IngestorRunInfoId = Guid.NewGuid(),
IngestorType = IngestorTypes.FosDnaDocument,
IndexTotal = 5,
IndexFilePath = "Path1",
IndexFileName = "Filename",
StartTimeStamp = new DateTime(2023, 03, 27),
EndTimeStamp = new DateTime(2023, 03, 27),
ArchiveTimeStamp = null,
},
new ()
{
IngestorRunInfoId = Guid.NewGuid(),
IngestorType = IngestorTypes.FosDnaDocument,
IndexTotal = 5,
IndexFilePath = "Path2",
IndexFileName = "Filename",
StartTimeStamp = new DateTime(2023, 03, 28),
EndTimeStamp = new DateTime(2023, 03, 28),
ArchiveTimeStamp = null,
},
new ()
{
IngestorRunInfoId = Guid.NewGuid(),
IngestorType = IngestorTypes.FosDnaDocument,
IndexTotal = 5,
IndexFilePath = "Path3",
IndexFileName = "Filename",
StartTimeStamp = new DateTime(2023, 03, 29),
EndTimeStamp = new DateTime(2023, 03, 29),
ArchiveTimeStamp = null,
}
};
_mockIngestorRunInfoService.Setup(x => x.FindByIngestionEndDateNotArchived(It.IsAny<DateTime>()))
.Returns(ingestorRunInfos).Verifiable();
_mockIngestorRunInfoService.Setup(x => x.Update(It.IsAny<IngestorRunInfo>())).Verifiable();
// Act
await _ingestionFolderCleanUpService.HandleIngestionFolderCleanUp(request);
// Assert
_mockIngestorRunInfoService.Verify(x => x.FindByIngestionEndDateNotArchived(It.IsAny<DateTime>()), Times.Once);
_mockIngestorRunInfoService.Verify(x => x.Update(It.IsAny<IngestorRunInfo>()), Times.Never);
_mockDocumentProcessingInfoService.Verify(x => x.CountCompletedByIngestorRunInfoIdAsync(It.IsAny<Guid>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFileList(It.Is<DynamicFileListRequest>(d => d.Filename.Equals("{ArchiveFiles}"))), Times.Never);
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFileList(It.Is<DynamicFileListRequest>(d => d.Filename.Equals("{ZipFileRegex}"))), Times.Never);
_mockFileOperationsApiService.Verify(x => x.DirectCreateDirectory(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.DirectDeleteDirectory(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.DirectMoveFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Never);
}
[Test]
public async Task HandleIngestionFolderCleanUp_DeleteUnzippedFolder_Exception()
{
var now = DateTime.Now.ToString("yyyyMMdd");
// Arrange
var request = new IngestionFolderCleanUpRequest()
{
ArchiveDate = new DateTime(2023, 03, 30),
ArchiveRootPath = "\\\\zeus\\some\\path\\",
IngestionEndedDate = new DateTime(2023, 3, 30)
};
var ingestorRunInfos = new List<IngestorRunInfo>()
{
new ()
{
IngestorRunInfoId = Guid.NewGuid(),
IngestorType = IngestorTypes.FosDnaDocument,
IndexTotal = 5,
IndexFilePath = $"Path1\\{now}\\Path1\\",
IndexFileName = "Filename",
StartTimeStamp = new DateTime(2023, 03, 27),
EndTimeStamp = new DateTime(2023, 03, 27),
ArchiveTimeStamp = null,
},
new ()
{
IngestorRunInfoId = Guid.NewGuid(),
IngestorType = IngestorTypes.FosDnaDocument,
IndexTotal = 5,
IndexFilePath = $"Path2\\{now}\\Path2\\",
IndexFileName = "Filename",
StartTimeStamp = new DateTime(2023, 03, 28),
EndTimeStamp = new DateTime(2023, 03, 28),
ArchiveTimeStamp = null,
},
new ()
{
IngestorRunInfoId = Guid.NewGuid(),
IngestorType = IngestorTypes.FosDnaDocument,
IndexTotal = 5,
IndexFilePath = $"Path3\\{now}\\Path3\\",
IndexFileName = "Filename",
StartTimeStamp = new DateTime(2023, 03, 29),
EndTimeStamp = new DateTime(2023, 03, 29),
ArchiveTimeStamp = null,
}
};
var docProcessingInfoFiles = new List<string>()
{
"Filename1.pdf",
"Filename2.pdf",
"Filename3.pdf",
"Filename4.pdf",
"Filename5.pdf"
};
var successfulRequestResponse = new RequestResponse()
{
IsSuccessful = true,
MessageStack = null,
ReturnResponse = null
};
_mockIngestorRunInfoService.Setup(x => x.FindByIngestionEndDateNotArchived(It.IsAny<DateTime>()))
.Returns(ingestorRunInfos).Verifiable();
_mockIngestorRunInfoService.Setup(x => x.Update(It.IsAny<IngestorRunInfo>())).Verifiable();
_mockDocumentProcessingInfoService.Setup(x => x.CountCompletedByIngestorRunInfoIdAsync(It.IsAny<Guid>()))
.ReturnsAsync(docProcessingInfoFiles.Count).Verifiable();
_mockFileOperationsApiService.Setup(x => x.BuildDynamicFileList(It.Is<DynamicFileListRequest>(d => d.Filename.Equals("{ArchiveFiles}")))).ReturnsAsync(docProcessingInfoFiles).Verifiable();
_mockFileOperationsApiService.Setup(x => x.BuildDynamicFileList(It.Is<DynamicFileListRequest>(d => d.Filename.Equals("{ZipFileRegex}")))).ReturnsAsync(new List<string>() { "" }).Verifiable();
_mockFileOperationsApiService.Setup(x => x.DirectCreateDirectory(It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(successfulRequestResponse).Verifiable();
_mockFileOperationsApiService.Setup(x => x.DirectDeleteDirectory(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>())).ThrowsAsync(new ServiceException("Exception from test")).Verifiable();
_mockFileOperationsApiService.Setup(x => x.DirectMoveFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).Verifiable();
// Act
await _ingestionFolderCleanUpService.HandleIngestionFolderCleanUp(request);
// Assert
_mockIngestorRunInfoService.Verify(x => x.FindByIngestionEndDateNotArchived(It.IsAny<DateTime>()), Times.Once);
_mockIngestorRunInfoService.Verify(x => x.Update(It.IsAny<IngestorRunInfo>()), Times.Exactly(ingestorRunInfos.Count));
_mockDocumentProcessingInfoService.Verify(x => x.CountCompletedByIngestorRunInfoIdAsync(It.IsAny<Guid>()), Times.Exactly(ingestorRunInfos.Count));
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFileList(It.Is<DynamicFileListRequest>(d => d.Filename.Equals("{ArchiveFiles}"))), Times.Exactly(ingestorRunInfos.Count));
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFileList(It.Is<DynamicFileListRequest>(d => d.Filename.Equals("{ZipFileRegex}"))), Times.Exactly(ingestorRunInfos.Count));
_mockFileOperationsApiService.Verify(x => x.DirectCreateDirectory(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.DirectDeleteDirectory(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>()), Times.Exactly(ingestorRunInfos.Count));
_mockFileOperationsApiService.Verify(x => x.DirectMoveFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Exactly(ingestorRunInfos.Count));
}
}
@@ -0,0 +1,606 @@
using LCU.API.Internal.DocumentIngestor.Configurations;
using LCU.API.Internal.DocumentIngestor.Services;
using LCU.API.Internal.DocumentIngestor.Services.IngestionOperationServices;
using LCU.API.Internal.DocumentIngestor.Services.MemberNotificationInfoDeterminingServices;
using LCU.API.Internal.DocumentIngestor.Services.MicroApiServices;
using LCU.Library.Internal.NotificationsModels.Models;
using LCU.Library.DocumentType.Models.Requests;
using LCU.Library.DocumentType.Models.Responses.External;
using LCU.Library.Internal.DocumentIngestorModels.Entities;
using LCU.Library.Internal.DocumentIngestorModels.Enums;
using LCU.Library.Internal.DocumentIngestorModels.Models;
using LCU.Library.Internal.LcuMassTransitModels;
using Moq;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using LCU.API.Internal.DocumentIngestor.Services.QueueServices;
namespace LCU.API.Internal.DocumentIngestorTests.Services.IngestionOperationServices;
public class MemberDocumentNotifierServiceTest
{
private MemberDocumentNotifierService _memberDocumentNotifierService;
private Mock<IMemberNotificationInfoService> _mockMemberNotificationInfoService;
private Mock<IDocumentTypeRetrieverService> _mockDocumentTypeRetrieverService;
private Mock<IDocumentProcessingInfoService> _mockDocumentProcessingInfoService;
private Mock<INotificationApiService> _mockNotificationApiService;
private Mock<IMemberNotificationInfoDeterminingService> _mockMemberNotificationInfoDeterminingService;
private Mock<IQueueMemberNotificationCompletionService> _mockQueueMemberNotificationCompletionService;
private ApiConfiguration _apiConfiguration;
private ConnectionConfiguration _connectionConfiguration;
private ReceiveEndpointConfigurations _receiveEndpointConfigurations;
private DigitalBankingConfiguration _digitalBankingConfiguration;
[SetUp]
public void Setup()
{
_apiConfiguration = new ApiConfiguration
{
MaxMemberNotificationAttempts = 3,
MaliciousFileSearchPaddingHours = 1,
TimeZone = "America/Chicago",
NotificationEmailTemplate = @"../../../../LCU.API.Internal.DocumentIngestor/Templates/NotificationEmailTemplate.html",
NotificationEmailRowTemplate = @"../../../../LCU.API.Internal.DocumentIngestor/Templates/NotificationEmailRowTemplate.html",
FeatureFlags = new FeatureFlags() { RestrictNotificationRecipients = false },
BatchSkipAmount = 10000,
Notifications = new Notifications
{
AllowedRecipientExpression = "*"
}
};
_connectionConfiguration = new ConnectionConfiguration()
{
HostUrl = "Test",
UserName = "Test",
Password = "Test"
};
_receiveEndpointConfigurations = new ReceiveEndpointConfigurations()
{
MemberNotificationCompletionEndpoint = new ReceiveEndpointConfiguration()
{
ReceiveEndpoint = "Test",
ReceiveEndpointType = "Exchange",
PrefetchLimit = 1
}
};
_digitalBankingConfiguration = new DigitalBankingConfiguration()
{
DigitalBankingUrl = "https://digitalbanking.landmarkcu.com/eDocs",
MobileBankingApiKey = "TEST",
MobileBankingBaseUrl = "https://qa-redirect-api.qa.applications.landmarkcu.com/index.html",
MobileBankingLinkId = "a4e648ff-247a-42a8-b153-4b65d4933d1c"
};
_mockMemberNotificationInfoService = new Mock<IMemberNotificationInfoService>();
_mockDocumentTypeRetrieverService = new Mock<IDocumentTypeRetrieverService>();
_mockDocumentProcessingInfoService = new Mock<IDocumentProcessingInfoService>();
_mockNotificationApiService = new Mock<INotificationApiService>();
_mockMemberNotificationInfoDeterminingService = new Mock<IMemberNotificationInfoDeterminingService>();
_mockQueueMemberNotificationCompletionService = new Mock<IQueueMemberNotificationCompletionService>();
_memberDocumentNotifierService = new MemberDocumentNotifierService(_mockMemberNotificationInfoService.Object,
_mockDocumentTypeRetrieverService.Object,
_mockDocumentProcessingInfoService.Object,
_mockNotificationApiService.Object,
_mockMemberNotificationInfoDeterminingService.Object,
_mockQueueMemberNotificationCompletionService.Object,
_apiConfiguration,
_connectionConfiguration,
_receiveEndpointConfigurations,
_digitalBankingConfiguration);
}
[Test]
public async Task PrepareAndSendNotifications_Success()
{
var request = new MemberDocumentNotificationRequest() { RunCriticalFailureNotifications = false };
var memberNotificationInfos = GenerateMemberNotificationInfos();
var documentProcessingInfos = GenerateDocumentProcessingInfos();
var documentCodeDetailInfos = GenerateDocumentCodeDetailInfos();
var deliveryMethod = (memberNotificationInfos[2].EmailAddress, DeliveryMethod.Electronic);
List<DocumentMetadataResponse> maliciousDocuments = null;
_mockMemberNotificationInfoService
.Setup(x => x.GetSendableMemberNotificationInfosAsync(It.IsAny<DateTime>(), _apiConfiguration.MaxMemberNotificationAttempts))
.ReturnsAsync(memberNotificationInfos);
_mockDocumentProcessingInfoService.Setup(x => x.GetListByIdAsync(It.IsAny<List<int>>())).ReturnsAsync(documentProcessingInfos);
_mockMemberNotificationInfoDeterminingService.Setup(x => x.DetermineDeliveryMethod(It.IsAny<MemberNotificationInfo>())).ReturnsAsync(deliveryMethod);
_mockDocumentTypeRetrieverService.Setup(x => x.GetListOfMaliciousDocuments(It.IsAny<MaliciousDocumentSearchFilter>())).ReturnsAsync(maliciousDocuments);
_mockDocumentTypeRetrieverService.SetupSequence(x => x.GetDocumentCodeDetailByBusinessName(It.IsAny<string>()))
.ReturnsAsync(documentCodeDetailInfos[0])
.ReturnsAsync(documentCodeDetailInfos[1])
.ReturnsAsync(documentCodeDetailInfos[2]);
var result = await _memberDocumentNotifierService.PrepareAndSendNotifications(request);
Assert.NotNull(result);
Assert.IsTrue(result.IsSuccessful);
Assert.IsEmpty(result.Messages);
Assert.Zero(result.FailureCount);
_mockMemberNotificationInfoService.Verify(x => x.GetSendableMemberNotificationInfosAsync(It.IsAny<DateTime>(), It.IsAny<int>()), Times.Once);
_mockDocumentProcessingInfoService.Verify(x => x.GetListByIdAsync(It.IsAny<List<int>>()), Times.Once);
_mockMemberNotificationInfoDeterminingService.Verify(x => x.DetermineDeliveryMethod(It.IsAny<MemberNotificationInfo>()), Times.Once);
_mockDocumentTypeRetrieverService.Verify(x => x.GetListOfMaliciousDocuments(It.IsAny<MaliciousDocumentSearchFilter>()), Times.Once);
_mockDocumentTypeRetrieverService.Verify(x => x.GetDocumentCodeDetailByBusinessName(It.IsAny<string>()), Times.Exactly(3));
_mockNotificationApiService.Verify(x => x.SendEmailAsync(It.IsAny<EmailRequest>()), Times.Exactly(2));
}
[Test]
public async Task PrepareAndSendNotifications_Success_NoMemberNotificationsToSend()
{
var request = new MemberDocumentNotificationRequest() { RunCriticalFailureNotifications = false };
var memberNotificationInfos = new List<MemberNotificationInfo>();
_mockMemberNotificationInfoService
.Setup(x => x.GetSendableMemberNotificationInfosAsync(It.IsAny<DateTime>(), _apiConfiguration.MaxMemberNotificationAttempts))
.ReturnsAsync(memberNotificationInfos);
var result = await _memberDocumentNotifierService.PrepareAndSendNotifications(request);
Assert.NotNull(result);
Assert.IsTrue(result.IsSuccessful);
Assert.AreEqual(result.Messages.Count, 1);
Assert.Zero(result.FailureCount);
_mockMemberNotificationInfoService.Verify(x => x.GetSendableMemberNotificationInfosAsync(It.IsAny<DateTime>(), It.IsAny<int>()), Times.Once);
_mockDocumentProcessingInfoService.Verify(x => x.GetListByIdAsync(It.IsAny<List<int>>()), Times.Never);
_mockMemberNotificationInfoDeterminingService.Verify(x => x.DetermineDeliveryMethod(It.IsAny<MemberNotificationInfo>()), Times.Never);
_mockDocumentTypeRetrieverService.Verify(x => x.GetListOfMaliciousDocuments(It.IsAny<MaliciousDocumentSearchFilter>()), Times.Never);
_mockDocumentTypeRetrieverService.Verify(x => x.GetDocumentCodeDetailByBusinessName(It.IsAny<string>()), Times.Never);
_mockNotificationApiService.Verify(x => x.SendEmailAsync(It.IsAny<EmailRequest>()), Times.Never);
}
[Test]
public async Task PrepareAndSendNotifications_FailureCount()
{
var request = new MemberDocumentNotificationRequest() { RunCriticalFailureNotifications = false };
var memberNotificationInfos = GenerateMemberNotificationInfos();
var documentProcessingInfos = GenerateDocumentProcessingInfos();
_mockMemberNotificationInfoService
.Setup(x => x.GetSendableMemberNotificationInfosAsync(It.IsAny<DateTime>(), _apiConfiguration.MaxMemberNotificationAttempts))
.ReturnsAsync(memberNotificationInfos);
_mockDocumentProcessingInfoService.Setup(x => x.GetListByIdAsync(It.IsAny<List<int>>())).ReturnsAsync(documentProcessingInfos);
_mockDocumentProcessingInfoService.Setup(x => x.GetListByIdAsync(It.IsAny<List<int>>())).ThrowsAsync(new Exception("Failure"));
var result = await _memberDocumentNotifierService.PrepareAndSendNotifications(request);
Assert.NotNull(result);
Assert.IsTrue(result.IsFailure);
Assert.AreEqual(result.Messages.Count, 1);
Assert.AreEqual(result.FailureCount, 1);
_mockMemberNotificationInfoService.Verify(x => x.GetSendableMemberNotificationInfosAsync(It.IsAny<DateTime>(), It.IsAny<int>()), Times.Once);
_mockDocumentProcessingInfoService.Verify(x => x.GetListByIdAsync(It.IsAny<List<int>>()), Times.Once);
_mockMemberNotificationInfoDeterminingService.Verify(x => x.DetermineDeliveryMethod(It.IsAny<MemberNotificationInfo>()), Times.Never);
_mockDocumentTypeRetrieverService.Verify(x => x.GetListOfMaliciousDocuments(It.IsAny<MaliciousDocumentSearchFilter>()), Times.Never);
_mockDocumentTypeRetrieverService.Verify(x => x.GetDocumentCodeDetailByBusinessName(It.IsAny<string>()), Times.Never);
_mockNotificationApiService.Verify(x => x.SendEmailAsync(It.IsAny<EmailRequest>()), Times.Never);
}
[Test]
public async Task PrepareAndSendNotifications_Success_MaliciousFile()
{
var request = new MemberDocumentNotificationRequest() { RunCriticalFailureNotifications = false };
var memberNotificationInfos = GenerateMemberNotificationInfos();
var documentProcessingInfos = GenerateDocumentProcessingInfos();
var documentCodeDetailInfos = GenerateDocumentCodeDetailInfos();
var deliveryMethod = (memberNotificationInfos[2].EmailAddress, DeliveryMethod.Electronic);
var maliciousId = Guid.NewGuid();
var maliciousDocuments = new List<DocumentMetadataResponse>()
{
new()
{
DocumentId = maliciousId
}
};
documentProcessingInfos[1].DocumentId = maliciousId;
_mockMemberNotificationInfoService
.Setup(x => x.GetSendableMemberNotificationInfosAsync(It.IsAny<DateTime>(), _apiConfiguration.MaxMemberNotificationAttempts))
.ReturnsAsync(memberNotificationInfos);
_mockDocumentProcessingInfoService.Setup(x => x.GetListByIdAsync(It.IsAny<List<int>>())).ReturnsAsync(documentProcessingInfos);
_mockMemberNotificationInfoDeterminingService.Setup(x => x.DetermineDeliveryMethod(It.IsAny<MemberNotificationInfo>())).ReturnsAsync(deliveryMethod);
_mockDocumentTypeRetrieverService.Setup(x => x.GetListOfMaliciousDocuments(It.IsAny<MaliciousDocumentSearchFilter>())).ReturnsAsync(maliciousDocuments);
_mockDocumentTypeRetrieverService.SetupSequence(x => x.GetDocumentCodeDetailByBusinessName(It.IsAny<string>()))
.ReturnsAsync(documentCodeDetailInfos[0])
.ReturnsAsync(documentCodeDetailInfos[2]);
var result = await _memberDocumentNotifierService.PrepareAndSendNotifications(request);
Assert.NotNull(result);
Assert.IsTrue(result.IsSuccessful);
Assert.IsEmpty(result.Messages);
Assert.Zero(result.FailureCount);
_mockMemberNotificationInfoService.Verify(x => x.GetSendableMemberNotificationInfosAsync(It.IsAny<DateTime>(), It.IsAny<int>()), Times.Once);
_mockDocumentProcessingInfoService.Verify(x => x.GetListByIdAsync(It.IsAny<List<int>>()), Times.Once);
_mockDocumentTypeRetrieverService.Verify(x => x.GetListOfMaliciousDocuments(It.IsAny<MaliciousDocumentSearchFilter>()), Times.Once);
_mockDocumentTypeRetrieverService.Verify(x => x.GetDocumentCodeDetailByBusinessName(It.IsAny<string>()), Times.Exactly(2));
_mockNotificationApiService.Verify(x => x.SendEmailAsync(It.IsAny<EmailRequest>()), Times.Exactly(2));
}
[Test]
public async Task PrepareAndSendNotifications_RestrictNotificationRecipientsOff_SendsToAnyEmail()
{
var disallowedRecipient = MemberNotificationFactory();
_apiConfiguration.FeatureFlags.RestrictNotificationRecipients = false;
_apiConfiguration.Notifications.AllowedRecipientExpression = $"(?!{disallowedRecipient.EmailAddress})\\A";
var request = new MemberDocumentNotificationRequest
{
RunCriticalFailureNotifications = false
};
var memberNotificationInfos = Enumerable.Repeat(() => MemberNotificationFactory(), 3)
.Select(f => f())
.Concat(new[] { disallowedRecipient })
.ToArray();
var documentProcessingInfos = Enumerable.Repeat<Func<int, DocumentProcessingInfo>>
(
i => DocumentProcessingInfoFactory(documentProcessingInfoId: memberNotificationInfos[i].DocumentProcessingInfoId),
memberNotificationInfos.Length
)
.Select((f, i) => f(i))
.ToArray();
var documentCodeDetails = Enumerable.Repeat<Func<int, DocumentCodeDetailInfo>>
(
i => DocumentCodeDetailInfoFactory(documentBusinessName: documentProcessingInfos[i].DocumentBusinessName),
documentProcessingInfos.Length
)
.Select((f, i) => f(i))
.ToDictionary(dcd => dcd.DocumentBusinessName);
var sentEmails = new List<EmailRequest>();
_mockMemberNotificationInfoService
.Setup(mnis => mnis.GetSendableMemberNotificationInfosAsync(It.IsAny<DateTime>(), _apiConfiguration.MaxMemberNotificationAttempts))
.ReturnsAsync(memberNotificationInfos);
_mockDocumentProcessingInfoService
.Setup(dpis => dpis.GetListByIdAsync(It.IsAny<List<int>>()))
.ReturnsAsync(documentProcessingInfos);
_mockDocumentTypeRetrieverService
.Setup(dtrs => dtrs.GetListOfMaliciousDocuments(It.IsAny<MaliciousDocumentSearchFilter>()))
.ReturnsAsync((IEnumerable<DocumentMetadataResponse>)null);
_mockDocumentTypeRetrieverService
.Setup(dtrs => dtrs.GetDocumentCodeDetailByBusinessName(It.IsAny<string>()))
.Returns<string>(async businessName => documentCodeDetails.TryGetValue(businessName, out var documentCodeDetail) ? documentCodeDetail : null);
_mockNotificationApiService
.Setup(nas => nas.SendEmailAsync(It.IsAny<EmailRequest>()))
.Callback<EmailRequest>(sentEmails.Add);
var result = await _memberDocumentNotifierService.PrepareAndSendNotifications(request);
Assert.IsFalse(result.IsFailure);
Assert.IsTrue(result.IsSuccessful);
Assert.AreEqual(0, result.FailureCount);
Assert.AreEqual(memberNotificationInfos.Length, sentEmails.Select(se => se.Recipient).Distinct().Count());
}
[Test]
public async Task PrepareAndSendNotifications_RestrictNotificationRecipientsOnAndAnyUnmatched_DoesNotSendToUnmatchedEmails()
{
var disallowedRecipient = MemberNotificationFactory();
_apiConfiguration.FeatureFlags.RestrictNotificationRecipients = true;
_apiConfiguration.Notifications.AllowedRecipientExpression = $"(?!{disallowedRecipient.EmailAddress})\\A";
var request = new MemberDocumentNotificationRequest
{
RunCriticalFailureNotifications = false
};
var memberNotificationInfos = Enumerable.Repeat(() => MemberNotificationFactory(), 3)
.Select(f => f())
.Concat(new[] { disallowedRecipient })
.ToArray();
var documentProcessingInfos = Enumerable.Repeat<Func<int, DocumentProcessingInfo>>
(
i => DocumentProcessingInfoFactory(documentProcessingInfoId: memberNotificationInfos[i].DocumentProcessingInfoId),
memberNotificationInfos.Length
)
.Select((f, i) => f(i))
.ToArray();
var documentCodeDetails = Enumerable.Repeat<Func<int, DocumentCodeDetailInfo>>
(
i => DocumentCodeDetailInfoFactory(documentBusinessName: documentProcessingInfos[i].DocumentBusinessName),
documentProcessingInfos.Length
)
.Select((f, i) => f(i))
.ToDictionary(dcd => dcd.DocumentBusinessName);
var sentEmails = new List<EmailRequest>();
_mockMemberNotificationInfoService
.Setup(mnis => mnis.GetSendableMemberNotificationInfosAsync(It.IsAny<DateTime>(), _apiConfiguration.MaxMemberNotificationAttempts))
.ReturnsAsync(memberNotificationInfos);
_mockDocumentProcessingInfoService
.Setup(dpis => dpis.GetListByIdAsync(It.IsAny<List<int>>()))
.ReturnsAsync(documentProcessingInfos);
_mockDocumentTypeRetrieverService
.Setup(dtrs => dtrs.GetListOfMaliciousDocuments(It.IsAny<MaliciousDocumentSearchFilter>()))
.ReturnsAsync((IEnumerable<DocumentMetadataResponse>)null);
_mockDocumentTypeRetrieverService
.Setup(dtrs => dtrs.GetDocumentCodeDetailByBusinessName(It.IsAny<string>()))
.Returns<string>(async businessName => documentCodeDetails.TryGetValue(businessName, out var documentCodeDetail) ? documentCodeDetail : null);
_mockNotificationApiService
.Setup(nas => nas.SendEmailAsync(It.IsAny<EmailRequest>()))
.Callback<EmailRequest>(sentEmails.Add);
var result = await _memberDocumentNotifierService.PrepareAndSendNotifications(request);
Assert.IsTrue(result.IsFailure);
Assert.IsFalse(result.IsSuccessful);
Assert.AreEqual(1, result.FailureCount);
Assert.AreEqual(0, sentEmails.Count(se => se.Recipient.Contains(disallowedRecipient.EmailAddress)));
}
[Test]
public async Task PrepareAndSendNotifications_RestrictNotificationRecipientsOnAndAllMatched_SendsToMatchedEmails()
{
var disallowedRecipient = MemberNotificationFactory();
_apiConfiguration.FeatureFlags.RestrictNotificationRecipients = true;
_apiConfiguration.Notifications.AllowedRecipientExpression = $"(?!{disallowedRecipient.EmailAddress})\\A";
var request = new MemberDocumentNotificationRequest
{
RunCriticalFailureNotifications = false
};
var allowedMemberNotificationInfos = Enumerable.Repeat(() => MemberNotificationFactory(), 3)
.Select(f => f())
.ToArray();
var memberNotificationInfos = allowedMemberNotificationInfos
.Concat(new[] { disallowedRecipient })
.ToArray();
var documentProcessingInfos = Enumerable.Repeat<Func<int, DocumentProcessingInfo>>
(
i => DocumentProcessingInfoFactory(documentProcessingInfoId: memberNotificationInfos[i].DocumentProcessingInfoId),
memberNotificationInfos.Length
)
.Select((f, i) => f(i))
.ToArray();
var documentCodeDetails = Enumerable.Repeat<Func<int, DocumentCodeDetailInfo>>
(
i => DocumentCodeDetailInfoFactory(documentBusinessName: documentProcessingInfos[i].DocumentBusinessName),
documentProcessingInfos.Length
)
.Select((f, i) => f(i))
.ToDictionary(dcd => dcd.DocumentBusinessName);
var sentEmails = new List<EmailRequest>();
_mockMemberNotificationInfoService
.Setup(mnis => mnis.GetSendableMemberNotificationInfosAsync(It.IsAny<DateTime>(), _apiConfiguration.MaxMemberNotificationAttempts))
.ReturnsAsync(memberNotificationInfos);
_mockDocumentProcessingInfoService
.Setup(dpis => dpis.GetListByIdAsync(It.IsAny<List<int>>()))
.ReturnsAsync(documentProcessingInfos);
_mockDocumentTypeRetrieverService
.Setup(dtrs => dtrs.GetListOfMaliciousDocuments(It.IsAny<MaliciousDocumentSearchFilter>()))
.ReturnsAsync((IEnumerable<DocumentMetadataResponse>)null);
_mockDocumentTypeRetrieverService
.Setup(dtrs => dtrs.GetDocumentCodeDetailByBusinessName(It.IsAny<string>()))
.Returns<string>(async businessName => documentCodeDetails.TryGetValue(businessName, out var documentCodeDetail) ? documentCodeDetail : null);
_mockNotificationApiService
.Setup(nas => nas.SendEmailAsync(It.IsAny<EmailRequest>()))
.Callback<EmailRequest>(sentEmails.Add);
await _memberDocumentNotifierService.PrepareAndSendNotifications(request);
var allowedEmails = allowedMemberNotificationInfos.Select(mni => mni.EmailAddress);
Assert.AreEqual(allowedMemberNotificationInfos.Length, sentEmails.Count(se => se.Recipient.Any(r => allowedEmails.Contains(r))));
}
[Test]
public async Task PrepareAndSendNotifications_Failure_NullEmails()
{
var request = new MemberDocumentNotificationRequest() { RunCriticalFailureNotifications = false };
var memberNotificationInfos = GenerateMemberNotificationInfos();
memberNotificationInfos[0].EmailAddress = "";
memberNotificationInfos[1].EmailAddress = "";
memberNotificationInfos[2].EmailAddress = "";
var documentProcessingInfos = GenerateDocumentProcessingInfos();
var documentCodeDetailInfos = GenerateDocumentCodeDetailInfos();
var deliveryMethod = (memberNotificationInfos[2].EmailAddress, DeliveryMethod.Electronic);
var maliciousId = Guid.NewGuid();
List<DocumentMetadataResponse> maliciousDocuments = null;
_mockMemberNotificationInfoService
.Setup(x => x.GetSendableMemberNotificationInfosAsync(It.IsAny<DateTime>(), _apiConfiguration.MaxMemberNotificationAttempts))
.ReturnsAsync(memberNotificationInfos);
_mockDocumentProcessingInfoService.Setup(x => x.GetListByIdAsync(It.IsAny<List<int>>())).ReturnsAsync(documentProcessingInfos);
_mockMemberNotificationInfoDeterminingService.Setup(x => x.DetermineDeliveryMethod(It.IsAny<MemberNotificationInfo>())).ReturnsAsync(deliveryMethod);
_mockDocumentTypeRetrieverService.Setup(x => x.GetListOfMaliciousDocuments(It.IsAny<MaliciousDocumentSearchFilter>())).ReturnsAsync(maliciousDocuments);
var result = await _memberDocumentNotifierService.PrepareAndSendNotifications(request);
Assert.NotNull(result);
Assert.IsTrue(result.IsSuccessful);
Assert.AreEqual(result.Messages.Count, 0);
Assert.AreEqual(result.FailureCount, 0);
_mockMemberNotificationInfoService.Verify(x => x.GetSendableMemberNotificationInfosAsync(It.IsAny<DateTime>(), It.IsAny<int>()), Times.Once);
_mockDocumentProcessingInfoService.Verify(x => x.GetListByIdAsync(It.IsAny<List<int>>()), Times.Once);
_mockDocumentTypeRetrieverService.Verify(x => x.GetListOfMaliciousDocuments(It.IsAny<MaliciousDocumentSearchFilter>()), Times.Once);
_mockDocumentTypeRetrieverService.Verify(x => x.GetDocumentCodeDetailByBusinessName(It.IsAny<string>()), Times.Never);
_mockQueueMemberNotificationCompletionService.Verify(x => x.QueueMemberNotificationCompletionRequest(It.IsAny<MemberNotificationCompletionRequest>(),
It.IsAny<bool>(),
It.IsAny<List<string>>()), Times.Exactly(2));
_mockNotificationApiService.Verify(x => x.SendEmailAsync(It.IsAny<EmailRequest>()), Times.Never);
}
[Test]
public void PrepareAndSendNotifications_ArgumentNullException()
{
MemberDocumentNotificationRequest request = null;
Assert.ThrowsAsync<ArgumentNullException>(async () => await _memberDocumentNotifierService.HandleMemberDocumentNotification(request));
_mockMemberNotificationInfoService.Verify(x => x.GetSendableMemberNotificationInfosAsync(It.IsAny<DateTime>(), It.IsAny<int>()), Times.Never);
_mockMemberNotificationInfoDeterminingService.Verify(x => x.DetermineDeliveryMethod(It.IsAny<MemberNotificationInfo>()), Times.Never);
_mockDocumentProcessingInfoService.Verify(x => x.GetListByIdAsync(It.IsAny<List<int>>()), Times.Never);
_mockNotificationApiService.Verify(x => x.SendEmailAsync(It.IsAny<EmailRequest>()), Times.Never);
}
[Test]
public async Task PrepareAndSendNotifications_BreakLargeChunk_Success()
{
var request = new MemberDocumentNotificationRequest() { RunCriticalFailureNotifications = false };
var repeatAmount = 15000;
var randomInt = new Random();
var memberNotificationInfos = Enumerable.Repeat(1, repeatAmount)
.Select(_ => GenerateSingleMemberNotificationInfo(randomInt.Next(1, repeatAmount))).ToList();
var documentProcessingInfos = Enumerable.Repeat(1, repeatAmount)
.Select(_ => GenerateSingleDocumentProcessingInfo(Guid.NewGuid())).ToList();
var documentCodeDetailInfo = GenerateDocumentCodeDetailInfos().FirstOrDefault();
List<DocumentMetadataResponse> maliciousDocuments = null;
_mockMemberNotificationInfoService
.Setup(x => x.GetSendableMemberNotificationInfosAsync(It.IsAny<DateTime>(), _apiConfiguration.MaxMemberNotificationAttempts))
.ReturnsAsync(memberNotificationInfos);
_mockDocumentProcessingInfoService.SetupSequence(x => x.GetListByIdAsync(It.IsAny<List<int>>()))
.ReturnsAsync(documentProcessingInfos.Skip(0).Take(_apiConfiguration.BatchSkipAmount).ToList())
.ReturnsAsync(documentProcessingInfos.Skip(_apiConfiguration.BatchSkipAmount).Take(_apiConfiguration.BatchSkipAmount).ToList());
_mockDocumentTypeRetrieverService.Setup(x => x.GetListOfMaliciousDocuments(It.IsAny<MaliciousDocumentSearchFilter>())).ReturnsAsync(maliciousDocuments);
_mockDocumentTypeRetrieverService.Setup(x => x.GetDocumentCodeDetailByBusinessName(It.IsAny<string>()))
.ReturnsAsync(() => documentCodeDetailInfo);
var result = await _memberDocumentNotifierService.PrepareAndSendNotifications(request);
Assert.NotNull(result);
Assert.IsTrue(result.IsSuccessful);
Assert.IsEmpty(result.Messages);
Assert.Zero(result.FailureCount);
_mockMemberNotificationInfoService.Verify(x => x.GetSendableMemberNotificationInfosAsync(It.IsAny<DateTime>(), It.IsAny<int>()), Times.Once);
_mockMemberNotificationInfoService.Verify(x => x.UpdateRange(It.IsAny<IEnumerable<MemberNotificationInfo>>()), Times.Exactly(2));
_mockDocumentProcessingInfoService.Verify(x => x.GetListByIdAsync(It.IsAny<List<int>>()), Times.Exactly(2));
_mockMemberNotificationInfoDeterminingService.Verify(x => x.DetermineDeliveryMethod(It.IsAny<MemberNotificationInfo>()), Times.Never);
_mockDocumentTypeRetrieverService.Verify(x => x.GetListOfMaliciousDocuments(It.IsAny<MaliciousDocumentSearchFilter>()), Times.Once);
_mockDocumentTypeRetrieverService.Verify(x => x.GetDocumentCodeDetailByBusinessName(It.IsAny<string>()), Times.Exactly(repeatAmount));
_mockNotificationApiService.Verify(x => x.SendEmailAsync(It.IsAny<EmailRequest>()), Times.Once);
}
const string letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvqxyz";
private static readonly Random Random = new(DateTime.Now.Millisecond);
private static string RandomString => new(Enumerable.Repeat(() => letters[Random.Next(letters.Length)], 10).Select(c => c()).ToArray());
private static Random IdSeries = new();
private static MemberNotificationInfo MemberNotificationFactory
(
string? emailAddress = null,
string? agreeUserId = null,
int? documentProcessingInfoId = null,
NotificationStatusTypes? notificationStatusType = null
)
=> new()
{
MemberNotificationInfoId = IdSeries.Next(),
AgreeUserId = agreeUserId ?? $"{IdSeries.Next()}{IdSeries.Next()}{IdSeries.Next()}",
EmailAddress = emailAddress ?? $"{RandomString}@{RandomString}.com",
EntityName = Guid.NewGuid().ToString(),
DeliveryMethod = DeliveryMethod.Electronic,
DocumentProcessingInfoId = documentProcessingInfoId ?? IdSeries.Next(),
Attempts = 0,
NotificationStatusType = notificationStatusType ?? NotificationStatusTypes.Pending,
SentTimeStamp = DateTime.UtcNow,
UploadDate = DateTime.UtcNow
};
private static List<MemberNotificationInfo> GenerateMemberNotificationInfos()
{
return new List<MemberNotificationInfo>
{
MemberNotificationFactory
(
agreeUserId: "123",
emailAddress: "[email protected]",
documentProcessingInfoId: 5,
notificationStatusType: NotificationStatusTypes.Pending
),
MemberNotificationFactory
(
agreeUserId: "123",
emailAddress: "[email protected]",
documentProcessingInfoId: 6,
notificationStatusType: NotificationStatusTypes.Pending
),
MemberNotificationFactory
(
agreeUserId: "789",
emailAddress: "[email protected]",
documentProcessingInfoId: 7,
notificationStatusType: NotificationStatusTypes.Failure
)
};
}
private static DocumentProcessingInfo DocumentProcessingInfoFactory
(
int? documentProcessingInfoId = null
) => new()
{
DocumentId = new Guid(),
DocumentProcessingInfoId = documentProcessingInfoId ?? IdSeries.Next(),
DocumentFileName = Guid.NewGuid().ToString(),
DocumentBusinessName = Guid.NewGuid().ToString()
};
private static List<DocumentProcessingInfo> GenerateDocumentProcessingInfos()
{
return new List<DocumentProcessingInfo>()
{
DocumentProcessingInfoFactory
(
documentProcessingInfoId: 5
),
DocumentProcessingInfoFactory
(
documentProcessingInfoId: 6
),
DocumentProcessingInfoFactory
(
documentProcessingInfoId: 7
)
};
}
private static DocumentCodeDetailInfo DocumentCodeDetailInfoFactory
(
string? documentBusinessName = null
) => new()
{
DocumentBusinessName = documentBusinessName ?? Guid.NewGuid().ToString(),
DocumentMemberFacingName = Guid.NewGuid().ToString()
};
private static List<DocumentCodeDetailInfo> GenerateDocumentCodeDetailInfos()
{
return new List<DocumentCodeDetailInfo>
{
DocumentCodeDetailInfoFactory
(
documentBusinessName: "5498-SA HSA Contributions (Tax)"
),
DocumentCodeDetailInfoFactory
(
documentBusinessName: "1099-MISC"
),
DocumentCodeDetailInfoFactory
(
documentBusinessName: "5498 (Retirement Plan Contributions) (Tax)"
)
};
}
public MemberNotificationInfo GenerateSingleMemberNotificationInfo(int id)
{
return new MemberNotificationInfo()
{
MemberNotificationInfoId = id,
AgreeUserId = "123",
EmailAddress = "[email protected]",
EntityName = "Fred",
DeliveryMethod = DeliveryMethod.Electronic,
DocumentProcessingInfoId = 5,
Attempts = 1,
NotificationStatusType = NotificationStatusTypes.Pending,
SentTimeStamp = DateTime.UtcNow,
UploadDate = DateTime.UtcNow
};
}
public DocumentProcessingInfo GenerateSingleDocumentProcessingInfo(Guid id)
{
return new DocumentProcessingInfo()
{
DocumentId = id,
DocumentProcessingInfoId = 5,
DocumentFileName = "FileName1",
DocumentBusinessName = "5498-SA HSA Contributions (Tax)"
};
}
}
@@ -0,0 +1,340 @@
using LCU.API.Internal.DocumentIngestor.Configurations;
using LCU.API.Internal.DocumentIngestor.Services;
using LCU.API.Internal.DocumentIngestor.Services.IngestionOperationServices;
using LCU.API.Internal.DocumentIngestor.Services.MicroApiServices;
using LCU.Library.Internal.ApiResponse.Models;
using LCU.Library.Internal.DocumentIngestorModels.Entities;
using LCU.Library.Internal.DocumentIngestorModels.Enums;
using LCU.Library.Internal.Exceptions;
using Moq;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace LCU.API.Internal.DocumentIngestorTests.Services.IngestionOperationServices;
public class MemberNotificationCompletionServiceTest
{
private MemberNotificationCompletionService _memberNotificationCompletionService;
private Mock<IMemberNotificationInfoService> _mockMemberNotificationInfoService;
private Mock<IMemberPreferencesApiService> _mockMemberPreferencesApiService;
private Mock<IProcessingLogService> _mockProcessingLogService;
private ApiConfiguration _apiConfiguration;
[SetUp]
public void Setup()
{
_mockMemberNotificationInfoService = new Mock<IMemberNotificationInfoService>();
_mockMemberPreferencesApiService = new Mock<IMemberPreferencesApiService>();
_mockProcessingLogService = new Mock<IProcessingLogService>();
_apiConfiguration = new ApiConfiguration() { MaxMemberNotificationAttempts = 3, TimeZone = "America/Chicago" };
_memberNotificationCompletionService = new MemberNotificationCompletionService(_mockMemberNotificationInfoService.Object,
_mockMemberPreferencesApiService.Object,
_mockProcessingLogService.Object,
_apiConfiguration);
}
[Test]
public void HandleMemberNotificationCompletion_ArgumentNullException_ResponseNull()
{
Response response = null;
Assert.ThrowsAsync<ArgumentNullException>(async () => await _memberNotificationCompletionService.HandleMemberNotificationCompletion(response));
}
[Test]
public async Task CompleteAndUpdateStatuses_Success()
{
var memberNotificationInfoIds = new List<int> { 1, 2, 3, 4, 5 };
var success = true;
var logs = new List<string>();
var memberNotificationInfos = new List<MemberNotificationInfo>()
{
new()
{
MemberNotificationInfoId = memberNotificationInfoIds[0],
NotificationStatusType = NotificationStatusTypes.Pending,
AgreeUserId = "111",
EmailAddress = "[email protected]"
},
new()
{
MemberNotificationInfoId = memberNotificationInfoIds[1],
NotificationStatusType = NotificationStatusTypes.Pending,
AgreeUserId = "111",
EmailAddress = "[email protected]"
},
new()
{
MemberNotificationInfoId = memberNotificationInfoIds[2],
NotificationStatusType = NotificationStatusTypes.Pending,
AgreeUserId = "111",
EmailAddress = "[email protected]"
},
new()
{
MemberNotificationInfoId = memberNotificationInfoIds[3],
NotificationStatusType = NotificationStatusTypes.Failure,
AgreeUserId = "444",
EmailAddress = "[email protected]"
},
new()
{
MemberNotificationInfoId = memberNotificationInfoIds[4],
NotificationStatusType = NotificationStatusTypes.Failure,
AgreeUserId = "444",
EmailAddress = "[email protected]"
},
};
// Get MemberNotificationInfos
_mockMemberNotificationInfoService.Setup(x => x.GetListByIdAsync(memberNotificationInfoIds)).ReturnsAsync(memberNotificationInfos);
// Update
_mockMemberNotificationInfoService.SetupSequence(x => x.Update(It.IsAny<MemberNotificationInfo>())).ReturnsAsync(memberNotificationInfos[0])
.ReturnsAsync(memberNotificationInfos[1])
.ReturnsAsync(memberNotificationInfos[2])
.ReturnsAsync(memberNotificationInfos[3])
.ReturnsAsync(memberNotificationInfos[4]);
await _memberNotificationCompletionService.CompleteAndUpdateStatuses(memberNotificationInfoIds, success, logs);
var completed = memberNotificationInfos?.Where(x => x.NotificationStatusType == NotificationStatusTypes.Complete).Count();
Assert.AreEqual(completed, 5);
_mockMemberNotificationInfoService.Verify(x => x.GetListByIdAsync(It.IsAny<List<int>>()), Times.Once);
_mockMemberPreferencesApiService.Verify(x => x.EmailStatusSend(It.IsAny<string>(),
It.IsAny<string>(),
success), Times.Exactly(2));
_mockMemberNotificationInfoService.Verify(x => x.Update(It.IsAny<MemberNotificationInfo>()), Times.Exactly(5));
_mockProcessingLogService.Verify(x => x.SaveAsync(It.IsAny<ProcessingLog>()), Times.Never);
}
[Test]
public async Task CompleteAndUpdateStatuses_Failure()
{
var memberNotificationInfoIds = new List<int> { 1, 2, 3, 4, 5 };
var success = false;
var logs = new List<string>() { "Failure 1", "Failure 2" };
var memberNotificationInfos = new List<MemberNotificationInfo>()
{
new()
{
MemberNotificationInfoId = memberNotificationInfoIds[0],
NotificationStatusType = NotificationStatusTypes.Pending,
AgreeUserId = "111",
EmailAddress = "[email protected]",
Attempts = 2
},
new()
{
MemberNotificationInfoId = memberNotificationInfoIds[1],
NotificationStatusType = NotificationStatusTypes.Pending,
AgreeUserId = "111",
EmailAddress = "[email protected]",
Attempts = 3
},
new()
{
MemberNotificationInfoId = memberNotificationInfoIds[2],
NotificationStatusType = NotificationStatusTypes.Pending,
AgreeUserId = "111",
EmailAddress = "[email protected]",
Attempts = 2
},
new()
{
MemberNotificationInfoId = memberNotificationInfoIds[3],
NotificationStatusType = NotificationStatusTypes.Failure,
AgreeUserId = "444",
EmailAddress = "[email protected]",
Attempts = 2
},
new()
{
MemberNotificationInfoId = memberNotificationInfoIds[4],
NotificationStatusType = NotificationStatusTypes.Failure,
AgreeUserId = "444",
EmailAddress = "[email protected]",
Attempts = 1
},
};
// Get MemberNotificationInfos
_mockMemberNotificationInfoService.Setup(x => x.GetListByIdAsync(memberNotificationInfoIds)).ReturnsAsync(memberNotificationInfos);
// Update
_mockMemberNotificationInfoService.SetupSequence(x => x.Update(It.IsAny<MemberNotificationInfo>())).ReturnsAsync(memberNotificationInfos[0])
.ReturnsAsync(memberNotificationInfos[1])
.ReturnsAsync(memberNotificationInfos[2])
.ReturnsAsync(memberNotificationInfos[3])
.ReturnsAsync(memberNotificationInfos[4]);
await _memberNotificationCompletionService.CompleteAndUpdateStatuses(memberNotificationInfoIds, success, logs);
var undeliverable = memberNotificationInfos?.Where(x => x.NotificationStatusType == NotificationStatusTypes.Undeliverable).Count();
var failure = memberNotificationInfos?.Where(x => x.NotificationStatusType == NotificationStatusTypes.Failure).Count();
Assert.AreEqual(undeliverable, 1);
Assert.AreEqual(failure, 4);
_mockMemberNotificationInfoService.Verify(x => x.GetListByIdAsync(It.IsAny<List<int>>()), Times.Once);
_mockMemberPreferencesApiService.Verify(x => x.EmailStatusSend(It.IsAny<string>(),
It.IsAny<string>(),
success), Times.Once);
_mockMemberNotificationInfoService.Verify(x => x.Update(It.IsAny<MemberNotificationInfo>()), Times.Exactly(5));
_mockProcessingLogService.Verify(x => x.SaveAsync(It.IsAny<ProcessingLog>()), Times.Exactly(10));
}
[Test]
public void CompleteAndUpdateStatuses_Exception()
{
var memberNotificationInfoIds = new List<int> { 1, 2, 3, 4, 5 };
var success = false;
var logs = new List<string>();
_mockMemberNotificationInfoService.Setup(x => x.GetListByIdAsync(It.IsAny<List<int>>())).Throws(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _memberNotificationCompletionService.CompleteAndUpdateStatuses(memberNotificationInfoIds, success, logs)); ;
_mockMemberNotificationInfoService.Verify(x => x.Update(It.IsAny<MemberNotificationInfo>()), Times.Never);
_mockMemberNotificationInfoService.Verify(x => x.GetListByIdAsync(It.IsAny<List<int>>()), Times.Once);
_mockMemberPreferencesApiService.Verify(x => x.EmailStatusSend(It.IsAny<string>(),
It.IsAny<string>(),
success), Times.Never);
_mockProcessingLogService.Verify(x => x.SaveAsync(It.IsAny<ProcessingLog>()), Times.Never);
}
[Test]
public async Task CompleteAndUpdateStatuses_Exception_EmailNotFound()
{
var memberNotificationInfoIds = new List<int> { 1, 2, 3, 4, 5 };
var success = false;
var logs = new List<string>();
var memberNotificationInfos = new List<MemberNotificationInfo>()
{
new()
{
MemberNotificationInfoId = memberNotificationInfoIds[0],
NotificationStatusType = NotificationStatusTypes.Pending,
AgreeUserId = "111",
EmailAddress = "[email protected]",
Attempts = 2
},
new()
{
MemberNotificationInfoId = memberNotificationInfoIds[1],
NotificationStatusType = NotificationStatusTypes.Pending,
AgreeUserId = "111",
EmailAddress = "[email protected]",
Attempts = 3
},
new()
{
MemberNotificationInfoId = memberNotificationInfoIds[2],
NotificationStatusType = NotificationStatusTypes.Pending,
AgreeUserId = "111",
EmailAddress = "[email protected]",
Attempts = 2
},
new()
{
MemberNotificationInfoId = memberNotificationInfoIds[3],
NotificationStatusType = NotificationStatusTypes.Failure,
AgreeUserId = "444",
EmailAddress = "[email protected]",
Attempts = 2
},
new()
{
MemberNotificationInfoId = memberNotificationInfoIds[4],
NotificationStatusType = NotificationStatusTypes.Failure,
AgreeUserId = "444",
EmailAddress = "[email protected]",
Attempts = 1
},
};
_mockMemberNotificationInfoService.Setup(x => x.GetListByIdAsync(It.IsAny<List<int>>())).ReturnsAsync(memberNotificationInfos);
_mockMemberPreferencesApiService.Setup(x => x.EmailStatusSend(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>()))
.Throws(new Exception("StatusCode:NotFound"));
await _memberNotificationCompletionService.CompleteAndUpdateStatuses(memberNotificationInfoIds, success, logs);
_mockMemberNotificationInfoService.Verify(x => x.GetListByIdAsync(It.IsAny<List<int>>()), Times.Once);
_mockMemberNotificationInfoService.Verify(x => x.Update(It.IsAny<MemberNotificationInfo>()), Times.Exactly(memberNotificationInfos.Count));
_mockMemberPreferencesApiService.Verify(x => x.EmailStatusSend(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<bool>()), Times.Once);
_mockProcessingLogService.Verify(x => x.SaveAsync(It.IsAny<ProcessingLog>()), Times.Never);
}
[Test]
public void CompleteAndUpdateStatuses_Exception_EmailOtherError()
{
var memberNotificationInfoIds = new List<int> { 1, 2, 3, 4, 5 };
var success = false;
var logs = new List<string>();
var memberNotificationInfos = new List<MemberNotificationInfo>()
{
new()
{
MemberNotificationInfoId = memberNotificationInfoIds[0],
NotificationStatusType = NotificationStatusTypes.Pending,
AgreeUserId = "111",
EmailAddress = "[email protected]",
Attempts = 2
},
new()
{
MemberNotificationInfoId = memberNotificationInfoIds[1],
NotificationStatusType = NotificationStatusTypes.Pending,
AgreeUserId = "111",
EmailAddress = "[email protected]",
Attempts = 3
},
new()
{
MemberNotificationInfoId = memberNotificationInfoIds[2],
NotificationStatusType = NotificationStatusTypes.Pending,
AgreeUserId = "111",
EmailAddress = "[email protected]",
Attempts = 2
},
new()
{
MemberNotificationInfoId = memberNotificationInfoIds[3],
NotificationStatusType = NotificationStatusTypes.Failure,
AgreeUserId = "444",
EmailAddress = "[email protected]",
Attempts = 2
},
new()
{
MemberNotificationInfoId = memberNotificationInfoIds[4],
NotificationStatusType = NotificationStatusTypes.Failure,
AgreeUserId = "444",
EmailAddress = "[email protected]",
Attempts = 1
},
};
var pendingCount = memberNotificationInfos.Count(x => x.NotificationStatusType == NotificationStatusTypes.Pending);
_mockMemberNotificationInfoService.Setup(x => x.GetListByIdAsync(It.IsAny<List<int>>())).ReturnsAsync(memberNotificationInfos);
_mockMemberPreferencesApiService.Setup(x => x.EmailStatusSend(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>()))
.Throws(new Exception("Unexpected Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _memberNotificationCompletionService.CompleteAndUpdateStatuses(memberNotificationInfoIds, success, logs));
_mockMemberNotificationInfoService.Verify(x => x.GetListByIdAsync(It.IsAny<List<int>>()), Times.Once);
_mockMemberNotificationInfoService.Verify(x => x.Update(It.IsAny<MemberNotificationInfo>()), Times.Exactly(pendingCount));
_mockMemberPreferencesApiService.Verify(x => x.EmailStatusSend(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<bool>()), Times.Once);
_mockProcessingLogService.Verify(x => x.SaveAsync(It.IsAny<ProcessingLog>()), Times.Never);
}
}
@@ -0,0 +1,773 @@
using System;
using System.IO;
using System.Collections.Generic;
using System.Threading.Tasks;
using Moq;
using NUnit.Framework;
using LCU.Library.Internal.DocumentIngestorModels.Models;
using LCU.API.Internal.DocumentIngestor.Services.IngestionOperationServices;
using LCU.API.Internal.DocumentIngestor.Services.MicroApiServices;
using LCU.Library.Internal.Exceptions;
using LCU.API.Internal.DocumentIngestor.Services;
using LCU.API.Internal.DocumentIngestor.Configurations;
using LCU.Library.Internal.FileOperationsModels.Models;
namespace LCU.API.Internal.DocumentIngestorTests.Services.IngestionOperationServices;
public class OsgPreprocessorServiceTest
{
private OsgPreprocessorService _osgPreprocessorService;
private Mock<IFileOperationsApiService> _mockFileOperationsApiService;
private Mock<IOsgPreprocessorInfoService> _mockOsgPreprocessorInfoService;
private ApiConfiguration _apiConfiguration;
[SetUp]
public void Setup()
{
_mockFileOperationsApiService = new Mock<IFileOperationsApiService>();
_mockOsgPreprocessorInfoService = new Mock<IOsgPreprocessorInfoService>();
_apiConfiguration = new ApiConfiguration() { TimeZone = "America/Chicago" };
_osgPreprocessorService = new OsgPreprocessorService(_mockFileOperationsApiService.Object,
_mockOsgPreprocessorInfoService.Object,
_apiConfiguration);
}
public OsgPreprocessorRequest BuildTestOsgPreprocessorRequest()
{
return new OsgPreprocessorRequest()
{
ArchiveStartDate = new DateTime(2020, 10, 1),
SourceBasePath = @"\TEST\SourceBasePath",
WorkingBasePath = Path.GetFullPath(@"..\..\..\TestContent"),
OutputBasePath = @"\TEST\OutputBasePath",
IncompleteOutputBasePath = @"\TEST\IncompleteOutputBasePath"
};
}
[Test]
public async Task HandleOsgPreprocessing_Success()
{
var request = BuildTestOsgPreprocessorRequest();
var allZipsInDirectory = new List<string>() { "Test_OSG_Index_File.ZIP" };
var pdfList = new List<string>() { "testPdf.1.PDF", "testPdf.2.PDF" };
var indexFiles = new List<string>() { "Test_OSG_Index_File.XML" };
var requestResponse = new RequestResponse() { IsSuccessful = true };
_mockFileOperationsApiService.SetupSequence(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>())).ReturnsAsync(allZipsInDirectory)
.ReturnsAsync(indexFiles)
.ReturnsAsync(pdfList);
_mockFileOperationsApiService.SetupSequence(x => x.DirectMoveFile(request.SourceBasePath, allZipsInDirectory[0], request.WorkingBasePath)).ReturnsAsync(requestResponse);
_mockFileOperationsApiService.SetupSequence(x => x.DirectUnzipFile(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<bool>())).ReturnsAsync(requestResponse)
.ReturnsAsync(requestResponse);
_mockFileOperationsApiService.SetupSequence(x => x.DirectDeleteFile(It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(requestResponse)
.ReturnsAsync(requestResponse);
_mockFileOperationsApiService.SetupSequence(x => x.ValidateFileExists(It.IsAny<string>())).ReturnsAsync(false)
.ReturnsAsync(false);
_mockFileOperationsApiService.SetupSequence(x => x.DirectCreateDirectory(It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(requestResponse)
.ReturnsAsync(requestResponse)
.ReturnsAsync(requestResponse);
_mockFileOperationsApiService.SetupSequence(x => x.DirectMoveFile(It.Is<string>(folderPath => folderPath.Contains(request.WorkingBasePath)),
It.IsAny<string>(),
It.Is<string>(targetDirectory => targetDirectory.Contains(request.WorkingBasePath)))).ReturnsAsync(requestResponse)
.ReturnsAsync(requestResponse)
.ReturnsAsync(requestResponse);
_mockFileOperationsApiService.SetupSequence(x => x.DirectWriteFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(requestResponse)
.ReturnsAsync(requestResponse)
.ReturnsAsync(requestResponse);
_mockFileOperationsApiService.Setup(x => x.DirectZipDirectory(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(requestResponse);
_mockFileOperationsApiService.Setup(x => x.DirectMoveFile(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>())).ReturnsAsync(requestResponse);
_mockFileOperationsApiService.Setup(x => x.DirectDeleteDirectory(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>())).ReturnsAsync(requestResponse);
await _osgPreprocessorService.HandleOsgPreprocessing(request);
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>()), Times.Exactly(3));
_mockFileOperationsApiService.Verify(x => x.DirectMoveFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Exactly(4));
_mockFileOperationsApiService.Verify(x => x.DirectUnzipFile(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<bool>()), Times.Exactly(2));
_mockFileOperationsApiService.Verify(x => x.DirectDeleteFile(It.IsAny<string>(), It.IsAny<string>()), Times.Exactly(2));
_mockFileOperationsApiService.Verify(x => x.ValidateFileExists(It.IsAny<string>()), Times.Exactly(2));
_mockFileOperationsApiService.Verify(x => x.DirectCreateDirectory(It.IsAny<string>(), It.IsAny<string>()), Times.Exactly(3));
_mockFileOperationsApiService.Verify(x => x.DirectWriteFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Exactly(3));
_mockFileOperationsApiService.Verify(x => x.DirectZipDirectory(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.DirectDeleteDirectory(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>()), Times.Once);
}
[Test]
public async Task HandleOsgPreprocessing_Failure_IndexFileDoesNotExist()
{
var request = BuildTestOsgPreprocessorRequest();
var allZipsInDirectory = new List<string>() { "Test_OSG_Index_File.ZIP" };
var indexFiles = new List<string>() { };
var requestResponse = new RequestResponse() { IsSuccessful = true };
_mockFileOperationsApiService.SetupSequence(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>())).ReturnsAsync(allZipsInDirectory)
.ReturnsAsync(indexFiles);
_mockFileOperationsApiService.SetupSequence(x => x.DirectMoveFile(request.SourceBasePath, allZipsInDirectory[0], request.WorkingBasePath)).ReturnsAsync(requestResponse);
_mockFileOperationsApiService.Setup(x => x.DirectUnzipFile(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<bool>())).ReturnsAsync(requestResponse);
_mockFileOperationsApiService.Setup(x => x.DirectDeleteFile(It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(requestResponse);
_mockFileOperationsApiService.Setup(x => x.DirectWriteFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(requestResponse);
_mockFileOperationsApiService.Setup(x => x.DirectZipDirectory(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(requestResponse);
_mockFileOperationsApiService.Setup(x => x.DirectMoveFile(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>())).ReturnsAsync(requestResponse);
_mockFileOperationsApiService.Setup(x => x.DirectDeleteDirectory(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>())).ReturnsAsync(requestResponse);
await _osgPreprocessorService.HandleOsgPreprocessing(request);
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>()), Times.Exactly(2));
_mockFileOperationsApiService.Verify(x => x.DirectMoveFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Exactly(2));
_mockFileOperationsApiService.Verify(x => x.DirectUnzipFile(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<bool>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.DirectDeleteFile(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.ValidateFileExists(It.IsAny<string>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.DirectCreateDirectory(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.DirectWriteFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.DirectZipDirectory(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()), Times.Once);
}
[Test]
public async Task HandleOsgPreprocessing_Failure_ParseReturnedNoRecords()
{
var request = BuildTestOsgPreprocessorRequest();
var allZipsInDirectory = new List<string>() { "Test_OSG_Index_File.ZIP" };
var indexFiles = new List<string>() { "Test_OSG_Index_File_1099_MISC.XML" };
var requestResponse = new RequestResponse() { IsSuccessful = true };
_mockFileOperationsApiService.SetupSequence(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>())).ReturnsAsync(allZipsInDirectory)
.ReturnsAsync(indexFiles);
_mockFileOperationsApiService.SetupSequence(x => x.DirectMoveFile(request.SourceBasePath, allZipsInDirectory[0], request.WorkingBasePath)).ReturnsAsync(requestResponse);
_mockFileOperationsApiService.SetupSequence(x => x.DirectUnzipFile(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<bool>())).ReturnsAsync(requestResponse);
_mockFileOperationsApiService.SetupSequence(x => x.DirectDeleteFile(It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(requestResponse)
.ReturnsAsync(requestResponse);
_mockFileOperationsApiService.SetupSequence(x => x.DirectMoveFile(It.Is<string>(folderPath => folderPath.Contains(request.WorkingBasePath)),
It.IsAny<string>(),
It.Is<string>(targetDirectory => targetDirectory.Contains(request.WorkingBasePath)))).ReturnsAsync(requestResponse)
.ReturnsAsync(requestResponse)
.ReturnsAsync(requestResponse);
_mockFileOperationsApiService.Setup(x => x.DirectWriteFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(requestResponse);
_mockFileOperationsApiService.Setup(x => x.DirectZipDirectory(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(requestResponse);
_mockFileOperationsApiService.Setup(x => x.DirectMoveFile(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>())).ReturnsAsync(requestResponse);
_mockFileOperationsApiService.Setup(x => x.DirectDeleteDirectory(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>())).ReturnsAsync(requestResponse);
await _osgPreprocessorService.HandleOsgPreprocessing(request);
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>()), Times.Exactly(2));
_mockFileOperationsApiService.Verify(x => x.DirectMoveFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Exactly(1));
_mockFileOperationsApiService.Verify(x => x.DirectUnzipFile(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<bool>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.DirectDeleteFile(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.ValidateFileExists(It.IsAny<string>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.DirectCreateDirectory(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.DirectWriteFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.DirectZipDirectory(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.DirectDeleteDirectory(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>()), Times.Once);
}
[Test]
public async Task HandleOsgPreprocessing_Failure_NoMatchingPdfsFound()
{
var request = BuildTestOsgPreprocessorRequest();
var allZipsInDirectory = new List<string>() { "Test_OSG_Index_File.ZIP" };
var pdfList = new List<string>() { "testPdf.3.PDF", "testPdf.4.PDF" };
var indexFiles = new List<string>() { "Test_OSG_Index_File.XML" };
var requestResponse = new RequestResponse() { IsSuccessful = true };
_mockFileOperationsApiService.SetupSequence(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>())).ReturnsAsync(allZipsInDirectory)
.ReturnsAsync(indexFiles)
.ReturnsAsync(pdfList);
_mockFileOperationsApiService.Setup(x => x.DirectMoveFile(request.SourceBasePath, allZipsInDirectory[0], request.WorkingBasePath)).ReturnsAsync(requestResponse);
_mockFileOperationsApiService.Setup(x => x.DirectUnzipFile(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<bool>())).ReturnsAsync(requestResponse);
_mockFileOperationsApiService.Setup(x => x.DirectDeleteFile(It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(requestResponse);
_mockFileOperationsApiService.SetupSequence(x => x.ValidateFileExists(It.IsAny<string>())).ReturnsAsync(false)
.ReturnsAsync(false);
_mockFileOperationsApiService.Setup(x => x.DirectWriteFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(requestResponse);
_mockFileOperationsApiService.Setup(x => x.DirectZipDirectory(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(requestResponse);
_mockFileOperationsApiService.Setup(x => x.DirectMoveFile(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>())).ReturnsAsync(requestResponse);
_mockFileOperationsApiService.Setup(x => x.DirectDeleteDirectory(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>())).ReturnsAsync(requestResponse);
await _osgPreprocessorService.HandleOsgPreprocessing(request);
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>()), Times.Exactly(3));
_mockFileOperationsApiService.Verify(x => x.DirectMoveFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Exactly(2));
_mockFileOperationsApiService.Verify(x => x.DirectUnzipFile(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<bool>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.DirectDeleteFile(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.ValidateFileExists(It.IsAny<string>()), Times.Exactly(2));
_mockFileOperationsApiService.Verify(x => x.DirectCreateDirectory(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.DirectWriteFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.DirectZipDirectory(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.DirectDeleteDirectory(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>()), Times.Once);
}
[Test]
public void HandleOsgPreprocessing_Failure_FailedToDeleteIndexFile()
{
var request = BuildTestOsgPreprocessorRequest();
var allZipsInDirectory = new List<string>() { "Test_OSG_Index_File.ZIP" };
var responseSuccess = new RequestResponse() { IsSuccessful = true };
var responseFailure = new RequestResponse() { IsSuccessful = false };
_mockFileOperationsApiService.Setup(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>())).ReturnsAsync(allZipsInDirectory);
_mockFileOperationsApiService.Setup(x => x.DirectMoveFile(request.SourceBasePath, allZipsInDirectory[0], request.WorkingBasePath)).ReturnsAsync(responseSuccess);
_mockFileOperationsApiService.Setup(x => x.DirectUnzipFile(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<bool>())).ReturnsAsync(responseSuccess);
_mockFileOperationsApiService.Setup(x => x.DirectDeleteFile(It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(responseFailure);
Assert.ThrowsAsync<ServiceException>(async () => await _osgPreprocessorService.HandleOsgPreprocessing(request));
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.DirectMoveFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.DirectUnzipFile(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<bool>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.DirectDeleteFile(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.ValidateFileExists(It.IsAny<string>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.DirectCreateDirectory(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.DirectWriteFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.DirectZipDirectory(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.DirectDeleteDirectory(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>()), Times.Never);
}
[Test]
public void HandleOsgPreprocessing_FailureToWriteInfoLog()
{
var request = BuildTestOsgPreprocessorRequest();
var allZipsInDirectory = new List<string>() { "Test_OSG_Index_File.ZIP" };
var pdfList = new List<string>() { "testPdf.1.PDF", "testPdf.2.PDF" };
var indexFiles = new List<string>() { "Test_OSG_Index_File.XML" };
var responseSuccess = new RequestResponse() { IsSuccessful = true };
var responseFailure = new RequestResponse() { IsSuccessful = false };
_mockFileOperationsApiService.SetupSequence(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>())).ReturnsAsync(allZipsInDirectory)
.ReturnsAsync(indexFiles)
.ReturnsAsync(pdfList);
_mockFileOperationsApiService.SetupSequence(x => x.DirectMoveFile(request.SourceBasePath, allZipsInDirectory[0], request.WorkingBasePath)).ReturnsAsync(responseSuccess);
_mockFileOperationsApiService.SetupSequence(x => x.DirectUnzipFile(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<bool>())).ReturnsAsync(responseSuccess);
_mockFileOperationsApiService.SetupSequence(x => x.DirectDeleteFile(It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(responseSuccess)
.ReturnsAsync(responseSuccess);
_mockFileOperationsApiService.SetupSequence(x => x.ValidateFileExists(It.IsAny<string>())).ReturnsAsync(false)
.ReturnsAsync(false);
_mockFileOperationsApiService.SetupSequence(x => x.DirectCreateDirectory(It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(responseSuccess)
.ReturnsAsync(responseSuccess)
.ReturnsAsync(responseSuccess);
_mockFileOperationsApiService.SetupSequence(x => x.DirectMoveFile(It.Is<string>(folderPath => folderPath.Contains(request.WorkingBasePath)),
It.IsAny<string>(),
It.Is<string>(targetDirectory => targetDirectory.Contains(request.WorkingBasePath)))).ReturnsAsync(responseSuccess)
.ReturnsAsync(responseSuccess)
.ReturnsAsync(responseSuccess);
_mockFileOperationsApiService.SetupSequence(x => x.DirectWriteFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(responseSuccess)
.ReturnsAsync(responseSuccess)
.ReturnsAsync(responseFailure);
Assert.ThrowsAsync<ServiceException>(async () => await _osgPreprocessorService.HandleOsgPreprocessing(request));
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>()), Times.Exactly(3));
_mockFileOperationsApiService.Verify(x => x.DirectMoveFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Exactly(3));
_mockFileOperationsApiService.Verify(x => x.DirectUnzipFile(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<bool>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.DirectDeleteFile(It.IsAny<string>(), It.IsAny<string>()), Times.Exactly(2));
_mockFileOperationsApiService.Verify(x => x.ValidateFileExists(It.IsAny<string>()), Times.Exactly(2));
_mockFileOperationsApiService.Verify(x => x.DirectCreateDirectory(It.IsAny<string>(), It.IsAny<string>()), Times.Exactly(2));
_mockFileOperationsApiService.Verify(x => x.DirectWriteFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Exactly(3));
_mockFileOperationsApiService.Verify(x => x.DirectZipDirectory(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.DirectDeleteDirectory(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>()), Times.Never);
}
[Test]
public async Task HandleOsgPreprocessing_WriteParsedRecordGroup_Failure_ParsedFileExists()
{
var request = BuildTestOsgPreprocessorRequest();
var allZipsInDirectory = new List<string>() { "Test_OSG_Index_File.ZIP" };
var pdfList = new List<string>() { "testPdf.1.PDF", "testPdf.2.PDF" };
var indexFiles = new List<string>() { "Test_OSG_Index_File.XML" };
var responseSuccess = new RequestResponse() { IsSuccessful = true };
_mockFileOperationsApiService.SetupSequence(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>())).ReturnsAsync(allZipsInDirectory)
.ReturnsAsync(indexFiles)
.ReturnsAsync(pdfList);
_mockFileOperationsApiService.SetupSequence(x => x.DirectMoveFile(request.SourceBasePath, allZipsInDirectory[0], request.WorkingBasePath)).ReturnsAsync(responseSuccess);
_mockFileOperationsApiService.SetupSequence(x => x.DirectUnzipFile(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<bool>())).ReturnsAsync(responseSuccess);
_mockFileOperationsApiService.Setup(x => x.DirectDeleteFile(It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(responseSuccess);
_mockFileOperationsApiService.SetupSequence(x => x.ValidateFileExists(It.IsAny<string>())).ReturnsAsync(true)
.ReturnsAsync(false);
_mockFileOperationsApiService.SetupSequence(x => x.DirectMoveFile(It.Is<string>(folderPath => folderPath.Contains(request.WorkingBasePath)),
It.IsAny<string>(),
It.Is<string>(targetDirectory => targetDirectory.Contains(request.WorkingBasePath)))).ReturnsAsync(responseSuccess)
.ReturnsAsync(responseSuccess);
_mockFileOperationsApiService.SetupSequence(x => x.DirectWriteFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(responseSuccess)
.ReturnsAsync(responseSuccess);
_mockFileOperationsApiService.Setup(x => x.DirectZipDirectory(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(responseSuccess);
_mockFileOperationsApiService.Setup(x => x.DirectMoveFile(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>())).ReturnsAsync(responseSuccess);
_mockFileOperationsApiService.Setup(x => x.DirectDeleteDirectory(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>())).ReturnsAsync(responseSuccess);
await _osgPreprocessorService.HandleOsgPreprocessing(request);
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>()), Times.Exactly(3));
_mockFileOperationsApiService.Verify(x => x.DirectMoveFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Exactly(2));
_mockFileOperationsApiService.Verify(x => x.DirectUnzipFile(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<bool>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.DirectDeleteFile(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.ValidateFileExists(It.IsAny<string>()), Times.Exactly(2));
_mockFileOperationsApiService.Verify(x => x.DirectCreateDirectory(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.DirectWriteFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.DirectZipDirectory(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.DirectDeleteDirectory(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>()), Times.Once);
}
[Test]
public async Task HandleOsgPreprocessing_WriteParsedRecordGroup_Failure_FailedToCreateDirectory()
{
var request = BuildTestOsgPreprocessorRequest();
var allZipsInDirectory = new List<string>() { "Test_OSG_Index_File.ZIP" };
var pdfList = new List<string>() { "testPdf.1.PDF", "testPdf.2.PDF" };
var indexFiles = new List<string>() { "Test_OSG_Index_File.XML" };
var responseSuccess = new RequestResponse() { IsSuccessful = true };
var responseFailure = new RequestResponse() { IsSuccessful = false };
_mockFileOperationsApiService.SetupSequence(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>())).ReturnsAsync(allZipsInDirectory)
.ReturnsAsync(indexFiles)
.ReturnsAsync(pdfList);
_mockFileOperationsApiService.SetupSequence(x => x.DirectMoveFile(request.SourceBasePath, allZipsInDirectory[0], request.WorkingBasePath)).ReturnsAsync(responseSuccess);
_mockFileOperationsApiService.SetupSequence(x => x.DirectUnzipFile(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<bool>())).ReturnsAsync(responseSuccess);
_mockFileOperationsApiService.SetupSequence(x => x.DirectDeleteFile(It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(responseSuccess);
_mockFileOperationsApiService.SetupSequence(x => x.ValidateFileExists(It.IsAny<string>())).ReturnsAsync(false)
.ReturnsAsync(false);
_mockFileOperationsApiService.SetupSequence(x => x.DirectCreateDirectory(It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(responseFailure)
.ReturnsAsync(responseSuccess)
.ReturnsAsync(responseSuccess);
_mockFileOperationsApiService.SetupSequence(x => x.DirectMoveFile(It.Is<string>(folderPath => folderPath.Contains(request.WorkingBasePath)),
It.IsAny<string>(),
It.Is<string>(targetDirectory => targetDirectory.Contains(request.WorkingBasePath)))).ReturnsAsync(responseSuccess)
.ReturnsAsync(responseSuccess);
_mockFileOperationsApiService.SetupSequence(x => x.DirectWriteFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(responseSuccess)
.ReturnsAsync(responseSuccess);
_mockFileOperationsApiService.Setup(x => x.DirectZipDirectory(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(responseSuccess);
_mockFileOperationsApiService.Setup(x => x.DirectMoveFile(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>())).ReturnsAsync(responseSuccess);
_mockFileOperationsApiService.Setup(x => x.DirectDeleteDirectory(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>())).ReturnsAsync(responseSuccess);
await _osgPreprocessorService.HandleOsgPreprocessing(request);
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>()), Times.Exactly(3));
_mockFileOperationsApiService.Verify(x => x.DirectMoveFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Exactly(3));
_mockFileOperationsApiService.Verify(x => x.DirectUnzipFile(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<bool>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.DirectDeleteFile(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.ValidateFileExists(It.IsAny<string>()), Times.Exactly(2));
_mockFileOperationsApiService.Verify(x => x.DirectCreateDirectory(It.IsAny<string>(), It.IsAny<string>()), Times.Exactly(2));
_mockFileOperationsApiService.Verify(x => x.DirectWriteFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Exactly(2));
_mockFileOperationsApiService.Verify(x => x.DirectZipDirectory(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.DirectDeleteDirectory(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>()), Times.Once);
}
[Test]
public async Task HandleOsgPreprocessing_WriteParsedRecordGroup_Failure_FailedToMovePdf()
{
var request = BuildTestOsgPreprocessorRequest();
var allZipsInDirectory = new List<string>() { "Test_OSG_Index_File.ZIP" };
var pdfList = new List<string>() { "testPdf.1.PDF", "testPdf.2.PDF" };
var indexFiles = new List<string>() { "Test_OSG_Index_File.XML" };
var responseSuccess = new RequestResponse() { IsSuccessful = true };
var responseFailure = new RequestResponse() { IsSuccessful = false };
_mockFileOperationsApiService.SetupSequence(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>())).ReturnsAsync(allZipsInDirectory)
.ReturnsAsync(indexFiles)
.ReturnsAsync(pdfList);
_mockFileOperationsApiService.SetupSequence(x => x.DirectUnzipFile(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<bool>())).ReturnsAsync(responseSuccess);
_mockFileOperationsApiService.SetupSequence(x => x.DirectDeleteFile(It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(responseSuccess)
.ReturnsAsync(responseSuccess);
_mockFileOperationsApiService.SetupSequence(x => x.ValidateFileExists(It.IsAny<string>())).ReturnsAsync(false)
.ReturnsAsync(false);
_mockFileOperationsApiService.SetupSequence(x => x.DirectCreateDirectory(It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(responseSuccess)
.ReturnsAsync(responseSuccess)
.ReturnsAsync(responseSuccess);
_mockFileOperationsApiService.SetupSequence(x => x.DirectMoveFile(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>())).ReturnsAsync(responseSuccess)
.ReturnsAsync(responseFailure)
.ReturnsAsync(responseSuccess)
.ReturnsAsync(responseSuccess);
_mockFileOperationsApiService.SetupSequence(x => x.DirectWriteFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(responseSuccess)
.ReturnsAsync(responseSuccess)
.ReturnsAsync(responseSuccess);
_mockFileOperationsApiService.Setup(x => x.DirectZipDirectory(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(responseSuccess);
_mockFileOperationsApiService.Setup(x => x.DirectDeleteDirectory(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>())).ReturnsAsync(responseSuccess);
await _osgPreprocessorService.HandleOsgPreprocessing(request);
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>()), Times.Exactly(3));
_mockFileOperationsApiService.Verify(x => x.DirectMoveFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Exactly(4));
_mockFileOperationsApiService.Verify(x => x.DirectUnzipFile(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<bool>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.DirectDeleteFile(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.ValidateFileExists(It.IsAny<string>()), Times.Exactly(2));
_mockFileOperationsApiService.Verify(x => x.DirectCreateDirectory(It.IsAny<string>(), It.IsAny<string>()), Times.Exactly(2));
_mockFileOperationsApiService.Verify(x => x.DirectWriteFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Exactly(2));
_mockFileOperationsApiService.Verify(x => x.DirectZipDirectory(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.DirectDeleteDirectory(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>()), Times.Once);
}
[Test]
public async Task HandleOsgPreprocessing_WriteParsedRecordGroup_Failure_FailedToWriteIndexFile()
{
var request = BuildTestOsgPreprocessorRequest();
var allZipsInDirectory = new List<string>() { "Test_OSG_Index_File.ZIP" };
var pdfList = new List<string>() { "testPdf.1.PDF", "testPdf.2.PDF" };
var indexFiles = new List<string>() { "Test_OSG_Index_File.XML" };
var responseSuccess = new RequestResponse() { IsSuccessful = true };
var responseFailure = new RequestResponse() { IsSuccessful = false };
_mockFileOperationsApiService.SetupSequence(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>())).ReturnsAsync(allZipsInDirectory)
.ReturnsAsync(indexFiles)
.ReturnsAsync(pdfList);
_mockFileOperationsApiService.SetupSequence(x => x.DirectUnzipFile(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<bool>())).ReturnsAsync(responseSuccess);
_mockFileOperationsApiService.SetupSequence(x => x.DirectDeleteFile(It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(responseSuccess)
.ReturnsAsync(responseSuccess);
_mockFileOperationsApiService.SetupSequence(x => x.ValidateFileExists(It.IsAny<string>())).ReturnsAsync(false)
.ReturnsAsync(false);
_mockFileOperationsApiService.SetupSequence(x => x.DirectCreateDirectory(It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(responseSuccess)
.ReturnsAsync(responseSuccess)
.ReturnsAsync(responseSuccess);
_mockFileOperationsApiService.SetupSequence(x => x.DirectMoveFile(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>())).ReturnsAsync(responseSuccess)
.ReturnsAsync(responseSuccess)
.ReturnsAsync(responseSuccess)
.ReturnsAsync(responseSuccess);
_mockFileOperationsApiService.SetupSequence(x => x.DirectWriteFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(responseSuccess)
.ReturnsAsync(responseFailure)
.ReturnsAsync(responseSuccess);
_mockFileOperationsApiService.Setup(x => x.DirectZipDirectory(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(responseSuccess);
_mockFileOperationsApiService.Setup(x => x.DirectDeleteDirectory(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>())).ReturnsAsync(responseSuccess);
await _osgPreprocessorService.HandleOsgPreprocessing(request);
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>()), Times.Exactly(3));
_mockFileOperationsApiService.Verify(x => x.DirectMoveFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Exactly(4));
_mockFileOperationsApiService.Verify(x => x.DirectUnzipFile(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<bool>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.DirectDeleteFile(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.ValidateFileExists(It.IsAny<string>()), Times.Exactly(2));
_mockFileOperationsApiService.Verify(x => x.DirectCreateDirectory(It.IsAny<string>(), It.IsAny<string>()), Times.Exactly(2));
_mockFileOperationsApiService.Verify(x => x.DirectWriteFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Exactly(3));
_mockFileOperationsApiService.Verify(x => x.DirectZipDirectory(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.DirectDeleteDirectory(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>()), Times.Once);
}
[Test]
public void HandleOsgPreprocessing_PrepareZipFile_Failure_FailedToMoveZipFile()
{
var request = BuildTestOsgPreprocessorRequest();
var allZipsInDirectory = new List<string>() { "Test_OSG_Index_File.ZIP" };
var pdfList = new List<string>() { "testPdf.1.PDF", "testPdf.2.PDF" };
var indexFiles = new List<string>() { "Test_OSG_Index_File.XML" };
var responseSuccess = new RequestResponse() { IsSuccessful = true };
var responseFailure = new RequestResponse() { IsSuccessful = false };
_mockFileOperationsApiService.Setup(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>())).ReturnsAsync(allZipsInDirectory);
_mockFileOperationsApiService.Setup(x => x.DirectMoveFile(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>())).ReturnsAsync(responseFailure);
Assert.ThrowsAsync<ServiceException>(async () => await _osgPreprocessorService.HandleOsgPreprocessing(request));
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.DirectMoveFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.DirectUnzipFile(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<bool>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.DirectDeleteFile(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.ValidateFileExists(It.IsAny<string>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.DirectCreateDirectory(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.DirectWriteFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.DirectZipDirectory(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.DirectDeleteDirectory(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>()), Times.Never);
}
[Test]
public void HandleOsgPreprocessing_PrepareZipFile_Failure_FailedToUnzipZipFile()
{
var request = BuildTestOsgPreprocessorRequest();
var allZipsInDirectory = new List<string>() { "Test_OSG_Index_File.ZIP" };
var pdfList = new List<string>() { "testPdf.1.PDF", "testPdf.2.PDF" };
var indexFiles = new List<string>() { "Test_OSG_Index_File.XML" };
var responseSuccess = new RequestResponse() { IsSuccessful = true };
var responseFailure = new RequestResponse() { IsSuccessful = false };
_mockFileOperationsApiService.Setup(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>())).ReturnsAsync(allZipsInDirectory);
_mockFileOperationsApiService.Setup(x => x.DirectMoveFile(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>())).ReturnsAsync(responseSuccess);
_mockFileOperationsApiService.Setup(x => x.DirectUnzipFile(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<bool>())).ReturnsAsync(responseFailure);
Assert.ThrowsAsync<ServiceException>(async () => await _osgPreprocessorService.HandleOsgPreprocessing(request));
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.DirectMoveFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.DirectUnzipFile(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<bool>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.DirectDeleteFile(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.ValidateFileExists(It.IsAny<string>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.DirectCreateDirectory(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.DirectWriteFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.DirectZipDirectory(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.DirectDeleteDirectory(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>()), Times.Never);
}
[Test]
public void HandleOsgPreprocessing_PrepareZipFile_Failure_FailedToDeleteZipFile()
{
var request = BuildTestOsgPreprocessorRequest();
var allZipsInDirectory = new List<string>() { "Test_OSG_Index_File.ZIP" };
var pdfList = new List<string>() { "testPdf.1.PDF", "testPdf.2.PDF" };
var indexFiles = new List<string>() { "Test_OSG_Index_File.XML" };
var responseSuccess = new RequestResponse() { IsSuccessful = true };
var responseFailure = new RequestResponse() { IsSuccessful = false };
_mockFileOperationsApiService.Setup(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>())).ReturnsAsync(allZipsInDirectory);
_mockFileOperationsApiService.Setup(x => x.DirectMoveFile(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>())).ReturnsAsync(responseSuccess);
_mockFileOperationsApiService.Setup(x => x.DirectUnzipFile(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<bool>())).ReturnsAsync(responseSuccess);
_mockFileOperationsApiService.SetupSequence(x => x.DirectDeleteFile(It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(responseFailure);
Assert.ThrowsAsync<ServiceException>(async () => await _osgPreprocessorService.HandleOsgPreprocessing(request));
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.DirectMoveFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.DirectUnzipFile(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<bool>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.DirectDeleteFile(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.ValidateFileExists(It.IsAny<string>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.DirectCreateDirectory(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.DirectWriteFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.DirectZipDirectory(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.DirectDeleteDirectory(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>()), Times.Never);
}
[Test]
public void HandleOsgPreprocessing_ZipAndMoveResults_Failure_FailedToZipFiles()
{
var request = BuildTestOsgPreprocessorRequest();
var allZipsInDirectory = new List<string>() { "Test_OSG_Index_File.ZIP" };
var pdfList = new List<string>() { "testPdf.1.PDF", "testPdf.2.PDF" };
var indexFiles = new List<string>() { "Test_OSG_Index_File.XML" };
var responseSuccess = new RequestResponse() { IsSuccessful = true };
var responseFailure = new RequestResponse() { IsSuccessful = false };
_mockFileOperationsApiService.SetupSequence(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>())).ReturnsAsync(allZipsInDirectory)
.ReturnsAsync(indexFiles)
.ReturnsAsync(pdfList);
_mockFileOperationsApiService.SetupSequence(x => x.DirectMoveFile(request.SourceBasePath, allZipsInDirectory[0], request.WorkingBasePath)).ReturnsAsync(responseSuccess);
_mockFileOperationsApiService.SetupSequence(x => x.DirectUnzipFile(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<bool>())).ReturnsAsync(responseSuccess)
.ReturnsAsync(responseSuccess);
_mockFileOperationsApiService.SetupSequence(x => x.DirectDeleteFile(It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(responseSuccess)
.ReturnsAsync(responseSuccess);
_mockFileOperationsApiService.SetupSequence(x => x.ValidateFileExists(It.IsAny<string>())).ReturnsAsync(false)
.ReturnsAsync(false);
_mockFileOperationsApiService.SetupSequence(x => x.DirectCreateDirectory(It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(responseSuccess)
.ReturnsAsync(responseSuccess)
.ReturnsAsync(responseSuccess);
_mockFileOperationsApiService.SetupSequence(x => x.DirectMoveFile(It.Is<string>(folderPath => folderPath.Contains(request.WorkingBasePath)),
It.IsAny<string>(),
It.Is<string>(targetDirectory => targetDirectory.Contains(request.WorkingBasePath)))).ReturnsAsync(responseSuccess)
.ReturnsAsync(responseSuccess)
.ReturnsAsync(responseSuccess);
_mockFileOperationsApiService.SetupSequence(x => x.DirectWriteFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(responseSuccess)
.ReturnsAsync(responseSuccess)
.ReturnsAsync(responseSuccess);
_mockFileOperationsApiService.Setup(x => x.DirectZipDirectory(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(responseFailure);
_mockFileOperationsApiService.Setup(x => x.DirectMoveFile(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>())).ReturnsAsync(responseSuccess);
Assert.ThrowsAsync<ServiceException>(async () => await _osgPreprocessorService.HandleOsgPreprocessing(request));
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>()), Times.Exactly(3));
_mockFileOperationsApiService.Verify(x => x.DirectMoveFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Exactly(3));
_mockFileOperationsApiService.Verify(x => x.DirectUnzipFile(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<bool>()), Times.Exactly(1));
_mockFileOperationsApiService.Verify(x => x.DirectDeleteFile(It.IsAny<string>(), It.IsAny<string>()), Times.Exactly(2));
_mockFileOperationsApiService.Verify(x => x.ValidateFileExists(It.IsAny<string>()), Times.Exactly(2));
_mockFileOperationsApiService.Verify(x => x.DirectCreateDirectory(It.IsAny<string>(), It.IsAny<string>()), Times.Exactly(3));
_mockFileOperationsApiService.Verify(x => x.DirectWriteFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Exactly(3));
_mockFileOperationsApiService.Verify(x => x.DirectZipDirectory(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.DirectDeleteDirectory(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>()), Times.Never);
}
[Test]
public void HandleOsgPreprocessing_Failure_FailedToDeleteDirectory()
{
var request = BuildTestOsgPreprocessorRequest();
var allZipsInDirectory = new List<string>() { "Test_OSG_Index_File.ZIP" };
var pdfList = new List<string>() { "testPdf.1.PDF", "testPdf.2.PDF" };
var indexFiles = new List<string>() { "Test_OSG_Index_File.XML" };
var responseSuccess = new RequestResponse() { IsSuccessful = true };
var responseFailure = new RequestResponse() { IsSuccessful = false };
_mockFileOperationsApiService.SetupSequence(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>())).ReturnsAsync(allZipsInDirectory)
.ReturnsAsync(indexFiles)
.ReturnsAsync(pdfList);
_mockFileOperationsApiService.SetupSequence(x => x.DirectUnzipFile(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<bool>())).ReturnsAsync(responseSuccess)
.ReturnsAsync(responseSuccess);
_mockFileOperationsApiService.SetupSequence(x => x.DirectDeleteFile(It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(responseSuccess)
.ReturnsAsync(responseSuccess);
_mockFileOperationsApiService.SetupSequence(x => x.ValidateFileExists(It.IsAny<string>())).ReturnsAsync(false)
.ReturnsAsync(false);
_mockFileOperationsApiService.SetupSequence(x => x.DirectCreateDirectory(It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(responseSuccess)
.ReturnsAsync(responseSuccess)
.ReturnsAsync(responseSuccess);
_mockFileOperationsApiService.SetupSequence(x => x.DirectWriteFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(responseSuccess)
.ReturnsAsync(responseSuccess)
.ReturnsAsync(responseSuccess);
_mockFileOperationsApiService.SetupSequence(x => x.DirectMoveFile(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>())).ReturnsAsync(responseSuccess)
.ReturnsAsync(responseSuccess)
.ReturnsAsync(responseSuccess)
.ReturnsAsync(responseSuccess);
_mockFileOperationsApiService.Setup(x => x.DirectZipDirectory(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(responseSuccess);
_mockFileOperationsApiService.SetupSequence(x => x.DirectDeleteDirectory(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>())).ReturnsAsync(responseFailure)
.ReturnsAsync(responseFailure);
Assert.ThrowsAsync<ServiceException>(async () => await _osgPreprocessorService.HandleOsgPreprocessing(request));
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>()), Times.Exactly(3));
_mockFileOperationsApiService.Verify(x => x.DirectMoveFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Exactly(4));
_mockFileOperationsApiService.Verify(x => x.DirectUnzipFile(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<bool>()), Times.Exactly(2));
_mockFileOperationsApiService.Verify(x => x.DirectDeleteFile(It.IsAny<string>(), It.IsAny<string>()), Times.Exactly(2));
_mockFileOperationsApiService.Verify(x => x.ValidateFileExists(It.IsAny<string>()), Times.Exactly(2));
_mockFileOperationsApiService.Verify(x => x.DirectCreateDirectory(It.IsAny<string>(), It.IsAny<string>()), Times.Exactly(3));
_mockFileOperationsApiService.Verify(x => x.DirectWriteFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Exactly(3));
_mockFileOperationsApiService.Verify(x => x.DirectZipDirectory(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.DirectDeleteDirectory(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>()), Times.Once);
}
[Test]
public void HandleOsgPreprocessing_ArgumentNullException_RequestNull()
{
OsgPreprocessorRequest request = null;
Assert.ThrowsAsync<ArgumentNullException>(async () => await _osgPreprocessorService.HandleOsgPreprocessing(request));
_mockFileOperationsApiService.Verify(x => x.ValidateFileExists(It.IsAny<string>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.DirectCreateDirectory(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.DirectMoveFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.DirectWriteFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Never);
}
}
@@ -0,0 +1,198 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Moq;
using NUnit.Framework;
using LCU.Library.Internal.DocumentIngestorModels.Models;
using LCU.Library.Internal.LcuMassTransitModels;
using LCU.Library.Internal.DocumentIngestorModels.Entities;
using LCU.Library.Internal.DocumentIngestorModels.Enums;
using LCU.Library.Internal.Exceptions;
using LCU.API.Internal.DocumentIngestor.Services.IngestionOperationServices;
using LCU.API.Internal.DocumentIngestor.Services.MicroApiServices;
using LCU.API.Internal.DocumentIngestor.Configurations;
using LCU.API.Internal.DocumentIngestor.Services;
using LCU.API.Internal.DocumentIngestor.Services.QueueServices;
using LCU.API.Internal.DocumentIngestor.Services.PdfParserServices;
using LCU.Library.Internal.ApiResponse.Models;
using Newtonsoft.Json;
using LCU.Library.Internal.FileOperationsModels.Models.NameSettings;
namespace LCU.API.Internal.DocumentIngestorTests.Services.IngestionOperationServices;
public class PdfPartitionerCompletionServiceTest
{
private PdfPartitionerCompletionService _pdfPartitionerCompletionService;
private Mock<IPdfPartitionerRunInfoService> _mockPdfPartitionerRunInfoService;
private Mock<IPdfPartitionerLogService> _mockPdfPartitionerLogService;
[SetUp]
public void Setup()
{
_mockPdfPartitionerRunInfoService = new Mock<IPdfPartitionerRunInfoService>();
_mockPdfPartitionerLogService = new Mock<IPdfPartitionerLogService>();
_pdfPartitionerCompletionService = new PdfPartitionerCompletionService(_mockPdfPartitionerRunInfoService.Object,
_mockPdfPartitionerLogService.Object);
}
[Test]
public void HandlePdfPartitionerCompletion_ArgumentNullException_ResponseNull()
{
Response response = null;
Assert.ThrowsAsync<ArgumentNullException>(async () => await _pdfPartitionerCompletionService.HandlePdfPartitionerCompletion(response));
_mockPdfPartitionerRunInfoService.Verify(x => x.IncreaseCountsAndUpdate(It.IsAny<Guid>(), It.IsAny<bool>()), Times.Never);
_mockPdfPartitionerLogService.Verify(x => x.SaveListAsync(It.IsAny<Guid>(), It.IsAny<List<string>>()), Times.Never);
_mockPdfPartitionerLogService.Verify(x => x.GetByPdfPartitionerRunInfoIdAsync(It.IsAny<Guid>()), Times.Never);
}
[Test]
public void HandlePdfPartitionerCompletion_ArgumentNullException_PdfPartitionerResultNull()
{
PdfPartitionerResult result = null;
var response = new Response
{
ResponsePayload = JsonConvert.SerializeObject(result)
};
Assert.ThrowsAsync<ArgumentNullException>(async () => await _pdfPartitionerCompletionService.HandlePdfPartitionerCompletion(response));
_mockPdfPartitionerRunInfoService.Verify(x => x.IncreaseCountsAndUpdate(It.IsAny<Guid>(), It.IsAny<bool>()), Times.Never);
_mockPdfPartitionerLogService.Verify(x => x.SaveListAsync(It.IsAny<Guid>(), It.IsAny<List<string>>()), Times.Never);
_mockPdfPartitionerLogService.Verify(x => x.GetByPdfPartitionerRunInfoIdAsync(It.IsAny<Guid>()), Times.Never);
}
[Test]
public void HandlePdfPartitionerCompletion_ServiceException_IncreaseCountsAndUpdate_ThrowException()
{
var pdfPartitionerRequest = new PdfPartitionerRequest
{
RootBasePath = "\\\\Tester\\path",
ParentDynamicDirectory = "TestParentDynamicDirectory",
PdfParserType = PdfParserTypes.FosLoanStatement,
DynamicIndexFileName = "TestDynamicIndexFileName.txt",
DynamicPdfName = "TestDynamicPdfname",
DynamicPdfSettings = new DynamicNameSetting()
};
var result = new PdfPartitionerResult(Guid.NewGuid(), pdfPartitionerRequest);
var response = new Response
{
ResponsePayload = JsonConvert.SerializeObject(result)
};
_mockPdfPartitionerRunInfoService.Setup(x => x.IncreaseCountsAndUpdate(It.IsAny<Guid>(), It.IsAny<bool>())).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _pdfPartitionerCompletionService.HandlePdfPartitionerCompletion(response));
_mockPdfPartitionerRunInfoService.Verify(x => x.IncreaseCountsAndUpdate(It.IsAny<Guid>(), It.IsAny<bool>()), Times.Once);
_mockPdfPartitionerLogService.Verify(x => x.SaveListAsync(It.IsAny<Guid>(), It.IsAny<List<string>>()), Times.Never);
_mockPdfPartitionerLogService.Verify(x => x.GetByPdfPartitionerRunInfoIdAsync(It.IsAny<Guid>()), Times.Never);
}
[Test]
public void HandlePdfPartitionerCompletion_ServiceException_PdfPartitionerLogService_SaveListAsync_ThrowException()
{
var pdfPartitionerRequest = new PdfPartitionerRequest
{
RootBasePath = "\\\\Tester\\path",
ParentDynamicDirectory = "TestParentDynamicDirectory",
PdfParserType = PdfParserTypes.FosLoanStatement,
DynamicIndexFileName = "TestDynamicIndexFileName.txt",
DynamicPdfName = "TestDynamicPdfname",
DynamicPdfSettings = new DynamicNameSetting()
};
var result = new PdfPartitionerResult(Guid.NewGuid(), pdfPartitionerRequest);
var response = new Response
{
ResponsePayload = JsonConvert.SerializeObject(result)
};
var pdfPartitionerRunInfo = new PdfPartitionerRunInfo
{
PdfPartitionerRunInfoId = result.PdfPartitionerRunInfoId,
IndexTotal = 3,
SuccessCount = 1,
FailureCount = 1
};
_mockPdfPartitionerRunInfoService.Setup(x => x.IncreaseCountsAndUpdate(It.IsAny<Guid>(), It.IsAny<bool>())).ReturnsAsync(pdfPartitionerRunInfo);
_mockPdfPartitionerLogService.Setup(x => x.SaveListAsync(It.IsAny<Guid>(), It.IsAny<List<string>>())).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _pdfPartitionerCompletionService.HandlePdfPartitionerCompletion(response));
_mockPdfPartitionerRunInfoService.Verify(x => x.IncreaseCountsAndUpdate(It.IsAny<Guid>(), It.IsAny<bool>()), Times.Once);
_mockPdfPartitionerLogService.Verify(x => x.SaveListAsync(It.IsAny<Guid>(), It.IsAny<List<string>>()), Times.Once);
_mockPdfPartitionerLogService.Verify(x => x.GetByPdfPartitionerRunInfoIdAsync(It.IsAny<Guid>()), Times.Never);
}
[Test]
public void HandlePdfPartitionerCompletion_ServiceException_PdfPartitionerLogService_GetByPdfPartitionerRunInfoIdAsync_ThrowException()
{
var pdfPartitionerRequest = new PdfPartitionerRequest
{
RootBasePath = "\\\\Tester\\path",
ParentDynamicDirectory = "TestParentDynamicDirectory",
PdfParserType = PdfParserTypes.FosLoanStatement,
DynamicIndexFileName = "TestDynamicIndexFileName.txt",
DynamicPdfName = "TestDynamicPdfname",
DynamicPdfSettings = new DynamicNameSetting()
};
var result = new PdfPartitionerResult(Guid.NewGuid(), pdfPartitionerRequest);
var response = new Response
{
ResponsePayload = JsonConvert.SerializeObject(result)
};
var pdfPartitionerRunInfo = new PdfPartitionerRunInfo
{
PdfPartitionerRunInfoId = result.PdfPartitionerRunInfoId,
IndexTotal = 3,
SuccessCount = 2,
FailureCount = 1
};
_mockPdfPartitionerRunInfoService.Setup(x => x.IncreaseCountsAndUpdate(It.IsAny<Guid>(), It.IsAny<bool>())).ReturnsAsync(pdfPartitionerRunInfo);
_mockPdfPartitionerLogService.Setup(x => x.SaveListAsync(It.IsAny<Guid>(), It.IsAny<List<string>>()));
_mockPdfPartitionerLogService.Setup(x => x.GetByPdfPartitionerRunInfoIdAsync(It.IsAny<Guid>())).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _pdfPartitionerCompletionService.HandlePdfPartitionerCompletion(response));
_mockPdfPartitionerRunInfoService.Verify(x => x.IncreaseCountsAndUpdate(It.IsAny<Guid>(), It.IsAny<bool>()), Times.Once);
_mockPdfPartitionerLogService.Verify(x => x.SaveListAsync(It.IsAny<Guid>(), It.IsAny<List<string>>()), Times.Once);
_mockPdfPartitionerLogService.Verify(x => x.GetByPdfPartitionerRunInfoIdAsync(It.IsAny<Guid>()), Times.Once);
}
[Test]
public async Task HandlePdfPartitionerCompletion_Success()
{
var pdfPartitionerRequest = new PdfPartitionerRequest
{
RootBasePath = "\\\\Tester\\path",
ParentDynamicDirectory = "TestParentDynamicDirectory",
PdfParserType = PdfParserTypes.FosLoanStatement,
DynamicIndexFileName = "TestDynamicIndexFileName.txt",
DynamicPdfName = "TestDynamicPdfname",
DynamicPdfSettings = new DynamicNameSetting()
};
var result = new PdfPartitionerResult(Guid.NewGuid(), pdfPartitionerRequest);
result.FailedToQueueToParse = false;
var response = new Response
{
ResponsePayload = JsonConvert.SerializeObject(result),
ResponseStack = new List<string>
{
"Test ResponseStack"
}
};
var pdfPartitionerRunInfo = new PdfPartitionerRunInfo
{
PdfPartitionerRunInfoId = result.PdfPartitionerRunInfoId,
IndexTotal = 3,
SuccessCount = 2,
FailureCount = 1
};
_mockPdfPartitionerRunInfoService.Setup(x => x.IncreaseCountsAndUpdate(It.IsAny<Guid>(), It.IsAny<bool>())).ReturnsAsync(pdfPartitionerRunInfo);
_mockPdfPartitionerLogService.Setup(x => x.SaveListAsync(It.IsAny<Guid>(), It.IsAny<List<string>>()));
await _pdfPartitionerCompletionService.HandlePdfPartitionerCompletion(response);
_mockPdfPartitionerRunInfoService.Verify(x => x.IncreaseCountsAndUpdate(It.IsAny<Guid>(), It.IsAny<bool>()), Times.Once);
_mockPdfPartitionerLogService.Verify(x => x.SaveListAsync(It.IsAny<Guid>(), It.IsAny<List<string>>()), Times.Once);
_mockPdfPartitionerLogService.Verify(x => x.GetByPdfPartitionerRunInfoIdAsync(It.IsAny<Guid>()), Times.Once);
}
}
@@ -0,0 +1,579 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Moq;
using NUnit.Framework;
using LCU.Library.Internal.DocumentIngestorModels.Models;
using LCU.Library.Internal.LcuMassTransitModels;
using LCU.Library.Internal.DocumentIngestorModels.Entities;
using LCU.Library.Internal.DocumentIngestorModels.Enums;
using LCU.Library.Internal.Exceptions;
using LCU.API.Internal.DocumentIngestor.Services.IngestionOperationServices;
using LCU.API.Internal.DocumentIngestor.Services.MicroApiServices;
using LCU.API.Internal.DocumentIngestor.Configurations;
using LCU.API.Internal.DocumentIngestor.Services;
using LCU.API.Internal.DocumentIngestor.Services.QueueServices;
using LCU.API.Internal.DocumentIngestor.Services.PdfParserServices;
using LCU.Library.Internal.FileOperationsModels.Models;
using LCU.Library.Internal.FileOperationsModels.Models.NameSettings;
using LCU.Library.Internal.LCUServiceFactory.Services;
namespace LCU.API.Internal.DocumentIngestorTests.Services.IngestionOperationServices;
public class PdfPartitionerServiceTest
{
private PdfPartitionerService _pdfPartitionerService;
private ConnectionConfiguration _connectionConfiguration;
private Mock<IPdfPartitionerRunInfoService> _mockPdfPartitionerRunInfoService;
private Mock<IFileOperationsApiService> _mockFileOperationsApiService;
private Mock<IQueuePdfPartitionerCompletionService> _mockQueuePdfPartitionerCompletionService;
private Mock<ILcuServiceFactory<IPdfParserService>> _mockLcuServiceFactory;
[SetUp]
public void Setup()
{
_connectionConfiguration = new ConnectionConfiguration
{
HostUrl = "test.com",
UserName = "testUserName",
Password = "testpassword"
};
var receiveEndpointConfigurations = new ReceiveEndpointConfigurations
{
PdfPartitionerCompletionEndpoint = new ReceiveEndpointConfiguration
{
ReceiveEndpoint = "testCompletionReceiveEndpoint",
ReceiveEndpointType = "exchange"
}
};
_mockPdfPartitionerRunInfoService = new Mock<IPdfPartitionerRunInfoService>();
_mockFileOperationsApiService = new Mock<IFileOperationsApiService>();
_mockQueuePdfPartitionerCompletionService = new Mock<IQueuePdfPartitionerCompletionService>();
_mockLcuServiceFactory = new Mock<ILcuServiceFactory<IPdfParserService>>();
_pdfPartitionerService = new PdfPartitionerService(_connectionConfiguration,
receiveEndpointConfigurations,
_mockPdfPartitionerRunInfoService.Object,
_mockFileOperationsApiService.Object,
_mockQueuePdfPartitionerCompletionService.Object,
_mockLcuServiceFactory.Object);
}
[Test]
public void HandlePdfPartition_ArgumentNullException_RequestNull()
{
PdfPartitionerRequest request = null;
Assert.ThrowsAsync<ArgumentNullException>(async () => await _pdfPartitionerService.HandlePdfPartition(request));
_mockFileOperationsApiService.Verify(x => x.BuildDynamicDirectoryList(It.IsAny<DynamicDirectoryListRequest>()), Times.Never);
_mockPdfPartitionerRunInfoService.Verify(x => x.SaveAsync(It.IsAny<PdfPartitionerRunInfo>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFile(It.IsAny<DynamicFileListRequest>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>()), Times.Never);
_mockLcuServiceFactory.Verify(x => x.GetService(It.IsAny<string>()), Times.Never);
_mockQueuePdfPartitionerCompletionService.Verify(x => x.QueuePdfPartitionerCompletionRequest(It.IsAny<PdfPartitionerResult>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.QueueBatchPdfParser(It.IsAny<BatchParsePdfRequest>()), Times.Never);
}
[Test]
public void HandlePdfPartition_ServiceException_BuildDynamicDirectoryList_ThrowsException()
{
var request = new PdfPartitionerRequest
{
RootBasePath = "\\\\Tester\\path",
ParentDynamicDirectory = "TestParentDynamicDirectory",
PdfParserType = PdfParserTypes.FosLoanStatement
};
_mockFileOperationsApiService.Setup(x => x.BuildDynamicDirectoryList(It.IsAny<DynamicDirectoryListRequest>())).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _pdfPartitionerService.HandlePdfPartition(request));
_mockFileOperationsApiService.Verify(x => x.BuildDynamicDirectoryList(It.IsAny<DynamicDirectoryListRequest>()), Times.Once);
_mockPdfPartitionerRunInfoService.Verify(x => x.SaveAsync(It.IsAny<PdfPartitionerRunInfo>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFile(It.IsAny<DynamicFileListRequest>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>()), Times.Never);
_mockLcuServiceFactory.Verify(x => x.GetService(It.IsAny<string>()), Times.Never);
_mockQueuePdfPartitionerCompletionService.Verify(x => x.QueuePdfPartitionerCompletionRequest(It.IsAny<PdfPartitionerResult>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.QueueBatchPdfParser(It.IsAny<BatchParsePdfRequest>()), Times.Never);
}
[Test]
public void HandlePdfPartition_ServiceException_PartitionerRunInfo_SaveAsync_ThrowsException()
{
var request = new PdfPartitionerRequest
{
RootBasePath = "\\\\Tester\\path",
ParentDynamicDirectory = "TestParentDynamicDirectory",
PdfParserType = PdfParserTypes.FosLoanStatement
};
var dynamicDirectoryListResult = new List<string>
{
"TestParentDynamicDirectory1",
"TestParentDynamicDirectory2"
};
_mockFileOperationsApiService.Setup(x => x.BuildDynamicDirectoryList(It.IsAny<DynamicDirectoryListRequest>())).ReturnsAsync(dynamicDirectoryListResult);
var indexService = new Mock<IPdfParserService>();
_mockLcuServiceFactory.Setup(x => x.GetService(request.PdfParserType)).Returns(indexService.Object);
_mockPdfPartitionerRunInfoService.Setup(x => x.SaveAsync(It.IsAny<PdfPartitionerRunInfo>())).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _pdfPartitionerService.HandlePdfPartition(request));
_mockFileOperationsApiService.Verify(x => x.BuildDynamicDirectoryList(It.IsAny<DynamicDirectoryListRequest>()), Times.Once);
_mockPdfPartitionerRunInfoService.Verify(x => x.SaveAsync(It.IsAny<PdfPartitionerRunInfo>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFile(It.IsAny<DynamicFileListRequest>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>()), Times.Never);
indexService.Verify(x => x.DetermineBatchParsePdfRequest(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Never);
_mockQueuePdfPartitionerCompletionService.Verify(x => x.QueuePdfPartitionerCompletionRequest(It.IsAny<PdfPartitionerResult>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.QueueBatchPdfParser(It.IsAny<BatchParsePdfRequest>()), Times.Never);
}
[Test]
public async Task HandlePdfPartition_ServiceException_DetermineIndexFile_BuildDynamicFileList_ThrowsException()
{
var request = new PdfPartitionerRequest
{
RootBasePath = "\\\\Tester\\path",
ParentDynamicDirectory = "TestParentDynamicDirectory",
PdfParserType = PdfParserTypes.FosLoanStatement,
DynamicIndexFileName = "TestDynamicIndexFileName",
DynamicPdfName = "TestDynamicPdfname"
};
var dynamicDirectoryListResult = new List<string>
{
"TestParentDynamicDirectory1",
"TestParentDynamicDirectory2"
};
_mockFileOperationsApiService.Setup(x => x.BuildDynamicDirectoryList(It.IsAny<DynamicDirectoryListRequest>())).ReturnsAsync(dynamicDirectoryListResult);
var indexService = new Mock<IPdfParserService>();
_mockLcuServiceFactory.Setup(x => x.GetService(request.PdfParserType)).Returns(indexService.Object);
var pdfPartitionerRunInfo = new PdfPartitionerRunInfo(Convert.ToDateTime("1/1/2022"), PdfParserTypes.FosLoanStatement, "\\\\Tester\\path", 2);
_mockPdfPartitionerRunInfoService.Setup(x => x.SaveAsync(It.IsAny<PdfPartitionerRunInfo>())).ReturnsAsync(pdfPartitionerRunInfo);
_mockFileOperationsApiService.Setup(x => x.BuildDynamicFile(It.Is<DynamicFileListRequest>(dynamicFileListRequest => dynamicFileListRequest.Filename == request.DynamicIndexFileName)))
.ThrowsAsync(new Exception("Error"));
await _pdfPartitionerService.HandlePdfPartition(request);
_mockFileOperationsApiService.Verify(x => x.BuildDynamicDirectoryList(It.IsAny<DynamicDirectoryListRequest>()), Times.Once);
_mockPdfPartitionerRunInfoService.Verify(x => x.SaveAsync(It.IsAny<PdfPartitionerRunInfo>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFile(It.IsAny<DynamicFileListRequest>()), Times.Exactly(2));
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>()), Times.Never);
indexService.Verify(x => x.DetermineBatchParsePdfRequest(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Never);
_mockQueuePdfPartitionerCompletionService.Verify(x => x.QueuePdfPartitionerCompletionRequest(It.IsAny<PdfPartitionerResult>()), Times.Exactly(2));
_mockFileOperationsApiService.Verify(x => x.QueueBatchPdfParser(It.IsAny<BatchParsePdfRequest>()), Times.Never);
}
[Test]
public async Task HandlePdfPartition_ServiceException_DetermineAllPdfsInDirectory_BuildDynamicFile_ThrowsException()
{
var request = new PdfPartitionerRequest
{
RootBasePath = "\\\\Tester\\path",
ParentDynamicDirectory = "TestParentDynamicDirectory",
PdfParserType = PdfParserTypes.FosLoanStatement,
DynamicIndexFileName = "TestDynamicIndexFileName",
DynamicPdfName = "TestDynamicPdfname"
};
var dynamicDirectoryListResult = new List<string>
{
"TestParentDynamicDirectory1",
"TestParentDynamicDirectory2"
};
_mockFileOperationsApiService.Setup(x => x.BuildDynamicDirectoryList(It.IsAny<DynamicDirectoryListRequest>())).ReturnsAsync(dynamicDirectoryListResult);
var indexService = new Mock<IPdfParserService>();
_mockLcuServiceFactory.Setup(x => x.GetService(request.PdfParserType)).Returns(indexService.Object);
var pdfPartitionerRunInfo = new PdfPartitionerRunInfo(Convert.ToDateTime("1/1/2022"), PdfParserTypes.FosLoanStatement, "\\\\Tester\\path", 2);
_mockPdfPartitionerRunInfoService.Setup(x => x.SaveAsync(It.IsAny<PdfPartitionerRunInfo>())).ReturnsAsync(pdfPartitionerRunInfo);
_mockFileOperationsApiService.Setup(x => x.BuildDynamicFile(It.Is<DynamicFileListRequest>(dynamicFileListRequest =>
dynamicFileListRequest.Filename == request.DynamicIndexFileName)))
.ReturnsAsync("TestDynamicIndexFileName");
_mockFileOperationsApiService.Setup(x => x.BuildDynamicFile(It.Is<DynamicFileListRequest>(dynamicFileListRequest => dynamicFileListRequest.Filename == "{Regex0}")))
.ThrowsAsync(new Exception("Error"));
await _pdfPartitionerService.HandlePdfPartition(request);
_mockFileOperationsApiService.Verify(x => x.BuildDynamicDirectoryList(It.IsAny<DynamicDirectoryListRequest>()), Times.Once);
_mockPdfPartitionerRunInfoService.Verify(x => x.SaveAsync(It.IsAny<PdfPartitionerRunInfo>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFile(It.IsAny<DynamicFileListRequest>()), Times.Exactly(2));
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>()), Times.Exactly(2));
indexService.Verify(x => x.DetermineBatchParsePdfRequest(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Never);
_mockQueuePdfPartitionerCompletionService.Verify(x => x.QueuePdfPartitionerCompletionRequest(It.IsAny<PdfPartitionerResult>()), Times.Exactly(2));
_mockFileOperationsApiService.Verify(x => x.QueueBatchPdfParser(It.IsAny<BatchParsePdfRequest>()), Times.Never);
}
[Test]
public async Task HandlePdfPartition_ServiceException_FosLoanStatementPdfService_DetermineBatchParsePdfRequest_ThrowsException()
{
var request = new PdfPartitionerRequest
{
RootBasePath = "\\\\Tester\\path",
ParentDynamicDirectory = "TestParentDynamicDirectory",
PdfParserType = PdfParserTypes.FosLoanStatement,
DynamicIndexFileName = "TestDynamicIndexFileName.txt",
DynamicPdfName = "TestDynamicPdfname",
DynamicPdfSettings = new DynamicNameSetting()
};
var dynamicDirectoryListResult = new List<string>
{
"TestParentDynamicDirectory1",
"TestParentDynamicDirectory2"
};
_mockFileOperationsApiService.Setup(x => x.BuildDynamicDirectoryList(It.IsAny<DynamicDirectoryListRequest>())).ReturnsAsync(dynamicDirectoryListResult);
var indexService = new Mock<IPdfParserService>();
_mockLcuServiceFactory.Setup(x => x.GetService(request.PdfParserType)).Returns(indexService.Object);
var pdfPartitionerRunInfo = new PdfPartitionerRunInfo(Convert.ToDateTime("1/1/2022"), PdfParserTypes.FosLoanStatement, "\\\\Tester\\path", 2);
_mockPdfPartitionerRunInfoService.Setup(x => x.SaveAsync(It.IsAny<PdfPartitionerRunInfo>())).ReturnsAsync(pdfPartitionerRunInfo);
_mockFileOperationsApiService.Setup(x => x.BuildDynamicFile(It.Is<DynamicFileListRequest>(dynamicFileListRequest =>
dynamicFileListRequest.Filename == request.DynamicIndexFileName)))
.ReturnsAsync("TestDynamicIndexFileName");
var pdfFileList = new List<string>
{
"TestDynamicPdfname.pdf"
};
_mockFileOperationsApiService.Setup(x => x.BuildDynamicFileList(It.Is<DynamicFileListRequest>(dynamicFileListRequest =>
dynamicFileListRequest.Filename == "{Regex0}.(?i:pdf)")))
.ReturnsAsync(pdfFileList);
indexService.Setup(x => x.DetermineBatchParsePdfRequest(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).ThrowsAsync(new Exception("Error"));
await _pdfPartitionerService.HandlePdfPartition(request);
_mockFileOperationsApiService.Verify(x => x.BuildDynamicDirectoryList(It.IsAny<DynamicDirectoryListRequest>()), Times.Once);
_mockPdfPartitionerRunInfoService.Verify(x => x.SaveAsync(It.IsAny<PdfPartitionerRunInfo>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFile(It.IsAny<DynamicFileListRequest>()), Times.Exactly(2));
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>()), Times.Exactly(2));
indexService.Verify(x => x.DetermineBatchParsePdfRequest(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Exactly(2));
_mockQueuePdfPartitionerCompletionService.Verify(x => x.QueuePdfPartitionerCompletionRequest(It.IsAny<PdfPartitionerResult>()), Times.Exactly(2));
_mockFileOperationsApiService.Verify(x => x.QueueBatchPdfParser(It.IsAny<BatchParsePdfRequest>()), Times.Never);
}
[Test]
public async Task HandlePdfPartition_ServiceException_QueueBatchPdfParser_QueuedTwice()
{
var request = new PdfPartitionerRequest
{
RootBasePath = "\\\\Tester\\path",
ParentDynamicDirectory = "TestParentDynamicDirectory",
PdfParserType = PdfParserTypes.FosLoanStatement,
DynamicIndexFileName = "TestDynamicIndexFileName",
DynamicPdfName = "TestDynamicPdfname"
};
var dynamicDirectoryListResult = new List<string>
{
"TestParentDynamicDirectory1",
"TestParentDynamicDirectory2"
};
_mockFileOperationsApiService.Setup(x => x.BuildDynamicDirectoryList(It.IsAny<DynamicDirectoryListRequest>())).ReturnsAsync(dynamicDirectoryListResult);
var indexService = new Mock<IPdfParserService>();
_mockLcuServiceFactory.Setup(x => x.GetService(request.PdfParserType)).Returns(indexService.Object);
var pdfPartitionerRunInfo = new PdfPartitionerRunInfo(Convert.ToDateTime("1/1/2022"), PdfParserTypes.FosLoanStatement, "\\\\Tester\\path", 2);
_mockPdfPartitionerRunInfoService.Setup(x => x.SaveAsync(It.IsAny<PdfPartitionerRunInfo>())).ReturnsAsync(pdfPartitionerRunInfo);
_mockFileOperationsApiService.Setup(x => x.BuildDynamicFile(It.Is<DynamicFileListRequest>(dynamicFileListRequest =>
dynamicFileListRequest.Filename == request.DynamicIndexFileName)))
.ReturnsAsync("TestDynamicIndexFileName");
var pdfFileList = new List<string>
{
"TestDynamicPdfname.pdf"
};
_mockFileOperationsApiService.Setup(x => x.BuildDynamicFileList(It.Is<DynamicFileListRequest>(dynamicFileListRequest =>
dynamicFileListRequest.Filename == "{Regex0}.(?i:pdf)")))
.ReturnsAsync(pdfFileList);
var batchPdfParserRequest = new BatchParsePdfRequest
{
RootPath = "\\\\Tester\\path",
PdfName = "TestDynamicPdfname",
BatchPdfs = new List<BatchPdf>
{
new BatchPdf
{
PageStart = 1,
PageStop = 2,
ParsedPdfname = "TestDynamicPdfname_Test"
}
}
};
indexService.Setup(x => x.DetermineBatchParsePdfRequest(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
.ReturnsAsync(batchPdfParserRequest);
await _pdfPartitionerService.HandlePdfPartition(request);
_mockFileOperationsApiService.Verify(x => x.BuildDynamicDirectoryList(It.IsAny<DynamicDirectoryListRequest>()), Times.Once);
_mockPdfPartitionerRunInfoService.Verify(x => x.SaveAsync(It.IsAny<PdfPartitionerRunInfo>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFile(It.IsAny<DynamicFileListRequest>()), Times.Exactly(2));
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>()), Times.Exactly(2));
indexService.Verify(x => x.DetermineBatchParsePdfRequest(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Exactly(2));
_mockQueuePdfPartitionerCompletionService.Verify(x => x.QueuePdfPartitionerCompletionRequest(It.IsAny<PdfPartitionerResult>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.QueueBatchPdfParser(It.IsAny<BatchParsePdfRequest>()), Times.Exactly(2));
}
[Test]
public void Osg_HandlePdfPartition_ArgumentNullException_RequestNull()
{
PdfPartitionerRequest request = null;
Assert.ThrowsAsync<ArgumentNullException>(async () => await _pdfPartitionerService.HandlePdfPartition(request));
_mockFileOperationsApiService.Verify(x => x.BuildDynamicDirectoryList(It.IsAny<DynamicDirectoryListRequest>()), Times.Never);
_mockPdfPartitionerRunInfoService.Verify(x => x.SaveAsync(It.IsAny<PdfPartitionerRunInfo>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFile(It.IsAny<DynamicFileListRequest>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>()), Times.Never);
_mockLcuServiceFactory.Verify(x => x.GetService(It.IsAny<string>()), Times.Never);
_mockQueuePdfPartitionerCompletionService.Verify(x => x.QueuePdfPartitionerCompletionRequest(It.IsAny<PdfPartitionerResult>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.QueueBatchPdfParser(It.IsAny<BatchParsePdfRequest>()), Times.Never);
}
[Test]
public void Osg_HandlePdfPartition_ServiceException_BuildDynamicDirectoryList_ThrowsException()
{
var request = new PdfPartitionerRequest
{
RootBasePath = "\\\\Tester\\path",
ParentDynamicDirectory = "TestParentDynamicDirectory",
PdfParserType = PdfParserTypes.OsgDnaNoticesDocument
};
_mockFileOperationsApiService.Setup(x => x.BuildDynamicDirectoryList(It.IsAny<DynamicDirectoryListRequest>())).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _pdfPartitionerService.HandlePdfPartition(request));
_mockFileOperationsApiService.Verify(x => x.BuildDynamicDirectoryList(It.IsAny<DynamicDirectoryListRequest>()), Times.Once);
_mockPdfPartitionerRunInfoService.Verify(x => x.SaveAsync(It.IsAny<PdfPartitionerRunInfo>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFile(It.IsAny<DynamicFileListRequest>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>()), Times.Never);
_mockQueuePdfPartitionerCompletionService.Verify(x => x.QueuePdfPartitionerCompletionRequest(It.IsAny<PdfPartitionerResult>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.QueueBatchPdfParser(It.IsAny<BatchParsePdfRequest>()), Times.Never);
}
[Test]
public void Osg_HandlePdfPartition_ServiceException_PartitionerRunInfo_SaveAsync_ThrowsException()
{
var request = new PdfPartitionerRequest
{
RootBasePath = "\\\\Tester\\path",
ParentDynamicDirectory = "TestParentDynamicDirectory",
PdfParserType = PdfParserTypes.OsgDnaNoticesDocument
};
var dynamicDirectoryListResult = new List<string>
{
"TestParentDynamicDirectory1",
"TestParentDynamicDirectory2"
};
_mockFileOperationsApiService.Setup(x => x.BuildDynamicDirectoryList(It.IsAny<DynamicDirectoryListRequest>())).ReturnsAsync(dynamicDirectoryListResult);
_mockPdfPartitionerRunInfoService.Setup(x => x.SaveAsync(It.IsAny<PdfPartitionerRunInfo>())).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _pdfPartitionerService.HandlePdfPartition(request));
_mockFileOperationsApiService.Verify(x => x.BuildDynamicDirectoryList(It.IsAny<DynamicDirectoryListRequest>()), Times.Once);
_mockPdfPartitionerRunInfoService.Verify(x => x.SaveAsync(It.IsAny<PdfPartitionerRunInfo>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFile(It.IsAny<DynamicFileListRequest>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>()), Times.Never);
_mockLcuServiceFactory.Verify(x => x.GetService(It.IsAny<string>()), Times.Never);
_mockQueuePdfPartitionerCompletionService.Verify(x => x.QueuePdfPartitionerCompletionRequest(It.IsAny<PdfPartitionerResult>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.QueueBatchPdfParser(It.IsAny<BatchParsePdfRequest>()), Times.Never);
}
[Test]
public async Task Osg_HandlePdfPartition_ServiceException_DetermineIndexFile_BuildDynamicFileList_ThrowsException()
{
var request = new PdfPartitionerRequest
{
RootBasePath = "\\\\Tester\\path",
ParentDynamicDirectory = "TestParentDynamicDirectory",
PdfParserType = PdfParserTypes.OsgDnaNoticesDocument,
DynamicIndexFileName = "TestDynamicIndexFileName",
DynamicPdfName = "TestDynamicPdfname"
};
var dynamicDirectoryListResult = new List<string>
{
"TestParentDynamicDirectory1",
"TestParentDynamicDirectory2"
};
_mockFileOperationsApiService.Setup(x => x.BuildDynamicDirectoryList(It.IsAny<DynamicDirectoryListRequest>())).ReturnsAsync(dynamicDirectoryListResult);
var pdfPartitionerRunInfo = new PdfPartitionerRunInfo(Convert.ToDateTime("1/1/2022"), PdfParserTypes.OsgDnaNoticesDocument, "\\\\Tester\\path", 2);
_mockPdfPartitionerRunInfoService.Setup(x => x.SaveAsync(It.IsAny<PdfPartitionerRunInfo>())).ReturnsAsync(pdfPartitionerRunInfo);
_mockFileOperationsApiService.Setup(x => x.BuildDynamicFile(It.Is<DynamicFileListRequest>(dynamicFileListRequest => dynamicFileListRequest.Filename == request.DynamicIndexFileName)))
.ThrowsAsync(new Exception("Error"));
await _pdfPartitionerService.HandlePdfPartition(request);
_mockFileOperationsApiService.Verify(x => x.BuildDynamicDirectoryList(It.IsAny<DynamicDirectoryListRequest>()), Times.Once);
_mockPdfPartitionerRunInfoService.Verify(x => x.SaveAsync(It.IsAny<PdfPartitionerRunInfo>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFile(It.IsAny<DynamicFileListRequest>()), Times.Exactly(2));
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>()), Times.Never);
_mockLcuServiceFactory.Verify(x => x.GetService(It.IsAny<string>()), Times.Never);
_mockQueuePdfPartitionerCompletionService.Verify(x => x.QueuePdfPartitionerCompletionRequest(It.IsAny<PdfPartitionerResult>()), Times.Exactly(2));
_mockFileOperationsApiService.Verify(x => x.QueueBatchPdfParser(It.IsAny<BatchParsePdfRequest>()), Times.Never);
}
[Test]
public async Task Osg_HandlePdfPartition_ServiceException_DetermineAllPdfsInDirectory_BuildDynamicFile_ThrowsException()
{
var request = new PdfPartitionerRequest
{
RootBasePath = "\\\\Tester\\path",
ParentDynamicDirectory = "TestParentDynamicDirectory",
PdfParserType = PdfParserTypes.OsgDnaNoticesDocument,
DynamicIndexFileName = "TestDynamicIndexFileName",
DynamicPdfName = "TestDynamicPdfname"
};
var dynamicDirectoryListResult = new List<string>
{
"TestParentDynamicDirectory1",
"TestParentDynamicDirectory2"
};
_mockFileOperationsApiService.Setup(x => x.BuildDynamicDirectoryList(It.IsAny<DynamicDirectoryListRequest>())).ReturnsAsync(dynamicDirectoryListResult);
var pdfPartitionerRunInfo = new PdfPartitionerRunInfo(Convert.ToDateTime("1/1/2022"), PdfParserTypes.OsgDnaNoticesDocument, "\\\\Tester\\path", 2);
_mockPdfPartitionerRunInfoService.Setup(x => x.SaveAsync(It.IsAny<PdfPartitionerRunInfo>())).ReturnsAsync(pdfPartitionerRunInfo);
_mockFileOperationsApiService.Setup(x => x.BuildDynamicFile(It.Is<DynamicFileListRequest>(dynamicFileListRequest =>
dynamicFileListRequest.Filename == request.DynamicIndexFileName)))
.ReturnsAsync("TestDynamicIndexFileName");
_mockFileOperationsApiService.Setup(x => x.BuildDynamicFile(It.Is<DynamicFileListRequest>(dynamicFileListRequest => dynamicFileListRequest.Filename == "{Regex0}")))
.ThrowsAsync(new Exception("Error"));
await _pdfPartitionerService.HandlePdfPartition(request);
_mockFileOperationsApiService.Verify(x => x.BuildDynamicDirectoryList(It.IsAny<DynamicDirectoryListRequest>()), Times.Once);
_mockPdfPartitionerRunInfoService.Verify(x => x.SaveAsync(It.IsAny<PdfPartitionerRunInfo>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFile(It.IsAny<DynamicFileListRequest>()), Times.Exactly(2));
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>()), Times.Exactly(2));
_mockLcuServiceFactory.Verify(x => x.GetService(It.IsAny<string>()), Times.Never);
_mockQueuePdfPartitionerCompletionService.Verify(x => x.QueuePdfPartitionerCompletionRequest(It.IsAny<PdfPartitionerResult>()), Times.Exactly(2));
_mockFileOperationsApiService.Verify(x => x.QueueBatchPdfParser(It.IsAny<BatchParsePdfRequest>()), Times.Never);
}
[Test]
public async Task HandlePdfPartition_ServiceException_OsgDnaNoticesPdfService_DetermineBatchParsePdfRequest_ThrowsException()
{
var request = new PdfPartitionerRequest
{
RootBasePath = "\\\\Tester\\path",
ParentDynamicDirectory = "TestParentDynamicDirectory",
PdfParserType = PdfParserTypes.OsgDnaNoticesDocument,
DynamicIndexFileName = "TestDynamicIndexFileName.txt",
DynamicPdfName = "TestDynamicPdfname",
DynamicPdfSettings = new DynamicNameSetting()
};
var dynamicDirectoryListResult = new List<string>
{
"TestParentDynamicDirectory1",
"TestParentDynamicDirectory2"
};
_mockFileOperationsApiService.Setup(x => x.BuildDynamicDirectoryList(It.IsAny<DynamicDirectoryListRequest>())).ReturnsAsync(dynamicDirectoryListResult);
var indexService = new Mock<IPdfParserService>();
_mockLcuServiceFactory.Setup(x => x.GetService(request.PdfParserType)).Returns(indexService.Object);
var pdfPartitionerRunInfo = new PdfPartitionerRunInfo(Convert.ToDateTime("1/1/2022"), PdfParserTypes.OsgDnaNoticesDocument, "\\\\Tester\\path", 2);
_mockPdfPartitionerRunInfoService.Setup(x => x.SaveAsync(It.IsAny<PdfPartitionerRunInfo>())).ReturnsAsync(pdfPartitionerRunInfo);
_mockFileOperationsApiService.Setup(x => x.BuildDynamicFile(It.Is<DynamicFileListRequest>(dynamicFileListRequest =>
dynamicFileListRequest.Filename == request.DynamicIndexFileName)))
.ReturnsAsync("TestDynamicIndexFileName");
var pdfFileList = new List<string>
{
"TestDynamicPdfname.pdf"
};
_mockFileOperationsApiService.Setup(x => x.BuildDynamicFileList(It.Is<DynamicFileListRequest>(dynamicFileListRequest =>
dynamicFileListRequest.Filename == "{Regex0}.(?i:pdf)")))
.ReturnsAsync(pdfFileList);
indexService.Setup(x => x.DetermineBatchParsePdfRequest(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).ThrowsAsync(new Exception("Error"));
await _pdfPartitionerService.HandlePdfPartition(request);
_mockFileOperationsApiService.Verify(x => x.BuildDynamicDirectoryList(It.IsAny<DynamicDirectoryListRequest>()), Times.Once);
_mockPdfPartitionerRunInfoService.Verify(x => x.SaveAsync(It.IsAny<PdfPartitionerRunInfo>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFile(It.IsAny<DynamicFileListRequest>()), Times.Exactly(2));
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>()), Times.Exactly(2));
indexService.Verify(x => x.DetermineBatchParsePdfRequest(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Exactly(2));
_mockQueuePdfPartitionerCompletionService.Verify(x => x.QueuePdfPartitionerCompletionRequest(It.IsAny<PdfPartitionerResult>()), Times.Exactly(2));
_mockFileOperationsApiService.Verify(x => x.QueueBatchPdfParser(It.IsAny<BatchParsePdfRequest>()), Times.Never);
}
[Test]
public async Task Osg_HandlePdfPartition_ServiceException_QueueBatchPdfParser_QueuedTwice()
{
var request = new PdfPartitionerRequest
{
RootBasePath = "\\\\Tester\\path",
ParentDynamicDirectory = "TestParentDynamicDirectory",
PdfParserType = PdfParserTypes.OsgDnaNoticesDocument,
DynamicIndexFileName = "TestDynamicIndexFileName",
DynamicPdfName = "TestDynamicPdfname"
};
var dynamicDirectoryListResult = new List<string>
{
"TestParentDynamicDirectory1",
"TestParentDynamicDirectory2"
};
_mockFileOperationsApiService.Setup(x => x.BuildDynamicDirectoryList(It.IsAny<DynamicDirectoryListRequest>())).ReturnsAsync(dynamicDirectoryListResult);
var indexService = new Mock<IPdfParserService>();
_mockLcuServiceFactory.Setup(x => x.GetService(request.PdfParserType)).Returns(indexService.Object);
var pdfPartitionerRunInfo = new PdfPartitionerRunInfo(Convert.ToDateTime("1/1/2022"), PdfParserTypes.OsgDnaNoticesDocument, "\\\\Tester\\path", 2);
_mockPdfPartitionerRunInfoService.Setup(x => x.SaveAsync(It.IsAny<PdfPartitionerRunInfo>())).ReturnsAsync(pdfPartitionerRunInfo);
_mockFileOperationsApiService.Setup(x => x.BuildDynamicFile(It.Is<DynamicFileListRequest>(dynamicFileListRequest =>
dynamicFileListRequest.Filename == request.DynamicIndexFileName)))
.ReturnsAsync("TestDynamicIndexFileName");
var pdfFileList = new List<string>
{
"TestDynamicPdfname.pdf"
};
_mockFileOperationsApiService.Setup(x => x.BuildDynamicFileList(It.Is<DynamicFileListRequest>(dynamicFileListRequest =>
dynamicFileListRequest.Filename == "{Regex0}.(?i:pdf)")))
.ReturnsAsync(pdfFileList);
var batchPdfParserRequest = new BatchParsePdfRequest
{
RootPath = "\\\\Tester\\path",
PdfName = "TestDynamicPdfname",
BatchPdfs = new List<BatchPdf>
{
new BatchPdf
{
PageStart = 1,
PageStop = 2,
ParsedPdfname = "TestDynamicPdfname_Test"
}
}
};
indexService.Setup(x => x.DetermineBatchParsePdfRequest(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
.ReturnsAsync(batchPdfParserRequest);
await _pdfPartitionerService.HandlePdfPartition(request);
_mockFileOperationsApiService.Verify(x => x.BuildDynamicDirectoryList(It.IsAny<DynamicDirectoryListRequest>()), Times.Once);
_mockPdfPartitionerRunInfoService.Verify(x => x.SaveAsync(It.IsAny<PdfPartitionerRunInfo>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFile(It.IsAny<DynamicFileListRequest>()), Times.Exactly(2));
_mockFileOperationsApiService.Verify(x => x.BuildDynamicFileList(It.IsAny<DynamicFileListRequest>()), Times.Exactly(2));
indexService.Verify(x => x.DetermineBatchParsePdfRequest(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Exactly(2));
_mockQueuePdfPartitionerCompletionService.Verify(x => x.QueuePdfPartitionerCompletionRequest(It.IsAny<PdfPartitionerResult>()), Times.Never);
_mockFileOperationsApiService.Verify(x => x.QueueBatchPdfParser(It.IsAny<BatchParsePdfRequest>()), Times.Exactly(2));
}
}
@@ -0,0 +1,104 @@
using Moq;
using NUnit.Framework;
using System.Collections.Generic;
using System.Threading.Tasks;
using LCU.API.Internal.DocumentIngestor.Configurations;
using LCU.API.Internal.DocumentIngestor.Services;
using LCU.API.Internal.DocumentIngestor.Services.MicroApiServices;
using LCU.Library.Internal.NotificationsModels.Models;
using LCU.Library.Internal.DocumentIngestorModels.Enums;
using LCU.Library.Internal.DocumentIngestorModels.Entities;
using LCU.Library.Internal.Exceptions;
using LCU.Library.Internal.DocumentIngestorModels.Requests;
using LCU.API.Internal.DocumentIngestor.Services.IngestionOperationServices;
namespace LCU.API.Internal.DocumentIngestorTests.Services.IngestionOperationServices;
public class ProcessStatusTypeEmailServiceTest
{
private ProcessStatusTypeEmailService _processStatusTypeEmailService;
private Mock<INotificationApiService> _mockNotificationApiService;
private Mock<IDocumentProcessingInfoService> _mockDocumentProcessingInfoService;
private ApiConfiguration _apiConfiguration;
[SetUp]
public void Setup()
{
_mockNotificationApiService = new Mock<INotificationApiService>();
_mockDocumentProcessingInfoService = new Mock<IDocumentProcessingInfoService>();
_apiConfiguration = new ApiConfiguration();
_processStatusTypeEmailService = new ProcessStatusTypeEmailService(_mockNotificationApiService.Object,
_mockDocumentProcessingInfoService.Object,
_apiConfiguration);
}
[Test]
public async Task SendDataMappingEmailAsync_Success()
{
var request = new ProcessStatusTypeEmailRequest(
new List<string>() { "[email protected]" },
new List<ProcessStatusTypes>() { ProcessStatusTypes.DataMappingFailure },
"testurl.com");
var documentProcessingInfos = new List<DocumentProcessingInfo>
{
new()
{
StatusType = ProcessStatusTypes.DataMappingFailure,
EntityUnknown = false
},
new()
{
StatusType = ProcessStatusTypes.CriticalFailure,
EntityUnknown = false
},
new()
{
StatusType = ProcessStatusTypes.NotificationDataFailure,
EntityUnknown = false
}
};
_mockDocumentProcessingInfoService.Setup(x => x.GetByProcessStatusTypeAsync(It.IsAny<ProcessStatusTypes>(), It.IsAny<bool?>()))
.ReturnsAsync(documentProcessingInfos).Verifiable();
_mockNotificationApiService.Setup(x => x.SendEmailAsync(It.IsAny<EmailRequest>())).Verifiable();
await _processStatusTypeEmailService.SendProcessStatusEmailAsync(documentProcessingInfos, request);
_mockNotificationApiService.Verify(x => x.SendEmailAsync(It.IsAny<EmailRequest>()), Times.Once);
}
[Test]
public async Task SendDataMappingEmailAsync_Exception()
{
var request = new ProcessStatusTypeEmailRequest(
new List<string>() { "[email protected]" },
new List<ProcessStatusTypes>() { ProcessStatusTypes.DataMappingFailure },
"testurl.com");
_mockDocumentProcessingInfoService.Setup(x =>
x.GetByProcessStatusTypeListAsync(It.IsAny<List<ProcessStatusTypes>>(), It.IsAny<bool?>())).ThrowsAsync(new ServiceException("Error"));
await _processStatusTypeEmailService.HandleProcessStatusTypeEmailRequest(request);
_mockDocumentProcessingInfoService.Verify(x => x.GetByProcessStatusTypeListAsync(It.IsAny<List<ProcessStatusTypes>>(), It.IsAny<bool?>()), Times.Once);
_mockNotificationApiService.Verify(x => x.SendEmailAsync(It.IsAny<EmailRequest>()), Times.Never);
}
[Test]
public async Task SendDataMappingEmailAsync_ServiceException()
{
var request = new ProcessStatusTypeEmailRequest(
new List<string>() { "[email protected]" },
new List<ProcessStatusTypes>() { ProcessStatusTypes.CriticalFailure },
"testurl.com");
_mockDocumentProcessingInfoService.Setup(x =>
x.GetByProcessStatusTypeListAsync(It.IsAny<List<ProcessStatusTypes>>(), It.IsAny<bool?>())).ThrowsAsync(new ServiceException("Error"));
await _processStatusTypeEmailService.HandleProcessStatusTypeEmailRequest(request);
_mockDocumentProcessingInfoService.Verify(x => x.GetByProcessStatusTypeListAsync(It.IsAny<List<ProcessStatusTypes>>(), It.IsAny<bool?>()), Times.Once);
_mockNotificationApiService.Verify(x => x.SendEmailAsync(It.IsAny<EmailRequest>()), Times.Never);
}
}
@@ -0,0 +1,154 @@
using System;
using System.Threading.Tasks;
using System.Collections.Generic;
using Moq;
using NUnit.Framework;
using Newtonsoft.Json;
using LCU.API.Internal.DocumentIngestor.Services;
using LCU.API.Internal.DocumentIngestor.Services.IngestionOperationServices;
using LCU.API.Internal.DocumentIngestor.Services.MemberNotificationInfoDeterminingServices;
using LCU.API.Internal.DocumentIngestor.Services.MicroApiServices;
using LCU.API.Internal.DocumentIngestor.Services.QueueServices;
using LCU.API.Internal.DocumentIngestorLib.Exceptions;
using LCU.Library.Internal.DocumentIngestorModels.Models;
using LCU.Library.Internal.ApiResponse.Models;
using LCU.Library.Internal.DocumentIngestorModels.Constants;
using LCU.Library.Internal.DocumentIngestorModels.Entities;
using LCU.Library.Internal.Exceptions;
using LCU.Library.Internal.DocumentIngestorModels.Enums;
using LCU.Library.Internal.FileOperationsModels.Models;
namespace LCU.API.Internal.DocumentIngestorTests.Services.IngestionOperationServices;
public class UploadCompletionServiceTest
{
private UploadCompletionService _uploadCompletionService;
private Mock<IQueueCompletionService> _mockQueueCompletionService;
private Mock<IFileOperationsApiService> _mockFileOperationsService;
private Mock<IDocumentProcessingInfoService> _mockDocumentProcessingInfoService;
private Mock<IMemberNotificationInfoDeterminingService> _mockMemberNotificationInfoDeterminingService;
private Mock<IQueueGatherMemberNotificationInfoService> _mockQueueGatherMemberNotificationInfoService;
[SetUp]
public void Setup()
{
_mockQueueCompletionService = new Mock<IQueueCompletionService>();
_mockFileOperationsService = new Mock<IFileOperationsApiService>();
_mockDocumentProcessingInfoService = new Mock<IDocumentProcessingInfoService>();
_mockMemberNotificationInfoDeterminingService = new Mock<IMemberNotificationInfoDeterminingService>();
_mockQueueGatherMemberNotificationInfoService = new Mock<IQueueGatherMemberNotificationInfoService>();
_uploadCompletionService = new UploadCompletionService(_mockQueueCompletionService.Object,
_mockFileOperationsService.Object,
_mockDocumentProcessingInfoService.Object,
_mockMemberNotificationInfoDeterminingService.Object,
_mockQueueGatherMemberNotificationInfoService.Object);
}
[Test]
public async Task HandleUploadCompletion_Success()
{
var documentProcessingInfoId = 1234;
var response = GenerateUploadResponse(documentProcessingInfoId);
var deserializedResponse = JsonConvert.DeserializeObject<CompletionRequest>(response.ResponsePayload);
var info = new DocumentProcessingInfo()
{
DocumentProcessingInfoId = documentProcessingInfoId
};
var documentProcessingInfo = new List<DocumentProcessingInfo>
{
new DocumentProcessingInfo()
{
DocumentProcessingInfoId = documentProcessingInfoId
}
};
_mockDocumentProcessingInfoService.Setup(x => x.GetListByIdAsync(It.IsAny<List<int>>())).ReturnsAsync(documentProcessingInfo).Verifiable();
_mockDocumentProcessingInfoService.Setup(x => x.UpdateRangeAsync(It.IsAny<List<DocumentProcessingInfo>>())).ReturnsAsync(documentProcessingInfo).Verifiable();
await _uploadCompletionService.HandleUploadCompletion(new List<Response>() { response });
_mockDocumentProcessingInfoService.Verify(x => x.GetListByIdAsync(It.IsAny<List<int>>()), Times.Once);
_mockDocumentProcessingInfoService.Verify(x => x.UpdateRangeAsync(It.IsAny<List<DocumentProcessingInfo>>()), Times.Once);
_mockQueueGatherMemberNotificationInfoService.Verify(x => x.QueueGatherMemberNotificationInfoRequest(It.IsAny<GatherMemberNotificationInfoRequest>()), Times.Once);
_mockQueueCompletionService.Verify(x => x.QueueCompletionRequest(It.IsAny<ProcessingRequest>(), It.IsAny<ProcessResult>()), Times.Never);
}
[Test]
public async Task HandleUploadCompletion_Failure_ResponseFailure()
{
var documentProcessingInfoId = 1234;
var uploadResponse = GenerateUploadResponse(documentProcessingInfoId);
uploadResponse.Successful = false;
uploadResponse.ResponseStack = new List<string> { "Test Failure" };
var moveResponse = new RequestResponse
{
IsSuccessful = true
};
_mockFileOperationsService.Setup(x => x.DirectMoveFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(moveResponse).Verifiable();
await _uploadCompletionService.HandleUploadCompletion(new List<Response>() { uploadResponse });
_mockFileOperationsService.Verify(x => x.DirectMoveFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Once);
_mockQueueCompletionService.Verify(x => x.QueueCompletionRequest(It.IsAny<ProcessingRequest>(), It.IsAny<ProcessResult>()), Times.Once);
}
private static CompletionRequest GenerateCompletionRequest()
=> new()
{
ProcessingRequest = new ProcessingRequest
{
DocumentFileName = Guid.NewGuid().ToString(),
IngestorRequest = new()
{
RootPath = Guid.NewGuid().ToString()
}
},
ProcessResult = new ProcessResult
{
ProcessStatusType = ProcessStatusTypes.Processing
}
};
private static CompletionRequest GenerateCompletionRequest(int documentProcessingInfoId)
=> new()
{
ProcessingRequest = new ProcessingRequest
{
DocumentFileName = Guid.NewGuid().ToString(),
IngestorRequest = new()
{
RootPath = Guid.NewGuid().ToString()
},
DocumentProcessingInfoId = documentProcessingInfoId
},
ProcessResult = new ProcessResult
{
ProcessStatusType = ProcessStatusTypes.Processing
}
};
private static Response GenerateUploadResponse()
=> new()
{
Successful = true,
ResponsePayload = JsonConvert.SerializeObject(GenerateCompletionRequest()),
ReturnCollection = new Dictionary<string, string>
{
{"DocumentId", Guid.NewGuid().ToString()}
}
};
private static Response GenerateUploadResponse(int documentProcessingInfoId)
=> new()
{
Successful = true,
ResponsePayload = JsonConvert.SerializeObject(GenerateCompletionRequest(documentProcessingInfoId)),
ReturnCollection = new Dictionary<string, string>
{
{"DocumentId", Guid.NewGuid().ToString()}
}
};
}
@@ -0,0 +1,173 @@
using System;
using System.Threading.Tasks;
using Moq;
using NUnit.Framework;
using LCU.Library.Internal.DocumentIngestorModels.Entities;
using LCU.Library.Internal.DocumentIngestorModels.Enums;
using LCU.Library.Internal.Exceptions;
using LCU.API.Internal.DocumentIngestor.Services;
using LCU.API.Internal.DocumentIngestorLib.Repositories;
namespace LCU.API.Internal.DocumentIngestorTests.Services;
public class IngestorRunInfoServiceTest
{
private IngestorRunInfoService _ingestorRunInfoService;
private Mock<IUnitOfWork> _unitOfWork;
private Mock<IIngestorRunInfoRepository> _mockIngestorRunInfoRepository;
[SetUp]
public void Setup()
{
_unitOfWork = new Mock<IUnitOfWork>();
_mockIngestorRunInfoRepository = new Mock<IIngestorRunInfoRepository>();
_ingestorRunInfoService = new IngestorRunInfoService(_unitOfWork.Object, _mockIngestorRunInfoRepository.Object);
}
[Test]
public async Task GetByIdAsync_IngestorRunInfo_Returned()
{
var ingestorRunInfoId = Guid.NewGuid();
var ingestorRunInfo = new IngestorRunInfo()
{
IngestorRunInfoId = ingestorRunInfoId
};
_mockIngestorRunInfoRepository.Setup(x => x.FindByIdAsync(ingestorRunInfoId)).ReturnsAsync(ingestorRunInfo);
var result = await _ingestorRunInfoService.GetByIdAsync(ingestorRunInfoId);
Assert.IsNotNull(result);
Assert.AreEqual(ingestorRunInfoId, result.IngestorRunInfoId);
_mockIngestorRunInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<Guid>()), Times.Once);
}
[Test]
public void GetByIdAsync_Exception()
{
var ingestorRunInfoId = Guid.NewGuid();
_mockIngestorRunInfoRepository.Setup(x => x.FindByIdAsync(ingestorRunInfoId)).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _ingestorRunInfoService.GetByIdAsync(ingestorRunInfoId));
_mockIngestorRunInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<Guid>()), Times.Once);
}
[Test]
public async Task SaveAsync_IngestorRunInfo_Returned()
{
var ingestorRunInfoId = Guid.NewGuid();
var ingestorRunInfo = new IngestorRunInfo()
{
IngestorRunInfoId = ingestorRunInfoId
};
_mockIngestorRunInfoRepository.Setup(x => x.AddAsync(ingestorRunInfo)).ReturnsAsync(ingestorRunInfo);
var result = await _ingestorRunInfoService.SaveAsync(ingestorRunInfo);
Assert.IsNotNull(result);
Assert.AreEqual(ingestorRunInfoId, result.IngestorRunInfoId);
_mockIngestorRunInfoRepository.Verify(x => x.AddAsync(It.IsAny<IngestorRunInfo>()), Times.Once);
}
[Test]
public void SaveAsync_Exception()
{
var ingestorRunInfoId = Guid.NewGuid();
var ingestorRunInfo = new IngestorRunInfo()
{
IngestorRunInfoId = ingestorRunInfoId
};
_mockIngestorRunInfoRepository.Setup(x => x.AddAsync(ingestorRunInfo)).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _ingestorRunInfoService.SaveAsync(ingestorRunInfo));
_mockIngestorRunInfoRepository.Verify(x => x.AddAsync(It.IsAny<IngestorRunInfo>()), Times.Once);
}
[Test]
public async Task Update_IngestorRunInfo_Returned()
{
var ingestorRunInfoId = Guid.NewGuid();
var ingestorRunInfo = new IngestorRunInfo()
{
IngestorRunInfoId = ingestorRunInfoId
};
_mockIngestorRunInfoRepository.Setup(x => x.FindByIdAsync(ingestorRunInfoId)).ReturnsAsync(ingestorRunInfo);
_mockIngestorRunInfoRepository.Setup(x => x.Update(ingestorRunInfo));
var result = await _ingestorRunInfoService.Update(ingestorRunInfo);
Assert.IsNotNull(result);
Assert.AreEqual(ingestorRunInfoId, result.IngestorRunInfoId);
_mockIngestorRunInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<Guid>()), Times.Once);
_mockIngestorRunInfoRepository.Verify(x => x.Update(It.IsAny<IngestorRunInfo>()), Times.Once);
}
[Test]
public void Update_FindByIdAsync_ThrowsException()
{
var ingestorRunInfoId = Guid.NewGuid();
var ingestorRunInfo = new IngestorRunInfo()
{
IngestorRunInfoId = ingestorRunInfoId
};
_mockIngestorRunInfoRepository.Setup(x => x.FindByIdAsync(ingestorRunInfoId)).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _ingestorRunInfoService.Update(ingestorRunInfo));
_mockIngestorRunInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<Guid>()), Times.Once);
_mockIngestorRunInfoRepository.Verify(x => x.Update(It.IsAny<IngestorRunInfo>()), Times.Never);
}
[Test]
public void Update_Update_ThrowsException()
{
var ingestorRunInfoId = Guid.NewGuid();
var ingestorRunInfo = new IngestorRunInfo()
{
IngestorRunInfoId = ingestorRunInfoId
};
_mockIngestorRunInfoRepository.Setup(x => x.FindByIdAsync(ingestorRunInfoId)).ReturnsAsync(ingestorRunInfo);
_mockIngestorRunInfoRepository.Setup(x => x.Update(ingestorRunInfo)).Throws(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _ingestorRunInfoService.Update(ingestorRunInfo));
_mockIngestorRunInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<Guid>()), Times.Once);
_mockIngestorRunInfoRepository.Verify(x => x.Update(It.IsAny<IngestorRunInfo>()), Times.Once);
}
[Test]
public async Task Delete_Success()
{
var ingestorRunInfoId = Guid.NewGuid();
var ingestorRunInfo = new IngestorRunInfo()
{
IngestorRunInfoId = ingestorRunInfoId
};
_mockIngestorRunInfoRepository.Setup(x => x.FindByIdAsync(ingestorRunInfoId)).ReturnsAsync(ingestorRunInfo);
_mockIngestorRunInfoRepository.Setup(x => x.Remove(ingestorRunInfo));
await _ingestorRunInfoService.Delete(ingestorRunInfoId);
_mockIngestorRunInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<Guid>()), Times.Once);
_mockIngestorRunInfoRepository.Verify(x => x.Remove(It.IsAny<IngestorRunInfo>()), Times.Once);
}
[Test]
public void Delete_FindByIdAsync_ThrowsException()
{
var ingestorRunInfoId = Guid.NewGuid();
var ingestorRunInfo = new IngestorRunInfo()
{
IngestorRunInfoId = ingestorRunInfoId
};
_mockIngestorRunInfoRepository.Setup(x => x.FindByIdAsync(ingestorRunInfoId)).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _ingestorRunInfoService.Delete(ingestorRunInfoId));
_mockIngestorRunInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<Guid>()), Times.Once);
_mockIngestorRunInfoRepository.Verify(x => x.Remove(It.IsAny<IngestorRunInfo>()), Times.Never);
}
[Test]
public void Delete_Remove_ThrowsException()
{
var ingestorRunInfoId = Guid.NewGuid();
var ingestorRunInfo = new IngestorRunInfo()
{
IngestorRunInfoId = ingestorRunInfoId
};
_mockIngestorRunInfoRepository.Setup(x => x.FindByIdAsync(ingestorRunInfoId)).ReturnsAsync(ingestorRunInfo);
_mockIngestorRunInfoRepository.Setup(x => x.Remove(ingestorRunInfo)).Throws(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _ingestorRunInfoService.Delete(ingestorRunInfoId));
_mockIngestorRunInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<Guid>()), Times.Once);
_mockIngestorRunInfoRepository.Verify(x => x.Remove(It.IsAny<IngestorRunInfo>()), Times.Once);
}
}
@@ -0,0 +1,105 @@
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);
}
}
@@ -0,0 +1,386 @@
using LCU.API.Internal.DocumentIngestor.Models.MemberPreferencesDtos;
using LCU.API.Internal.DocumentIngestor.Services;
using LCU.API.Internal.DocumentIngestor.Services.MemberNotificationInfoDeterminingServices;
using LCU.API.Internal.DocumentIngestor.Services.MicroApiServices;
using LCU.Library.Internal.DocumentIngestorModels.Entities;
using LCU.Library.Internal.DocumentIngestorModels.Enums;
using LCU.Library.Internal.Exceptions;
using Moq;
using NUnit.Framework;
using System;
using System.Threading.Tasks;
using LCU.Library.DocumentType.Extensions;
namespace LCU.API.Internal.DocumentIngestorTests.Services.MemberNotificationInfoDeterminingServices;
public class MemberNotificationInfoDeterminingServiceTest
{
private MemberNotificationInfoDeterminingService _memberNotificationInfoDeterminingService;
private Mock<IAccountNotificationInfoDeterminingService> _mockAccountNotificationInfoDeterminingService;
private Mock<IPrimaryNotificationInfoDeterminingService> _mockPrimaryNotificationInfoDeterminingService;
private Mock<IMemberNotificationInfoService> _mockMemberNotificationInfoService;
private Mock<IMemberPreferencesApiService> _mockMemberPreferencesApiService;
private Mock<IDocumentProcessingInfoService> _mockDocumentProcessingInfoService;
[SetUp]
public void Setup()
{
_mockAccountNotificationInfoDeterminingService = new Mock<IAccountNotificationInfoDeterminingService>();
_mockPrimaryNotificationInfoDeterminingService = new Mock<IPrimaryNotificationInfoDeterminingService>();
_mockMemberNotificationInfoService = new Mock<IMemberNotificationInfoService>();
_mockMemberPreferencesApiService = new Mock<IMemberPreferencesApiService>();
_mockDocumentProcessingInfoService = new Mock<IDocumentProcessingInfoService>();
_memberNotificationInfoDeterminingService = new MemberNotificationInfoDeterminingService(_mockAccountNotificationInfoDeterminingService.Object,
_mockPrimaryNotificationInfoDeterminingService.Object,
_mockMemberNotificationInfoService.Object,
_mockMemberPreferencesApiService.Object,
_mockDocumentProcessingInfoService.Object);
}
[Test]
public async Task DetermineDeliveryMethod_UniversalOptIn_NotNull()
{
var memberNotificationInfoId = 10;
var documentProcessingInfoId = 1;
var userId = "555";
var memberNotificationInfo = new MemberNotificationInfo()
{
AgreeUserId = userId,
MemberNotificationInfoId = memberNotificationInfoId,
DocumentProcessingInfoId = documentProcessingInfoId,
UploadDate = Convert.ToDateTime("1/1/2022")
};
var memberOptInSettings = new MemberOptInInformation()
{
MemberOptinSettings = new MemberOptInSettings()
{
UniversalOptIn = "Electronic",
UnifiedOptInEmail = "[email protected]"
}
};
var contact = (EmailAddress: "[email protected]", DeliveryMethod: DeliveryMethod.Electronic);
_mockMemberPreferencesApiService.Setup(x => x.GetMemberOptInSettingsByUserId(userId)).ReturnsAsync(memberOptInSettings);
var result = await _memberNotificationInfoDeterminingService.DetermineDeliveryMethod(memberNotificationInfo);
Assert.IsNotNull(result);
Assert.AreEqual(result.DeliveryMethod, contact.DeliveryMethod);
Assert.AreEqual(result.EmailAddress, contact.EmailAddress);
_mockMemberPreferencesApiService.Verify(x => x.GetMemberOptInSettingsByUserId(It.IsAny<string>()), Times.Once);
_mockDocumentProcessingInfoService.Verify(x => x.GetByIdAsync(It.IsAny<int>()), Times.Never);
}
[Test]
public async Task DetermineDeliveryMethod_UniversalOptIn_UserIdNull()
{
var memberNotificationInfoId = 10;
var documentProcessingInfoId = 1;
var memberNotificationInfo = new MemberNotificationInfo()
{
MemberNotificationInfoId = memberNotificationInfoId,
DocumentProcessingInfoId = documentProcessingInfoId,
UploadDate = Convert.ToDateTime("1/1/2022")
};
var contact = (EmailAddress: "", DeliveryMethod: DeliveryMethod.Paper);
var result = await _memberNotificationInfoDeterminingService.DetermineDeliveryMethod(memberNotificationInfo);
Assert.IsNotNull(result);
Assert.AreEqual(result.DeliveryMethod, contact.DeliveryMethod);
Assert.AreEqual(result.EmailAddress, contact.EmailAddress);
_mockMemberPreferencesApiService.Verify(x => x.GetMemberOptInSettingsByUserId(It.IsAny<string>()), Times.Never);
_mockDocumentProcessingInfoService.Verify(x => x.GetByIdAsync(It.IsAny<int>()), Times.Never);
}
[Test]
public async Task DetermineDeliveryMethod_UniversalOptInNull_ENotification()
{
var memberNotificationInfoId = 10;
var documentProcessingInfoId = 1;
var userId = "555";
var memberNotificationInfo = new MemberNotificationInfo()
{
AgreeUserId = userId,
MemberNotificationInfoId = memberNotificationInfoId,
DocumentProcessingInfoId = documentProcessingInfoId,
UploadDate = Convert.ToDateTime("1/1/2022")
};
var memberOptInSettings = new MemberOptInInformation()
{
MemberOptinSettings = new MemberOptInSettings()
{
ENotifications = "Electronic",
ENotificationsEmail = "[email protected]"
}
};
var documentProcessingInfo = new DocumentProcessingInfo()
{
DocumentType = "1099-NEC"
};
var contact = (EmailAddress: "[email protected]", DeliveryMethod: DeliveryMethod.Electronic);
_mockMemberPreferencesApiService.Setup(x => x.GetMemberOptInSettingsByUserId(userId)).ReturnsAsync(memberOptInSettings);
_mockDocumentProcessingInfoService.Setup(x => x.GetByIdAsync(documentProcessingInfoId)).ReturnsAsync(documentProcessingInfo);
var result = await _memberNotificationInfoDeterminingService.DetermineDeliveryMethod(memberNotificationInfo);
Assert.IsNotNull(result);
Assert.AreEqual(result.DeliveryMethod, contact.DeliveryMethod);
Assert.AreEqual(result.EmailAddress, contact.EmailAddress);
_mockMemberPreferencesApiService.Verify(x => x.GetMemberOptInSettingsByUserId(It.IsAny<string>()), Times.Once);
_mockDocumentProcessingInfoService.Verify(x => x.GetByIdAsync(It.IsAny<int>()), Times.Once);
}
[Test]
public async Task DetermineDeliveryMethod_UniversalOptInNull_EStatements_DocTypeNotStatement()
{
var memberNotificationInfoId = 10;
var documentProcessingInfoId = 1;
var userId = "555";
var memberNotificationInfo = new MemberNotificationInfo
{
AgreeUserId = userId,
MemberNotificationInfoId = memberNotificationInfoId,
DocumentProcessingInfoId = documentProcessingInfoId,
UploadDate = Convert.ToDateTime("1/1/2022")
};
var memberOptInSettings = new MemberOptInInformation
{
MemberOptinSettings = new MemberOptInSettings
{
ENotifications = "Paper"
}
};
var documentProcessingInfo = new DocumentProcessingInfo
{
DocumentType = "1099-NEC"
};
var contact = (EmailAddress: "", DeliveryMethod: DeliveryMethod.Paper);
_mockMemberPreferencesApiService
.Setup(x => x.GetMemberOptInSettingsByUserId(userId))
.ReturnsAsync(memberOptInSettings);
_mockDocumentProcessingInfoService
.Setup(x => x.GetByIdAsync(documentProcessingInfoId))
.ReturnsAsync(documentProcessingInfo);
var result = await _memberNotificationInfoDeterminingService.DetermineDeliveryMethod(memberNotificationInfo);
Assert.IsNotNull(result);
Assert.AreEqual(result.DeliveryMethod, contact.DeliveryMethod);
Assert.AreEqual(result.EmailAddress, contact.EmailAddress);
}
[Test]
[TestCase("Paper", "Electronic")]
[TestCase("Electronic", "Paper")]
public async Task DetermineDeliveryMethod_StatementAndUniversalOptInNotNull_ReturnsUniversalOptInPreferences(string universalPreference, string statementPreference)
{
var documentProcessingInfoId = DateTime.Now.Millisecond;
var userId = DateTime.Now.Millisecond.ToString();
var memberNotificationInfo = new MemberNotificationInfo
{
AgreeUserId = userId,
MemberNotificationInfoId = DateTime.Now.Millisecond,
DocumentProcessingInfoId = documentProcessingInfoId,
UploadDate = DateTime.Now
};
var memberOptInSettings = new MemberOptInInformation
{
MemberOptinSettings = new MemberOptInSettings
{
UniversalOptIn = universalPreference,
UnifiedOptInEmail = Guid.NewGuid().ToString(),
ENotifications = statementPreference,
ENotificationsEmail = Guid.NewGuid().ToString()
}
};
var documentProcessingInfo = new DocumentProcessingInfo();
_mockMemberPreferencesApiService
.Setup(x => x.GetMemberOptInSettingsByUserId(userId))
.ReturnsAsync(memberOptInSettings);
_mockDocumentProcessingInfoService
.Setup(x => x.GetByIdAsync(documentProcessingInfoId))
.ReturnsAsync(documentProcessingInfo);
var result = await _memberNotificationInfoDeterminingService.DetermineDeliveryMethod(memberNotificationInfo);
Assert.IsNotNull(result);
Assert.AreEqual(result.DeliveryMethod, universalPreference.GetValueFromName<DeliveryMethod>());
Assert.AreEqual(result.EmailAddress, universalPreference == "Paper" ? string.Empty : memberOptInSettings.MemberOptinSettings.UnifiedOptInEmail);
}
[Test]
[TestCase("Paper")]
[TestCase("Electronic")]
public async Task DetermineDeliveryMethod_StatementAndUniversalOptInNull_ReturnsEStatementPreferences(string statementPreference)
{
var documentProcessingInfoId = DateTime.Now.Millisecond;
var userId = DateTime.Now.Millisecond.ToString();
var memberNotificationInfo = new MemberNotificationInfo
{
AgreeUserId = userId,
MemberNotificationInfoId = DateTime.Now.Millisecond,
DocumentProcessingInfoId = documentProcessingInfoId,
UploadDate = DateTime.Now
};
var memberOptInSettings = new MemberOptInInformation
{
MemberOptinSettings = new MemberOptInSettings
{
UniversalOptIn = null!,
EStatements = statementPreference,
EStatementsEmail = Guid.NewGuid().ToString()
}
};
var documentProcessingInfo = new DocumentProcessingInfo
{
DocumentType = "Statement"
};
_mockMemberPreferencesApiService
.Setup(x => x.GetMemberOptInSettingsByUserId(userId))
.ReturnsAsync(memberOptInSettings);
_mockDocumentProcessingInfoService
.Setup(x => x.GetByIdAsync(documentProcessingInfoId))
.ReturnsAsync(documentProcessingInfo);
var result = await _memberNotificationInfoDeterminingService.DetermineDeliveryMethod(memberNotificationInfo);
Assert.IsNotNull(result);
Assert.AreEqual(result.DeliveryMethod, statementPreference.GetValueFromName<DeliveryMethod>());
Assert.AreEqual(result.EmailAddress, statementPreference == "Paper" ? string.Empty : memberOptInSettings.MemberOptinSettings.EStatementsEmail);
}
[Test]
[TestCase("Paper", "Electronic")]
[TestCase("Electronic", "Paper")]
[TestCase("Electronic", "Electronic")]
public async Task DetermineDeliveryMethod_StatementAndUniversalOptInNullAndENotificationNotNull_ReturnsEStatementPreferences(string statementPreference, string notificationPreference)
{
var documentProcessingInfoId = DateTime.Now.Millisecond;
var userId = DateTime.Now.Millisecond.ToString();
var memberNotificationInfo = new MemberNotificationInfo
{
AgreeUserId = userId,
MemberNotificationInfoId = DateTime.Now.Millisecond,
DocumentProcessingInfoId = documentProcessingInfoId,
UploadDate = DateTime.Now
};
var memberOptInSettings = new MemberOptInInformation
{
MemberOptinSettings = new MemberOptInSettings
{
UniversalOptIn = null!,
EStatements = statementPreference,
EStatementsEmail = Guid.NewGuid().ToString(),
ENotifications = notificationPreference,
ENotificationsEmail = Guid.NewGuid().ToString()
}
};
var documentProcessingInfo = new DocumentProcessingInfo
{
DocumentType = "Statement"
};
_mockMemberPreferencesApiService
.Setup(x => x.GetMemberOptInSettingsByUserId(userId))
.ReturnsAsync(memberOptInSettings);
_mockDocumentProcessingInfoService
.Setup(x => x.GetByIdAsync(documentProcessingInfoId))
.ReturnsAsync(documentProcessingInfo);
var result = await _memberNotificationInfoDeterminingService.DetermineDeliveryMethod(memberNotificationInfo);
Assert.IsNotNull(result);
Assert.AreEqual(result.DeliveryMethod, statementPreference.GetValueFromName<DeliveryMethod>());
Assert.AreEqual(result.EmailAddress, statementPreference == "Paper" ? string.Empty : memberOptInSettings.MemberOptinSettings.EStatementsEmail);
}
[Test]
public async Task DetermineDeliveryMethod_StatementAndAllPreferencesNull_ReturnsPaper()
{
var documentProcessingInfoId = DateTime.Now.Millisecond;
var userId = DateTime.Now.Millisecond.ToString();
var memberNotificationInfo = new MemberNotificationInfo
{
AgreeUserId = userId,
MemberNotificationInfoId = DateTime.Now.Millisecond,
DocumentProcessingInfoId = documentProcessingInfoId,
UploadDate = DateTime.Now
};
var memberOptInSettings = new MemberOptInInformation
{
MemberOptinSettings = new MemberOptInSettings
{
UniversalOptIn = null!,
ENotifications = null!,
EStatements = null!
}
};
var documentProcessingInfo = new DocumentProcessingInfo
{
DocumentType = "Statement"
};
_mockMemberPreferencesApiService
.Setup(x => x.GetMemberOptInSettingsByUserId(userId))
.ReturnsAsync(memberOptInSettings);
_mockDocumentProcessingInfoService
.Setup(x => x.GetByIdAsync(documentProcessingInfoId))
.ReturnsAsync(documentProcessingInfo);
var result = await _memberNotificationInfoDeterminingService.DetermineDeliveryMethod(memberNotificationInfo);
Assert.IsNotNull(result);
Assert.AreEqual(result.DeliveryMethod, "Paper".GetValueFromName<DeliveryMethod>());
Assert.AreEqual(result.EmailAddress, string.Empty);
}
[Test]
public async Task DetermineDeliveryMethod_NotStatementAndAllPreferencesNull_ReturnsPaper()
{
var documentProcessingInfoId = DateTime.Now.Millisecond;
var userId = DateTime.Now.Millisecond.ToString();
var memberNotificationInfo = new MemberNotificationInfo
{
AgreeUserId = userId,
MemberNotificationInfoId = DateTime.Now.Millisecond,
DocumentProcessingInfoId = documentProcessingInfoId,
UploadDate = DateTime.Now
};
var memberOptInSettings = new MemberOptInInformation
{
MemberOptinSettings = new MemberOptInSettings
{
UniversalOptIn = null!,
ENotifications = null!,
EStatements = null!
}
};
var documentProcessingInfo = new DocumentProcessingInfo();
_mockMemberPreferencesApiService
.Setup(x => x.GetMemberOptInSettingsByUserId(userId))
.ReturnsAsync(memberOptInSettings);
_mockDocumentProcessingInfoService
.Setup(x => x.GetByIdAsync(documentProcessingInfoId))
.ReturnsAsync(documentProcessingInfo);
var result = await _memberNotificationInfoDeterminingService.DetermineDeliveryMethod(memberNotificationInfo);
Assert.IsNotNull(result);
Assert.AreEqual(result.DeliveryMethod, "Paper".GetValueFromName<DeliveryMethod>());
Assert.AreEqual(result.EmailAddress, string.Empty);
}
[Test]
public void DetermineDeliveryMethod_Exception()
{
var memberNotificationInfo = new MemberNotificationInfo() { AgreeUserId = "1111" };
_mockMemberPreferencesApiService.Setup(x => x.GetMemberOptInSettingsByUserId(memberNotificationInfo.AgreeUserId)).Throws(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _memberNotificationInfoDeterminingService.DetermineDeliveryMethod(memberNotificationInfo));
_mockMemberPreferencesApiService.Verify(x => x.GetMemberOptInSettingsByUserId(It.IsAny<string>()), Times.Once);
_mockDocumentProcessingInfoService.Verify(x => x.GetByIdAsync(It.IsAny<int>()), Times.Never);
}
}
@@ -0,0 +1,166 @@
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);
}
}
@@ -0,0 +1,627 @@
using Moq;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using LCU.API.Internal.DocumentIngestor.Services;
using LCU.API.Internal.DocumentIngestor.Configurations;
using LCU.API.Internal.DocumentIngestorLib.Repositories;
using LCU.Library.Internal.DocumentIngestorModels.Entities;
using LCU.Library.Internal.DocumentIngestorModels.Enums;
using LCU.Library.Internal.DocumentIngestorModels.Models;
using LCU.Library.Internal.DocumentIngestorModels.Models.Pagination;
using LCU.Library.Internal.Exceptions;
namespace LCU.API.Internal.DocumentIngestorTests.Services;
public class MemberNotificationInfoServiceTest
{
private MemberNotificationInfoService _memberNotificationInfoService;
private Mock<IUnitOfWork> _unitOfWork;
private ApiConfiguration _apiConfiguration;
private Mock<IMemberNotificationInfoRepository> _mockMemberNotificationInfoRepository;
private Mock<IProcessingLogService> _mockProcessingLogService;
[SetUp]
public void Setup()
{
_unitOfWork = new Mock<IUnitOfWork>();
_apiConfiguration = new ApiConfiguration { BatchSkipAmount = 10000 };
_mockMemberNotificationInfoRepository = new Mock<IMemberNotificationInfoRepository>();
_mockProcessingLogService = new Mock<IProcessingLogService>();
_memberNotificationInfoService = new MemberNotificationInfoService
(
_unitOfWork.Object,
_apiConfiguration,
_mockMemberNotificationInfoRepository.Object,
_mockProcessingLogService.Object
);
}
[Test]
public async Task GetAsync_MemberNotificationInfos_Returned()
{
var memberNotificationInfoId = 10;
var documentProcessingInfoId = 1;
var documentProcessingInfos = new List<MemberNotificationInfo>()
{
new MemberNotificationInfo()
{
MemberNotificationInfoId = memberNotificationInfoId,
DocumentProcessingInfoId = documentProcessingInfoId,
UploadDate = Convert.ToDateTime("1/1/2022")
}
};
_mockMemberNotificationInfoRepository.Setup(x => x.FindAsync()).ReturnsAsync(documentProcessingInfos);
var result = await _memberNotificationInfoService.GetAsync();
Assert.IsNotNull(result);
Assert.AreEqual(1, result.Count());
_mockMemberNotificationInfoRepository.Verify(x => x.FindAsync(), Times.Once);
}
[Test]
public void GetAsync_Exception()
{
_mockMemberNotificationInfoRepository.Setup(x => x.FindAsync()).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _memberNotificationInfoService.GetAsync());
_mockMemberNotificationInfoRepository.Verify(x => x.FindAsync(), Times.Once);
}
[Test]
public async Task GetByIdAsync_MemberNotificationInfo_Returned()
{
var memberNotificationInfoId = 10;
var documentProcessingInfoId = 1;
var memberNotificationInfo = new MemberNotificationInfo()
{
MemberNotificationInfoId = memberNotificationInfoId,
DocumentProcessingInfoId = documentProcessingInfoId,
UploadDate = Convert.ToDateTime("1/1/2022")
};
_mockMemberNotificationInfoRepository.Setup(x => x.FindByIdAsync(memberNotificationInfoId)).ReturnsAsync(memberNotificationInfo);
var result = await _memberNotificationInfoService.GetByIdAsync(memberNotificationInfoId);
Assert.IsNotNull(result);
Assert.AreEqual(documentProcessingInfoId, result.DocumentProcessingInfoId);
Assert.AreEqual(memberNotificationInfoId, result.MemberNotificationInfoId);
_mockMemberNotificationInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>()), Times.Once);
}
[Test]
public void GetByIdAsync_Exception()
{
var id = 1;
_mockMemberNotificationInfoRepository.Setup(x => x.FindByIdAsync(id)).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _memberNotificationInfoService.GetByIdAsync(id));
_mockMemberNotificationInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>()), Times.Once);
}
[Test]
public async Task GetByDocumentProcessingInfoIdAsync_MemberNotificationInfos_Returned()
{
var memberNotificationInfoId = 10;
var documentProcessingInfoId = 1;
var documentProcessingInfos = new List<MemberNotificationInfo>()
{
new MemberNotificationInfo()
{
MemberNotificationInfoId = memberNotificationInfoId,
DocumentProcessingInfoId = documentProcessingInfoId,
UploadDate = Convert.ToDateTime("1/1/2022")
}
};
_mockMemberNotificationInfoRepository.Setup(x => x.FindByDocumentProcessingInfoIdAsync(documentProcessingInfoId)).ReturnsAsync(documentProcessingInfos);
var result = await _memberNotificationInfoService.GetByDocumentProcessingInfoIdAsync(documentProcessingInfoId);
Assert.IsNotNull(result);
Assert.AreEqual(1, result.Count());
_mockMemberNotificationInfoRepository.Verify(x => x.FindByDocumentProcessingInfoIdAsync(It.IsAny<int>()), Times.Once);
}
[Test]
public void GetByDocumentProcessingInfoIdAsync_Exception()
{
var documentProcessingInfoId = 1;
_mockMemberNotificationInfoRepository.Setup(x => x.FindByDocumentProcessingInfoIdAsync(documentProcessingInfoId)).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _memberNotificationInfoService.GetByDocumentProcessingInfoIdAsync(documentProcessingInfoId));
_mockMemberNotificationInfoRepository.Verify(x => x.FindByDocumentProcessingInfoIdAsync(It.IsAny<int>()), Times.Once);
}
[Test]
public async Task SaveAsync_MemberNotificationInfo_Returned()
{
var memberNotificationInfoId = 10;
var documentProcessingInfoId = 1;
var memberNotificationInfo = new MemberNotificationInfo()
{
MemberNotificationInfoId = memberNotificationInfoId,
DocumentProcessingInfoId = documentProcessingInfoId,
UploadDate = Convert.ToDateTime("1/1/2022")
};
_mockMemberNotificationInfoRepository.Setup(x => x.AddAsync(memberNotificationInfo)).ReturnsAsync(memberNotificationInfo);
var result = await _memberNotificationInfoService.SaveAsync(memberNotificationInfo);
Assert.IsNotNull(result);
Assert.AreEqual(documentProcessingInfoId, result.DocumentProcessingInfoId);
Assert.AreEqual(memberNotificationInfoId, result.MemberNotificationInfoId);
_mockMemberNotificationInfoRepository.Verify(x => x.AddAsync(It.IsAny<MemberNotificationInfo>()), Times.Once);
}
[Test]
public void SaveAsync_Exception()
{
var memberNotificationInfoId = 10;
var documentProcessingInfoId = 1;
var memberNotificationInfo = new MemberNotificationInfo()
{
MemberNotificationInfoId = memberNotificationInfoId,
DocumentProcessingInfoId = documentProcessingInfoId,
UploadDate = Convert.ToDateTime("1/1/2022")
};
_mockMemberNotificationInfoRepository.Setup(x => x.AddAsync(memberNotificationInfo)).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _memberNotificationInfoService.SaveAsync(memberNotificationInfo));
_mockMemberNotificationInfoRepository.Verify(x => x.AddAsync(It.IsAny<MemberNotificationInfo>()), Times.Once);
}
[Test]
public async Task Update_MemberNotificationInfo_Returned()
{
var memberNotificationInfoId = 10;
var documentProcessingInfoId = 1;
var memberNotificationInfo = new MemberNotificationInfo()
{
MemberNotificationInfoId = memberNotificationInfoId,
DocumentProcessingInfoId = documentProcessingInfoId,
UploadDate = Convert.ToDateTime("1/1/2022")
};
_mockMemberNotificationInfoRepository.Setup(x => x.Update(memberNotificationInfo));
var result = await _memberNotificationInfoService.Update(memberNotificationInfo);
Assert.IsNotNull(result);
Assert.AreEqual(documentProcessingInfoId, result.DocumentProcessingInfoId);
Assert.AreEqual(memberNotificationInfoId, result.MemberNotificationInfoId);
_mockMemberNotificationInfoRepository.Verify(x => x.Update(It.IsAny<MemberNotificationInfo>()), Times.Once);
}
[Test]
public void Update_FindByIdAsync_ThrowsException()
{
var memberNotificationInfoId = 10;
var documentProcessingInfoId = 1;
var memberNotificationInfo = new MemberNotificationInfo()
{
MemberNotificationInfoId = memberNotificationInfoId,
DocumentProcessingInfoId = documentProcessingInfoId,
UploadDate = Convert.ToDateTime("1/1/2022")
};
_mockMemberNotificationInfoRepository.Setup(x => x.FindByIdAsync(memberNotificationInfoId)).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _memberNotificationInfoService.GetByIdAsync(memberNotificationInfo.MemberNotificationInfoId));
_mockMemberNotificationInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>()), Times.Once);
_mockMemberNotificationInfoRepository.Verify(x => x.Update(It.IsAny<MemberNotificationInfo>()), Times.Never);
}
[Test]
public void Update_Update_ThrowsException()
{
var memberNotificationInfoId = 10;
var documentProcessingInfoId = 1;
var memberNotificationInfo = new MemberNotificationInfo()
{
MemberNotificationInfoId = memberNotificationInfoId,
DocumentProcessingInfoId = documentProcessingInfoId,
UploadDate = Convert.ToDateTime("1/1/2022")
};
_mockMemberNotificationInfoRepository.Setup(x => x.Update(memberNotificationInfo)).Throws(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _memberNotificationInfoService.Update(memberNotificationInfo));
_mockMemberNotificationInfoRepository.Verify(x => x.Update(It.IsAny<MemberNotificationInfo>()), Times.Once);
}
[Test]
public async Task UpdateRange_MemberNotificationInfo_Returned()
{
var memberNotificationInfoId = 10;
var documentProcessingInfoId = 1;
var memberNotificationInfos = new List<MemberNotificationInfo>()
{
new()
{
MemberNotificationInfoId = memberNotificationInfoId,
DocumentProcessingInfoId = documentProcessingInfoId,
UploadDate = Convert.ToDateTime("1/1/2022")
}
};
_mockMemberNotificationInfoRepository.Setup(x => x.UpdateRange(memberNotificationInfos));
var result = await _memberNotificationInfoService.UpdateRange(memberNotificationInfos);
Assert.IsNotNull(result);
Assert.AreEqual(documentProcessingInfoId, result.FirstOrDefault()?.DocumentProcessingInfoId);
Assert.AreEqual(memberNotificationInfoId, result.FirstOrDefault()?.MemberNotificationInfoId);
_mockMemberNotificationInfoRepository.Verify(x => x.UpdateRange(It.IsAny<IEnumerable<MemberNotificationInfo>>()), Times.Once);
}
[Test]
public void UpdateRange_FindByIdAsync_ThrowsException()
{
var memberNotificationInfoId = 10;
var documentProcessingInfoId = 1;
var memberNotificationInfos = new List<MemberNotificationInfo>()
{
new()
{
MemberNotificationInfoId = memberNotificationInfoId,
DocumentProcessingInfoId = documentProcessingInfoId,
UploadDate = Convert.ToDateTime("1/1/2022")
}
};
_mockMemberNotificationInfoRepository.Setup(x => x.FindByIdAsync(memberNotificationInfoId)).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _memberNotificationInfoService.GetByIdAsync(memberNotificationInfoId));
_mockMemberNotificationInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>()), Times.Once);
}
[Test]
public void UpdateRange_Update_ThrowsException()
{
var memberNotificationInfoId = 10;
var documentProcessingInfoId = 1;
var memberNotificationInfos = new List<MemberNotificationInfo>()
{
new()
{
MemberNotificationInfoId = memberNotificationInfoId,
DocumentProcessingInfoId = documentProcessingInfoId,
UploadDate = Convert.ToDateTime("1/1/2022")
}
};
_mockMemberNotificationInfoRepository.Setup(x => x.UpdateRange(memberNotificationInfos)).Throws(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _memberNotificationInfoService.UpdateRange(memberNotificationInfos));
_mockMemberNotificationInfoRepository.Verify(x => x.UpdateRange(It.IsAny<IEnumerable<MemberNotificationInfo>>()), Times.Once);
}
[Test]
public async Task Delete_Success()
{
var memberNotificationInfoId = 10;
var documentProcessingInfoId = 1;
var memberNotificationInfo = new MemberNotificationInfo()
{
MemberNotificationInfoId = memberNotificationInfoId,
DocumentProcessingInfoId = documentProcessingInfoId,
UploadDate = Convert.ToDateTime("1/1/2022")
};
_mockMemberNotificationInfoRepository.Setup(x => x.FindByIdAsync(memberNotificationInfoId)).ReturnsAsync(memberNotificationInfo);
_mockMemberNotificationInfoRepository.Setup(x => x.Remove(memberNotificationInfo));
await _memberNotificationInfoService.Delete(memberNotificationInfoId);
_mockMemberNotificationInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>()), Times.Once);
_mockMemberNotificationInfoRepository.Verify(x => x.Remove(It.IsAny<MemberNotificationInfo>()), Times.Once);
}
[Test]
public void Delete_FindByIdAsync_ThrowsException()
{
var id = 1;
_mockMemberNotificationInfoRepository.Setup(x => x.FindByIdAsync(id)).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _memberNotificationInfoService.Delete(id));
_mockMemberNotificationInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>()), Times.Once);
_mockMemberNotificationInfoRepository.Verify(x => x.Remove(It.IsAny<MemberNotificationInfo>()), Times.Never);
}
[Test]
public void Delete_Remove_ThrowsException()
{
var memberNotificationInfoId = 10;
var documentProcessingInfoId = 1;
var memberNotificationInfo = new MemberNotificationInfo()
{
MemberNotificationInfoId = memberNotificationInfoId,
DocumentProcessingInfoId = documentProcessingInfoId,
UploadDate = Convert.ToDateTime("1/1/2022")
};
_mockMemberNotificationInfoRepository.Setup(x => x.FindByIdAsync(memberNotificationInfoId)).ReturnsAsync(memberNotificationInfo);
_mockMemberNotificationInfoRepository.Setup(x => x.Remove(memberNotificationInfo)).Throws(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _memberNotificationInfoService.Delete(memberNotificationInfoId));
_mockMemberNotificationInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>()), Times.Once);
_mockMemberNotificationInfoRepository.Verify(x => x.Remove(It.IsAny<MemberNotificationInfo>()), Times.Once);
}
[Test]
public async Task SetDocumentNotificationStatus_NotificationInfoDoesntExist_ReturnsFalseAndDoesNotUpdateOrLog()
{
var memberNotificationInfo = new MemberNotificationInfo
{ MemberNotificationInfoId = DateTime.Now.Millisecond };
var notificationStatus = NotificationStatusTypes.CriticalFailure;
var userName = Guid.NewGuid().ToString();
var reason = Guid.NewGuid().ToString();
_mockMemberNotificationInfoRepository
.Setup(s => s.FindByIdAsync(memberNotificationInfo.MemberNotificationInfoId))
.ReturnsAsync((MemberNotificationInfo)null);
var updated = await _memberNotificationInfoService.SetDocumentNotificationStatus
(
memberNotificationInfo.MemberNotificationInfoId,
notificationStatus,
userName,
reason
);
Assert.IsFalse(updated);
_mockMemberNotificationInfoRepository.Verify(r => r.Update(memberNotificationInfo), Times.Never);
_mockProcessingLogService.Verify(s => s.SaveAsync(It.IsAny<ProcessingLog>()), Times.Never);
}
[Test]
public void SetDocumentNotificationStatus_FindingNotificationInfoThrows_ThrowsServiceException()
{
var memberNotificationInfo = new MemberNotificationInfo
{ MemberNotificationInfoId = DateTime.Now.Millisecond };
var notificationStatus = NotificationStatusTypes.CriticalFailure;
var userName = Guid.NewGuid().ToString();
var reason = Guid.NewGuid().ToString();
_mockMemberNotificationInfoRepository
.Setup(s => s.FindByIdAsync(memberNotificationInfo.MemberNotificationInfoId))
.ThrowsAsync(new Exception());
var thrown = Assert.ThrowsAsync<ServiceException>(() => _memberNotificationInfoService.SetDocumentNotificationStatus(memberNotificationInfo.MemberNotificationInfoId, notificationStatus, userName, reason));
StringAssert.Contains(memberNotificationInfo.MemberNotificationInfoId.ToString(), thrown.Message);
StringAssert.Contains(notificationStatus.ToString(), thrown.Message);
}
[Test]
public async Task SetDocumentNotificationStatus_SetStatusThrows_ThrowsServiceExceptionAndDoesNotLog()
{
var notificationStatus = NotificationStatusTypes.CriticalFailure;
var memberNotificationInfo = new MemberNotificationInfo
{
MemberNotificationInfoId = DateTime.Now.Millisecond,
DocumentProcessingInfoId = DateTime.Now.Millisecond + 1,
NotificationStatusType = notificationStatus + 1
};
var userName = Guid.NewGuid().ToString();
var reason = Guid.NewGuid().ToString();
var processingLogs = new List<ProcessingLog>();
_mockMemberNotificationInfoRepository
.Setup(s => s.FindByIdAsync(memberNotificationInfo.MemberNotificationInfoId))
.ReturnsAsync(memberNotificationInfo);
_mockMemberNotificationInfoRepository
.Setup(r => r.Update(memberNotificationInfo))
.Throws(new Exception());
_mockProcessingLogService
.Setup(s => s.SaveAsync(It.IsAny<ProcessingLog>()))
.Callback<ProcessingLog>(processingLogs.Add);
var thrown = Assert.ThrowsAsync<ServiceException>(() => _memberNotificationInfoService.SetDocumentNotificationStatus(memberNotificationInfo.MemberNotificationInfoId, notificationStatus, userName, reason));
StringAssert.Contains(memberNotificationInfo.MemberNotificationInfoId.ToString(), thrown.Message);
StringAssert.Contains(notificationStatus.ToString(), thrown.Message);
CollectionAssert.IsEmpty(processingLogs);
}
[Test]
public async Task SetDocumentNotificationStatus_SetStatusSuccess_LogsChange()
{
var notificationStatus = NotificationStatusTypes.CriticalFailure;
var originalNotificationStatus = notificationStatus + 1;
var memberNotificationInfo = new MemberNotificationInfo
{
MemberNotificationInfoId = DateTime.Now.Millisecond,
DocumentProcessingInfoId = DateTime.Now.Millisecond + 1,
NotificationStatusType = originalNotificationStatus
};
var userName = Guid.NewGuid().ToString();
var reason = Guid.NewGuid().ToString();
var processingLogs = new List<ProcessingLog>();
_mockMemberNotificationInfoRepository
.Setup(s => s.FindByIdAsync(memberNotificationInfo.MemberNotificationInfoId))
.ReturnsAsync(memberNotificationInfo);
_mockProcessingLogService
.Setup(s => s.SaveAsync(It.IsAny<ProcessingLog>()))
.Callback<ProcessingLog>(processingLogs.Add);
var testStart = DateTime.UtcNow;
await _memberNotificationInfoService.SetDocumentNotificationStatus
(
memberNotificationInfo.MemberNotificationInfoId,
notificationStatus,
userName,
reason
);
var testEnd = DateTime.UtcNow;
Assert.AreEqual(1, processingLogs.Count);
var log = processingLogs.Single();
Assert.AreEqual(memberNotificationInfo.DocumentProcessingInfoId, log.DocumentProcessingInfoId);
Assert.That(log.LogTimeStamp, Is.InRange(testStart, testEnd));
StringAssert.Contains(originalNotificationStatus.ToString(), log.LogMessage);
StringAssert.Contains(notificationStatus.ToString(), log.LogMessage);
StringAssert.Contains(reason, log.LogMessage);
}
[Test]
public async Task SetDocumentNotificationStatus_LoggingChangeThrows_ThrowsServiceException()
{
var notificationStatus = NotificationStatusTypes.CriticalFailure;
var memberNotificationInfo = new MemberNotificationInfo
{
MemberNotificationInfoId = DateTime.Now.Millisecond,
NotificationStatusType = notificationStatus + 1
};
var userName = Guid.NewGuid().ToString();
var reason = Guid.NewGuid().ToString();
_mockMemberNotificationInfoRepository
.Setup(s => s.FindByIdAsync(memberNotificationInfo.MemberNotificationInfoId))
.ReturnsAsync(memberNotificationInfo);
_mockProcessingLogService
.Setup(s => s.SaveAsync(It.IsAny<ProcessingLog>()))
.ThrowsAsync(new Exception());
var thrown = Assert.ThrowsAsync<ServiceException>(() => _memberNotificationInfoService.SetDocumentNotificationStatus(memberNotificationInfo.MemberNotificationInfoId, notificationStatus, userName, reason));
StringAssert.Contains(memberNotificationInfo.MemberNotificationInfoId.ToString(), thrown.Message);
StringAssert.Contains(notificationStatus.ToString(), thrown.Message);
}
[Test]
public async Task SetDocumentNotificationStatus_SetStatusSuccessAndLogSuccess_ReturnsTrue()
{
var notificationStatus = NotificationStatusTypes.CriticalFailure;
var notificationInfo = new MemberNotificationInfo
{
MemberNotificationInfoId = DateTime.Now.Millisecond,
DocumentProcessingInfoId = DateTime.Now.Millisecond + 1,
NotificationStatusType = notificationStatus
};
var newNotificationStatus = notificationStatus + 1;
var userName = Guid.NewGuid().ToString();
var reason = Guid.NewGuid().ToString();
var processingLogs = new List<ProcessingLog>();
_mockMemberNotificationInfoRepository
.Setup(s => s.FindByIdAsync(notificationInfo.MemberNotificationInfoId))
.ReturnsAsync(notificationInfo);
_mockMemberNotificationInfoRepository
.Setup(r => r.Update(notificationInfo))
.Callback<MemberNotificationInfo>(returnedUpdated =>
returnedUpdated.NotificationStatusType = notificationInfo.NotificationStatusType);
_mockProcessingLogService
.Setup(s => s.SaveAsync(It.IsAny<ProcessingLog>()))
.Callback<ProcessingLog>(processingLogs.Add);
var updated = await _memberNotificationInfoService.SetDocumentNotificationStatus
(
notificationInfo.MemberNotificationInfoId,
newNotificationStatus,
userName,
reason
);
Assert.IsTrue(updated);
Assert.AreEqual(newNotificationStatus, notificationInfo.NotificationStatusType);
Assert.AreEqual(1, processingLogs.Count);
}
[Test]
public async Task BulkSetDocumentNotificationStatus_Success()
{
var notificationInfos = new List<MemberNotificationInfo>
{
new()
{
DocumentProcessingInfoId = DateTime.Now.Millisecond,
NotificationStatusType = NotificationStatusTypes.CriticalFailure
},
new()
{
DocumentProcessingInfoId = DateTime.Now.Millisecond + 1,
NotificationStatusType = NotificationStatusTypes.CriticalFailure
},
};
var request = new BulkNotificationStatusRequest
{
Filter = new()
{
NotificationStatusFilters = new List<NotificationStatusTypes>
{
NotificationStatusTypes.CriticalFailure
}
},
NotificationStatus = NotificationStatusTypes.Complete,
ReasonMessage = Guid.NewGuid().ToString()
};
var userName = Guid.NewGuid().ToString();
_mockMemberNotificationInfoRepository
.Setup(s => s.GetMemberNotificationInfosByFilter(request.Filter))
.ReturnsAsync(notificationInfos);
_mockMemberNotificationInfoRepository
.Setup(r => r.UpdateRange(notificationInfos));
_mockProcessingLogService
.Setup(s => s.SaveRangeAsync(It.IsAny<IEnumerable<ProcessingLog>>()));
var updated = await _memberNotificationInfoService.BulkSetDocumentNotificationStatus(request, userName);
Assert.IsTrue(updated);
Assert.AreEqual(request.NotificationStatus, notificationInfos[0].NotificationStatusType);
Assert.AreEqual(request.NotificationStatus, notificationInfos[1].NotificationStatusType);
_mockMemberNotificationInfoRepository.Verify(x => x.GetMemberNotificationInfosByFilter(It.IsAny<Filter>()), Times.Once);
_mockMemberNotificationInfoRepository.Verify(x => x.UpdateRange(It.IsAny<IEnumerable<MemberNotificationInfo>>()), Times.Once);
_mockProcessingLogService.Verify(x => x.SaveRangeAsync(It.IsAny<IEnumerable<ProcessingLog>>()), Times.Once);
}
[Test]
public async Task BulkSetDocumentNotificationStatus_Bulk_Success()
{
var repeatAmount = 15000;
var randomInt = new Random();
var notificationInfos = Enumerable.Repeat(1, repeatAmount)
.Select(_ => new MemberNotificationInfo
{
DocumentProcessingInfoId = randomInt.Next(1, repeatAmount),
NotificationStatusType = NotificationStatusTypes.CriticalFailure
}).ToList();
var request = new BulkNotificationStatusRequest
{
Filter = new()
{
NotificationStatusFilters = new List<NotificationStatusTypes>
{
NotificationStatusTypes.CriticalFailure
}
},
NotificationStatus = NotificationStatusTypes.Complete,
ReasonMessage = Guid.NewGuid().ToString()
};
var userName = Guid.NewGuid().ToString();
_mockMemberNotificationInfoRepository
.Setup(s => s.GetMemberNotificationInfosByFilter(request.Filter))
.ReturnsAsync(notificationInfos);
_mockMemberNotificationInfoRepository.Setup(s =>
s.UpdateRange(It.IsAny<IEnumerable<MemberNotificationInfo>>()));
_mockProcessingLogService
.Setup(s => s.SaveRangeAsync(It.IsAny<IEnumerable<ProcessingLog>>()));
Assert.IsTrue(await _memberNotificationInfoService.BulkSetDocumentNotificationStatus(request, userName));
_mockMemberNotificationInfoRepository.Verify(x => x.GetMemberNotificationInfosByFilter(It.IsAny<Filter>()), Times.Once);
_mockMemberNotificationInfoRepository.Verify(x => x.UpdateRange(It.IsAny<IEnumerable<MemberNotificationInfo>>()), Times.Exactly(2));
_mockProcessingLogService.Verify(x => x.SaveRangeAsync(It.IsAny<IEnumerable<ProcessingLog>>()), Times.Exactly(2));
}
[Test]
public Task BulkSetDocumentNotificationStatus_Failure_ServiceException()
{
var request = new BulkNotificationStatusRequest
{
Filter = new()
{
NotificationStatusFilters = new List<NotificationStatusTypes>
{
NotificationStatusTypes.CriticalFailure
}
},
NotificationStatus = NotificationStatusTypes.Complete,
ReasonMessage = Guid.NewGuid().ToString()
};
var userName = Guid.NewGuid().ToString();
_mockMemberNotificationInfoRepository
.Setup(s => s.GetMemberNotificationInfosByFilter(request.Filter))
.ThrowsAsync(new Exception());
Assert.ThrowsAsync<ServiceException>(() => _memberNotificationInfoService.BulkSetDocumentNotificationStatus(request, userName));
_mockMemberNotificationInfoRepository.Verify(x => x.GetMemberNotificationInfosByFilter(It.IsAny<Filter>()), Times.Once);
_mockMemberNotificationInfoRepository.Verify(x => x.UpdateRange(It.IsAny<IEnumerable<MemberNotificationInfo>>()), Times.Never);
_mockProcessingLogService.Verify(x => x.SaveRangeAsync(It.IsAny<IEnumerable<ProcessingLog>>()), Times.Never);
return Task.CompletedTask;
}
}
@@ -0,0 +1,293 @@
using System;
using System.Linq;
using System.Collections.Generic;
using System.Threading.Tasks;
using Moq;
using NUnit.Framework;
using LCU.Library.Internal.Exceptions;
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.Tax;
using LCU.API.Internal.DocumentIngestor.Services.MicroApiServices;
using LCU.API.Internal.DocumentIngestor.DataAccess;
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.Accounts;
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.MemberAgreements;
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.Agreements;
namespace LCU.API.Internal.DocumentIngestorTests.Services.MicroApiServices;
public class CoreApiWrapperServiceTest
{
private CoreApiWrapperService _coreApiWrapperService;
private Mock<ICoreApiWrapperDao> _mockCoreApiWrapperDao;
[SetUp]
public void Setup()
{
_mockCoreApiWrapperDao = new Mock<ICoreApiWrapperDao>();
_coreApiWrapperService = new CoreApiWrapperService(_mockCoreApiWrapperDao.Object);
}
[Test]
public void GetPersonsTaxIdData_Exception()
{
_mockCoreApiWrapperDao.Setup(x => x.GetPersonsTaxIdData(It.IsAny<string>()))
.ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _coreApiWrapperService.GetPersonsTaxIdData("12"));
_mockCoreApiWrapperDao.Verify(x => x.GetPersonsTaxIdData(It.IsAny<string>()), Times.Once);
}
[Test]
public async Task GetUserIdByOrganizationNumber_Return()
{
var personTaxIdDataResponse = new List<PersonTaxIdDataResponse>()
{
new PersonTaxIdDataResponse()
{
PersonNumber = 1
},
new PersonTaxIdDataResponse()
{
PersonNumber = 2
}
};
_mockCoreApiWrapperDao.Setup(x => x.GetPersonsTaxIdData(It.IsAny<string>())).ReturnsAsync(personTaxIdDataResponse);
var response = await _coreApiWrapperService.GetPersonsTaxIdData("12");
Assert.IsNotNull(response);
Assert.AreEqual(2, response.ToList().Count);
_mockCoreApiWrapperDao.Verify(x => x.GetPersonsTaxIdData(It.IsAny<string>()), Times.Once);
}
[Test]
public void GetOrganizationsTaxIdData_Exception()
{
_mockCoreApiWrapperDao.Setup(x => x.GetOrganizationsTaxIdData(It.IsAny<string>()))
.ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _coreApiWrapperService.GetOrganizationsTaxIdData("12"));
_mockCoreApiWrapperDao.Verify(x => x.GetOrganizationsTaxIdData(It.IsAny<string>()), Times.Once);
}
[Test]
public async Task GetOrganizationsTaxIdData_Return()
{
var personTaxIdDataResponse = new List<OrganizationTaxIdDataResponse>()
{
new OrganizationTaxIdDataResponse()
{
OrganizationNumber = 1
},
new OrganizationTaxIdDataResponse()
{
OrganizationNumber = 2
}
};
_mockCoreApiWrapperDao.Setup(x => x.GetOrganizationsTaxIdData(It.IsAny<string>())).ReturnsAsync(personTaxIdDataResponse);
var response = await _coreApiWrapperService.GetOrganizationsTaxIdData("12");
Assert.IsNotNull(response);
Assert.AreEqual(2, response.ToList().Count);
_mockCoreApiWrapperDao.Verify(x => x.GetOrganizationsTaxIdData(It.IsAny<string>()), Times.Once);
}
[Test]
public async Task GetOwnersByAccountNumber_Return()
{
var accountOwnershipsResponse = new List<AccountOwnership>()
{
new AccountOwnership()
{
PersonNumber = 1
},
new AccountOwnership()
{
PersonNumber = 2
}
};
_mockCoreApiWrapperDao.Setup(x => x.GetOwnersByAccountNumber(It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(accountOwnershipsResponse);
var response = await _coreApiWrapperService.GetOwnersByAccountNumber("12", "01022022");
Assert.IsNotNull(response);
Assert.AreEqual(2, response.ToList().Count);
_mockCoreApiWrapperDao.Verify(x => x.GetOwnersByAccountNumber(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
}
[Test]
public void GetOwnersByAccountNumber_Exception()
{
_mockCoreApiWrapperDao.Setup(x => x.GetOwnersByAccountNumber(It.IsAny<string>(), It.IsAny<string>()))
.ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _coreApiWrapperService.GetOwnersByAccountNumber("12", "01022022"));
_mockCoreApiWrapperDao.Verify(x => x.GetOwnersByAccountNumber(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
}
[Test]
public async Task GetOwnersByPersonName_Return()
{
var accountOwnershipsResponse = new List<AccountOwnership>()
{
new AccountOwnership()
{
PersonNumber = 1
},
new AccountOwnership()
{
PersonNumber = 2
}
};
_mockCoreApiWrapperDao.Setup(x => x.GetOwnersByPersonName(It.IsAny<string>())).ReturnsAsync(accountOwnershipsResponse);
var response = await _coreApiWrapperService.GetOwnersByPersonName("Test Tester");
Assert.IsNotNull(response);
Assert.AreEqual(2, response.ToList().Count);
_mockCoreApiWrapperDao.Verify(x => x.GetOwnersByPersonName(It.IsAny<string>()), Times.Once);
}
[Test]
public void GetOwnersByPersonName_Exception()
{
_mockCoreApiWrapperDao.Setup(x => x.GetOwnersByPersonName(It.IsAny<string>()))
.ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _coreApiWrapperService.GetOwnersByPersonName("Test Tester"));
_mockCoreApiWrapperDao.Verify(x => x.GetOwnersByPersonName(It.IsAny<string>()), Times.Once);
}
[Test]
public async Task GetOwnersByOrganizationName_Return()
{
var accountOwnershipsResponse = new List<AccountOwnership>()
{
new AccountOwnership()
{
PersonNumber = 1
},
new AccountOwnership()
{
PersonNumber = 2
}
};
_mockCoreApiWrapperDao.Setup(x => x.GetOwnersByOrganizationName(It.IsAny<string>())).ReturnsAsync(accountOwnershipsResponse);
var response = await _coreApiWrapperService.GetOwnersByOrganizationName("Test Company");
Assert.IsNotNull(response);
Assert.AreEqual(2, response.ToList().Count);
_mockCoreApiWrapperDao.Verify(x => x.GetOwnersByOrganizationName(It.IsAny<string>()), Times.Once);
}
[Test]
public void GetOwnersByOrganization_Exception()
{
_mockCoreApiWrapperDao.Setup(x => x.GetOwnersByOrganizationName(It.IsAny<string>()))
.ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _coreApiWrapperService.GetOwnersByOrganizationName("Test Company"));
_mockCoreApiWrapperDao.Verify(x => x.GetOwnersByOrganizationName(It.IsAny<string>()), Times.Once);
}
[Test]
public async Task GetAgreeUsersByAccount_Return()
{
var returnAgreeUserAccounts = new List<AgreeUserAccount>
{
new AgreeUserAccount
{
UserId = "1"
}
};
_mockCoreApiWrapperDao.Setup(x => x.GetAgreeUsersByAccount(It.IsAny<string>())).ReturnsAsync(returnAgreeUserAccounts);
var response = await _coreApiWrapperService.GetAgreeUsersByAccount("11");
Assert.IsNotNull(response);
var firstAgreeUserAccount = response.FirstOrDefault();
Assert.IsNotNull(firstAgreeUserAccount);
Assert.AreEqual("1", firstAgreeUserAccount?.UserId);
_mockCoreApiWrapperDao.Verify(x => x.GetAgreeUsersByAccount(It.IsAny<string>()), Times.Once);
}
[Test]
public void GetAgreeUsersByAccount_Exception()
{
_mockCoreApiWrapperDao.Setup(x => x.GetAgreeUsersByAccount(It.IsAny<string>())).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _coreApiWrapperService.GetAgreeUsersByAccount("11"));
_mockCoreApiWrapperDao.Verify(x => x.GetAgreeUsersByAccount(It.IsAny<string>()), Times.Once);
}
[Test]
public async Task GetAgreeUsersByPersonNumber_Return()
{
var userIds = new List<string> { "1", "2" };
_mockCoreApiWrapperDao.Setup(x => x.GetAgreeUsersByPersonNumber(It.IsAny<string>())).ReturnsAsync(userIds);
var response = await _coreApiWrapperService.GetAgreeUsersByPersonNumber("11");
Assert.IsNotNull(response);
Assert.AreEqual(2, response.ToList().Count);
_mockCoreApiWrapperDao.Verify(x => x.GetAgreeUsersByPersonNumber(It.IsAny<string>()), Times.Once);
}
[Test]
public void GetAgreeUsersByPersonNumber_Exception()
{
_mockCoreApiWrapperDao.Setup(x => x.GetAgreeUsersByPersonNumber(It.IsAny<string>())).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _coreApiWrapperService.GetAgreeUsersByPersonNumber("11"));
_mockCoreApiWrapperDao.Verify(x => x.GetAgreeUsersByPersonNumber(It.IsAny<string>()), Times.Once);
}
[Test]
public async Task GetAgreeUserByOrganizationNumber_Return()
{
var userIds = "1";
_mockCoreApiWrapperDao.Setup(x => x.GetAgreeUserByOrganizationNumber(It.IsAny<string>())).ReturnsAsync(userIds);
var response = await _coreApiWrapperService.GetAgreeUserByOrganizationNumber("11");
Assert.IsNotNull(response);
Assert.AreEqual("1", response);
_mockCoreApiWrapperDao.Verify(x => x.GetAgreeUserByOrganizationNumber(It.IsAny<string>()), Times.Once);
}
[Test]
public void GetAgreeUserByOrganizationNumber_Exception()
{
_mockCoreApiWrapperDao.Setup(x => x.GetAgreeUserByOrganizationNumber(It.IsAny<string>())).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _coreApiWrapperService.GetAgreeUserByOrganizationNumber("11"));
_mockCoreApiWrapperDao.Verify(x => x.GetAgreeUserByOrganizationNumber(It.IsAny<string>()), Times.Once);
}
[Test]
public async Task GetAgreementAccountsByUserId_Return()
{
var agreementAccounts = new List<AgreementAccount>()
{
new ()
{
AccountNumber = 1,
AccountDescription = "test",
TaxReportForPersonNumber = 2
}
};
_mockCoreApiWrapperDao.Setup(x => x.GetAgreementAccountsByUserId(It.IsAny<string>())).ReturnsAsync(agreementAccounts);
var response = await _coreApiWrapperService.GetAgreementAccountsByUserId(It.IsAny<string>());
var result = response as List<AgreementAccount>;
var first = result.FirstOrDefault();
Assert.IsNotNull(response);
Assert.AreEqual(1, first?.AccountNumber);
Assert.AreEqual("test", first?.AccountDescription);
Assert.AreEqual(2, first?.TaxReportForPersonNumber);
_mockCoreApiWrapperDao.Verify(x => x.GetAgreementAccountsByUserId(It.IsAny<string>()), Times.Once);
}
[Test]
public void GetAgreementAccountsByUserId_Exception()
{
_mockCoreApiWrapperDao.Setup(x => x.GetAgreementAccountsByUserId(It.IsAny<string>())).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _coreApiWrapperService.GetAgreementAccountsByUserId("11"));
_mockCoreApiWrapperDao.Verify(x => x.GetAgreementAccountsByUserId(It.IsAny<string>()), Times.Once);
}
}
@@ -0,0 +1,106 @@
using LCU.API.Internal.DocumentIngestor.DataAccess;
using LCU.API.Internal.DocumentIngestor.Services.MicroApiServices;
using LCU.Library.DocumentType.Models.Requests;
using LCU.Library.Internal.DocumentIngestorModels.Entities;
using LCU.Library.Internal.Exceptions;
using Microsoft.Extensions.Caching.Memory;
using Moq;
using NUnit.Framework;
using System;
using System.Threading.Tasks;
namespace LCU.API.Internal.DocumentIngestorTests.Services.MicroApiServices;
public class DocumentTypeRetrieverApiServiceTest
{
private DocumentTypeRetrieverService _documentTypeRetrieverApiService;
private Mock<IDocumentTypeRetrieverDao> _mockDocumentTypeRetrieverDao;
[SetUp]
public void Setup()
{
_mockDocumentTypeRetrieverDao = new Mock<IDocumentTypeRetrieverDao>();
_documentTypeRetrieverApiService = new DocumentTypeRetrieverService(_mockDocumentTypeRetrieverDao.Object);
}
[Test]
public async Task GetDocumentCodeDetail_Success()
{
var documentCode = "LnNent";
_mockDocumentTypeRetrieverDao.Setup(x => x.GetDocumentCodeDetail(It.IsAny<string>()));
await _documentTypeRetrieverApiService.GetDocumentCodeDetail(documentCode);
_mockDocumentTypeRetrieverDao.Verify(x => x.GetDocumentCodeDetail(It.IsAny<string>()), Times.Once);
}
[Test]
public void GetDocumentCodeDetail_Exception()
{
var documentCode = "LnNent";
_mockDocumentTypeRetrieverDao.Setup(x => x.GetDocumentCodeDetail(It.IsAny<string>()))
.ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _documentTypeRetrieverApiService.GetDocumentCodeDetail(documentCode));
_mockDocumentTypeRetrieverDao.Verify(x => x.GetDocumentCodeDetail(It.IsAny<string>()), Times.Once);
}
[Test]
public async Task GetDocumentCodeDetails_Success()
{
_mockDocumentTypeRetrieverDao.Setup(x => x.GetDocumentCodeDetails());
await _documentTypeRetrieverApiService.GetDocumentCodeDetails();
_mockDocumentTypeRetrieverDao.Verify(x => x.GetDocumentCodeDetails(), Times.Once);
}
[Test]
public void GetDocumentCodeDetails_Exception()
{
_mockDocumentTypeRetrieverDao.Setup(x => x.GetDocumentCodeDetails())
.ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _documentTypeRetrieverApiService.GetDocumentCodeDetails());
_mockDocumentTypeRetrieverDao.Verify(x => x.GetDocumentCodeDetails(), Times.Once);
}
[Test]
public async Task GetDocumentCodeDetailsCache_Success()
{
_mockDocumentTypeRetrieverDao.Setup(x => x.GetDocumentCodeDetailsCache());
await _documentTypeRetrieverApiService.GetDocumentCodeDetailByDisplayName(It.IsAny<string>());
_mockDocumentTypeRetrieverDao.Verify(x => x.GetDocumentCodeDetailsCache(), Times.Once);
}
[Test]
public void GetDocumentCodeDetailsCache_Exception()
{
_mockDocumentTypeRetrieverDao.Setup(x => x.GetDocumentCodeDetailsCache())
.ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _documentTypeRetrieverApiService
.GetDocumentCodeDetailByDisplayName(It.IsAny<string>()));
_mockDocumentTypeRetrieverDao.Verify(x => x.GetDocumentCodeDetailsCache(), Times.Once);
}
[Test]
public async Task GetListOfMaliciousDocuments_Success()
{
var filter = new MaliciousDocumentSearchFilter();
_mockDocumentTypeRetrieverDao.Setup(x => x.GetListOfMaliciousDocuments(It.IsAny<MaliciousDocumentSearchFilter>()));
await _documentTypeRetrieverApiService.GetListOfMaliciousDocuments(filter);
_mockDocumentTypeRetrieverDao.Verify(x => x.GetListOfMaliciousDocuments(It.IsAny<MaliciousDocumentSearchFilter>()), Times.Once);
}
[Test]
public void GetListOfMaliciousDocuments_Exception()
{
var filter = new MaliciousDocumentSearchFilter();
_mockDocumentTypeRetrieverDao.Setup(x => x.GetListOfMaliciousDocuments(It.IsAny<MaliciousDocumentSearchFilter>()))
.ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _documentTypeRetrieverApiService.GetListOfMaliciousDocuments(filter));
_mockDocumentTypeRetrieverDao.Verify(x => x.GetListOfMaliciousDocuments(It.IsAny<MaliciousDocumentSearchFilter>()), Times.Once);
}
}
@@ -0,0 +1,116 @@
using System.Threading.Tasks;
using System;
using Moq;
using NUnit.Framework;
using LCU.Library.Internal.Exceptions;
using LCU.Library.DocumentType.Models.Requests.PrimaryOwner;
using LCU.Library.DocumentType.Models.Requests.Account;
using LCU.Library.Internal.LcuMassTransitModels;
using LCU.API.Internal.DocumentIngestor.Services.MicroApiServices;
using LCU.API.Internal.DocumentIngestor.DataAccess;
using LCU.API.Internal.DocumentIngestor.Configurations;
using LCU.Library.Internal.DocumentIngestorModels.Models;
using LCU.Library.DocumentType.Models.Requests.Attributes;
using LCU.Library.DocumentType.Models.Requests.Generic;
namespace LCU.API.Internal.DocumentIngestorTests.Services.MicroApiServices;
public class DocumentTypeUploaderApiServiceTest
{
private DocumentTypeUploaderApiService _documentTypeUploaderApiService;
private Mock<IDocumentTypeUploaderApiDao> _mockDocumentTypeUploaderApiDao;
[SetUp]
public void Setup()
{
var connectionConfiguration = new ConnectionConfiguration()
{
HostUrl = "Test",
UserName = "Test",
Password = "Test"
};
var receiveEndpointConfigurations = new ReceiveEndpointConfigurations()
{
UploadCompletionEndpoint = new ReceiveEndpointConfiguration()
{
ReceiveEndpoint = "Test",
ReceiveEndpointType = "Exchange",
PrefetchLimit = 1
}
};
_mockDocumentTypeUploaderApiDao = new Mock<IDocumentTypeUploaderApiDao>();
_documentTypeUploaderApiService = new DocumentTypeUploaderApiService(_mockDocumentTypeUploaderApiDao.Object,
connectionConfiguration,
receiveEndpointConfigurations);
}
[Test]
public void UploadPrimaryOwnerDocument_Exception()
{
_mockDocumentTypeUploaderApiDao.Setup(x => x.UploadPrimaryOwnerDocument(It.IsAny<PrimaryOwnerDocumentRequest>()))
.ThrowsAsync(new Exception("Error"));
var request = new PrimaryOwnerDocumentRequest
{
PrimaryOwnerAttribute = new PrimaryOwnerAttribute
{
PersonNumber = "1"
}
};
var processRequest = new ProcessingRequest();
var processResult = new ProcessResult();
Assert.ThrowsAsync<ServiceException>(async () => await _documentTypeUploaderApiService.UploadPrimaryOwnerDocument(request, processRequest, processResult));
_mockDocumentTypeUploaderApiDao.Verify(x => x.UploadPrimaryOwnerDocument(It.IsAny<PrimaryOwnerDocumentRequest>()), Times.Once);
}
[Test]
public void UploadAccountOwnerDocument_Exception()
{
_mockDocumentTypeUploaderApiDao.Setup(x => x.UploadAccountDocument(It.IsAny<AccountDocumentRequest>()))
.ThrowsAsync(new Exception("Error"));
var request = new AccountDocumentRequest
{
AccountAttribute = new AccountAttribute
{
AccountNumber = "1"
}
};
var processRequest = new ProcessingRequest();
var processResult = new ProcessResult();
Assert.ThrowsAsync<ServiceException>(async () => await _documentTypeUploaderApiService.UploadAccountDocument(request, processRequest, processResult));
_mockDocumentTypeUploaderApiDao.Verify(x => x.UploadAccountDocument(It.IsAny<AccountDocumentRequest>()), Times.Once);
}
[Test]
public void UploadGenericDocument_Exception()
{
_mockDocumentTypeUploaderApiDao.Setup(x => x.UploadGenericDocument(It.IsAny<GenericDocumentRequest>()))
.ThrowsAsync(new Exception("Error"));
var request = new GenericDocumentRequest();
var processRequest = new ProcessingRequest();
var processResult = new ProcessResult();
Assert.ThrowsAsync<ServiceException>(async () => await _documentTypeUploaderApiService.UploadGenericDocument(request, processRequest, processResult));
_mockDocumentTypeUploaderApiDao.Verify(x => x.UploadGenericDocument(It.IsAny<GenericDocumentRequest>()), Times.Once);
}
[Test]
public async Task GetUserIdByOrganizationNumber_Return()
{
_mockDocumentTypeUploaderApiDao.Setup(x => x.UploadPrimaryOwnerDocument(It.IsAny<PrimaryOwnerDocumentRequest>()));
var request = new PrimaryOwnerDocumentRequest
{
PrimaryOwnerAttribute = new PrimaryOwnerAttribute
{
PersonNumber = "1"
}
};
var processRequest = new ProcessingRequest();
var processResult = new ProcessResult();
await _documentTypeUploaderApiService.UploadPrimaryOwnerDocument(request, processRequest, processResult);
_mockDocumentTypeUploaderApiDao.Verify(x => x.UploadPrimaryOwnerDocument(It.IsAny<PrimaryOwnerDocumentRequest>()), Times.Once);
}
}
@@ -0,0 +1,358 @@
using System;
using System.Text;
using System.Threading.Tasks;
using Moq;
using NUnit.Framework;
using LCU.Library.Internal.LcuMassTransitModels;
using LCU.Library.Internal.DocumentIngestorModels.Models;
using LCU.Library.Internal.Exceptions;
using LCU.API.Internal.DocumentIngestor.Configurations;
using LCU.API.Internal.DocumentIngestor.Services.MicroApiServices;
using LCU.API.Internal.DocumentIngestor.DataAccess;
using LCU.Library.Internal.FileOperationsModels.Models;
namespace LCU.API.Internal.DocumentIngestorTests.Services.MicroApiServices;
public class FileOperationsApiServiceTest
{
private FileOperationsApiService _fileOperationsApiService;
private Mock<IFileOperationsApiDao> _mockFileOperationsApiDao;
[SetUp]
public void Setup()
{
_mockFileOperationsApiDao = new Mock<IFileOperationsApiDao>();
_fileOperationsApiService = new FileOperationsApiService(_mockFileOperationsApiDao.Object);
}
[Test]
public void DirectMoveFile_Exception()
{
_mockFileOperationsApiDao.Setup(x => x.DirectMoveFile(It.IsAny<MoveFileRequest>()))
.ThrowsAsync(new Exception("Error"));
var path = "\\path\\";
var file = "file.pdf";
var destination = "\\destination\\";
var completionRequest = new CompletionRequest();
Assert.ThrowsAsync<ServiceException>(async () => await _fileOperationsApiService.DirectMoveFile(path, file, destination));
_mockFileOperationsApiDao.Verify(x => x.DirectMoveFile(It.IsAny<MoveFileRequest>()), Times.Once);
}
[Test]
public async Task DirectMoveFile_Success()
{
_mockFileOperationsApiDao.Setup(x => x.DirectMoveFile(It.IsAny<MoveFileRequest>()));
var path = "\\path\\";
var file = "file.pdf";
var destination = "\\destination\\";
var completionRequest = new CompletionRequest();
await _fileOperationsApiService.DirectMoveFile(path, file, destination);
_mockFileOperationsApiDao.Verify(x => x.DirectMoveFile(It.IsAny<MoveFileRequest>()), Times.Once);
}
[Test]
public void DirectWriteFile_Exception()
{
_mockFileOperationsApiDao.Setup(x => x.DirectWriteFile(It.IsAny<WriteFileRequest>()))
.ThrowsAsync(new Exception("Error"));
var fileName = "file";
var extension = ".csv";
var fileData = "testFile";
var destination = "\\destination\\";
Assert.ThrowsAsync<ServiceException>(async () => await _fileOperationsApiService.DirectWriteFile(fileName, extension, fileData, destination));
_mockFileOperationsApiDao.Verify(x => x.DirectWriteFile(It.IsAny<WriteFileRequest>()), Times.Once);
}
[Test]
public async Task DirectWriteFile_Success()
{
_mockFileOperationsApiDao.Setup(x => x.DirectWriteFile(It.IsAny<WriteFileRequest>()));
var fileName = "file";
var extension = ".csv";
var fileData = "testFile";
var destination = "\\destination\\";
await _fileOperationsApiService.DirectWriteFile(fileName, extension, fileData, destination);
_mockFileOperationsApiDao.Verify(x => x.DirectWriteFile(It.IsAny<WriteFileRequest>()), Times.Once);
}
[Test]
public void DirectCreateDirectory_Exception()
{
_mockFileOperationsApiDao.Setup(x => x.DirectCreateDirectory(It.IsAny<CreateDirectoryRequest>()))
.ThrowsAsync(new Exception("Error"));
var directoryPath = "\\path\\";
var directoryName = "newFolder";
Assert.ThrowsAsync<ServiceException>(async () => await _fileOperationsApiService.DirectCreateDirectory(directoryPath, directoryName));
_mockFileOperationsApiDao.Verify(x => x.DirectCreateDirectory(It.IsAny<CreateDirectoryRequest>()), Times.Once);
}
[Test]
public async Task DirectCreateDirectory_Success()
{
_mockFileOperationsApiDao.Setup(x => x.DirectCreateDirectory(It.IsAny<CreateDirectoryRequest>()));
var directoryPath = "\\path\\";
var directoryName = "newFolder";
await _fileOperationsApiService.DirectCreateDirectory(directoryPath, directoryName);
_mockFileOperationsApiDao.Verify(x => x.DirectCreateDirectory(It.IsAny<CreateDirectoryRequest>()), Times.Once);
}
[Test]
public void DirectUnzipFile_Exception()
{
_mockFileOperationsApiDao.Setup(x => x.DirectUnzipFile(It.IsAny<UnzipFileRequest>()))
.ThrowsAsync(new Exception("Error"));
var sourceDirectory = "\\oldPath\\";
var destinationPath = "\\newPath\\";
var zipFileName = "newFolder";
Assert.ThrowsAsync<ServiceException>(async () => await _fileOperationsApiService.DirectUnzipFile(sourceDirectory, zipFileName, destinationPath, true));
_mockFileOperationsApiDao.Verify(x => x.DirectUnzipFile(It.IsAny<UnzipFileRequest>()), Times.Once);
}
[Test]
public async Task DirectUnzipFile_Success()
{
_mockFileOperationsApiDao.Setup(x => x.DirectUnzipFile(It.IsAny<UnzipFileRequest>()));
var sourceDirectory = "\\oldPath\\";
var destinationPath = "\\newPath\\";
var zipFileName = "newFolder";
await _fileOperationsApiService.DirectUnzipFile(sourceDirectory, zipFileName, destinationPath, true);
_mockFileOperationsApiDao.Verify(x => x.DirectUnzipFile(It.IsAny<UnzipFileRequest>()), Times.Once);
}
[Test]
public void DirectZipDirectory_Exception()
{
_mockFileOperationsApiDao.Setup(x => x.DirectZipDirectory(It.IsAny<ZipDirectoryRequest>()))
.ThrowsAsync(new Exception("Error"));
var sourceDirectory = "\\oldPath\\";
var zipPath = "\\newPath\\";
var zipFileName = "newFolder";
Assert.ThrowsAsync<ServiceException>(async () => await _fileOperationsApiService.DirectZipDirectory(sourceDirectory, zipPath, zipFileName));
_mockFileOperationsApiDao.Verify(x => x.DirectZipDirectory(It.IsAny<ZipDirectoryRequest>()), Times.Once);
}
[Test]
public async Task DirectZipDirectory_Success()
{
_mockFileOperationsApiDao.Setup(x => x.DirectZipDirectory(It.IsAny<ZipDirectoryRequest>()));
var sourceDirectory = "\\oldPath\\";
var zipPath = "\\newPath\\";
var zipFileName = "newFolder";
await _fileOperationsApiService.DirectZipDirectory(sourceDirectory, zipPath, zipFileName);
_mockFileOperationsApiDao.Verify(x => x.DirectZipDirectory(It.IsAny<ZipDirectoryRequest>()), Times.Once);
}
[Test]
public void DirectDeleteDirectory_Exception()
{
_mockFileOperationsApiDao.Setup(x => x.DirectDeleteDirectory(It.IsAny<DeleteDirectoryRequest>()))
.ThrowsAsync(new Exception("Error"));
var directoryName = "folder";
var directoryRootPath = "\\testPath\\";
var maxAmountOfDirectories = 1;
Assert.ThrowsAsync<ServiceException>(async () => await _fileOperationsApiService.DirectDeleteDirectory(directoryName, directoryRootPath, maxAmountOfDirectories));
_mockFileOperationsApiDao.Verify(x => x.DirectDeleteDirectory(It.IsAny<DeleteDirectoryRequest>()), Times.Once);
}
[Test]
public async Task DirectDeleteDirectory_Success()
{
_mockFileOperationsApiDao.Setup(x => x.DirectDeleteDirectory(It.IsAny<DeleteDirectoryRequest>()));
var directoryName = "folder";
var directoryRootPath = "\\testPath\\";
var maxAmountOfDirectories = 1;
await _fileOperationsApiService.DirectDeleteDirectory(directoryName, directoryRootPath, maxAmountOfDirectories);
_mockFileOperationsApiDao.Verify(x => x.DirectDeleteDirectory(It.IsAny<DeleteDirectoryRequest>()), Times.Once);
}
[Test]
public void GetFileContent_Exception()
{
_mockFileOperationsApiDao.Setup(x => x.GetFileContent(It.IsAny<string>()))
.ThrowsAsync(new Exception("Error"));
var filePath = "\\path\\file.pdf";
Assert.ThrowsAsync<ServiceException>(async () =>
await _fileOperationsApiService.GetFileContent(filePath));
_mockFileOperationsApiDao.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Once);
}
[Test]
public async Task GetFileContent_Success()
{
var content = "test, test, test";
_mockFileOperationsApiDao.Setup(x => x.GetFileContent(It.IsAny<string>())).ReturnsAsync(content);
var filePath = "\\path\\file.pdf";
var result = await _fileOperationsApiService.GetFileContent(filePath);
Assert.AreEqual(content, result);
_mockFileOperationsApiDao.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Once);
}
[Test]
public void GetContentBytes_Exception()
{
_mockFileOperationsApiDao.Setup(x => x.GetPdfByteContent(It.IsAny<string>()))
.ThrowsAsync(new Exception("Error"));
var documentPath = "\\path\\";
var documentFileName = "file.pdf";
Assert.ThrowsAsync<ServiceException>(async () =>
await _fileOperationsApiService.GetContentBytes(documentPath, documentFileName));
_mockFileOperationsApiDao.Verify(x => x.GetPdfByteContent(It.IsAny<string>()), Times.Once);
}
[Test]
public async Task GetContentBytes_Success()
{
var content = "test, test, test";
var contentBytes = Encoding.ASCII.GetBytes(content);
_mockFileOperationsApiDao.Setup(x => x.GetPdfByteContent(It.IsAny<string>())).ReturnsAsync(contentBytes);
var documentPath = "\\path\\";
var documentFileName = "file.pdf";
var result = await _fileOperationsApiService.GetContentBytes(documentPath, documentFileName);
Assert.AreEqual(contentBytes, result);
_mockFileOperationsApiDao.Verify(x => x.GetPdfByteContent(It.IsAny<string>()), Times.Once);
}
[Test]
public void ValidateFileExists_Exception()
{
_mockFileOperationsApiDao.Setup(x => x.ValidateFileExists(It.IsAny<string>()))
.ThrowsAsync(new Exception("Error"));
var filePath = "\\path\\file.pdf";
Assert.ThrowsAsync<ServiceException>(async () =>
await _fileOperationsApiService.ValidateFileExists(filePath));
_mockFileOperationsApiDao.Verify(x => x.ValidateFileExists(It.IsAny<string>()), Times.Once);
}
[Test]
public async Task ValidateFileExists_Success()
{
_mockFileOperationsApiDao.Setup(x => x.ValidateFileExists(It.IsAny<string>())).ReturnsAsync(true);
var filePath = "\\path\\file.pdf";
var result = await _fileOperationsApiService.ValidateFileExists(filePath);
Assert.IsTrue(result);
_mockFileOperationsApiDao.Verify(x => x.ValidateFileExists(It.IsAny<string>()), Times.Once);
}
[Test]
public void ValidateFileExistsAndNotArchived_ValidateFileExists_FilePath_Exception()
{
var filePath = "\\path\\file.pdf";
var archiveFilePath = "\\path\\archive\\file.pdf";
_mockFileOperationsApiDao.Setup(x => x.ValidateFileExists(filePath))
.ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () =>
await _fileOperationsApiService.ValidateFileExistsAndNotArchived(filePath, archiveFilePath));
_mockFileOperationsApiDao.Verify(x => x.ValidateFileExists(It.IsAny<string>()), Times.Once);
}
[Test]
public void ValidateFileExistsAndNotArchived_ValidateFileExists_ArchiveFilePath_Exception()
{
var filePath = "\\path\\file.pdf";
var archiveFilePath = "\\path\\archive\\file.pdf";
_mockFileOperationsApiDao.Setup(x => x.ValidateFileExists(filePath)).ReturnsAsync(false);
_mockFileOperationsApiDao.Setup(x => x.ValidateFileExists(archiveFilePath))
.ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () =>
await _fileOperationsApiService.ValidateFileExistsAndNotArchived(filePath, archiveFilePath));
_mockFileOperationsApiDao.Verify(x => x.ValidateFileExists(It.IsAny<string>()), Times.Exactly(2));
}
[Test]
public async Task ValidateFileExistsAndNotArchived_True()
{
var filePath = "\\path\\file.pdf";
var archiveFilePath = "\\path\\archive\\file.pdf";
_mockFileOperationsApiDao.Setup(x => x.ValidateFileExists(filePath)).ReturnsAsync(true);
var result = await _fileOperationsApiService.ValidateFileExistsAndNotArchived(filePath, archiveFilePath);
Assert.IsTrue(result);
_mockFileOperationsApiDao.Verify(x => x.ValidateFileExists(It.IsAny<string>()), Times.Once);
}
[Test]
public async Task ValidateFileExistsAndNotArchived_False()
{
var filePath = "\\path\\file.pdf";
var archiveFilePath = "\\path\\archive\\file.pdf";
_mockFileOperationsApiDao.Setup(x => x.ValidateFileExists(filePath)).ReturnsAsync(false);
_mockFileOperationsApiDao.Setup(x => x.ValidateFileExists(archiveFilePath)).ReturnsAsync(true);
var result = await _fileOperationsApiService.ValidateFileExistsAndNotArchived(filePath, archiveFilePath);
Assert.IsFalse(result);
_mockFileOperationsApiDao.Verify(x => x.ValidateFileExists(It.IsAny<string>()), Times.Exactly(2));
}
[Test]
public async Task ValidatePdfPageExists_Success()
{
var requestResponse = new RequestResponse()
{
IsSuccessful = true
};
_mockFileOperationsApiDao.Setup(x => x.ValidatePdfPageExists(It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(requestResponse);
var filePath = "\\path\\file.pdf";
var result = await _fileOperationsApiService.ValidatePdfPageExists(filePath, "5");
_mockFileOperationsApiDao.Verify(x => x.ValidatePdfPageExists(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
}
[Test]
public void ValidatePdfPageExists_Exception()
{
_mockFileOperationsApiDao.Setup(x => x.ValidatePdfPageExists(It.IsAny<string>(), It.IsAny<string>()))
.ThrowsAsync(new Exception("Error"));
var filePath = "\\path\\file.pdf";
Assert.ThrowsAsync<ServiceException>(async () =>
await _fileOperationsApiService.ValidatePdfPageExists(filePath, "5"));
_mockFileOperationsApiDao.Verify(x => x.ValidatePdfPageExists(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
}
[Test]
public async Task QueueBatchPdfParser_Success()
{
_mockFileOperationsApiDao.Setup(x => x.QueueBatchPdfParser(It.IsAny<BatchParsePdfRequest>()));
var batchParsePdfRequest = new BatchParsePdfRequest();
await _fileOperationsApiService.QueueBatchPdfParser(batchParsePdfRequest);
_mockFileOperationsApiDao.Verify(x => x.QueueBatchPdfParser(It.IsAny<BatchParsePdfRequest>()), Times.Once);
}
[Test]
public void QueueBatchPdfParser_Exception()
{
_mockFileOperationsApiDao.Setup(x => x.QueueBatchPdfParser(It.IsAny<BatchParsePdfRequest>()))
.ThrowsAsync(new Exception("Error"));
var batchParsePdfRequest = new BatchParsePdfRequest();
Assert.ThrowsAsync<ServiceException>(async () => await _fileOperationsApiService.QueueBatchPdfParser(batchParsePdfRequest));
_mockFileOperationsApiDao.Verify(x => x.QueueBatchPdfParser(It.IsAny<BatchParsePdfRequest>()), Times.Once);
}
}
@@ -0,0 +1,103 @@
using System;
using System.Threading.Tasks;
using Moq;
using NUnit.Framework;
using LCU.Library.Internal.Exceptions;
using LCU.API.Internal.DocumentIngestor.Services.MicroApiServices;
using LCU.API.Internal.DocumentIngestor.DataAccess;
using LCU.API.Internal.DocumentIngestor.Models.MemberPreferencesDtos;
namespace LCU.API.Internal.DocumentIngestorTests.Services.MicroApiServices;
public class MemberPreferencesApiServiceTest
{
private MemberPreferencesApiService _memberPreferencesApiService;
private Mock<IMemberPreferencesApiDao> _mockMemberPreferencesApiDao;
[SetUp]
public void Setup()
{
_mockMemberPreferencesApiDao = new Mock<IMemberPreferencesApiDao>();
_memberPreferencesApiService = new MemberPreferencesApiService(_mockMemberPreferencesApiDao.Object);
}
[Test]
public async Task GetMemberOptInAgreementInfoByUserId_Return()
{
var memberOptInAgreementInformation = new MemberOptInAgreementInformation();
_mockMemberPreferencesApiDao.Setup(x => x.GetMemberOptInAgreementInfoByUserId(It.IsAny<string>())).ReturnsAsync(memberOptInAgreementInformation);
var response = await _memberPreferencesApiService.GetMemberOptInAgreementInfoByUserId("11");
Assert.IsNotNull(response);
_mockMemberPreferencesApiDao.Verify(x => x.GetMemberOptInAgreementInfoByUserId(It.IsAny<string>()), Times.Once);
}
[Test]
public void GetMemberOptInAgreementInfoByUserId_Exception()
{
_mockMemberPreferencesApiDao.Setup(x => x.GetMemberOptInAgreementInfoByUserId(It.IsAny<string>())).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _memberPreferencesApiService.GetMemberOptInAgreementInfoByUserId("11"));
_mockMemberPreferencesApiDao.Verify(x => x.GetMemberOptInAgreementInfoByUserId(It.IsAny<string>()), Times.Once);
}
[Test]
public async Task GetMemberOptInSettingsByUserId_Return()
{
var memberOptInSettings = new MemberOptInInformation();
_mockMemberPreferencesApiDao.Setup(x => x.GetMemberOptInSettingsByUserId(It.IsAny<string>())).ReturnsAsync(memberOptInSettings);
var response = await _memberPreferencesApiService.GetMemberOptInSettingsByUserId("11");
Assert.IsNotNull(response);
_mockMemberPreferencesApiDao.Verify(x => x.GetMemberOptInSettingsByUserId(It.IsAny<string>()), Times.Once);
}
[Test]
public void GetMemberOptInSettingsByUserId_Exception()
{
_mockMemberPreferencesApiDao.Setup(x => x.GetMemberOptInSettingsByUserId(It.IsAny<string>())).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _memberPreferencesApiService.GetMemberOptInSettingsByUserId("11"));
_mockMemberPreferencesApiDao.Verify(x => x.GetMemberOptInSettingsByUserId(It.IsAny<string>()), Times.Once);
}
[Test]
public async Task EmailSuccessfulSend_Return()
{
var memberOptInSettings = new MemberOptInInformation();
_mockMemberPreferencesApiDao.Setup(x => x.EmailSuccessfulSend(It.IsAny<string>(), It.IsAny<string>()));
await _memberPreferencesApiService.EmailStatusSend("11", "[email protected]", true);
_mockMemberPreferencesApiDao.Verify(x => x.EmailSuccessfulSend(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
_mockMemberPreferencesApiDao.Verify(x => x.EmailFailureSend(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
}
[Test]
public void EmailSuccessfulSend_Exception()
{
_mockMemberPreferencesApiDao.Setup(x => x.EmailSuccessfulSend(It.IsAny<string>(), It.IsAny<string>())).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _memberPreferencesApiService.EmailStatusSend("11", "[email protected]", true));
_mockMemberPreferencesApiDao.Verify(x => x.EmailSuccessfulSend(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
_mockMemberPreferencesApiDao.Verify(x => x.EmailFailureSend(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
}
[Test]
public async Task EmailFailureSend_Return()
{
_mockMemberPreferencesApiDao.Setup(x => x.EmailFailureSend(It.IsAny<string>(), It.IsAny<string>()));
await _memberPreferencesApiService.EmailStatusSend("11", "[email protected]", false);
_mockMemberPreferencesApiDao.Verify(x => x.EmailFailureSend(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
_mockMemberPreferencesApiDao.Verify(x => x.EmailSuccessfulSend(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
}
[Test]
public void EmailFailureSend_Exception()
{
_mockMemberPreferencesApiDao.Setup(x => x.EmailFailureSend(It.IsAny<string>(), It.IsAny<string>())).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _memberPreferencesApiService.EmailStatusSend("11", "[email protected]", false));
_mockMemberPreferencesApiDao.Verify(x => x.EmailFailureSend(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
_mockMemberPreferencesApiDao.Verify(x => x.EmailSuccessfulSend(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
}
}
@@ -0,0 +1,57 @@
using LCU.API.Internal.DocumentIngestor.DataAccess;
using LCU.API.Internal.DocumentIngestor.Services.MicroApiServices;
using LCU.Library.Internal.Exceptions;
using LCU.Library.Internal.NotificationsModels.Models;
using Moq;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace LCU.API.Internal.DocumentIngestorTests.Services.MicroApiServices;
public class NotificationApiServiceTest
{
private NotificationApiService _notificationApiService;
private Mock<INotificationApiDao> _mockNotificationApiDao;
[SetUp]
public void Setup()
{
_mockNotificationApiDao = new Mock<INotificationApiDao>();
_notificationApiService = new NotificationApiService(_mockNotificationApiDao.Object);
}
[Test]
public void SendEmailAsync_Exception()
{
_mockNotificationApiDao.Setup(x => x.SendEmailAsync(It.IsAny<EmailRequest>()))
.ThrowsAsync(new Exception("Error"));
var request = new EmailRequest()
{
Subject = "",
Body = "",
Recipient = new List<string>(new string[] { "" })
};
Assert.ThrowsAsync<ServiceException>(async () => await _notificationApiService.SendEmailAsync(request));
_mockNotificationApiDao.Verify(x => x.SendEmailAsync(It.IsAny<EmailRequest>()), Times.Once);
}
[Test]
public async Task SendEmailAsync_Return()
{
_mockNotificationApiDao.Setup(x => x.SendEmailAsync(It.IsAny<EmailRequest>()));
var request = new EmailRequest()
{
Subject = "",
Body = "",
Recipient = new List<string>(new string[] { "" })
};
await _notificationApiService.SendEmailAsync(request);
_mockNotificationApiDao.Verify(x => x.SendEmailAsync(It.IsAny<EmailRequest>()), Times.Once);
}
}
@@ -0,0 +1,366 @@
using LCU.API.Internal.DocumentIngestor.Services;
using LCU.API.Internal.DocumentIngestorLib.Repositories;
using LCU.Library.Internal.DocumentIngestorModels.Entities;
using LCU.Library.Internal.Exceptions;
using Moq;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace LCU.API.Internal.DocumentIngestorTests.Services;
public class OsgPreprocessorInfoServiceTest
{
private OsgPreprocessorInfoService _osgPreprocessorInfoService;
private Mock<IUnitOfWork> _unitOfWork;
private Mock<IOsgPreprocessorInfoRepository> _mockOsgPreprocessorInfoRepository;
[SetUp]
public void Setup()
{
_unitOfWork = new Mock<IUnitOfWork>();
_mockOsgPreprocessorInfoRepository = new Mock<IOsgPreprocessorInfoRepository>();
_osgPreprocessorInfoService = new OsgPreprocessorInfoService(_unitOfWork.Object,
_mockOsgPreprocessorInfoRepository.Object);
}
[Test]
public async Task GetAsync_OsgPreprocessorInfos_Returned()
{
var osgPreprocessorInfoId = 10;
var documentType = "Statement";
var osgPreprocessorInfos = new List<OsgPreprocessorInfo>()
{
new OsgPreprocessorInfo()
{
OsgPreprocessorInfoId = osgPreprocessorInfoId,
DocumentType = documentType,
CreatedDate = Convert.ToDateTime("1/1/2022")
}
};
_mockOsgPreprocessorInfoRepository.Setup(x => x.FindAsync()).ReturnsAsync(osgPreprocessorInfos);
var result = await _osgPreprocessorInfoService.GetAsync();
Assert.IsNotNull(result);
Assert.AreEqual(1, result.Count());
_mockOsgPreprocessorInfoRepository.Verify(x => x.FindAsync(), Times.Once);
}
[Test]
public void GetAsync_Exception()
{
_mockOsgPreprocessorInfoRepository.Setup(x => x.FindAsync()).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _osgPreprocessorInfoService.GetAsync());
_mockOsgPreprocessorInfoRepository.Verify(x => x.FindAsync(), Times.Once);
}
[Test]
public async Task GetByIdAsync_OsgPreprocessorInfo_Returned()
{
var osgPreprocessorInfoId = 10;
var documentType = "Statement";
var osgPreprocessorInfo = new OsgPreprocessorInfo()
{
OsgPreprocessorInfoId = osgPreprocessorInfoId,
DocumentType = documentType,
CreatedDate = Convert.ToDateTime("1/1/2022")
};
_mockOsgPreprocessorInfoRepository.Setup(x => x.FindByIdAsync(osgPreprocessorInfoId)).ReturnsAsync(osgPreprocessorInfo);
var result = await _osgPreprocessorInfoService.GetByIdAsync(osgPreprocessorInfoId);
Assert.IsNotNull(result);
Assert.AreEqual(osgPreprocessorInfoId, result.OsgPreprocessorInfoId);
Assert.AreEqual(documentType, result.DocumentType);
_mockOsgPreprocessorInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>()), Times.Once);
}
[Test]
public void GetByIdAsync_Exception()
{
var id = 1;
_mockOsgPreprocessorInfoRepository.Setup(x => x.FindByIdAsync(id)).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _osgPreprocessorInfoService.GetByIdAsync(id));
_mockOsgPreprocessorInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>()), Times.Once);
}
[Test]
public async Task GetByDocumentTypeAsync_OsgPreprocessorInfos_Returned()
{
var osgPreprocessorInfoId = 10;
var documentType = "Statement";
var entityName = "John Smith";
var osgPreprocessorInfos = new List<OsgPreprocessorInfo>()
{
new OsgPreprocessorInfo()
{
OsgPreprocessorInfoId = osgPreprocessorInfoId,
DocumentType = documentType,
EntityName = entityName,
CreatedDate = Convert.ToDateTime("1/1/2022")
}
};
_mockOsgPreprocessorInfoRepository.Setup(x => x.FindByDocumentType(documentType)).ReturnsAsync(osgPreprocessorInfos);
var result = await _osgPreprocessorInfoService.GetByDocumentTypeAsync(documentType);
Assert.IsNotNull(result);
Assert.AreEqual(1, result.Count());
_mockOsgPreprocessorInfoRepository.Verify(x => x.FindByDocumentType(It.IsAny<string>()), Times.Once);
}
[Test]
public void GetByDocumentTypeAsync_Exception()
{
var documentType = "Statement";
_mockOsgPreprocessorInfoRepository.Setup(x => x.FindByDocumentType(documentType)).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _osgPreprocessorInfoService.GetByDocumentTypeAsync(documentType));
_mockOsgPreprocessorInfoRepository.Verify(x => x.FindByDocumentType(It.IsAny<string>()), Times.Once);
}
[Test]
public async Task GetByMemberNumberAsync_OsgPreprocessorInfos_Returned()
{
var osgPreprocessorInfoId = 10;
var documentType = "Statement";
var memberNumber = "123";
var osgPreprocessorInfos = new List<OsgPreprocessorInfo>()
{
new OsgPreprocessorInfo()
{
OsgPreprocessorInfoId = osgPreprocessorInfoId,
DocumentType = documentType,
MemberNumber = memberNumber,
CreatedDate = Convert.ToDateTime("1/1/2022")
}
};
_mockOsgPreprocessorInfoRepository.Setup(x => x.FindByMemberNumber(memberNumber)).ReturnsAsync(osgPreprocessorInfos);
var result = await _osgPreprocessorInfoService.GetByMemberNumberAsync(memberNumber);
Assert.IsNotNull(result);
Assert.AreEqual(1, result.Count());
_mockOsgPreprocessorInfoRepository.Verify(x => x.FindByMemberNumber(It.IsAny<string>()), Times.Once);
}
[Test]
public void GetByMemberNumberAsync_Exception()
{
var memberNumber = "123";
_mockOsgPreprocessorInfoRepository.Setup(x => x.FindByMemberNumber(memberNumber)).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _osgPreprocessorInfoService.GetByMemberNumberAsync(memberNumber));
_mockOsgPreprocessorInfoRepository.Verify(x => x.FindByMemberNumber(It.IsAny<string>()), Times.Once);
}
[Test]
public async Task SaveAsync_OsgPreprocessorInfo_Returned()
{
var osgPreprocessorInfoId = 10;
var documentType = "Statement";
var osgPreprocessorInfo = new OsgPreprocessorInfo()
{
OsgPreprocessorInfoId = osgPreprocessorInfoId,
DocumentType = documentType,
CreatedDate = Convert.ToDateTime("1/1/2022")
};
_mockOsgPreprocessorInfoRepository.Setup(x => x.AddAsync(osgPreprocessorInfo)).ReturnsAsync(osgPreprocessorInfo);
var result = await _osgPreprocessorInfoService.SaveAsync(osgPreprocessorInfo);
Assert.IsNotNull(result);
Assert.AreEqual(osgPreprocessorInfoId, result.OsgPreprocessorInfoId);
Assert.AreEqual(documentType, result.DocumentType);
_mockOsgPreprocessorInfoRepository.Verify(x => x.AddAsync(It.IsAny<OsgPreprocessorInfo>()), Times.Once);
}
[Test]
public void SaveAsync_Exception()
{
var osgPreprocessorInfoId = 10;
var documentType = "Statement";
var osgPreprocessorInfo = new OsgPreprocessorInfo()
{
OsgPreprocessorInfoId = osgPreprocessorInfoId,
DocumentType = documentType,
CreatedDate = Convert.ToDateTime("1/1/2022")
};
_mockOsgPreprocessorInfoRepository.Setup(x => x.AddAsync(osgPreprocessorInfo)).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _osgPreprocessorInfoService.SaveAsync(osgPreprocessorInfo));
_mockOsgPreprocessorInfoRepository.Verify(x => x.AddAsync(It.IsAny<OsgPreprocessorInfo>()), Times.Once);
}
[Test]
public async Task Update_OsgPreprocessorInfo_Returned()
{
var osgPreprocessorInfoId = 10;
var documentType = "Statement";
var osgPreprocessorInfo = new OsgPreprocessorInfo()
{
OsgPreprocessorInfoId = osgPreprocessorInfoId,
DocumentType = documentType,
CreatedDate = Convert.ToDateTime("1/1/2022")
};
_mockOsgPreprocessorInfoRepository.Setup(x => x.FindByIdAsync(osgPreprocessorInfoId)).ReturnsAsync(osgPreprocessorInfo);
_mockOsgPreprocessorInfoRepository.Setup(x => x.Update(osgPreprocessorInfo));
var result = await _osgPreprocessorInfoService.Update(osgPreprocessorInfo);
Assert.IsNotNull(result);
Assert.AreEqual(documentType, result.DocumentType);
Assert.AreEqual(osgPreprocessorInfoId, result.OsgPreprocessorInfoId);
_mockOsgPreprocessorInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>()), Times.Once);
_mockOsgPreprocessorInfoRepository.Verify(x => x.Update(It.IsAny<OsgPreprocessorInfo>()), Times.Once);
}
[Test]
public void Update_FindByIdAsync_ThrowsException()
{
var osgPreprocessorInfoId = 10;
var documentType = "Statement";
var osgPreprocessorInfo = new OsgPreprocessorInfo()
{
OsgPreprocessorInfoId = osgPreprocessorInfoId,
DocumentType = documentType,
CreatedDate = Convert.ToDateTime("1/1/2022")
};
_mockOsgPreprocessorInfoRepository.Setup(x => x.FindByIdAsync(osgPreprocessorInfoId)).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _osgPreprocessorInfoService.Update(osgPreprocessorInfo));
_mockOsgPreprocessorInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>()), Times.Once);
_mockOsgPreprocessorInfoRepository.Verify(x => x.Update(It.IsAny<OsgPreprocessorInfo>()), Times.Never);
}
[Test]
public void Update_Update_ThrowsException()
{
var osgPreprocessorInfoId = 10;
var documentType = "Statement";
var osgPreprocessorInfo = new OsgPreprocessorInfo()
{
OsgPreprocessorInfoId = osgPreprocessorInfoId,
DocumentType = documentType,
CreatedDate = Convert.ToDateTime("1/1/2022")
};
_mockOsgPreprocessorInfoRepository.Setup(x => x.FindByIdAsync(osgPreprocessorInfoId)).ReturnsAsync(osgPreprocessorInfo);
_mockOsgPreprocessorInfoRepository.Setup(x => x.Update(osgPreprocessorInfo)).Throws(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _osgPreprocessorInfoService.Update(osgPreprocessorInfo));
_mockOsgPreprocessorInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>()), Times.Once);
_mockOsgPreprocessorInfoRepository.Verify(x => x.Update(It.IsAny<OsgPreprocessorInfo>()), Times.Once);
}
[Test]
public async Task UpdateRange_OsgPreprocessorInfo_Returned()
{
var osgPreprocessorInfoId = 10;
var documentType = "Statement";
var entityName = "John Smith";
var osgPreprocessorInfos = new List<OsgPreprocessorInfo>()
{
new OsgPreprocessorInfo()
{
OsgPreprocessorInfoId = osgPreprocessorInfoId,
DocumentType = documentType,
EntityName = entityName,
CreatedDate = Convert.ToDateTime("1/1/2022")
}
};
_mockOsgPreprocessorInfoRepository.Setup(x => x.FindByIdAsync(osgPreprocessorInfoId)).ReturnsAsync(osgPreprocessorInfos[0]);
_mockOsgPreprocessorInfoRepository.Setup(x => x.UpdateRange(osgPreprocessorInfos));
var result = await _osgPreprocessorInfoService.UpdateRange(osgPreprocessorInfos);
Assert.IsNotNull(result);
Assert.AreEqual(documentType, result.FirstOrDefault()?.DocumentType);
Assert.AreEqual(osgPreprocessorInfoId, result.FirstOrDefault()?.OsgPreprocessorInfoId);
_mockOsgPreprocessorInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>()), Times.Once);
_mockOsgPreprocessorInfoRepository.Verify(x => x.UpdateRange(It.IsAny<IEnumerable<OsgPreprocessorInfo>>()), Times.Once);
}
[Test]
public void UpdateRange_FindByIdAsync_ThrowsException()
{
var osgPreprocessorInfoId = 10;
var documentType = "Statement";
var entityName = "John Smith";
var osgPreprocessorInfos = new List<OsgPreprocessorInfo>()
{
new OsgPreprocessorInfo()
{
OsgPreprocessorInfoId = osgPreprocessorInfoId,
DocumentType = documentType,
EntityName = entityName,
CreatedDate = Convert.ToDateTime("1/1/2022")
}
};
_mockOsgPreprocessorInfoRepository.Setup(x => x.FindByIdAsync(osgPreprocessorInfoId)).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _osgPreprocessorInfoService.UpdateRange(osgPreprocessorInfos));
_mockOsgPreprocessorInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>()), Times.Once);
_mockOsgPreprocessorInfoRepository.Verify(x => x.UpdateRange(It.IsAny<IEnumerable<OsgPreprocessorInfo>>()), Times.Never);
}
[Test]
public void UpdateRange_Update_ThrowsException()
{
var osgPreprocessorInfoId = 10;
var documentType = "Statement";
var entityName = "John Smith";
var osgPreprocessorInfos = new List<OsgPreprocessorInfo>()
{
new OsgPreprocessorInfo()
{
OsgPreprocessorInfoId = osgPreprocessorInfoId,
DocumentType = documentType,
EntityName = entityName,
CreatedDate = Convert.ToDateTime("1/1/2022")
}
};
_mockOsgPreprocessorInfoRepository.Setup(x => x.FindByIdAsync(osgPreprocessorInfoId)).ReturnsAsync(osgPreprocessorInfos[0]);
_mockOsgPreprocessorInfoRepository.Setup(x => x.UpdateRange(osgPreprocessorInfos)).Throws(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _osgPreprocessorInfoService.UpdateRange(osgPreprocessorInfos));
_mockOsgPreprocessorInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>()), Times.Once);
_mockOsgPreprocessorInfoRepository.Verify(x => x.UpdateRange(It.IsAny<IEnumerable<OsgPreprocessorInfo>>()), Times.Once);
}
[Test]
public async Task Delete_Success()
{
var osgPreprocessorInfoId = 10;
var documentType = "Statement";
var osgPreprocessorInfo = new OsgPreprocessorInfo()
{
OsgPreprocessorInfoId = osgPreprocessorInfoId,
DocumentType = documentType,
CreatedDate = Convert.ToDateTime("1/1/2022")
};
_mockOsgPreprocessorInfoRepository.Setup(x => x.FindByIdAsync(osgPreprocessorInfoId)).ReturnsAsync(osgPreprocessorInfo);
_mockOsgPreprocessorInfoRepository.Setup(x => x.Remove(osgPreprocessorInfo));
await _osgPreprocessorInfoService.Delete(osgPreprocessorInfoId);
_mockOsgPreprocessorInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>()), Times.Once);
_mockOsgPreprocessorInfoRepository.Verify(x => x.Remove(It.IsAny<OsgPreprocessorInfo>()), Times.Once);
}
[Test]
public void Delete_FindByIdAsync_ThrowsException()
{
var id = 1;
_mockOsgPreprocessorInfoRepository.Setup(x => x.FindByIdAsync(id)).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _osgPreprocessorInfoService.Delete(id));
_mockOsgPreprocessorInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>()), Times.Once);
_mockOsgPreprocessorInfoRepository.Verify(x => x.Remove(It.IsAny<OsgPreprocessorInfo>()), Times.Never);
}
[Test]
public void Delete_Remove_ThrowsException()
{
var osgPreprocessorInfoId = 10;
var documentType = "Statement";
var osgPreprocessorInfo = new OsgPreprocessorInfo()
{
OsgPreprocessorInfoId = osgPreprocessorInfoId,
DocumentType = documentType,
CreatedDate = Convert.ToDateTime("1/1/2022")
};
_mockOsgPreprocessorInfoRepository.Setup(x => x.FindByIdAsync(osgPreprocessorInfoId)).ReturnsAsync(osgPreprocessorInfo);
_mockOsgPreprocessorInfoRepository.Setup(x => x.Remove(osgPreprocessorInfo)).Throws(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _osgPreprocessorInfoService.Delete(osgPreprocessorInfoId));
_mockOsgPreprocessorInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>()), Times.Once);
_mockOsgPreprocessorInfoRepository.Verify(x => x.Remove(It.IsAny<OsgPreprocessorInfo>()), Times.Once);
}
}
@@ -0,0 +1,197 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Linq;
using Moq;
using NUnit.Framework;
using LCU.Library.Internal.DocumentIngestorModels.Entities;
using LCU.Library.Internal.Exceptions;
using LCU.API.Internal.DocumentIngestor.Services;
using LCU.API.Internal.DocumentIngestorLib.Repositories;
namespace LCU.API.Internal.DocumentIngestorTests.Services;
public class OwnerOverrideInfoServiceTest
{
private OwnerOverrideInfoService _ownerOverrideInfoService;
private Mock<IUnitOfWork> _unitOfWork;
private Mock<IOwnerOverrideInfoRepository> _mockOwnerOverrideInfoRepository;
private Mock<IProcessingLogService> _mockProcessingLogService;
[SetUp]
public void Setup()
{
_unitOfWork = new Mock<IUnitOfWork>();
_mockOwnerOverrideInfoRepository = new Mock<IOwnerOverrideInfoRepository>();
_mockProcessingLogService = new Mock<IProcessingLogService>();
_ownerOverrideInfoService = new OwnerOverrideInfoService(_unitOfWork.Object, _mockOwnerOverrideInfoRepository.Object);
}
[Test]
public async Task GetAsync_OwnerOverrideInfos_Returned()
{
var id = 1;
var ownerOverrideInfos = new List<OwnerOverrideInfo>()
{
new OwnerOverrideInfo()
{
OwnerOverrideInfoId = id
}
};
_mockOwnerOverrideInfoRepository.Setup(x => x.FindAsync()).ReturnsAsync(ownerOverrideInfos);
var result = await _ownerOverrideInfoService.GetAsync();
Assert.IsNotNull(result);
Assert.AreEqual(1, result.Count());
_mockOwnerOverrideInfoRepository.Verify(x => x.FindAsync(), Times.Once);
}
[Test]
public void GetAsync_Exception()
{
_mockOwnerOverrideInfoRepository.Setup(x => x.FindAsync()).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _ownerOverrideInfoService.GetAsync());
_mockOwnerOverrideInfoRepository.Verify(x => x.FindAsync(), Times.Once);
}
[Test]
public async Task GetByIdAsync_OwnerOverrideInfo_Returned()
{
var id = 1;
var documentProcessingInfoId = 2;
var ownerOverrideInfo = new OwnerOverrideInfo()
{
OwnerOverrideInfoId = id,
DocumentProcessingInfoId = documentProcessingInfoId
};
_mockOwnerOverrideInfoRepository.Setup(x => x.FindByIdAsync(id)).ReturnsAsync(ownerOverrideInfo);
var result = await _ownerOverrideInfoService.GetByIdAsync(id);
Assert.IsNotNull(result);
Assert.AreEqual(documentProcessingInfoId, result.DocumentProcessingInfoId);
Assert.AreEqual(id, result.OwnerOverrideInfoId);
_mockOwnerOverrideInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>()), Times.Once);
}
[Test]
public void GetByIdAsync_Exception()
{
var id = 1;
_mockOwnerOverrideInfoRepository.Setup(x => x.FindByIdAsync(id)).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _ownerOverrideInfoService.GetByIdAsync(id));
_mockOwnerOverrideInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>()), Times.Once);
}
[Test]
public async Task GetByDocumentProcessingInfoIdAsync_OwnerOverrideInfos_Returned()
{
var id = 1;
var documentProcessingInfoId = 2;
var ownerOverrideInfos = new List<OwnerOverrideInfo>()
{
new OwnerOverrideInfo()
{
OwnerOverrideInfoId = id,
DocumentProcessingInfoId = documentProcessingInfoId
}
};
_mockOwnerOverrideInfoRepository.Setup(x => x.FindByDocumentProcessingInfoIdAsync(documentProcessingInfoId)).ReturnsAsync(ownerOverrideInfos);
var result = await _ownerOverrideInfoService.GetByDocumentProcessingInfoIdAsync(documentProcessingInfoId);
Assert.IsNotNull(result);
Assert.AreEqual(1, result.Count());
_mockOwnerOverrideInfoRepository.Verify(x => x.FindByDocumentProcessingInfoIdAsync(It.IsAny<int>()), Times.Once);
}
[Test]
public void GetByDocumentProcessingInfoIdAsync_Exception()
{
var documentProcessingInfoId = 2;
_mockOwnerOverrideInfoRepository.Setup(x => x.FindByDocumentProcessingInfoIdAsync(documentProcessingInfoId)).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _ownerOverrideInfoService.GetByDocumentProcessingInfoIdAsync(documentProcessingInfoId));
_mockOwnerOverrideInfoRepository.Verify(x => x.FindByDocumentProcessingInfoIdAsync(It.IsAny<int>()), Times.Once);
}
[Test]
public async Task SaveAsync_OwnerOverrideInfo_Returned()
{
var id = 1;
var documentProcessingInfoId = 2;
var ownerOverrideInfo = new OwnerOverrideInfo()
{
OwnerOverrideInfoId = id,
DocumentProcessingInfoId = documentProcessingInfoId
};
_mockOwnerOverrideInfoRepository.Setup(x => x.AddAsync(ownerOverrideInfo)).ReturnsAsync(ownerOverrideInfo);
var result = await _ownerOverrideInfoService.SaveAsync(ownerOverrideInfo);
Assert.IsNotNull(result);
Assert.AreEqual(documentProcessingInfoId, result.DocumentProcessingInfoId);
Assert.AreEqual(id, result.OwnerOverrideInfoId);
_mockOwnerOverrideInfoRepository.Verify(x => x.AddAsync(It.IsAny<OwnerOverrideInfo>()), Times.Once);
}
[Test]
public void SaveAsync_Exception()
{
var id = 1;
var documentProcessingInfoId = 2;
var ownerOverrideInfo = new OwnerOverrideInfo()
{
OwnerOverrideInfoId = id,
DocumentProcessingInfoId = documentProcessingInfoId
};
_mockOwnerOverrideInfoRepository.Setup(x => x.AddAsync(ownerOverrideInfo)).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _ownerOverrideInfoService.SaveAsync(ownerOverrideInfo));
_mockOwnerOverrideInfoRepository.Verify(x => x.AddAsync(It.IsAny<OwnerOverrideInfo>()), Times.Once);
}
[Test]
public async Task Delete_Success()
{
var id = 1;
var documentProcessingInfoId = 2;
var ownerOverrideInfo = new OwnerOverrideInfo()
{
OwnerOverrideInfoId = id,
DocumentProcessingInfoId = documentProcessingInfoId
};
_mockOwnerOverrideInfoRepository.Setup(x => x.FindByIdAsync(id)).ReturnsAsync(ownerOverrideInfo);
_mockOwnerOverrideInfoRepository.Setup(x => x.Remove(ownerOverrideInfo));
await _ownerOverrideInfoService.Delete(id);
_mockOwnerOverrideInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>()), Times.Once);
_mockOwnerOverrideInfoRepository.Verify(x => x.Remove(It.IsAny<OwnerOverrideInfo>()), Times.Once);
}
[Test]
public void Delete_FindByIdAsync_ThrowsException()
{
var id = 1;
var documentProcessingInfoId = 2;
var ownerOverrideInfo = new OwnerOverrideInfo()
{
OwnerOverrideInfoId = id,
DocumentProcessingInfoId = documentProcessingInfoId
};
_mockOwnerOverrideInfoRepository.Setup(x => x.FindByIdAsync(id)).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _ownerOverrideInfoService.Delete(id));
_mockOwnerOverrideInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>()), Times.Once);
_mockOwnerOverrideInfoRepository.Verify(x => x.Remove(It.IsAny<OwnerOverrideInfo>()), Times.Never);
}
[Test]
public void Delete_Remove_ThrowsException()
{
var id = 1;
var documentProcessingInfoId = 2;
var ownerOverrideInfo = new OwnerOverrideInfo()
{
OwnerOverrideInfoId = id,
DocumentProcessingInfoId = documentProcessingInfoId
};
_mockOwnerOverrideInfoRepository.Setup(x => x.FindByIdAsync(id)).ReturnsAsync(ownerOverrideInfo);
_mockOwnerOverrideInfoRepository.Setup(x => x.Remove(ownerOverrideInfo)).Throws(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _ownerOverrideInfoService.Delete(id));
_mockOwnerOverrideInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>()), Times.Once);
_mockOwnerOverrideInfoRepository.Verify(x => x.Remove(It.IsAny<OwnerOverrideInfo>()), Times.Once);
}
}
@@ -0,0 +1,188 @@
using System;
using System.Collections.Generic;
using Moq;
using NUnit.Framework;
using LCU.Library.Internal.Exceptions;
using LCU.Library.Internal.DocumentIngestorModels.Models.IndexFileDocuments;
using LCU.API.Internal.DocumentIngestor.Services.MicroApiServices;
using LCU.API.Internal.DocumentIngestor.Services.IndexParserServices;
using LCU.API.Internal.DocumentIngestor.Services.PdfParserServices;
using System.Threading.Tasks;
using System.Linq;
using LCU.Library.Internal.DocumentIngestorModels.Enums;
using LCU.Library.Internal.FileOperationsModels.Models;
using LCU.Library.Internal.LCUServiceFactory.Configurations;
using LCU.Library.Internal.LCUServiceFactory.Services;
namespace LCU.API.Internal.DocumentIngestorTests.Services.PdfParserServices;
public class FosLoanStatementPdfServiceTest
{
private FosLoanStatementPdfService _fosLoanStatementPdfService;
private Mock<ILcuServiceFactory<IPdfIndexParserService>> _mockLcuServiceFactory;
private Mock<IFileOperationsApiService> _mockFileOperationsApiService;
[SetUp]
public void Setup()
{
_mockLcuServiceFactory = new Mock<ILcuServiceFactory<IPdfIndexParserService>>();
_mockFileOperationsApiService = new Mock<IFileOperationsApiService>();
var serviceFactoryConfiguration = new ServicesFactoryConfiguration
{
ServiceFactoryRegistrations = new List<ServiceFactoryRegistration>
{
new()
{
ServiceInterfaceName = "IPdfIndexParserService",
ServiceRegistrations = new List<ServiceRegistration>
{
new()
{
ServiceName = "PdfIndexParserService",
ServiceId = "0"
},
new()
{
ServiceName = "PdfIndexParserService",
ServiceId = "3"
}
}
}
}
};
_fosLoanStatementPdfService = new FosLoanStatementPdfService(_mockFileOperationsApiService.Object,
_mockLcuServiceFactory.Object,
serviceFactoryConfiguration);
}
[Test]
public void DetermineBatchParsePdfRequest_GetFileContentAndParseRecords_ThrowException_Failure()
{
var rootPath = "\\\\Test\\root\\Path\\";
var indexFile = "TestIndexFile";
var pdfName = "TestPdfName";
var indexService = new Mock<IPdfIndexParserService>();
_mockLcuServiceFactory.Setup(x => x.GetService(IngestorTypes.FosLoanStatement)).Returns(indexService.Object);
indexService.Setup(x => x.GetFileContentAndParseRecords<FosLoanStatement>(It.IsAny<string>())).ThrowsAsync(new Exception("Errors"));
Assert.ThrowsAsync<ServiceException>(async () => await _fosLoanStatementPdfService.DetermineBatchParsePdfRequest(rootPath, indexFile, pdfName));
indexService.Verify(x => x.GetFileContentAndParseRecords<FosLoanStatement>(It.IsAny<string>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.ValidatePdfPageExists(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
indexService.Verify(x => x.CreateParsedPdfName(It.IsAny<FosLoanStatement>()), Times.Never);
}
[Test]
public void DetermineBatchParsePdfRequest_ValidatePdfPageExists_ThrowException_Failure()
{
var rootPath = "\\\\Test\\root\\Path\\";
var indexFile = "TestIndexFile";
var pdfName = "TestPdfName";
var records = new List<FosLoanStatement>
{
new FosLoanStatement
{
DocType = "TestDocType",
AccountNumber = "1",
EntityName = "Test EntityName",
EmailAddress = "Test EmailAddress",
CreationDate = "1/1/2022",
StartingPage = "1",
NumberOfPages = "3",
DocName = "Test DocName"
}
};
var indexService = new Mock<IPdfIndexParserService>();
_mockLcuServiceFactory.Setup(x => x.GetService(IngestorTypes.FosLoanStatement)).Returns(indexService.Object);
indexService.Setup(x => x.GetFileContentAndParseRecords<FosLoanStatement>(It.IsAny<string>())).ReturnsAsync(records);
_mockFileOperationsApiService.Setup(x => x.ValidatePdfPageExists(It.IsAny<string>(), It.IsAny<string>())).ThrowsAsync(new Exception("Errors"));
Assert.ThrowsAsync<ServiceException>(async () => await _fosLoanStatementPdfService.DetermineBatchParsePdfRequest(rootPath, indexFile, pdfName));
indexService.Verify(x => x.GetFileContentAndParseRecords<FosLoanStatement>(It.IsAny<string>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.ValidatePdfPageExists(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
indexService.Verify(x => x.CreateParsedPdfName(It.IsAny<FosLoanStatement>()), Times.Never);
}
[Test]
public void DetermineBatchParsePdfRequest_CreateParsedPdfName_ThrowException_Failure()
{
var rootPath = "\\\\Test\\root\\Path\\";
var indexFile = "TestIndexFile";
var pdfName = "TestPdfName";
var records = new List<FosLoanStatement>
{
new FosLoanStatement
{
DocType = "TestDocType",
AccountNumber = "1",
EntityName = "Test EntityName",
EmailAddress = "Test EmailAddress",
CreationDate = "1/1/2022",
StartingPage = "1",
NumberOfPages = "3",
DocName = "Test DocName"
}
};
var indexService = new Mock<IPdfIndexParserService>();
_mockLcuServiceFactory.Setup(x => x.GetService(IngestorTypes.FosLoanStatement)).Returns(indexService.Object);
indexService.Setup(x => x.GetFileContentAndParseRecords<FosLoanStatement>(It.IsAny<string>())).ReturnsAsync(records);
var requestResponse = new RequestResponse
{
IsSuccessful = true
};
_mockFileOperationsApiService.Setup(x => x.ValidatePdfPageExists(It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(requestResponse);
indexService.Setup(x => x.CreateParsedPdfName(It.IsAny<FosLoanStatement>())).Throws(new Exception("Errors"));
Assert.ThrowsAsync<ServiceException>(async () => await _fosLoanStatementPdfService.DetermineBatchParsePdfRequest(rootPath, indexFile, pdfName));
indexService.Verify(x => x.GetFileContentAndParseRecords<FosLoanStatement>(It.IsAny<string>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.ValidatePdfPageExists(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
indexService.Verify(x => x.CreateParsedPdfName(It.IsAny<FosLoanStatement>()), Times.Once);
}
[Test]
public async Task DetermineBatchParsePdfRequest_Success()
{
var rootPath = "\\\\Test\\root\\Path\\";
var indexFile = "TestIndexFile";
var pdfName = "TestPdfName";
var records = new List<FosLoanStatement>
{
new FosLoanStatement
{
DocType = "TestDocType",
AccountNumber = "1",
EntityName = "Test EntityName",
EmailAddress = "Test EmailAddress",
CreationDate = "1/1/2022",
StartingPage = "1",
NumberOfPages = "3",
DocName = "Test DocName"
}
};
var indexService = new Mock<IPdfIndexParserService>();
_mockLcuServiceFactory.Setup(x => x.GetService(IngestorTypes.FosLoanStatement)).Returns(indexService.Object);
indexService.Setup(x => x.GetFileContentAndParseRecords<FosLoanStatement>(It.IsAny<string>())).ReturnsAsync(records);
var requestResponse = new RequestResponse
{
IsSuccessful = true
};
_mockFileOperationsApiService.Setup(x => x.ValidatePdfPageExists(It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(requestResponse);
var parsedPdfName = "TestPdfName_Test EntityName_1";
indexService.Setup(x => x.CreateParsedPdfName(It.IsAny<FosLoanStatement>())).Returns(parsedPdfName);
var batchParsePdfRequest = await _fosLoanStatementPdfService.DetermineBatchParsePdfRequest(rootPath, indexFile, pdfName);
Assert.AreEqual(1, batchParsePdfRequest.BatchPdfs.Count);
var batchPdf = batchParsePdfRequest.BatchPdfs.FirstOrDefault();
Assert.IsNotNull(batchPdf);
Assert.AreEqual($"{parsedPdfName}.pdf", batchPdf?.ParsedPdfname);
Assert.AreEqual(1, batchPdf?.PageStart);
Assert.AreEqual(3, batchPdf?.PageStop);
indexService.Verify(x => x.GetFileContentAndParseRecords<FosLoanStatement>(It.IsAny<string>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.ValidatePdfPageExists(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
indexService.Verify(x => x.CreateParsedPdfName(It.IsAny<FosLoanStatement>()), Times.Once);
}
}
@@ -0,0 +1,182 @@
using System;
using System.Collections.Generic;
using Moq;
using NUnit.Framework;
using LCU.Library.Internal.Exceptions;
using LCU.Library.Internal.DocumentIngestorModels.Models.IndexFileDocuments;
using LCU.API.Internal.DocumentIngestor.Services.MicroApiServices;
using LCU.API.Internal.DocumentIngestor.Services.IndexParserServices;
using LCU.API.Internal.DocumentIngestor.Services.PdfParserServices;
using System.Threading.Tasks;
using System.Linq;
using LCU.Library.Internal.DocumentIngestorModels.Enums;
using LCU.Library.Internal.FileOperationsModels.Models;
using LCU.Library.Internal.LCUServiceFactory.Configurations;
using LCU.Library.Internal.LCUServiceFactory.Services;
namespace LCU.API.Internal.DocumentIngestorTests.Services.PdfParserServices;
public class OsgDnaNoticesPdfServiceTest
{
private OsgDnaNoticesPdfService _osgDnaNoticesPdfService;
private Mock<ILcuServiceFactory<IPdfIndexParserService>> _mockLcuServiceFactory;
private Mock<IFileOperationsApiService> _mockFileOperationsApiService;
[SetUp]
public void Setup()
{
_mockLcuServiceFactory = new Mock<ILcuServiceFactory<IPdfIndexParserService>>();
_mockFileOperationsApiService = new Mock<IFileOperationsApiService>();
var serviceFactoryConfiguration = new ServicesFactoryConfiguration
{
ServiceFactoryRegistrations = new List<ServiceFactoryRegistration>
{
new()
{
ServiceInterfaceName = "IPdfIndexParserService",
ServiceRegistrations = new List<ServiceRegistration>
{
new()
{
ServiceName = "PdfIndexParserService",
ServiceId = "0"
},
new()
{
ServiceName = "PdfIndexParserService",
ServiceId = "4"
}
}
}
}
};
_osgDnaNoticesPdfService = new OsgDnaNoticesPdfService(_mockLcuServiceFactory.Object,
_mockFileOperationsApiService.Object,
serviceFactoryConfiguration);
}
[Test]
public void DetermineBatchParsePdfRequest_GetFileContentAndParseRecords_ThrowException_Failure()
{
var rootPath = "\\\\Test\\root\\Path\\";
var indexFile = "TestIndexFile";
var pdfName = "TestPdfName";
var indexService = new Mock<IPdfIndexParserService>();
_mockLcuServiceFactory.Setup(x => x.GetService(IngestorTypes.OsgDnaNoticesDocument)).Returns(indexService.Object);
indexService.Setup(x => x.GetFileContentAndParseRecords<OsgDnaNoticesDocument>(It.IsAny<string>())).ThrowsAsync(new Exception("Errors"));
Assert.ThrowsAsync<ServiceException>(async () => await _osgDnaNoticesPdfService.DetermineBatchParsePdfRequest(rootPath, indexFile, pdfName));
indexService.Verify(x => x.GetFileContentAndParseRecords<OsgDnaNoticesDocument>(It.IsAny<string>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.ValidatePdfPageExists(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
indexService.Verify(x => x.CreateParsedPdfName(It.IsAny<OsgDnaNoticesDocument>()), Times.Never);
}
[Test]
public void DetermineBatchParsePdfRequest_ValidatePdfPageExists_ThrowException_Failure()
{
var rootPath = "\\\\Test\\root\\Path\\";
var indexFile = "TestIndexFile";
var pdfName = "TestPdfName";
var records = new List<OsgDnaNoticesDocument>
{
new OsgDnaNoticesDocument
{
DocType = "TestDocType",
AccountNumber = "1",
MemberNumberOrUserId = "2",
CreationDate = "20220823",
StartingPage = "1",
NumberOfPages = "3"
}
};
var indexService = new Mock<IPdfIndexParserService>();
_mockLcuServiceFactory.Setup(x => x.GetService(IngestorTypes.OsgDnaNoticesDocument)).Returns(indexService.Object);
indexService.Setup(x => x.GetFileContentAndParseRecords<OsgDnaNoticesDocument>(It.IsAny<string>())).ReturnsAsync(records);
_mockFileOperationsApiService.Setup(x => x.ValidatePdfPageExists(It.IsAny<string>(), It.IsAny<string>())).ThrowsAsync(new Exception("Errors"));
Assert.ThrowsAsync<ServiceException>(async () => await _osgDnaNoticesPdfService.DetermineBatchParsePdfRequest(rootPath, indexFile, pdfName));
indexService.Verify(x => x.GetFileContentAndParseRecords<OsgDnaNoticesDocument>(It.IsAny<string>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.ValidatePdfPageExists(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
indexService.Verify(x => x.CreateParsedPdfName(It.IsAny<OsgDnaNoticesDocument>()), Times.Never);
}
[Test]
public void DetermineBatchParsePdfRequest_CreateParsedPdfName_ThrowException_Failure()
{
var rootPath = "\\\\Test\\root\\Path\\";
var indexFile = "TestIndexFile";
var pdfName = "TestPdfName";
var records = new List<OsgDnaNoticesDocument>
{
new OsgDnaNoticesDocument
{
DocType = "TestDocType",
AccountNumber = "1",
MemberNumberOrUserId = "2",
CreationDate = "20220823",
StartingPage = "1",
NumberOfPages = "3"
}
};
var indexService = new Mock<IPdfIndexParserService>();
_mockLcuServiceFactory.Setup(x => x.GetService(IngestorTypes.OsgDnaNoticesDocument)).Returns(indexService.Object);
indexService.Setup(x => x.GetFileContentAndParseRecords<OsgDnaNoticesDocument>(It.IsAny<string>())).ReturnsAsync(records);
var requestResponse = new RequestResponse
{
IsSuccessful = true
};
_mockFileOperationsApiService.Setup(x => x.ValidatePdfPageExists(It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(requestResponse);
indexService.Setup(x => x.CreateParsedPdfName(It.IsAny<OsgDnaNoticesDocument>())).Throws(new Exception("Errors"));
Assert.ThrowsAsync<ServiceException>(async () => await _osgDnaNoticesPdfService.DetermineBatchParsePdfRequest(rootPath, indexFile, pdfName));
indexService.Verify(x => x.GetFileContentAndParseRecords<OsgDnaNoticesDocument>(It.IsAny<string>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.ValidatePdfPageExists(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
indexService.Verify(x => x.CreateParsedPdfName(It.IsAny<OsgDnaNoticesDocument>()), Times.Once);
}
[Test]
public async Task DetermineBatchParsePdfRequest_Success()
{
var rootPath = "\\\\Test\\root\\Path\\";
var indexFile = "TestIndexFile";
var pdfName = "TestPdfName";
var records = new List<OsgDnaNoticesDocument>
{
new OsgDnaNoticesDocument
{
DocType = "TestDocType",
AccountNumber = "1",
MemberNumberOrUserId = "2",
CreationDate = "20220823",
StartingPage = "1",
NumberOfPages = "3"
}
};
var indexService = new Mock<IPdfIndexParserService>();
_mockLcuServiceFactory.Setup(x => x.GetService(IngestorTypes.OsgDnaNoticesDocument)).Returns(indexService.Object);
indexService.Setup(x => x.GetFileContentAndParseRecords<OsgDnaNoticesDocument>(It.IsAny<string>())).ReturnsAsync(records);
var requestResponse = new RequestResponse
{
IsSuccessful = true
};
_mockFileOperationsApiService.Setup(x => x.ValidatePdfPageExists(It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(requestResponse);
var parsedPdfName = "TestPdfName_Test EntityName_1";
indexService.Setup(x => x.CreateParsedPdfName(It.IsAny<OsgDnaNoticesDocument>())).Returns(parsedPdfName);
var batchParsePdfRequest = await _osgDnaNoticesPdfService.DetermineBatchParsePdfRequest(rootPath, indexFile, pdfName);
Assert.AreEqual(1, batchParsePdfRequest.BatchPdfs.Count);
var batchPdf = batchParsePdfRequest.BatchPdfs.FirstOrDefault();
Assert.IsNotNull(batchPdf);
Assert.AreEqual($"{parsedPdfName}.pdf", batchPdf?.ParsedPdfname);
Assert.AreEqual(1, batchPdf?.PageStart);
Assert.AreEqual(3, batchPdf?.PageStop);
indexService.Verify(x => x.GetFileContentAndParseRecords<OsgDnaNoticesDocument>(It.IsAny<string>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.ValidatePdfPageExists(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
indexService.Verify(x => x.CreateParsedPdfName(It.IsAny<OsgDnaNoticesDocument>()), Times.Once);
}
}
@@ -0,0 +1,182 @@
using System;
using System.Collections.Generic;
using Moq;
using NUnit.Framework;
using LCU.Library.Internal.Exceptions;
using LCU.Library.Internal.DocumentIngestorModels.Models.IndexFileDocuments;
using LCU.API.Internal.DocumentIngestor.Services.MicroApiServices;
using LCU.API.Internal.DocumentIngestor.Services.IndexParserServices;
using LCU.API.Internal.DocumentIngestor.Services.PdfParserServices;
using System.Threading.Tasks;
using System.Linq;
using LCU.Library.Internal.DocumentIngestorModels.Enums;
using LCU.Library.Internal.FileOperationsModels.Models;
using LCU.Library.Internal.LCUServiceFactory.Configurations;
using LCU.Library.Internal.LCUServiceFactory.Services;
namespace LCU.API.Internal.DocumentIngestorTests.Services.PdfParserServices;
public class OsgHistoricalDocumentPdfServiceTest
{
private OsgHistoricalDocumentPdfService _osgHistoricalDocumentPdfService;
private Mock<ILcuServiceFactory<IPdfIndexParserService>> _mockLcuServiceFactory;
private Mock<IFileOperationsApiService> _mockFileOperationsApiService;
[SetUp]
public void Setup()
{
_mockLcuServiceFactory = new Mock<ILcuServiceFactory<IPdfIndexParserService>>();
_mockFileOperationsApiService = new Mock<IFileOperationsApiService>();
var serviceFactoryConfiguration = new ServicesFactoryConfiguration
{
ServiceFactoryRegistrations = new List<ServiceFactoryRegistration>
{
new()
{
ServiceInterfaceName = "IPdfIndexParserService",
ServiceRegistrations = new List<ServiceRegistration>
{
new()
{
ServiceName = "PdfIndexParserService",
ServiceId = "0"
},
new()
{
ServiceName = "PdfIndexParserService",
ServiceId = "6"
}
}
}
}
};
_osgHistoricalDocumentPdfService = new OsgHistoricalDocumentPdfService(_mockLcuServiceFactory.Object,
_mockFileOperationsApiService.Object,
serviceFactoryConfiguration);
}
[Test]
public void DetermineBatchParsePdfRequest_GetFileContentAndParseRecords_ThrowException_Failure()
{
var rootPath = "\\\\Test\\root\\Path\\";
var indexFile = "TestIndexFile";
var pdfName = "TestPdfName";
var indexService = new Mock<IPdfIndexParserService>();
_mockLcuServiceFactory.Setup(x => x.GetService(IngestorTypes.OsgHistoricalDocument)).Returns(indexService.Object);
indexService.Setup(x => x.GetFileContentAndParseRecords<OsgHistoricalDocument>(It.IsAny<string>())).ThrowsAsync(new Exception("Errors"));
Assert.ThrowsAsync<ServiceException>(async () => await _osgHistoricalDocumentPdfService.DetermineBatchParsePdfRequest(rootPath, indexFile, pdfName));
indexService.Verify(x => x.GetFileContentAndParseRecords<OsgHistoricalDocument>(It.IsAny<string>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.ValidatePdfPageExists(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
indexService.Verify(x => x.CreateParsedPdfName(It.IsAny<OsgHistoricalDocument>()), Times.Never);
}
[Test]
public void DetermineBatchParsePdfRequest_ValidatePdfPageExists_ThrowException_Failure()
{
var rootPath = "\\\\Test\\root\\Path\\";
var indexFile = "TestIndexFile";
var pdfName = "TestPdfName";
var records = new List<OsgHistoricalDocument>
{
new OsgHistoricalDocument
{
DocType = "TestDocType",
EntityName = "Jim Jones",
MemberNumberOrUserId = "2",
CreationDate = "20220823",
StartingPage = "1",
NumberOfPages = "3"
}
};
var indexService = new Mock<IPdfIndexParserService>();
_mockLcuServiceFactory.Setup(x => x.GetService(IngestorTypes.OsgHistoricalDocument)).Returns(indexService.Object);
indexService.Setup(x => x.GetFileContentAndParseRecords<OsgHistoricalDocument>(It.IsAny<string>())).ReturnsAsync(records);
_mockFileOperationsApiService.Setup(x => x.ValidatePdfPageExists(It.IsAny<string>(), It.IsAny<string>())).ThrowsAsync(new Exception("Errors"));
Assert.ThrowsAsync<ServiceException>(async () => await _osgHistoricalDocumentPdfService.DetermineBatchParsePdfRequest(rootPath, indexFile, pdfName));
indexService.Verify(x => x.GetFileContentAndParseRecords<OsgHistoricalDocument>(It.IsAny<string>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.ValidatePdfPageExists(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
indexService.Verify(x => x.CreateParsedPdfName(It.IsAny<OsgHistoricalDocument>()), Times.Never);
}
[Test]
public void DetermineBatchParsePdfRequest_CreateParsedPdfName_ThrowException_Failure()
{
var rootPath = "\\\\Test\\root\\Path\\";
var indexFile = "TestIndexFile";
var pdfName = "TestPdfName";
var records = new List<OsgHistoricalDocument>
{
new OsgHistoricalDocument
{
DocType = "TestDocType",
EntityName = "Jan James",
MemberNumberOrUserId = "2",
CreationDate = "20220823",
StartingPage = "1",
NumberOfPages = "3"
}
};
var indexService = new Mock<IPdfIndexParserService>();
_mockLcuServiceFactory.Setup(x => x.GetService(IngestorTypes.OsgHistoricalDocument)).Returns(indexService.Object);
indexService.Setup(x => x.GetFileContentAndParseRecords<OsgHistoricalDocument>(It.IsAny<string>())).ReturnsAsync(records);
var requestResponse = new RequestResponse
{
IsSuccessful = true
};
_mockFileOperationsApiService.Setup(x => x.ValidatePdfPageExists(It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(requestResponse);
indexService.Setup(x => x.CreateParsedPdfName(It.IsAny<OsgHistoricalDocument>())).Throws(new Exception("Errors"));
Assert.ThrowsAsync<ServiceException>(async () => await _osgHistoricalDocumentPdfService.DetermineBatchParsePdfRequest(rootPath, indexFile, pdfName));
indexService.Verify(x => x.GetFileContentAndParseRecords<OsgHistoricalDocument>(It.IsAny<string>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.ValidatePdfPageExists(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
indexService.Verify(x => x.CreateParsedPdfName(It.IsAny<OsgHistoricalDocument>()), Times.Once);
}
[Test]
public async Task DetermineBatchParsePdfRequest_Success()
{
var rootPath = "\\\\Test\\root\\Path\\";
var indexFile = "TestIndexFile";
var pdfName = "TestPdfName";
var records = new List<OsgHistoricalDocument>
{
new OsgHistoricalDocument
{
DocType = "TestDocType",
EntityName = "Jeff June",
MemberNumberOrUserId = "2",
CreationDate = "20220823",
StartingPage = "1",
NumberOfPages = "3"
}
};
var indexService = new Mock<IPdfIndexParserService>();
_mockLcuServiceFactory.Setup(x => x.GetService(IngestorTypes.OsgHistoricalDocument)).Returns(indexService.Object);
indexService.Setup(x => x.GetFileContentAndParseRecords<OsgHistoricalDocument>(It.IsAny<string>())).ReturnsAsync(records);
var requestResponse = new RequestResponse
{
IsSuccessful = true
};
_mockFileOperationsApiService.Setup(x => x.ValidatePdfPageExists(It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(requestResponse);
var parsedPdfName = "TestPdfName_Test EntityName_1";
indexService.Setup(x => x.CreateParsedPdfName(It.IsAny<OsgHistoricalDocument>())).Returns(parsedPdfName);
var batchParsePdfRequest = await _osgHistoricalDocumentPdfService.DetermineBatchParsePdfRequest(rootPath, indexFile, pdfName);
Assert.AreEqual(1, batchParsePdfRequest.BatchPdfs.Count);
var batchPdf = batchParsePdfRequest.BatchPdfs.FirstOrDefault();
Assert.IsNotNull(batchPdf);
Assert.AreEqual($"{parsedPdfName}.pdf", batchPdf?.ParsedPdfname);
Assert.AreEqual(1, batchPdf?.PageStart);
Assert.AreEqual(3, batchPdf?.PageStop);
indexService.Verify(x => x.GetFileContentAndParseRecords<OsgHistoricalDocument>(It.IsAny<string>()), Times.Once);
_mockFileOperationsApiService.Verify(x => x.ValidatePdfPageExists(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
indexService.Verify(x => x.CreateParsedPdfName(It.IsAny<OsgHistoricalDocument>()), Times.Once);
}
}
@@ -0,0 +1,196 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Linq;
using Moq;
using NUnit.Framework;
using LCU.Library.Internal.DocumentIngestorModels.Entities;
using LCU.Library.Internal.Exceptions;
using LCU.API.Internal.DocumentIngestor.Services;
using LCU.API.Internal.DocumentIngestorLib.Repositories;
namespace LCU.API.Internal.DocumentIngestorTests.Services;
public class PdfPartitionerLogServiceTest
{
private PdfPartitionerLogService _pdfPartitionerLogService;
private Mock<IUnitOfWork> _unitOfWork;
private Mock<IPdfPartitionerLogRepository> _mockIPdfPartitionerLogRepository;
[SetUp]
public void Setup()
{
_unitOfWork = new Mock<IUnitOfWork>();
_mockIPdfPartitionerLogRepository = new Mock<IPdfPartitionerLogRepository>();
_pdfPartitionerLogService = new PdfPartitionerLogService(_unitOfWork.Object, _mockIPdfPartitionerLogRepository.Object);
}
[Test]
public async Task GetAsync_PdfPartitionerLogs_Returned()
{
var pdfPartitionerRunInfoId = Guid.NewGuid();
var pdfPartitionerLogId = 2;
var pdfPartitionerLogs = new List<PdfPartitionerLog>()
{
new PdfPartitionerLog()
{
PdfPartitionerLogId = pdfPartitionerLogId,
PdfPartitionerRunInfoId = pdfPartitionerRunInfoId
}
};
_mockIPdfPartitionerLogRepository.Setup(x => x.FindAsync()).ReturnsAsync(pdfPartitionerLogs);
var result = await _pdfPartitionerLogService.GetAsync();
Assert.IsNotNull(result);
Assert.AreEqual(1, result.Count());
_mockIPdfPartitionerLogRepository.Verify(x => x.FindAsync(), Times.Once);
}
[Test]
public void GetAsync_Exception()
{
_mockIPdfPartitionerLogRepository.Setup(x => x.FindAsync()).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _pdfPartitionerLogService.GetAsync());
_mockIPdfPartitionerLogRepository.Verify(x => x.FindAsync(), Times.Once);
}
[Test]
public async Task GetByIdAsync_PdfPartitionerLog_Returned()
{
var pdfPartitionerRunInfoId = Guid.NewGuid();
var pdfPartitionerLogId = 2;
var pdfPartitionerLog = new PdfPartitionerLog()
{
PdfPartitionerLogId = pdfPartitionerLogId,
PdfPartitionerRunInfoId = pdfPartitionerRunInfoId
};
_mockIPdfPartitionerLogRepository.Setup(x => x.FindByIdAsync(pdfPartitionerLogId)).ReturnsAsync(pdfPartitionerLog);
var result = await _pdfPartitionerLogService.GetByIdAsync(pdfPartitionerLogId);
Assert.IsNotNull(result);
Assert.AreEqual(pdfPartitionerRunInfoId, result.PdfPartitionerRunInfoId);
Assert.AreEqual(pdfPartitionerLogId, result.PdfPartitionerLogId);
_mockIPdfPartitionerLogRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>()), Times.Once);
}
[Test]
public void GetByIdAsync_Exception()
{
var pdfPartitionerLogId = 2;
_mockIPdfPartitionerLogRepository.Setup(x => x.FindByIdAsync(pdfPartitionerLogId)).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _pdfPartitionerLogService.GetByIdAsync(pdfPartitionerLogId));
_mockIPdfPartitionerLogRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>()), Times.Once);
}
[Test]
public async Task GetByPdfPartitionerRunInfoIdAsync_PdfPartitionerLogs_Returned()
{
var pdfPartitionerRunInfoId = Guid.NewGuid();
var pdfPartitionerLogId = 2;
var pdfPartitionerLogs = new List<PdfPartitionerLog>()
{
new PdfPartitionerLog()
{
PdfPartitionerLogId = pdfPartitionerLogId,
PdfPartitionerRunInfoId = pdfPartitionerRunInfoId
}
};
_mockIPdfPartitionerLogRepository.Setup(x => x.FindByPdfPartitionerRunInfoIdAsync(pdfPartitionerRunInfoId)).ReturnsAsync(pdfPartitionerLogs);
var result = await _pdfPartitionerLogService.GetByPdfPartitionerRunInfoIdAsync(pdfPartitionerRunInfoId);
Assert.IsNotNull(result);
Assert.AreEqual(1, result.Count());
_mockIPdfPartitionerLogRepository.Verify(x => x.FindByPdfPartitionerRunInfoIdAsync(It.IsAny<Guid>()), Times.Once);
}
[Test]
public void GetByPdfPartitionerRunInfoIdAsync_Exception()
{
var pdfPartitionerRunInfoId = Guid.NewGuid();
_mockIPdfPartitionerLogRepository.Setup(x => x.FindByPdfPartitionerRunInfoIdAsync(pdfPartitionerRunInfoId)).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _pdfPartitionerLogService.GetByPdfPartitionerRunInfoIdAsync(pdfPartitionerRunInfoId));
_mockIPdfPartitionerLogRepository.Verify(x => x.FindByPdfPartitionerRunInfoIdAsync(It.IsAny<Guid>()), Times.Once);
}
[Test]
public async Task SaveAsync_PdfPartitionerLog_Returned()
{
var pdfPartitionerRunInfoId = Guid.NewGuid();
var pdfPartitionerLogId = 2;
var pdfPartitionerLog = new PdfPartitionerLog()
{
PdfPartitionerLogId = pdfPartitionerLogId,
PdfPartitionerRunInfoId = pdfPartitionerRunInfoId
};
_mockIPdfPartitionerLogRepository.Setup(x => x.AddAsync(pdfPartitionerLog)).ReturnsAsync(pdfPartitionerLog);
var result = await _pdfPartitionerLogService.SaveAsync(pdfPartitionerLog);
Assert.IsNotNull(result);
Assert.AreEqual(pdfPartitionerRunInfoId, result.PdfPartitionerRunInfoId);
Assert.AreEqual(pdfPartitionerLogId, result.PdfPartitionerLogId);
_mockIPdfPartitionerLogRepository.Verify(x => x.AddAsync(It.IsAny<PdfPartitionerLog>()), Times.Once);
}
[Test]
public void SaveAsync_Exception()
{
var pdfPartitionerRunInfoId = Guid.NewGuid();
var pdfPartitionerLogId = 2;
var pdfPartitionerLog = new PdfPartitionerLog()
{
PdfPartitionerLogId = pdfPartitionerLogId,
PdfPartitionerRunInfoId = pdfPartitionerRunInfoId
};
_mockIPdfPartitionerLogRepository.Setup(x => x.AddAsync(pdfPartitionerLog)).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _pdfPartitionerLogService.SaveAsync(pdfPartitionerLog));
_mockIPdfPartitionerLogRepository.Verify(x => x.AddAsync(It.IsAny<PdfPartitionerLog>()), Times.Once);
}
[Test]
public async Task Delete_Success()
{
var pdfPartitionerRunInfoId = Guid.NewGuid();
var pdfPartitionerLogId = 2;
var pdfPartitionerLog = new PdfPartitionerLog()
{
PdfPartitionerLogId = pdfPartitionerLogId,
PdfPartitionerRunInfoId = pdfPartitionerRunInfoId
};
_mockIPdfPartitionerLogRepository.Setup(x => x.FindByIdAsync(pdfPartitionerLogId)).ReturnsAsync(pdfPartitionerLog);
_mockIPdfPartitionerLogRepository.Setup(x => x.Remove(pdfPartitionerLog));
await _pdfPartitionerLogService.Delete(pdfPartitionerLogId);
_mockIPdfPartitionerLogRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>()), Times.Once);
_mockIPdfPartitionerLogRepository.Verify(x => x.Remove(It.IsAny<PdfPartitionerLog>()), Times.Once);
}
[Test]
public void Delete_FindByIdAsync_ThrowsException()
{
var pdfPartitionerRunInfoId = Guid.NewGuid();
var pdfPartitionerLogId = 2;
var pdfPartitionerLog = new PdfPartitionerLog()
{
PdfPartitionerLogId = pdfPartitionerLogId,
PdfPartitionerRunInfoId = pdfPartitionerRunInfoId
};
_mockIPdfPartitionerLogRepository.Setup(x => x.FindByIdAsync(pdfPartitionerLogId)).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _pdfPartitionerLogService.Delete(pdfPartitionerLogId));
_mockIPdfPartitionerLogRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>()), Times.Once);
_mockIPdfPartitionerLogRepository.Verify(x => x.Remove(It.IsAny<PdfPartitionerLog>()), Times.Never);
}
[Test]
public void Delete_Remove_ThrowsException()
{
var pdfPartitionerRunInfoId = Guid.NewGuid();
var pdfPartitionerLogId = 2;
var pdfPartitionerLog = new PdfPartitionerLog()
{
PdfPartitionerLogId = pdfPartitionerLogId,
PdfPartitionerRunInfoId = pdfPartitionerRunInfoId
};
_mockIPdfPartitionerLogRepository.Setup(x => x.FindByIdAsync(pdfPartitionerLogId)).ReturnsAsync(pdfPartitionerLog);
_mockIPdfPartitionerLogRepository.Setup(x => x.Remove(pdfPartitionerLog)).Throws(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _pdfPartitionerLogService.Delete(pdfPartitionerLogId));
_mockIPdfPartitionerLogRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>()), Times.Once);
_mockIPdfPartitionerLogRepository.Verify(x => x.Remove(It.IsAny<PdfPartitionerLog>()), Times.Once);
}
}
@@ -0,0 +1,209 @@
using System;
using System.Threading.Tasks;
using Moq;
using NUnit.Framework;
using LCU.Library.Internal.DocumentIngestorModels.Entities;
using LCU.Library.Internal.DocumentIngestorModels.Enums;
using LCU.Library.Internal.Exceptions;
using LCU.API.Internal.DocumentIngestor.Services;
using LCU.API.Internal.DocumentIngestorLib.Repositories;
namespace LCU.API.Internal.DocumentIngestorTests.Services;
public class PdfPartitionerRunInfoServiceTest
{
private PdfPartitionerRunInfoService _pdfPartitionerRunInfoService;
private Mock<IUnitOfWork> _unitOfWork;
private Mock<IPdfPartitionerRunInfoRepository> _mockPdfPartitionerRunInfoRepository;
[SetUp]
public void Setup()
{
_unitOfWork = new Mock<IUnitOfWork>();
_mockPdfPartitionerRunInfoRepository = new Mock<IPdfPartitionerRunInfoRepository>();
_pdfPartitionerRunInfoService = new PdfPartitionerRunInfoService(_unitOfWork.Object, _mockPdfPartitionerRunInfoRepository.Object);
}
[Test]
public async Task GetByIdAsync_PdfPartitionerRunInfo_Returned()
{
var pdfPartitionerRunInfoId = Guid.NewGuid();
var pdfPartitionerRunInfo = new PdfPartitionerRunInfo()
{
PdfPartitionerRunInfoId = pdfPartitionerRunInfoId,
StartTimeStamp = Convert.ToDateTime("1/1/2022"),
PdfParserType = PdfParserTypes.FosLoanStatement,
Path = "\\\\Test\\Path",
IndexTotal = 3
};
_mockPdfPartitionerRunInfoRepository.Setup(x => x.FindByIdAsync(pdfPartitionerRunInfoId)).ReturnsAsync(pdfPartitionerRunInfo);
var result = await _pdfPartitionerRunInfoService.GetByIdAsync(pdfPartitionerRunInfoId);
Assert.IsNotNull(result);
Assert.AreEqual(pdfPartitionerRunInfoId, result.PdfPartitionerRunInfoId);
_mockPdfPartitionerRunInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<Guid>()), Times.Once);
}
[Test]
public void GetByIdAsync_Exception()
{
var pdfPartitionerRunInfoId = Guid.NewGuid();
_mockPdfPartitionerRunInfoRepository.Setup(x => x.FindByIdAsync(pdfPartitionerRunInfoId)).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _pdfPartitionerRunInfoService.GetByIdAsync(pdfPartitionerRunInfoId));
_mockPdfPartitionerRunInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<Guid>()), Times.Once);
}
[Test]
public async Task SaveAsync_PdfPartitionerRunInfo_Returned()
{
var pdfPartitionerRunInfoId = Guid.NewGuid();
var pdfPartitionerRunInfo = new PdfPartitionerRunInfo()
{
PdfPartitionerRunInfoId = pdfPartitionerRunInfoId,
StartTimeStamp = Convert.ToDateTime("1/1/2022"),
PdfParserType = PdfParserTypes.FosLoanStatement,
Path = "\\\\Test\\Path",
IndexTotal = 3
};
_mockPdfPartitionerRunInfoRepository.Setup(x => x.AddAsync(pdfPartitionerRunInfo)).ReturnsAsync(pdfPartitionerRunInfo);
var result = await _pdfPartitionerRunInfoService.SaveAsync(pdfPartitionerRunInfo);
Assert.IsNotNull(result);
Assert.AreEqual(pdfPartitionerRunInfoId, result.PdfPartitionerRunInfoId);
_mockPdfPartitionerRunInfoRepository.Verify(x => x.AddAsync(It.IsAny<PdfPartitionerRunInfo>()), Times.Once);
}
[Test]
public void SaveAsync_Exception()
{
var pdfPartitionerRunInfoId = Guid.NewGuid();
var pdfPartitionerRunInfo = new PdfPartitionerRunInfo()
{
PdfPartitionerRunInfoId = pdfPartitionerRunInfoId,
StartTimeStamp = Convert.ToDateTime("1/1/2022"),
PdfParserType = PdfParserTypes.FosLoanStatement,
Path = "\\\\Test\\Path",
IndexTotal = 3
};
_mockPdfPartitionerRunInfoRepository.Setup(x => x.AddAsync(pdfPartitionerRunInfo)).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _pdfPartitionerRunInfoService.SaveAsync(pdfPartitionerRunInfo));
_mockPdfPartitionerRunInfoRepository.Verify(x => x.AddAsync(It.IsAny<PdfPartitionerRunInfo>()), Times.Once);
}
[Test]
public async Task Update_PdfPartitionerRunInfo_Returned()
{
var pdfPartitionerRunInfoId = Guid.NewGuid();
var pdfPartitionerRunInfo = new PdfPartitionerRunInfo()
{
PdfPartitionerRunInfoId = pdfPartitionerRunInfoId,
StartTimeStamp = Convert.ToDateTime("1/1/2022"),
PdfParserType = PdfParserTypes.FosLoanStatement,
Path = "\\\\Test\\Path",
IndexTotal = 3
};
_mockPdfPartitionerRunInfoRepository.Setup(x => x.FindByIdAsync(pdfPartitionerRunInfoId)).ReturnsAsync(pdfPartitionerRunInfo);
_mockPdfPartitionerRunInfoRepository.Setup(x => x.Update(pdfPartitionerRunInfo));
var result = await _pdfPartitionerRunInfoService.Update(pdfPartitionerRunInfo);
Assert.IsNotNull(result);
Assert.AreEqual(pdfPartitionerRunInfoId, result.PdfPartitionerRunInfoId);
_mockPdfPartitionerRunInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<Guid>()), Times.Once);
_mockPdfPartitionerRunInfoRepository.Verify(x => x.Update(It.IsAny<PdfPartitionerRunInfo>()), Times.Once);
}
[Test]
public void Update_FindByIdAsync_ThrowsException()
{
var pdfPartitionerRunInfoId = Guid.NewGuid();
var pdfPartitionerRunInfo = new PdfPartitionerRunInfo()
{
PdfPartitionerRunInfoId = pdfPartitionerRunInfoId,
StartTimeStamp = Convert.ToDateTime("1/1/2022"),
PdfParserType = PdfParserTypes.FosLoanStatement,
Path = "\\\\Test\\Path",
IndexTotal = 3
};
_mockPdfPartitionerRunInfoRepository.Setup(x => x.FindByIdAsync(pdfPartitionerRunInfoId)).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _pdfPartitionerRunInfoService.Update(pdfPartitionerRunInfo));
_mockPdfPartitionerRunInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<Guid>()), Times.Once);
_mockPdfPartitionerRunInfoRepository.Verify(x => x.Update(It.IsAny<PdfPartitionerRunInfo>()), Times.Never);
}
[Test]
public void Update_Update_ThrowsException()
{
var pdfPartitionerRunInfoId = Guid.NewGuid();
var pdfPartitionerRunInfo = new PdfPartitionerRunInfo()
{
PdfPartitionerRunInfoId = pdfPartitionerRunInfoId,
StartTimeStamp = Convert.ToDateTime("1/1/2022"),
PdfParserType = PdfParserTypes.FosLoanStatement,
Path = "\\\\Test\\Path",
IndexTotal = 3
};
_mockPdfPartitionerRunInfoRepository.Setup(x => x.FindByIdAsync(pdfPartitionerRunInfoId)).ReturnsAsync(pdfPartitionerRunInfo);
_mockPdfPartitionerRunInfoRepository.Setup(x => x.Update(pdfPartitionerRunInfo)).Throws(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _pdfPartitionerRunInfoService.Update(pdfPartitionerRunInfo));
_mockPdfPartitionerRunInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<Guid>()), Times.Once);
_mockPdfPartitionerRunInfoRepository.Verify(x => x.Update(It.IsAny<PdfPartitionerRunInfo>()), Times.Once);
}
[Test]
public async Task Delete_Success()
{
var pdfPartitionerRunInfoId = Guid.NewGuid();
var pdfPartitionerRunInfo = new PdfPartitionerRunInfo()
{
PdfPartitionerRunInfoId = pdfPartitionerRunInfoId,
StartTimeStamp = Convert.ToDateTime("1/1/2022"),
PdfParserType = PdfParserTypes.FosLoanStatement,
Path = "\\\\Test\\Path",
IndexTotal = 3
};
_mockPdfPartitionerRunInfoRepository.Setup(x => x.FindByIdAsync(pdfPartitionerRunInfoId)).ReturnsAsync(pdfPartitionerRunInfo);
_mockPdfPartitionerRunInfoRepository.Setup(x => x.Remove(pdfPartitionerRunInfo));
await _pdfPartitionerRunInfoService.Delete(pdfPartitionerRunInfoId);
_mockPdfPartitionerRunInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<Guid>()), Times.Once);
_mockPdfPartitionerRunInfoRepository.Verify(x => x.Remove(It.IsAny<PdfPartitionerRunInfo>()), Times.Once);
}
[Test]
public void Delete_FindByIdAsync_ThrowsException()
{
var pdfPartitionerRunInfoId = Guid.NewGuid();
var pdfPartitionerRunInfo = new PdfPartitionerRunInfo()
{
PdfPartitionerRunInfoId = pdfPartitionerRunInfoId,
StartTimeStamp = Convert.ToDateTime("1/1/2022"),
PdfParserType = PdfParserTypes.FosLoanStatement,
Path = "\\\\Test\\Path",
IndexTotal = 3
};
_mockPdfPartitionerRunInfoRepository.Setup(x => x.FindByIdAsync(pdfPartitionerRunInfoId)).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _pdfPartitionerRunInfoService.Delete(pdfPartitionerRunInfoId));
_mockPdfPartitionerRunInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<Guid>()), Times.Once);
_mockPdfPartitionerRunInfoRepository.Verify(x => x.Remove(It.IsAny<PdfPartitionerRunInfo>()), Times.Never);
}
[Test]
public void Delete_Remove_ThrowsException()
{
var pdfPartitionerRunInfoId = Guid.NewGuid();
var pdfPartitionerRunInfo = new PdfPartitionerRunInfo()
{
PdfPartitionerRunInfoId = pdfPartitionerRunInfoId,
StartTimeStamp = Convert.ToDateTime("1/1/2022"),
PdfParserType = PdfParserTypes.FosLoanStatement,
Path = "\\\\Test\\Path",
IndexTotal = 3
};
_mockPdfPartitionerRunInfoRepository.Setup(x => x.FindByIdAsync(pdfPartitionerRunInfoId)).ReturnsAsync(pdfPartitionerRunInfo);
_mockPdfPartitionerRunInfoRepository.Setup(x => x.Remove(pdfPartitionerRunInfo)).Throws(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _pdfPartitionerRunInfoService.Delete(pdfPartitionerRunInfoId));
_mockPdfPartitionerRunInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<Guid>()), Times.Once);
_mockPdfPartitionerRunInfoRepository.Verify(x => x.Remove(It.IsAny<PdfPartitionerRunInfo>()), Times.Once);
}
}
@@ -0,0 +1,304 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Linq;
using Moq;
using NUnit.Framework;
using LCU.Library.Internal.DocumentIngestorModels.Entities;
using LCU.Library.Internal.Exceptions;
using LCU.API.Internal.DocumentIngestor.Services;
using LCU.API.Internal.DocumentIngestorLib.Repositories;
namespace LCU.API.Internal.DocumentIngestorTests.Services;
public class ProcessingLogServiceTest
{
private ProcessingLogService _processingLogService;
private Mock<IUnitOfWork> _unitOfWork;
private Mock<IProcessingLogRepository> _mockProcessingLogRepository;
[SetUp]
public void Setup()
{
_unitOfWork = new Mock<IUnitOfWork>();
_mockProcessingLogRepository = new Mock<IProcessingLogRepository>();
_processingLogService = new ProcessingLogService(_unitOfWork.Object, _mockProcessingLogRepository.Object);
}
[Test]
public async Task GetAsync_ProcessingLogs_Returned()
{
var documentProcessingInfoId = 1;
var processingLogId = 2;
var processingLogs = new List<ProcessingLog>()
{
new ProcessingLog()
{
ProcessingLogId = processingLogId,
DocumentProcessingInfoId = documentProcessingInfoId
}
};
_mockProcessingLogRepository.Setup(x => x.FindAsync()).ReturnsAsync(processingLogs);
var result = await _processingLogService.GetAsync();
Assert.IsNotNull(result);
Assert.AreEqual(1, result.Count());
_mockProcessingLogRepository.Verify(x => x.FindAsync(), Times.Once);
}
[Test]
public void GetAsync_Exception()
{
_mockProcessingLogRepository.Setup(x => x.FindAsync()).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _processingLogService.GetAsync());
_mockProcessingLogRepository.Verify(x => x.FindAsync(), Times.Once);
}
[Test]
public async Task GetByIdAsync_ProcessingLog_Returned()
{
var documentProcessingInfoId = 1;
var processingLogId = 2;
var processingLog = new ProcessingLog()
{
ProcessingLogId = processingLogId,
DocumentProcessingInfoId = documentProcessingInfoId
};
_mockProcessingLogRepository.Setup(x => x.FindByIdAsync(processingLogId)).ReturnsAsync(processingLog);
var result = await _processingLogService.GetByIdAsync(processingLogId);
Assert.IsNotNull(result);
Assert.AreEqual(documentProcessingInfoId, result.DocumentProcessingInfoId);
Assert.AreEqual(processingLogId, result.ProcessingLogId);
_mockProcessingLogRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>()), Times.Once);
}
[Test]
public void GetByIdAsync_Exception()
{
var processingLogId = 2;
_mockProcessingLogRepository.Setup(x => x.FindByIdAsync(processingLogId)).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _processingLogService.GetByIdAsync(processingLogId));
_mockProcessingLogRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>()), Times.Once);
}
[Test]
public async Task GetByDocumentProcessingInfoIdAsync_ProcessingLogs_Returned()
{
var documentProcessingInfoId = 1;
var processingLogId = 2;
var processingLogs = new List<ProcessingLog>()
{
new ProcessingLog()
{
ProcessingLogId = processingLogId,
DocumentProcessingInfoId = documentProcessingInfoId
}
};
_mockProcessingLogRepository.Setup(x => x.FindByDocumentProcessingInfoIdAsync(documentProcessingInfoId)).ReturnsAsync(processingLogs);
var result = await _processingLogService.GetByDocumentProcessingInfoIdAsync(documentProcessingInfoId);
Assert.IsNotNull(result);
Assert.AreEqual(1, result.Count());
_mockProcessingLogRepository.Verify(x => x.FindByDocumentProcessingInfoIdAsync(It.IsAny<int>()), Times.Once);
}
[Test]
public void GetByDocumentProcessingInfoIdAsync_Exception()
{
var documentProcessingInfoId = 1;
_mockProcessingLogRepository.Setup(x => x.FindByDocumentProcessingInfoIdAsync(documentProcessingInfoId)).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _processingLogService.GetByDocumentProcessingInfoIdAsync(documentProcessingInfoId));
_mockProcessingLogRepository.Verify(x => x.FindByDocumentProcessingInfoIdAsync(It.IsAny<int>()), Times.Once);
}
[Test]
public async Task SaveAsync_ProcessingLog_Returned()
{
var documentProcessingInfoId = 1;
var processingLogId = 2;
var processingLog = new ProcessingLog()
{
ProcessingLogId = processingLogId,
DocumentProcessingInfoId = documentProcessingInfoId
};
_mockProcessingLogRepository.Setup(x => x.AddAsync(processingLog)).ReturnsAsync(processingLog);
var result = await _processingLogService.SaveAsync(processingLog);
Assert.IsNotNull(result);
Assert.AreEqual(documentProcessingInfoId, result.DocumentProcessingInfoId);
Assert.AreEqual(processingLogId, result.ProcessingLogId);
_mockProcessingLogRepository.Verify(x => x.AddAsync(It.IsAny<ProcessingLog>()), Times.Once);
}
[Test]
public void SaveAsync_Exception()
{
var documentProcessingInfoId = 1;
var processingLogId = 2;
var processingLog = new ProcessingLog()
{
ProcessingLogId = processingLogId,
DocumentProcessingInfoId = documentProcessingInfoId
};
_mockProcessingLogRepository.Setup(x => x.AddAsync(processingLog)).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _processingLogService.SaveAsync(processingLog));
_mockProcessingLogRepository.Verify(x => x.AddAsync(It.IsAny<ProcessingLog>()), Times.Once);
}
[Test]
public async Task SaveRangeAsync_ProcessingLog_Returned()
{
var processingLogs = new List<ProcessingLog>
{
new()
{
ProcessingLogId = DateTime.Now.Millisecond,
DocumentProcessingInfoId = DateTime.Now.Millisecond
},
new()
{
ProcessingLogId = DateTime.Now.Millisecond + 1,
DocumentProcessingInfoId = DateTime.Now.Millisecond
},
new()
{
ProcessingLogId = DateTime.Now.Millisecond + 2,
DocumentProcessingInfoId = DateTime.Now.Millisecond
}
};
_mockProcessingLogRepository.Setup(x => x.AddRangeAsync(processingLogs));
await _processingLogService.SaveRangeAsync(processingLogs);
_mockProcessingLogRepository.Verify(x => x.AddRangeAsync(It.IsAny<IEnumerable<ProcessingLog>>()), Times.Once);
}
[Test]
public void SaveRangeAsync_Exception()
{
var processingLogs = new List<ProcessingLog>
{
new()
{
ProcessingLogId = DateTime.Now.Millisecond,
DocumentProcessingInfoId = DateTime.Now.Millisecond
},
new()
{
ProcessingLogId = DateTime.Now.Millisecond + 1,
DocumentProcessingInfoId = DateTime.Now.Millisecond
},
new()
{
ProcessingLogId = DateTime.Now.Millisecond + 2,
DocumentProcessingInfoId = DateTime.Now.Millisecond
}
};
_mockProcessingLogRepository.Setup(x => x.AddRangeAsync(processingLogs)).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _processingLogService.SaveRangeAsync(processingLogs));
_mockProcessingLogRepository.Verify(x => x.AddRangeAsync(It.IsAny<IEnumerable<ProcessingLog>>()), Times.Once);
}
[Test]
public async Task Update_ProcessingLog_Returned()
{
var documentProcessingInfoId = 1;
var processingLogId = 2;
var processingLog = new ProcessingLog()
{
ProcessingLogId = processingLogId,
DocumentProcessingInfoId = documentProcessingInfoId
};
_mockProcessingLogRepository.Setup(x => x.FindByIdAsync(processingLogId)).ReturnsAsync(processingLog);
_mockProcessingLogRepository.Setup(x => x.Update(processingLog));
var result = await _processingLogService.Update(processingLog);
Assert.IsNotNull(result);
Assert.AreEqual(documentProcessingInfoId, result.DocumentProcessingInfoId);
Assert.AreEqual(processingLogId, result.ProcessingLogId);
_mockProcessingLogRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>()), Times.Once);
_mockProcessingLogRepository.Verify(x => x.Update(It.IsAny<ProcessingLog>()), Times.Once);
}
[Test]
public void Update_FindByIdAsync_ThrowsException()
{
var documentProcessingInfoId = 1;
var processingLogId = 2;
var processingLog = new ProcessingLog()
{
ProcessingLogId = processingLogId,
DocumentProcessingInfoId = documentProcessingInfoId
};
_mockProcessingLogRepository.Setup(x => x.FindByIdAsync(processingLogId)).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _processingLogService.Update(processingLog));
_mockProcessingLogRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>()), Times.Once);
_mockProcessingLogRepository.Verify(x => x.Update(It.IsAny<ProcessingLog>()), Times.Never);
}
[Test]
public void Update_Update_ThrowsException()
{
var documentProcessingInfoId = 1;
var processingLogId = 2;
var processingLog = new ProcessingLog()
{
ProcessingLogId = processingLogId,
DocumentProcessingInfoId = documentProcessingInfoId
};
_mockProcessingLogRepository.Setup(x => x.FindByIdAsync(processingLogId)).ReturnsAsync(processingLog);
_mockProcessingLogRepository.Setup(x => x.Update(processingLog)).Throws(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _processingLogService.Update(processingLog));
_mockProcessingLogRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>()), Times.Once);
_mockProcessingLogRepository.Verify(x => x.Update(It.IsAny<ProcessingLog>()), Times.Once);
}
[Test]
public async Task Delete_Success()
{
var documentProcessingInfoId = 1;
var processingLogId = 2;
var processingLog = new ProcessingLog()
{
ProcessingLogId = processingLogId,
DocumentProcessingInfoId = documentProcessingInfoId
};
_mockProcessingLogRepository.Setup(x => x.FindByIdAsync(processingLogId)).ReturnsAsync(processingLog);
_mockProcessingLogRepository.Setup(x => x.Remove(processingLog));
await _processingLogService.Delete(processingLogId);
_mockProcessingLogRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>()), Times.Once);
_mockProcessingLogRepository.Verify(x => x.Remove(It.IsAny<ProcessingLog>()), Times.Once);
}
[Test]
public void Delete_FindByIdAsync_ThrowsException()
{
var documentProcessingInfoId = 1;
var processingLogId = 2;
var processingLog = new ProcessingLog()
{
ProcessingLogId = processingLogId,
DocumentProcessingInfoId = documentProcessingInfoId
};
_mockProcessingLogRepository.Setup(x => x.FindByIdAsync(processingLogId)).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _processingLogService.Delete(processingLogId));
_mockProcessingLogRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>()), Times.Once);
_mockProcessingLogRepository.Verify(x => x.Remove(It.IsAny<ProcessingLog>()), Times.Never);
}
[Test]
public void Delete_Remove_ThrowsException()
{
var documentProcessingInfoId = 1;
var processingLogId = 2;
var processingLog = new ProcessingLog()
{
ProcessingLogId = processingLogId,
DocumentProcessingInfoId = documentProcessingInfoId
};
_mockProcessingLogRepository.Setup(x => x.FindByIdAsync(processingLogId)).ReturnsAsync(processingLog);
_mockProcessingLogRepository.Setup(x => x.Remove(processingLog)).Throws(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _processingLogService.Delete(processingLogId));
_mockProcessingLogRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>()), Times.Once);
_mockProcessingLogRepository.Verify(x => x.Remove(It.IsAny<ProcessingLog>()), Times.Once);
}
}
@@ -0,0 +1,251 @@
using System;
using System.Threading.Tasks;
using System.Linq;
using Moq;
using NUnit.Framework;
using LCU.API.Internal.DocumentIngestor.Services;
using LCU.Library.Internal.DocumentIngestorModels.Entities;
using LCU.Library.Internal.DocumentIngestorModels.Enums;
using LCU.API.Internal.DocumentIngestor.Configurations;
using LCU.API.Internal.DocumentIngestor.Services.IngestionOperationServices;
using LCU.API.Internal.DocumentIngestor.Services.MicroApiServices;
using LCU.Library.DocumentType.Models.Responses.External;
using LCU.Library.Internal.ApiResponse.Models;
using LCU.Library.Internal.Exceptions;
using Serilog;
using System.Collections.Generic;
namespace LCU.API.Internal.DocumentIngestorTests.Services;
public class UploadCompletionReprocessingServiceTest
{
private UploadCompletionReprocessingService _uploadCompletionReprocessingService;
private Mock<IIngestorRunInfoService> _mockIngestorRunInfoService;
private Mock<IDocumentProcessingInfoService> _mockDocumentProcessingInfoService;
private Mock<IUploadCompletionService> _mockUploadCompletionService;
private Mock<IDocumentTypeRetrieverService> _mockDocumentTypeRetrieverService;
private ApiConfiguration _apiConfiguration;
private readonly Mock<ILogger> _logger = new();
private readonly ILogger _originalLogger = Log.Logger;
[SetUp]
public void Setup()
{
Log.Logger = _logger.Object;
_mockIngestorRunInfoService = new Mock<IIngestorRunInfoService>();
_mockDocumentProcessingInfoService = new Mock<IDocumentProcessingInfoService>();
_mockDocumentTypeRetrieverService = new Mock<IDocumentTypeRetrieverService>();
_mockUploadCompletionService = new Mock<IUploadCompletionService>();
_apiConfiguration = new ApiConfiguration();
_uploadCompletionReprocessingService = new UploadCompletionReprocessingService(_mockIngestorRunInfoService.Object,
_mockDocumentProcessingInfoService.Object,
_mockDocumentTypeRetrieverService.Object,
_mockUploadCompletionService.Object,
_apiConfiguration);
}
[TearDown]
public void TearDown()
{
Log.Logger = _originalLogger;
}
[Test]
public async Task QueueReprocessUploadCompletionByDocumentProcessingInfoId_Success()
{
var documentProcessingInfoId = DateTime.Now.Millisecond;
var userName = Guid.NewGuid().ToString();
var documentProcessingInfo = SetupGetDocumentProcessingInfo(documentProcessingInfoId);
var ingestorRunInfo = SetupGetIngestorRunInfo(documentProcessingInfo.IngestorRunInfoId);
SetupDocumentInformation(documentProcessingInfo.DocumentId);
_mockDocumentProcessingInfoService.Setup(x => x.UpdateStatusAndAddLog(documentProcessingInfoId,
documentProcessingInfo.StatusType,
It.IsAny<string>(),
userName,
It.IsAny<bool?>())).ReturnsAsync(documentProcessingInfo);
await _uploadCompletionReprocessingService.QueueReprocessUploadCompletionByDocumentProcessingInfoId(documentProcessingInfoId, userName);
_mockDocumentProcessingInfoService.Verify(x => x.GetByIdAsync(documentProcessingInfoId), Times.Once);
_mockIngestorRunInfoService.Verify(x => x.GetByIdAsync(ingestorRunInfo.IngestorRunInfoId), Times.Once);
_mockDocumentTypeRetrieverService.Verify(x => x.GetDocumentInformationById(documentProcessingInfo.DocumentId ?? Guid.Empty), Times.Once);
_mockDocumentProcessingInfoService.Verify(x => x.UpdateStatusAndAddLog(documentProcessingInfoId,
It.IsAny<ProcessStatusTypes>(),
It.IsAny<string>(),
userName,
It.IsAny<bool?>()), Times.Once);
_mockUploadCompletionService.Verify(x => x.HandleUploadCompletion(It.IsAny<List<Response>>()), Times.Once);
}
[Test]
public void QueueReprocessUploadCompletionByDocumentProcessingInfoId_Failure_Exception()
{
var id = DateTime.Now.Millisecond;
var userName = Guid.NewGuid().ToString();
_mockDocumentProcessingInfoService.Setup(x => x.GetByIdAsync(id)).ThrowsAsync(new Exception("Test Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _uploadCompletionReprocessingService
.QueueReprocessUploadCompletionByDocumentProcessingInfoId(id, userName));
_mockDocumentProcessingInfoService.Verify(x => x.GetByIdAsync(It.IsAny<int>()), Times.Once);
_mockIngestorRunInfoService.Verify(x => x.GetByIdAsync(It.IsAny<Guid>()), Times.Never);
_mockDocumentTypeRetrieverService.Verify(x => x.GetDocumentInformationById(It.IsAny<Guid>()), Times.Never);
_mockDocumentProcessingInfoService.Verify(x => x.UpdateStatusAndAddLog(It.IsAny<int>(),
It.IsAny<ProcessStatusTypes>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<bool?>()), Times.Never);
_mockUploadCompletionService.Verify(x => x.HandleUploadCompletion(It.IsAny<List<Response>>()), Times.Never);
}
[Test]
public void QueueReprocessUploadCompletionByDocumentProcessingInfoId_Failure_ArgumentNullException()
{
var id = DateTime.Now.Millisecond;
var userName = Guid.NewGuid().ToString();
_mockDocumentProcessingInfoService.Setup(x => x.GetByIdAsync(id)).ThrowsAsync(new ArgumentNullException("Test Error"));
Assert.ThrowsAsync<ArgumentNullException>(async () => await _uploadCompletionReprocessingService
.QueueReprocessUploadCompletionByDocumentProcessingInfoId(id, userName));
_mockDocumentProcessingInfoService.Verify(x => x.GetByIdAsync(id), Times.Once);
_mockIngestorRunInfoService.Verify(x => x.GetByIdAsync(It.IsAny<Guid>()), Times.Never);
_mockDocumentProcessingInfoService.Verify(x => x.UpdateStatusAndAddLog(It.IsAny<int>(),
It.IsAny<ProcessStatusTypes>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<bool?>()), Times.Never);
_mockUploadCompletionService.Verify(x => x.HandleUploadCompletion(It.IsAny<List<Response>>()), Times.Never);
}
[Test]
public void QueueReprocessAllNotificationDataFailures_InfoServiceThrowsArgumentNull_ThrowsServiceException()
{
var processStatus = ProcessStatusTypes.NotificationDataFailure;
_mockDocumentProcessingInfoService
.Setup(s => s.GetByProcessStatusTypeAsync(processStatus, null))
.ThrowsAsync(new ArgumentNullException());
Assert.ThrowsAsync<ServiceException>(() => _uploadCompletionReprocessingService.QueueReprocessAllNotificationDataFailures(Guid.NewGuid().ToString()));
}
[Test]
public async Task QueueReprocessAllNotificationDataFailures_InfoServiceThrows_ThrowsServiceException()
{
var processStatus = ProcessStatusTypes.NotificationDataFailure;
_mockDocumentProcessingInfoService
.Setup(s => s.GetByProcessStatusTypeAsync(processStatus, null))
.ThrowsAsync(new Exception());
Assert.ThrowsAsync<ServiceException>(() => _uploadCompletionReprocessingService.QueueReprocessAllNotificationDataFailures(Guid.NewGuid().ToString()));
}
[Test]
public async Task QueueReprocessAllNotificationDataFailures_InfoServiceReturnsMoreThanLimit_RequeuesUpToLimit()
{
var id = DateTime.Now.Millisecond;
var username = Guid.NewGuid().ToString();
var notificationDataFailures = Enumerable
.Repeat(() => SetupGetDocumentProcessingInfo(id), 16)
.Select(f => f())
.ToArray();
foreach (var info in notificationDataFailures)
{
SetupGetIngestorRunInfo(info.IngestorRunInfoId);
SetupDocumentInformation(info.DocumentId);
}
var processStatus = ProcessStatusTypes.NotificationDataFailure;
_apiConfiguration.NotificationDataFailureReprocessLimit = notificationDataFailures.Length / 2;
_mockDocumentProcessingInfoService
.Setup(s => s.GetByProcessStatusTypeAsync(processStatus, null))
.ReturnsAsync(notificationDataFailures);
await _uploadCompletionReprocessingService.QueueReprocessAllNotificationDataFailures(username);
_mockDocumentProcessingInfoService
.Verify
(
s => s.UpdateStatusAndAddLog
(
It.Is<int>(id => notificationDataFailures.Any(f => f.DocumentProcessingInfoId == id)),
ProcessStatusTypes.UploadCompletionReprocessing,
It.IsAny<string>(),
username,
It.IsAny<bool?>()
),
Times.Exactly(_apiConfiguration.NotificationDataFailureReprocessLimit)
);
_mockUploadCompletionService
.Verify
(
dp => dp.HandleUploadCompletion
(
It.IsAny<List<Response>>()
),
Times.Exactly(_apiConfiguration.NotificationDataFailureReprocessLimit)
);
}
private DocumentProcessingInfo SetupGetDocumentProcessingInfo(int id)
{
var info = new DocumentProcessingInfo
{
IngestorRunInfoId = Guid.NewGuid(),
CreatedDate = DateTime.Now,
DocumentValuePayload = Guid.NewGuid().ToString(),
StatusType = Random<ProcessStatusTypes>(),
DocumentFileName = Guid.NewGuid().ToString(),
ProcessCount = DateTime.Now.Millisecond,
DocumentType = "EAgreement",
DocumentBusinessName = Guid.NewGuid().ToString(),
DocumentProcessingInfoId = id,
DocumentId = Guid.NewGuid()
};
_mockDocumentProcessingInfoService
.Setup(s => s.GetByIdAsync(id))
.ReturnsAsync(info);
return info;
}
private IngestorRunInfo SetupGetIngestorRunInfo(Guid ingestorRunInfoId)
{
var info = new IngestorRunInfo
{
IngestorRunInfoId = ingestorRunInfoId,
StartTimeStamp = DateTime.Now,
IngestorType = Random<IngestorTypes>(),
IndexFileName = Guid.NewGuid().ToString(),
IndexFilePath = Guid.NewGuid().ToString(),
IndexTotal = DateTime.Now.Millisecond
};
_mockIngestorRunInfoService
.Setup(s => s.GetByIdAsync(ingestorRunInfoId))
.ReturnsAsync(info);
return info;
}
private EnrichedDocumentMetadataResponse SetupDocumentInformation(Guid? documentId)
{
var info = new EnrichedDocumentMetadataResponse()
{
DocumentId = documentId ?? Guid.Empty,
Type = "LnNent",
PersonNumbers = new[] { "123" },
AccountNumber = 345
};
_mockDocumentTypeRetrieverService
.Setup(s => s.GetDocumentInformationById(documentId ?? Guid.Empty))
.ReturnsAsync(info);
return info;
}
private static T Random<T>() where T : struct, Enum => Enum.GetValues<T>()[DateTime.Now.Millisecond % (Enum.GetValues<T>().Length - 1)];
}