732 lines
31 KiB
C#
732 lines
31 KiB
C#
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));
|
|
}
|
|
}
|
|
|