Files
monorepo/LCU.API.Internal.DocumentIngestor/LCU.API.Internal.DocumentIngestorTests/Services/DocumentProcessorServices/OsgDnaNoticesProcessingServiceTest.cs
T
2026-03-25 14:50:13 -05:00

467 lines
16 KiB
C#

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
);
}
}