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

166 lines
6.5 KiB
C#

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