Updating
This commit is contained in:
+49
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using LCU.Api.Internal.ArchiverApi.Controllers;
|
||||
using LCU.Api.Internal.ArchiverApi.Services;
|
||||
using LCU.Library.Internal.ArchiverApiModel.Models;
|
||||
namespace LCU.Api.Internal.ArchiverApiTest;
|
||||
|
||||
public class QueueArchiverControllerTest
|
||||
{
|
||||
private QueueArchiverController _queueArchiverController;
|
||||
private Mock<IQueueArchiverService> _mockQueueArchiverService;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_mockQueueArchiverService = new Mock<IQueueArchiverService>();
|
||||
_queueArchiverController = new QueueArchiverController(_mockQueueArchiverService.Object);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void QueueArchiver_OK()
|
||||
{
|
||||
var archiveRequest = new ArchiveRequest();
|
||||
_mockQueueArchiverService.Setup(x => x.QueueArchiver(archiveRequest));
|
||||
var result = _queueArchiverController.QueueArchiver(archiveRequest);
|
||||
|
||||
Assert.NotNull(result);
|
||||
var okResult = result as OkResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void QueueArchiver_Exception()
|
||||
{
|
||||
_mockQueueArchiverService.Setup(x => x.QueueArchiver(It.IsAny<ArchiveRequest>()))
|
||||
.Throws(new Exception("Oh nooo."));
|
||||
|
||||
var archiveRequest = new ArchiveRequest();
|
||||
var results = _queueArchiverController.QueueArchiver(archiveRequest);
|
||||
|
||||
Assert.NotNull(results);
|
||||
var badRes = results as StatusCodeResult;
|
||||
Assert.NotNull(badRes);
|
||||
Assert.AreEqual(500, badRes.StatusCode);
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="LCU.Library.Internal.LcuMassTransitModels" Version="1.1.0" />
|
||||
<PackageReference Include="Moq" Version="4.16.1" />
|
||||
<PackageReference Include="NUnit" Version="3.12.0" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\LCU.Api.Internal.ArchiverApi\LCU.Api.Internal.ArchiverApi.csproj" />
|
||||
<ProjectReference Include="..\LCU.Library.Internal.ArchiverApiModel\LCU.Library.Internal.ArchiverApiModel.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
+171
@@ -0,0 +1,171 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using LCU.Api.Internal.ArchiverApi.Services;
|
||||
using LCU.Api.Internal.ArchiverApi.Configuration;
|
||||
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.CoreRequests;
|
||||
namespace LCU.Api.Internal.ArchiverApiTest;
|
||||
|
||||
public class CoreApiWrapperServiceTest
|
||||
{
|
||||
private CoreApiWrapperService _coreApiWrapperService;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
var archiveApiConfig = new ArchiverApiConfig()
|
||||
{
|
||||
CoreApiWrapperGetApplicationHistory = "https://TEST/GetApplicationHistory"
|
||||
};
|
||||
_coreApiWrapperService = new CoreApiWrapperService(archiveApiConfig);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SetUpEndpoint_SetCorrect()
|
||||
{
|
||||
var applicationHistoryRequest = new ApplicationHistoryRequest()
|
||||
{
|
||||
ApplicationNumbers = new List<string> { "1", "2" },
|
||||
EffectiveDate = Convert.ToDateTime("1/1/2021").ToString()
|
||||
};
|
||||
|
||||
var request = _coreApiWrapperService.SetUpUrl(applicationHistoryRequest);
|
||||
|
||||
Assert.NotNull(request);
|
||||
var testUrl = $"https://TEST/GetApplicationHistory?ApplicationNumbers=1&ApplicationNumbers=2&" +
|
||||
"EffectiveDate=" + Convert.ToDateTime("1/1/2021").ToString();
|
||||
Assert.AreEqual(testUrl, request);
|
||||
}
|
||||
}
|
||||
+280
@@ -0,0 +1,280 @@
|
||||
using LCU.Api.Internal.ArchiverApi.Services;
|
||||
using LCU.Library.Internal.ArchiverApiLib.Repositories;
|
||||
using LCU.Library.Internal.ArchiverApiModel.Entities;
|
||||
using LCU.Library.Internal.Exceptions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LCU.Api.Internal.ArchiverApiTest.Services
|
||||
{
|
||||
public class RegexMappingServiceTest
|
||||
{
|
||||
private Mock<IUnitOfWork> mockUnitOfWork;
|
||||
private Mock<IRegexMappingRepository> mockRegexMappingRepository;
|
||||
|
||||
private RegexMappingService service;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
mockRegexMappingRepository = new Mock<IRegexMappingRepository>();
|
||||
|
||||
service = new RegexMappingService(
|
||||
mockUnitOfWork.Object, mockRegexMappingRepository.Object);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Post_Success()
|
||||
{
|
||||
mockRegexMappingRepository.Setup(repository => repository.AddAsync(It.IsAny<RegexMapping>()))
|
||||
.ReturnsAsync(new RegexMapping()
|
||||
{
|
||||
RegexMappingId = 1,
|
||||
ApplicationMappingId = 1,
|
||||
Tag = "{Regex5}",
|
||||
Regex = "[0-9]"
|
||||
})
|
||||
.Verifiable();
|
||||
|
||||
var regexMappingResponse = await service.SaveAsync(new RegexMapping()
|
||||
{
|
||||
ApplicationMappingId = 1,
|
||||
Tag = "{Regex5}",
|
||||
Regex = "[0-9]"
|
||||
});
|
||||
|
||||
Assert.NotNull(regexMappingResponse);
|
||||
|
||||
Assert.NotZero(regexMappingResponse.RegexMappingId);
|
||||
Assert.AreEqual(1, regexMappingResponse.ApplicationMappingId);
|
||||
Assert.AreEqual("{Regex5}", regexMappingResponse.Tag);
|
||||
Assert.AreEqual("[0-9]", regexMappingResponse.Regex);
|
||||
|
||||
mockUnitOfWork.Verify(x => x.CompleteAsync(), Times.Once);
|
||||
mockRegexMappingRepository.Verify(x => x.AddAsync(It.IsAny<RegexMapping>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Post_InvalidTag()
|
||||
{
|
||||
Assert.ThrowsAsync<ServiceException>(async () =>
|
||||
await service.SaveAsync(new RegexMapping()
|
||||
{
|
||||
ApplicationMappingId = 1,
|
||||
Tag = "{Regex1}",
|
||||
Regex = "[0-9]"
|
||||
}));
|
||||
|
||||
mockUnitOfWork.Verify(x => x.CompleteAsync(), Times.Never);
|
||||
mockRegexMappingRepository.Verify(x => x.AddAsync(It.IsAny<RegexMapping>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Post_Exception()
|
||||
{
|
||||
mockRegexMappingRepository.Setup(repository => repository.AddAsync(It.IsAny<RegexMapping>()))
|
||||
.ThrowsAsync(new Exception("Test")).Verifiable();
|
||||
|
||||
Assert.ThrowsAsync<ServiceException>(async () =>
|
||||
await service.SaveAsync(new RegexMapping()
|
||||
{
|
||||
ApplicationMappingId = 1,
|
||||
Tag = "{Regex5}",
|
||||
Regex = "[0-9]"
|
||||
}));
|
||||
|
||||
mockUnitOfWork.Verify(x => x.CompleteAsync(), Times.Never);
|
||||
mockRegexMappingRepository.Verify(x => x.AddAsync(It.IsAny<RegexMapping>()), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetByApplicationMappingId_Success()
|
||||
{
|
||||
mockRegexMappingRepository.Setup(repository => repository.FindByApplicationMappingIdAsync(It.IsAny<int>()))
|
||||
.ReturnsAsync(new RegexMapping()
|
||||
{
|
||||
RegexMappingId = 1,
|
||||
ApplicationMappingId = 1,
|
||||
Tag = "{Regex5}",
|
||||
Regex = "[0-9]"
|
||||
});
|
||||
|
||||
var regexMappingResponse = await service.GetByApplicationMappingIdAsync(1);
|
||||
|
||||
Assert.NotNull(regexMappingResponse);
|
||||
|
||||
Assert.NotZero(regexMappingResponse.RegexMappingId);
|
||||
Assert.AreEqual(1, regexMappingResponse.ApplicationMappingId);
|
||||
Assert.AreEqual("{Regex5}", regexMappingResponse.Tag);
|
||||
Assert.AreEqual("[0-9]", regexMappingResponse.Regex);
|
||||
|
||||
mockRegexMappingRepository.Verify(x => x.FindByApplicationMappingIdAsync(It.IsAny<int>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetByApplicationMappingId_Exception()
|
||||
{
|
||||
mockRegexMappingRepository.Setup(repository => repository.FindByRegexMappingIdAsync(It.IsAny<int>()))
|
||||
.ThrowsAsync(new Exception("Test")).Verifiable();
|
||||
|
||||
Assert.ThrowsAsync<ServiceException>(async () =>
|
||||
await service.GetByApplicationMappingIdAsync(1));
|
||||
|
||||
mockRegexMappingRepository.Verify(x => x.FindByApplicationMappingIdAsync(It.IsAny<int>()), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetByregexMappingId_Success()
|
||||
{
|
||||
mockRegexMappingRepository.Setup(repository => repository.FindByRegexMappingIdAsync(It.IsAny<int>()))
|
||||
.ReturnsAsync(new RegexMapping()
|
||||
{
|
||||
RegexMappingId = 1,
|
||||
ApplicationMappingId = 1,
|
||||
Tag = "{Regex5}",
|
||||
Regex = "[0-9]"
|
||||
});
|
||||
|
||||
var regexMappingResponse = await service.GetByRegexMappingIdAsync(1);
|
||||
|
||||
Assert.NotNull(regexMappingResponse);
|
||||
|
||||
Assert.NotZero(regexMappingResponse.RegexMappingId);
|
||||
Assert.AreEqual(1, regexMappingResponse.ApplicationMappingId);
|
||||
Assert.AreEqual("{Regex5}", regexMappingResponse.Tag);
|
||||
Assert.AreEqual("[0-9]", regexMappingResponse.Regex);
|
||||
|
||||
mockRegexMappingRepository.Verify(x => x.FindByRegexMappingIdAsync(It.IsAny<int>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetByRegexMappingId_Exception()
|
||||
{
|
||||
mockRegexMappingRepository.Setup(repository => repository.FindByRegexMappingIdAsync(It.IsAny<int>()))
|
||||
.ThrowsAsync(new Exception("Test")).Verifiable();
|
||||
|
||||
Assert.ThrowsAsync<ServiceException>(async () =>
|
||||
await service.GetByRegexMappingIdAsync(1));
|
||||
|
||||
mockUnitOfWork.Verify(x => x.CompleteAsync(), Times.Never);
|
||||
mockRegexMappingRepository.Verify(x => x.FindByRegexMappingIdAsync(It.IsAny<int>()), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Update_Success()
|
||||
{
|
||||
var originalRegex = new RegexMapping()
|
||||
{
|
||||
RegexMappingId = 1,
|
||||
ApplicationMappingId = 1,
|
||||
Tag = "{Regex5}",
|
||||
Regex = "[0-9]"
|
||||
};
|
||||
|
||||
var updatedRegex = new RegexMapping()
|
||||
{
|
||||
RegexMappingId = 1,
|
||||
ApplicationMappingId = 2,
|
||||
Tag = "{Regex50}",
|
||||
Regex = "[0-9]*"
|
||||
};
|
||||
|
||||
mockRegexMappingRepository.Setup(repository => repository.FindByRegexMappingIdAsync(It.IsAny<int>()))
|
||||
.ReturnsAsync((RegexMapping)originalRegex).Verifiable();
|
||||
|
||||
var regexMappingResponse = service.Update(updatedRegex);
|
||||
|
||||
Assert.NotNull(regexMappingResponse);
|
||||
|
||||
Assert.AreEqual(regexMappingResponse.RegexMappingId, originalRegex.RegexMappingId);
|
||||
Assert.AreEqual(regexMappingResponse.ApplicationMappingId, updatedRegex.ApplicationMappingId);
|
||||
Assert.AreEqual(regexMappingResponse.Tag, updatedRegex.Tag);
|
||||
Assert.AreEqual(regexMappingResponse.Regex, updatedRegex.Regex);
|
||||
|
||||
mockRegexMappingRepository.Verify(x => x.FindByRegexMappingIdAsync(It.IsAny<int>()), Times.Once());
|
||||
mockUnitOfWork.Verify(x => x.Complete(), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Update_InvalidTag()
|
||||
{
|
||||
Assert.ThrowsAsync<ServiceException>(async () =>
|
||||
await service.SaveAsync(new RegexMapping()
|
||||
{
|
||||
ApplicationMappingId = 1,
|
||||
Tag = "{Regex1}",
|
||||
Regex = "[0-9]"
|
||||
}));
|
||||
|
||||
mockUnitOfWork.Verify(x => x.CompleteAsync(), Times.Never);
|
||||
mockRegexMappingRepository.Verify(x => x.AddAsync(It.IsAny<RegexMapping>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Update_Exception()
|
||||
{
|
||||
var updatedRegex = new RegexMapping()
|
||||
{
|
||||
RegexMappingId = 1,
|
||||
ApplicationMappingId = 2,
|
||||
Tag = "{Regex50}",
|
||||
Regex = "[0-9]*"
|
||||
};
|
||||
|
||||
mockRegexMappingRepository.Setup(repository => repository.FindByRegexMappingIdAsync(It.IsAny<int>()))
|
||||
.ThrowsAsync(new Exception("Test")).Verifiable();
|
||||
|
||||
Assert.Throws<ServiceException>(() =>
|
||||
service.Update(updatedRegex));
|
||||
|
||||
mockUnitOfWork.Verify(x => x.CompleteAsync(), Times.Never);
|
||||
mockRegexMappingRepository.Verify(x => x.FindByRegexMappingIdAsync(It.IsAny<int>()), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Delete_Success()
|
||||
{
|
||||
mockRegexMappingRepository.Setup(repository => repository.FindByRegexMappingIdAsync(It.IsAny<int>()))
|
||||
.ReturnsAsync(new RegexMapping()
|
||||
{
|
||||
RegexMappingId = 1,
|
||||
ApplicationMappingId = 1,
|
||||
Tag = "{Regex5}",
|
||||
Regex = "[0-9]"
|
||||
})
|
||||
.Verifiable();
|
||||
|
||||
mockRegexMappingRepository.Setup(repository => repository.Remove(It.IsAny<RegexMapping>()))
|
||||
.Verifiable();
|
||||
|
||||
service.DeleteAsync(1);
|
||||
|
||||
mockRegexMappingRepository.Verify(x => x.FindByRegexMappingIdAsync(It.IsAny<int>()), Times.Once());
|
||||
mockUnitOfWork.Verify(x => x.Complete(), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Delete_Exception()
|
||||
{
|
||||
var deleteRegex = new RegexMapping()
|
||||
{
|
||||
RegexMappingId = 1,
|
||||
ApplicationMappingId = 2,
|
||||
Tag = "{Regex5}",
|
||||
Regex = "[0-9]*"
|
||||
};
|
||||
|
||||
mockRegexMappingRepository.Setup(repository => repository.FindByRegexMappingIdAsync(It.IsAny<int>()))
|
||||
.ThrowsAsync(new Exception("Test")).Verifiable();
|
||||
|
||||
Assert.Throws<ServiceException>(() =>
|
||||
service.Update(deleteRegex));
|
||||
|
||||
mockUnitOfWork.Verify(x => x.CompleteAsync(), Times.Never);
|
||||
mockRegexMappingRepository.Verify(x => x.FindByRegexMappingIdAsync(It.IsAny<int>()), Times.Once());
|
||||
}
|
||||
}
|
||||
}
|
||||
+597
@@ -0,0 +1,597 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using LCU.Api.Internal.ArchiverApi.Services;
|
||||
using LCU.Library.Internal.ArchiverApiModel.Models;
|
||||
using LCU.Library.Internal.ArchiverApiModel.Entities;
|
||||
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.ApplicationHistories;
|
||||
namespace LCU.Api.Internal.ArchiverApiTest;
|
||||
|
||||
public class ReportServiceTest
|
||||
{
|
||||
private ReportService _reportService;
|
||||
private Mock<ICoreApiWrapperService> _mockCoreApiWrapperService;
|
||||
private Mock<IApplicationMappingService> _mockApplicationMappingService;
|
||||
private Mock<IRegexMappingService> _mockRegexMappingService;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_mockCoreApiWrapperService = new Mock<ICoreApiWrapperService>();
|
||||
_mockApplicationMappingService = new Mock<IApplicationMappingService>();
|
||||
_mockRegexMappingService = new Mock<IRegexMappingService>();
|
||||
_reportService = new ReportService(_mockCoreApiWrapperService.Object, _mockApplicationMappingService.Object, _mockRegexMappingService.Object);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetReportsToArchive_OK()
|
||||
{
|
||||
var testReports = new List<Report>()
|
||||
{
|
||||
new Report()
|
||||
{
|
||||
ReportName = "Test",
|
||||
QueueNumber = "1234",
|
||||
StopDateTime = Convert.ToDateTime("1/1/2021")
|
||||
}
|
||||
};
|
||||
var archiveRequest = new ArchiveRequest();
|
||||
var applicationHistories = new List<ApplicationHistory>()
|
||||
{
|
||||
new ApplicationHistory()
|
||||
{
|
||||
ApplicationName = "Test",
|
||||
ApplicationNumber = 1,
|
||||
QueueNumber = 1234,
|
||||
StopDateTime = Convert.ToDateTime("1/1/2021")
|
||||
}
|
||||
};
|
||||
_mockCoreApiWrapperService.Setup(x => x.GetApplicationHistories(archiveRequest)).ReturnsAsync(applicationHistories);
|
||||
|
||||
var result = _reportService.GetReportsToArchiveAsync(archiveRequest).Result;
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.AreEqual("Test", result.FirstOrDefault().ReportName);
|
||||
Assert.AreEqual("1234", result.FirstOrDefault().QueueNumber);
|
||||
Assert.AreEqual(Convert.ToDateTime("1/1/2021"), result.FirstOrDefault().StopDateTime);
|
||||
Assert.AreEqual("Test", result.FirstOrDefault().DisplayReportName);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetReportsToArchive_DispalyReportName_FromApplicationMapping()
|
||||
{
|
||||
var testApplicationMapping1 = new ApplicationMapping()
|
||||
{
|
||||
Identifier = "1",
|
||||
DesignatedName = "Test_NEW_1",
|
||||
ParameterMappings = new List<ParameterMapping>()
|
||||
{
|
||||
new ParameterMapping()
|
||||
{
|
||||
ParameterCode = "TestingCode",
|
||||
ParameterValue = "TestingParameterValue"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var testApplicationMapping2 = new ApplicationMapping()
|
||||
{
|
||||
Identifier = "1",
|
||||
DesignatedName = "Test_NEW",
|
||||
ParameterMappings = new List<ParameterMapping>()
|
||||
{
|
||||
new ParameterMapping()
|
||||
{
|
||||
ParameterCode = "TestingCode2",
|
||||
ParameterValue = "TestingParameterValue2"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var applicationMappings = new List<ApplicationMapping>()
|
||||
{
|
||||
testApplicationMapping1,
|
||||
testApplicationMapping2
|
||||
};
|
||||
|
||||
var testReports = new List<Report>()
|
||||
{
|
||||
new Report()
|
||||
{
|
||||
ReportName = "Test",
|
||||
QueueNumber = "1234",
|
||||
StopDateTime = Convert.ToDateTime("1/1/2021")
|
||||
}
|
||||
};
|
||||
var archiveRequest = new ArchiveRequest();
|
||||
var applicationHistories = new List<ApplicationHistory>()
|
||||
{
|
||||
new ApplicationHistory()
|
||||
{
|
||||
ApplicationName = "Test",
|
||||
ApplicationNumber = 1,
|
||||
QueueNumber = 1234,
|
||||
StopDateTime = Convert.ToDateTime("1/1/2021"),
|
||||
QueueApplicationParameters = new List<QueueApplicationParameter>()
|
||||
{
|
||||
new QueueApplicationParameter()
|
||||
{
|
||||
QueueNumber = 1234,
|
||||
ApplicationNumber = 1,
|
||||
ParameterCode = "TestingCode",
|
||||
ParameterValue = "TestingParameterValue"
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
_mockCoreApiWrapperService.Setup(x => x.GetApplicationHistories(archiveRequest)).ReturnsAsync(applicationHistories);
|
||||
_mockApplicationMappingService.Setup(x => x.GetAsync()).ReturnsAsync(applicationMappings);
|
||||
|
||||
var result = _reportService.GetReportsToArchiveAsync(archiveRequest).Result;
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.AreEqual("Test", result.FirstOrDefault().ReportName);
|
||||
Assert.AreEqual("1234", result.FirstOrDefault().QueueNumber);
|
||||
Assert.AreEqual(Convert.ToDateTime("1/1/2021"), result.FirstOrDefault().StopDateTime);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetReportsToArchive_Exception()
|
||||
{
|
||||
var archiveRequest = new ArchiveRequest();
|
||||
_mockCoreApiWrapperService.Setup(x => x.GetApplicationHistories(archiveRequest)).Throws(new Exception("Error"));
|
||||
Assert.ThrowsAsync<Exception>(() => _reportService.GetReportsToArchiveAsync(archiveRequest));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeteriminApplicationMapping_Return_CorrectApplicationMapping1()
|
||||
{
|
||||
var testApplicationMapping1 = new ApplicationMapping()
|
||||
{
|
||||
Identifier = "1",
|
||||
DesignatedName = "Test_NEW",
|
||||
ParameterMappings = new List<ParameterMapping>()
|
||||
{
|
||||
new ParameterMapping()
|
||||
{
|
||||
ParameterCode = "TestingCode",
|
||||
ParameterValue = "TestingParameterValue"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var testApplicationMapping2 = new ApplicationMapping()
|
||||
{
|
||||
Identifier = "1",
|
||||
DesignatedName = "Test_NEW",
|
||||
ParameterMappings = new List<ParameterMapping>()
|
||||
{
|
||||
new ParameterMapping()
|
||||
{
|
||||
ParameterCode = "TestingCode2",
|
||||
ParameterValue = "TestingParameterValue2"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
List<ApplicationMapping> applicationMappings = new List<ApplicationMapping>()
|
||||
{
|
||||
testApplicationMapping1,
|
||||
testApplicationMapping2
|
||||
};
|
||||
|
||||
ApplicationHistory applicationHistory = new ApplicationHistory()
|
||||
{
|
||||
ApplicationName = "Test",
|
||||
ApplicationNumber = 1,
|
||||
QueueNumber = 1234,
|
||||
StopDateTime = Convert.ToDateTime("1/1/2021"),
|
||||
QueueApplicationParameters = new List<QueueApplicationParameter>()
|
||||
{
|
||||
new QueueApplicationParameter()
|
||||
{
|
||||
QueueNumber = 1234,
|
||||
ApplicationNumber = 1,
|
||||
ParameterCode = "TestingCode",
|
||||
ParameterValue = "TestingParameterValue"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var result = _reportService.DeteriminApplicationMapping(applicationMappings, applicationHistory);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.AreEqual(testApplicationMapping1, result);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void DeteriminApplicationMapping_Return_testApplicationMapping1_MatchBothParameters()
|
||||
{
|
||||
var testApplicationMapping1 = new ApplicationMapping()
|
||||
{
|
||||
Identifier = "1",
|
||||
DesignatedName = "Test_NEW",
|
||||
ParameterMappings = new List<ParameterMapping>()
|
||||
{
|
||||
new ParameterMapping()
|
||||
{
|
||||
ParameterCode = "TestingCode",
|
||||
ParameterValue = "TestingParameterValue"
|
||||
},
|
||||
new ParameterMapping()
|
||||
{
|
||||
ParameterCode = "TestingCode2",
|
||||
ParameterValue = "TestingParameterValue2"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var testApplicationMapping2 = new ApplicationMapping()
|
||||
{
|
||||
Identifier = "1",
|
||||
DesignatedName = "Test_NEW",
|
||||
ParameterMappings = new List<ParameterMapping>()
|
||||
{
|
||||
new ParameterMapping()
|
||||
{
|
||||
ParameterCode = "TestingCode2",
|
||||
ParameterValue = "TestingParameterValue2"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
List<ApplicationMapping> applicationMappings = new List<ApplicationMapping>()
|
||||
{
|
||||
testApplicationMapping1,
|
||||
testApplicationMapping2
|
||||
};
|
||||
|
||||
ApplicationHistory applicationHistory = new ApplicationHistory()
|
||||
{
|
||||
ApplicationName = "Test",
|
||||
ApplicationNumber = 1,
|
||||
QueueNumber = 1234,
|
||||
StopDateTime = Convert.ToDateTime("1/1/2021"),
|
||||
QueueApplicationParameters = new List<QueueApplicationParameter>()
|
||||
{
|
||||
new QueueApplicationParameter()
|
||||
{
|
||||
QueueNumber = 1234,
|
||||
ApplicationNumber = 1,
|
||||
ParameterCode = "TestingCode",
|
||||
ParameterValue = "TestingParameterValue"
|
||||
},
|
||||
new QueueApplicationParameter()
|
||||
{
|
||||
QueueNumber = 1234,
|
||||
ApplicationNumber = 1,
|
||||
ParameterCode = "TestingCode2",
|
||||
ParameterValue = "TestingParameterValue2"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var result = _reportService.DeteriminApplicationMapping(applicationMappings, applicationHistory);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.AreEqual(testApplicationMapping1, result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeteriminApplicationMapping_Return_Null_ParameterCodeNoMatch()
|
||||
{
|
||||
var testApplicationMapping1 = new ApplicationMapping()
|
||||
{
|
||||
Identifier = "1",
|
||||
DesignatedName = "Test_NEW",
|
||||
ParameterMappings = new List<ParameterMapping>()
|
||||
{
|
||||
new ParameterMapping()
|
||||
{
|
||||
ParameterCode = "TestingCode",
|
||||
ParameterValue = "TestingParameterValue"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var testApplicationMapping2 = new ApplicationMapping()
|
||||
{
|
||||
Identifier = "1",
|
||||
DesignatedName = "Test_NEW",
|
||||
ParameterMappings = new List<ParameterMapping>()
|
||||
{
|
||||
new ParameterMapping()
|
||||
{
|
||||
ParameterCode = "TestingCode2",
|
||||
ParameterValue = "TestingParameterValue2"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
List<ApplicationMapping> applicationMappings = new List<ApplicationMapping>()
|
||||
{
|
||||
testApplicationMapping1,
|
||||
testApplicationMapping2
|
||||
};
|
||||
|
||||
ApplicationHistory applicationHistory = new ApplicationHistory()
|
||||
{
|
||||
ApplicationName = "Test",
|
||||
ApplicationNumber = 1,
|
||||
QueueNumber = 1234,
|
||||
StopDateTime = Convert.ToDateTime("1/1/2021"),
|
||||
QueueApplicationParameters = new List<QueueApplicationParameter>()
|
||||
{
|
||||
new QueueApplicationParameter()
|
||||
{
|
||||
QueueNumber = 1234,
|
||||
ApplicationNumber = 1,
|
||||
ParameterCode = "TestingCode_NOPE",
|
||||
ParameterValue = "TestingParameterValue"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var result = _reportService.DeteriminApplicationMapping(applicationMappings, applicationHistory);
|
||||
|
||||
Assert.Null(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeteriminApplicationMapping_Return_Null_ParameterValueNoMatch()
|
||||
{
|
||||
var testApplicationMapping1 = new ApplicationMapping()
|
||||
{
|
||||
Identifier = "1",
|
||||
DesignatedName = "Test_NEW",
|
||||
ParameterMappings = new List<ParameterMapping>()
|
||||
{
|
||||
new ParameterMapping()
|
||||
{
|
||||
ParameterCode = "TestingCode",
|
||||
ParameterValue = "TestingParameterValue"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var testApplicationMapping2 = new ApplicationMapping()
|
||||
{
|
||||
Identifier = "1",
|
||||
DesignatedName = "Test_NEW",
|
||||
ParameterMappings = new List<ParameterMapping>()
|
||||
{
|
||||
new ParameterMapping()
|
||||
{
|
||||
ParameterCode = "TestingCode2",
|
||||
ParameterValue = "TestingParameterValue2"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
List<ApplicationMapping> applicationMappings = new List<ApplicationMapping>()
|
||||
{
|
||||
testApplicationMapping1,
|
||||
testApplicationMapping2
|
||||
};
|
||||
|
||||
ApplicationHistory applicationHistory = new ApplicationHistory()
|
||||
{
|
||||
ApplicationName = "Test",
|
||||
ApplicationNumber = 1,
|
||||
QueueNumber = 1234,
|
||||
StopDateTime = Convert.ToDateTime("1/1/2021"),
|
||||
QueueApplicationParameters = new List<QueueApplicationParameter>()
|
||||
{
|
||||
new QueueApplicationParameter()
|
||||
{
|
||||
QueueNumber = 1234,
|
||||
ApplicationNumber = 1,
|
||||
ParameterCode = "TestingCode",
|
||||
ParameterValue = "TestingParameterValue_NOPE"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var result = _reportService.DeteriminApplicationMapping(applicationMappings, applicationHistory);
|
||||
|
||||
Assert.Null(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeteriminApplicationMapping_Return_Null_DoesNotMatchBothParameters()
|
||||
{
|
||||
var testApplicationMapping1 = new ApplicationMapping()
|
||||
{
|
||||
Identifier = "1",
|
||||
DesignatedName = "Test_NEW",
|
||||
ParameterMappings = new List<ParameterMapping>()
|
||||
{
|
||||
new ParameterMapping()
|
||||
{
|
||||
ParameterCode = "TestingCode",
|
||||
ParameterValue = "TestingParameterValue"
|
||||
},
|
||||
new ParameterMapping()
|
||||
{
|
||||
ParameterCode = "TestingCode2",
|
||||
ParameterValue = "TestingParameterValue2"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var testApplicationMapping2 = new ApplicationMapping()
|
||||
{
|
||||
Identifier = "1",
|
||||
DesignatedName = "Test_NEW",
|
||||
ParameterMappings = new List<ParameterMapping>()
|
||||
{
|
||||
new ParameterMapping()
|
||||
{
|
||||
ParameterCode = "TestingCode2",
|
||||
ParameterValue = "TestingParameterValue2"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
List<ApplicationMapping> applicationMappings = new List<ApplicationMapping>()
|
||||
{
|
||||
testApplicationMapping1,
|
||||
testApplicationMapping2
|
||||
};
|
||||
|
||||
ApplicationHistory applicationHistory = new ApplicationHistory()
|
||||
{
|
||||
ApplicationName = "Test",
|
||||
ApplicationNumber = 1,
|
||||
QueueNumber = 1234,
|
||||
StopDateTime = Convert.ToDateTime("1/1/2021"),
|
||||
QueueApplicationParameters = new List<QueueApplicationParameter>()
|
||||
{
|
||||
new QueueApplicationParameter()
|
||||
{
|
||||
QueueNumber = 1234,
|
||||
ApplicationNumber = 1,
|
||||
ParameterCode = "TestingCode",
|
||||
ParameterValue = "TestingParameterValue"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var result = _reportService.DeteriminApplicationMapping(applicationMappings, applicationHistory);
|
||||
|
||||
Assert.Null(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeteriminApplicationMapping_Return_SingleWithParameters_CorrectApplicationMapping1()
|
||||
{
|
||||
var testApplicationMapping1 = new ApplicationMapping()
|
||||
{
|
||||
Identifier = "1",
|
||||
DesignatedName = "Test_NEW",
|
||||
ParameterMappings = new List<ParameterMapping>()
|
||||
{
|
||||
new ParameterMapping()
|
||||
{
|
||||
ParameterCode = "TestingCode",
|
||||
ParameterValue = "TestingParameterValue"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
List<ApplicationMapping> applicationMappings = new List<ApplicationMapping>()
|
||||
{
|
||||
testApplicationMapping1
|
||||
};
|
||||
|
||||
ApplicationHistory applicationHistory = new ApplicationHistory()
|
||||
{
|
||||
ApplicationName = "Test",
|
||||
ApplicationNumber = 1,
|
||||
QueueNumber = 1234,
|
||||
StopDateTime = Convert.ToDateTime("1/1/2021"),
|
||||
QueueApplicationParameters = new List<QueueApplicationParameter>()
|
||||
{
|
||||
new QueueApplicationParameter()
|
||||
{
|
||||
QueueNumber = 1234,
|
||||
ApplicationNumber = 1,
|
||||
ParameterCode = "TestingCode",
|
||||
ParameterValue = "TestingParameterValue"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var result = _reportService.DeteriminApplicationMapping(applicationMappings, applicationHistory);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.AreEqual(testApplicationMapping1, result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeteriminApplicationMapping_Return_SingleWithParameters_NoMatch_Null()
|
||||
{
|
||||
var testApplicationMapping1 = new ApplicationMapping()
|
||||
{
|
||||
Identifier = "1",
|
||||
DesignatedName = "Test_NEW",
|
||||
ParameterMappings = new List<ParameterMapping>()
|
||||
{
|
||||
new ParameterMapping()
|
||||
{
|
||||
ParameterCode = "TestingCode_NoMatch",
|
||||
ParameterValue = "TestingParameterValue"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
List<ApplicationMapping> applicationMappings = new List<ApplicationMapping>()
|
||||
{
|
||||
testApplicationMapping1
|
||||
};
|
||||
|
||||
ApplicationHistory applicationHistory = new ApplicationHistory()
|
||||
{
|
||||
ApplicationName = "Test",
|
||||
ApplicationNumber = 1,
|
||||
QueueNumber = 1234,
|
||||
StopDateTime = Convert.ToDateTime("1/1/2021"),
|
||||
QueueApplicationParameters = new List<QueueApplicationParameter>()
|
||||
{
|
||||
new QueueApplicationParameter()
|
||||
{
|
||||
QueueNumber = 1234,
|
||||
ApplicationNumber = 1,
|
||||
ParameterCode = "TestingCode",
|
||||
ParameterValue = "TestingParameterValue"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var result = _reportService.DeteriminApplicationMapping(applicationMappings, applicationHistory);
|
||||
|
||||
Assert.Null(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeteriminApplicationMapping_Return_SingleWithOutParameters_CorrectApplicationMapping1()
|
||||
{
|
||||
var testApplicationMapping1 = new ApplicationMapping()
|
||||
{
|
||||
Identifier = "1",
|
||||
DesignatedName = "Test_NEW",
|
||||
ApplicationOverrideName = "Test-File"
|
||||
};
|
||||
|
||||
List<ApplicationMapping> applicationMappings = new List<ApplicationMapping>()
|
||||
{
|
||||
testApplicationMapping1
|
||||
};
|
||||
|
||||
ApplicationHistory applicationHistory = new ApplicationHistory()
|
||||
{
|
||||
ApplicationName = "Test",
|
||||
ApplicationNumber = 1,
|
||||
QueueNumber = 1234,
|
||||
StopDateTime = Convert.ToDateTime("1/1/2021"),
|
||||
QueueApplicationParameters = new List<QueueApplicationParameter>()
|
||||
{
|
||||
new QueueApplicationParameter()
|
||||
{
|
||||
QueueNumber = 1234,
|
||||
ApplicationNumber = 1,
|
||||
ParameterCode = "TestingCode",
|
||||
ParameterValue = "TestingParameterValue"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var result = _reportService.DeteriminApplicationMapping(applicationMappings, applicationHistory);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.AreEqual(testApplicationMapping1, result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user