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 _mockAccountOwnerDeterminingService; private Mock _mockFileOperationsApiService; private Mock _mockDocumentTypeUploaderApiService; [SetUp] public void Setup() { _mockAccountOwnerDeterminingService = new Mock(); _mockFileOperationsApiService = new Mock(); _mockDocumentTypeUploaderApiService = new Mock(); var serviceFactoryConfiguration = new ServicesFactoryConfiguration { ServiceFactoryRegistrations = new List { new() { ServiceInterfaceName = "IIndexParserService", ServiceRegistrations = new List { 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(), It.IsAny(), DateTime.Now, It.IsAny()), Times.Never); _mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny(), It.IsAny()), Times.Never); _mockDocumentTypeUploaderApiService.Verify(x => x.UploadAccountDocument(It.IsAny(), It.IsAny(), It.IsAny()), 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(), It.IsAny(), DateTime.Now, It.IsAny()), Times.Never); _mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny(), It.IsAny()), Times.Never); _mockDocumentTypeUploaderApiService.Verify(x => x.UploadAccountDocument(It.IsAny(), It.IsAny(), It.IsAny()), 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(), It.IsAny(), DateTime.Now, It.IsAny()), Times.Never); _mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny(), It.IsAny()), Times.Never); _mockDocumentTypeUploaderApiService.Verify(x => x.UploadAccountDocument(It.IsAny(), It.IsAny(), It.IsAny()), 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.CreateErrorPayload("Error from unit test", null); _mockAccountOwnerDeterminingService.Verify(x => x.DetermineAccountOwnerAttribute(It.IsAny(), It.IsAny(), DateTime.Now, It.IsAny()), 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(), It.IsAny(), DateTime.Now, It.IsAny()), Times.Never); _mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny(), It.IsAny()), Times.Never); _mockDocumentTypeUploaderApiService.Verify(x => x.UploadAccountDocument(It.IsAny(), It.IsAny(), It.IsAny()), Times.Never); } }