171 lines
5.3 KiB
C#
171 lines
5.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Moq;
|
|
using NUnit.Framework;
|
|
using LCU.Api.Internal.ArchiverApi.Services;
|
|
using LCU.Library.Internal.ArchiverApiModel.Models;
|
|
using LCU.Library.Internal.FileOperationsModels.Models.NameSettings;
|
|
using LCU.Library.Internal.FileOperationsModels.Models;
|
|
using LCU.Api.Internal.ArchiverApi.Configuration;
|
|
using LCU.Library.Internal.LcuMassTransitModels;
|
|
using LCU.Library.Internal.ArchiverApiModel.Entities;
|
|
namespace LCU.Api.Internal.ArchiverApiTest;
|
|
|
|
public class ArchiverServiceTest
|
|
{
|
|
private ArchiverService _archiverService;
|
|
private Mock<IReportService> _mockReportService;
|
|
private Mock<IFileOperationsService> _mockFileOperationsService;
|
|
|
|
[SetUp]
|
|
public void Setup()
|
|
{
|
|
var config = new ArchiverApiConfig()
|
|
{
|
|
ReportPathDateFormat = "yyyyMMdd"
|
|
};
|
|
var connectionConfig = new ConnectionConfiguration();
|
|
var receiveEndpointConfigurations = new ReceiveEndpointConfigurations();
|
|
|
|
_mockReportService = new Mock<IReportService>();
|
|
_mockFileOperationsService = new Mock<IFileOperationsService>();
|
|
_archiverService = new ArchiverService(config,
|
|
_mockReportService.Object,
|
|
_mockFileOperationsService.Object,
|
|
connectionConfig,
|
|
receiveEndpointConfigurations);
|
|
}
|
|
|
|
[Test]
|
|
public void BuildRegexString_WithLisAndCsv()
|
|
{
|
|
var archiveRequest = new ArchiveRequest()
|
|
{
|
|
AllowedExensions = new List<string>() { "lis", "csv" }
|
|
};
|
|
|
|
var result = _archiverService.BuildExtensionRegexString(archiveRequest);
|
|
Assert.AreEqual("((?i)lis(?-i)|(?i)csv(?-i)|)$", result);
|
|
}
|
|
|
|
[Test]
|
|
public void CreateOperationRequests_CreateTwoRequests()
|
|
{
|
|
|
|
var report = new Report()
|
|
{
|
|
ReportName = "test",
|
|
ApplicationMapping = new ApplicationMapping()
|
|
{
|
|
DesignatedName = null
|
|
}
|
|
};
|
|
var dynamicNameSetting = new DynamicNameSetting();
|
|
var archiveRequest = new ArchiveRequest()
|
|
{
|
|
AllowedExensions = new List<string>() { "lis", "csv" }
|
|
};
|
|
var files = new List<string>() { "test1", "test2" };
|
|
_mockFileOperationsService.Setup(x => x.BuildDynamicFileListAsync(It.IsAny<string>(), It.IsAny<string>(), dynamicNameSetting)).ReturnsAsync(files);
|
|
|
|
var results = _archiverService.CreateOperationRequests(report, dynamicNameSetting, archiveRequest);
|
|
Assert.NotNull(results);
|
|
Assert.AreEqual(2, results.Count);
|
|
}
|
|
|
|
[Test]
|
|
public void SetDestinationName_SetCorrectDestination()
|
|
{
|
|
var testReport = new Report()
|
|
{
|
|
ReportName = "Test",
|
|
QueueNumber = "1234",
|
|
StopDateTime = Convert.ToDateTime("1/1/2021"),
|
|
ApplicationMapping = new ApplicationMapping()
|
|
};
|
|
|
|
var testRequest = new MoveFileRequest()
|
|
{
|
|
SourceFile = "Test.lis"
|
|
};
|
|
|
|
var archiveRequest = new ArchiveRequest()
|
|
{
|
|
AllowedExensions = new List<string>() { "lis", "csv" }
|
|
};
|
|
|
|
_archiverService.SetDestinationName(testReport, testRequest, archiveRequest);
|
|
|
|
Assert.NotNull(testRequest);
|
|
Assert.NotNull(testRequest.DestinationName);
|
|
}
|
|
|
|
[Test]
|
|
public void SetDestinationName_ExtentionNotSupported_DestinationNameNull()
|
|
{
|
|
var testReport = new Report()
|
|
{
|
|
ReportName = "Test",
|
|
QueueNumber = "1234",
|
|
StopDateTime = Convert.ToDateTime("1/1/2021")
|
|
};
|
|
|
|
var testRequest = new MoveFileRequest()
|
|
{
|
|
SourceFile = "Test.txt"
|
|
};
|
|
|
|
var archiveRequest = new ArchiveRequest()
|
|
{
|
|
AllowedExensions = new List<string>() { "lis", "csv" }
|
|
};
|
|
|
|
_archiverService.SetDestinationName(testReport, testRequest, archiveRequest);
|
|
|
|
Assert.NotNull(testRequest);
|
|
Assert.Null(testRequest.DestinationName);
|
|
}
|
|
|
|
[Test]
|
|
public void SetUpNameSettings_NoApplicationMapping()
|
|
{
|
|
var testReport = new Report()
|
|
{
|
|
ReportName = "Test",
|
|
QueueNumber = "1234",
|
|
StopDateTime = Convert.ToDateTime("1/1/2021"),
|
|
};
|
|
|
|
var nameSettings = _archiverService.SetUpNameSettings(testReport);
|
|
|
|
Assert.NotNull(nameSettings);
|
|
Assert.AreEqual(nameSettings.RegexSettings.Count, 2);
|
|
}
|
|
|
|
[Test]
|
|
public void SetUpNameSettings_HasApplicationMapping()
|
|
{
|
|
var testReport = new Report()
|
|
{
|
|
ReportName = "Test",
|
|
QueueNumber = "1234",
|
|
StopDateTime = Convert.ToDateTime("1/1/2021"),
|
|
ApplicationMapping = new ApplicationMapping()
|
|
{
|
|
RegexMappings = new List<RegexMapping>
|
|
{
|
|
new RegexMapping()
|
|
{
|
|
Tag = "{Regex10}",
|
|
Regex = "[0-9]"
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
var nameSettings = _archiverService.SetUpNameSettings(testReport);
|
|
|
|
Assert.NotNull(nameSettings);
|
|
Assert.AreEqual(nameSettings.RegexSettings.Count, 3);
|
|
}
|
|
} |