Updating
This commit is contained in:
+243
@@ -0,0 +1,243 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
using LCU.Api.Internal.FileOperations.Controllers;
|
||||
using LCU.Api.Internal.FileOperations.Services;
|
||||
using LCU.Api.Internal.FileOperations.Services.FileActionServices;
|
||||
using LCU.Library.Internal.FileOperationsModels.Models;
|
||||
using LCU.Library.Internal.Exceptions;
|
||||
namespace LCU.Api.Internal.FileOperationsTests.Controllers;
|
||||
|
||||
public class DirectFileOperationsControllerTest
|
||||
{
|
||||
private readonly DirectFileOperationsController _controller;
|
||||
private readonly Mock<IDirectFileOperationsService> _mockDirectFileOperationsService;
|
||||
private readonly Mock<IActionService<MoveFileRequest>> _mockMoveFileService;
|
||||
private readonly Mock<IActionService<WriteFileRequest>> _mockWriteFileService;
|
||||
private readonly Mock<IActionService<CreateDirectoryRequest>> _mockCreateDirectoryService;
|
||||
private readonly Mock<IActionService<UnzipFileRequest>> _mockUnzipFileService;
|
||||
private readonly Mock<IActionService<ZipDirectoryRequest>> _mockZipDirectoryService;
|
||||
private readonly Mock<IActionService<DeleteDirectoryRequest>> _mockDeleteDirectoryService;
|
||||
private readonly Mock<IActionService<DeleteFileRequest>> _mockDeleteFileService;
|
||||
private readonly Mock<IActionService<AppendFileRequest>> _mockAppendFileService;
|
||||
|
||||
public DirectFileOperationsControllerTest()
|
||||
{
|
||||
_mockDirectFileOperationsService = new Mock<IDirectFileOperationsService>();
|
||||
_mockMoveFileService = new Mock<IActionService<MoveFileRequest>>();
|
||||
_mockWriteFileService = new Mock<IActionService<WriteFileRequest>>();
|
||||
_mockCreateDirectoryService = new Mock<IActionService<CreateDirectoryRequest>>();
|
||||
_mockUnzipFileService = new Mock<IActionService<UnzipFileRequest>>();
|
||||
_mockZipDirectoryService = new Mock<IActionService<ZipDirectoryRequest>>();
|
||||
_mockDeleteDirectoryService = new Mock<IActionService<DeleteDirectoryRequest>>();
|
||||
_mockDeleteFileService = new Mock<IActionService<DeleteFileRequest>>();
|
||||
_mockAppendFileService = new Mock<IActionService<AppendFileRequest>>();
|
||||
_controller = new DirectFileOperationsController(_mockDirectFileOperationsService.Object,
|
||||
_mockMoveFileService.Object,
|
||||
_mockWriteFileService.Object,
|
||||
_mockCreateDirectoryService.Object,
|
||||
_mockUnzipFileService.Object,
|
||||
_mockZipDirectoryService.Object,
|
||||
_mockDeleteDirectoryService.Object,
|
||||
_mockDeleteFileService.Object,
|
||||
_mockAppendFileService.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task MoveFilePost_OK()
|
||||
{
|
||||
// arrange
|
||||
var request = new MoveFileRequest()
|
||||
{
|
||||
SourcePath = "",
|
||||
SourceFile = "",
|
||||
DestinationPath = ""
|
||||
};
|
||||
|
||||
var validRequestResponse = new RequestResponse() { MessageStack = new List<string>(), IsSuccessful = true };
|
||||
_mockMoveFileService.Setup(service => service.PreQueueValidation(It.IsAny<MoveFileRequest>())).Returns(validRequestResponse);
|
||||
_mockDirectFileOperationsService.Setup(service =>
|
||||
service.HandleDirectFileOperationsRequest(It.IsAny<MoveFileRequest>(), FileOperationType.Move))
|
||||
.ReturnsAsync(validRequestResponse)
|
||||
.Verifiable();
|
||||
|
||||
// act
|
||||
var result = await _controller.MoveFile(request);
|
||||
Assert.NotNull(result);
|
||||
var okResult = result as OkObjectResult;
|
||||
|
||||
// assert
|
||||
Assert.NotNull(okResult);
|
||||
Assert.Equal(200, okResult.StatusCode);
|
||||
_mockMoveFileService.Verify(service =>
|
||||
service.PreQueueValidation(It.IsAny<MoveFileRequest>()), Times.Once);
|
||||
_mockDirectFileOperationsService.Verify(service =>
|
||||
service.HandleDirectFileOperationsRequest(It.IsAny<MoveFileRequest>(), FileOperationType.Move), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task MoveFilePost_InvalidRequest()
|
||||
{
|
||||
// arrange
|
||||
var request = new MoveFileRequest() { };
|
||||
var validRequestResponse = new RequestResponse() { MessageStack = new List<string>() { "Invalid" }, IsSuccessful = false };
|
||||
_mockMoveFileService.Setup(service => service.PreQueueValidation(It.IsAny<MoveFileRequest>())).Returns(validRequestResponse);
|
||||
// act
|
||||
var result = await _controller.MoveFile(request);
|
||||
|
||||
Assert.NotNull(result);
|
||||
var badRequest = result as BadRequestObjectResult;
|
||||
Assert.Equal(400, badRequest.StatusCode);
|
||||
Assert.Equal($"Request is invalid. Response: {String.Join("\n ", validRequestResponse.MessageStack.ToArray())}", badRequest.Value);
|
||||
_mockMoveFileService.Verify(service =>
|
||||
service.PreQueueValidation(It.IsAny<MoveFileRequest>()), Times.Once);
|
||||
_mockDirectFileOperationsService.Verify(service =>
|
||||
service.HandleDirectFileOperationsRequest(It.IsAny<MoveFileRequest>(), FileOperationType.Move), Times.Never);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task MoveFile_Failure_UnexpectedException()
|
||||
{
|
||||
var request = new MoveFileRequest()
|
||||
{
|
||||
SourcePath = "",
|
||||
SourceFile = "",
|
||||
DestinationPath = ""
|
||||
};
|
||||
var validRequestResponse = new RequestResponse() { MessageStack = new List<string>(), IsSuccessful = true };
|
||||
_mockMoveFileService.Setup(service => service.PreQueueValidation(It.IsAny<MoveFileRequest>())).Returns(validRequestResponse).Verifiable();
|
||||
_mockDirectFileOperationsService.Setup(service =>
|
||||
service.HandleDirectFileOperationsRequest(It.IsAny<MoveFileRequest>(), FileOperationType.Move))
|
||||
.ThrowsAsync(new Exception("Thrown From Unit Test"))
|
||||
.Verifiable();
|
||||
|
||||
|
||||
|
||||
var result = await _controller.MoveFile(request);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var statusResult = result as StatusCodeResult;
|
||||
Assert.NotNull(statusResult);
|
||||
Assert.Equal(500, statusResult!.StatusCode);
|
||||
_mockMoveFileService.Verify(service =>
|
||||
service.PreQueueValidation(It.IsAny<MoveFileRequest>()), Times.Once);
|
||||
_mockDirectFileOperationsService.Verify(service =>
|
||||
service.HandleDirectFileOperationsRequest(It.IsAny<MoveFileRequest>(), FileOperationType.Move), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task MoveFile_Failure_ServiceException()
|
||||
{
|
||||
var request = new MoveFileRequest()
|
||||
{
|
||||
SourcePath = "",
|
||||
SourceFile = "",
|
||||
DestinationPath = ""
|
||||
};
|
||||
var validRequestResponse = new RequestResponse() { MessageStack = new List<string>(), IsSuccessful = true };
|
||||
_mockMoveFileService.Setup(service => service.PreQueueValidation(It.IsAny<MoveFileRequest>())).Returns(validRequestResponse).Verifiable();
|
||||
_mockDirectFileOperationsService.Setup(service =>
|
||||
service.HandleDirectFileOperationsRequest(It.IsAny<MoveFileRequest>(), FileOperationType.Move))
|
||||
.ThrowsAsync(new ServiceException("Thrown From Unit Test"))
|
||||
.Verifiable();
|
||||
|
||||
|
||||
|
||||
var result = await _controller.MoveFile(request);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var statusResult = result as ObjectResult;
|
||||
Assert.NotNull(statusResult);
|
||||
Assert.Equal(500, statusResult!.StatusCode);
|
||||
_mockMoveFileService.Verify(service =>
|
||||
service.PreQueueValidation(It.IsAny<MoveFileRequest>()), Times.Once);
|
||||
_mockDirectFileOperationsService.Verify(service =>
|
||||
service.HandleDirectFileOperationsRequest(It.IsAny<MoveFileRequest>(), FileOperationType.Move), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AppendFilePost_Ok()
|
||||
{
|
||||
var request = new AppendFileRequest()
|
||||
{
|
||||
FileData = "Text to write",
|
||||
DestinationPath = "SomePath",
|
||||
Extension = ".txt",
|
||||
FileName = "FileName"
|
||||
};
|
||||
|
||||
var validRequestResponse = new RequestResponse() { MessageStack = new List<string>(), IsSuccessful = true };
|
||||
_mockAppendFileService.Setup(service => service.PreQueueValidation(It.IsAny<AppendFileRequest>())).Returns(validRequestResponse);
|
||||
_mockDirectFileOperationsService.Setup(service =>
|
||||
service.HandleDirectFileOperationsRequest(It.IsAny<AppendFileRequest>(), FileOperationType.AppendFile))
|
||||
.ReturnsAsync(validRequestResponse)
|
||||
.Verifiable();
|
||||
|
||||
// act
|
||||
var result = await _controller.AppendFile(request);
|
||||
Assert.NotNull(result);
|
||||
var okResult = result as OkObjectResult;
|
||||
|
||||
// assert
|
||||
Assert.NotNull(okResult);
|
||||
Assert.Equal(200, okResult.StatusCode);
|
||||
_mockAppendFileService.Verify(service =>
|
||||
service.PreQueueValidation(It.IsAny<AppendFileRequest>()), Times.Once);
|
||||
_mockDirectFileOperationsService.Verify(service =>
|
||||
service.HandleDirectFileOperationsRequest(It.IsAny<AppendFileRequest>(), FileOperationType.AppendFile), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AppendFilePost_InvalidRequest()
|
||||
{
|
||||
// arrange
|
||||
var request = new AppendFileRequest() { };
|
||||
var validRequestResponse = new RequestResponse() { MessageStack = new List<string>() { "Invalid" }, IsSuccessful = false };
|
||||
_mockAppendFileService.Setup(service => service.PreQueueValidation(It.IsAny<AppendFileRequest>())).Returns(validRequestResponse);
|
||||
// act
|
||||
var result = await _controller.AppendFile(request);
|
||||
|
||||
Assert.NotNull(result);
|
||||
var badRequest = result as BadRequestObjectResult;
|
||||
Assert.Equal(400, badRequest.StatusCode);
|
||||
Assert.Equal($"Request is invalid. Response: {String.Join("\n ", validRequestResponse.MessageStack.ToArray())}", badRequest.Value);
|
||||
_mockAppendFileService.Verify(service =>
|
||||
service.PreQueueValidation(It.IsAny<AppendFileRequest>()), Times.Once);
|
||||
_mockDirectFileOperationsService.Verify(service =>
|
||||
service.HandleDirectFileOperationsRequest(It.IsAny<AppendFileRequest>(), FileOperationType.AppendFile), Times.Never);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AppendFile_Failure_ServiceException()
|
||||
{
|
||||
var request = new AppendFileRequest()
|
||||
{
|
||||
FileData = "Text to write",
|
||||
DestinationPath = "SomePath",
|
||||
Extension = ".txt",
|
||||
FileName = "FileName"
|
||||
};
|
||||
var validRequestResponse = new RequestResponse() { MessageStack = new List<string>(), IsSuccessful = true };
|
||||
_mockAppendFileService.Setup(service => service.PreQueueValidation(It.IsAny<AppendFileRequest>())).Returns(validRequestResponse).Verifiable();
|
||||
_mockDirectFileOperationsService.Setup(service =>
|
||||
service.HandleDirectFileOperationsRequest(It.IsAny<AppendFileRequest>(), FileOperationType.AppendFile))
|
||||
.ThrowsAsync(new ServiceException("Thrown From Unit Test"))
|
||||
.Verifiable();
|
||||
|
||||
|
||||
|
||||
var result = await _controller.AppendFile(request);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var statusResult = result as ObjectResult;
|
||||
Assert.NotNull(statusResult);
|
||||
Assert.Equal(500, statusResult!.StatusCode);
|
||||
_mockAppendFileService.Verify(service =>
|
||||
service.PreQueueValidation(It.IsAny<AppendFileRequest>()), Times.Once);
|
||||
_mockDirectFileOperationsService.Verify(service =>
|
||||
service.HandleDirectFileOperationsRequest(It.IsAny<AppendFileRequest>(), FileOperationType.AppendFile), Times.Once);
|
||||
}
|
||||
}
|
||||
+302
@@ -0,0 +1,302 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
using LCU.Api.Internal.FileOperations.Controllers;
|
||||
using LCU.Api.Internal.FileOperations.Services;
|
||||
using LCU.Api.Internal.FileOperations.Services.FileActionServices;
|
||||
using LCU.Library.Internal.FileOperationsModels.Models;
|
||||
using LCU.Api.Internal.FileOperations.Services.QueueServices;
|
||||
namespace LCU.Api.Internal.FileOperationsTests.Controllers;
|
||||
|
||||
public class FileOperationsControllerTest
|
||||
{
|
||||
private readonly FileOperationsController _controller;
|
||||
private readonly Mock<IQueueFileOperationsService> _mockFileOperationsService;
|
||||
private readonly Mock<IActionService<MoveFileRequest>> _mockMoveFileService;
|
||||
private readonly Mock<IActionService<CopyFileRequest>> _mockCopyFileService;
|
||||
private readonly Mock<IActionService<ModifyFileRequest>> _mockModifyFileService;
|
||||
private readonly Mock<IActionService<DeleteFileRequest>> _mockDeleteFileService;
|
||||
private readonly Mock<IActionService<RenameFileRequest>> _mockRenameFileService;
|
||||
private readonly Mock<IActionService<ZipDirectoryRequest>> _mockZipDirectoryService;
|
||||
private readonly Mock<IActionService<UnzipFileRequest>> _mockUnzipFileService;
|
||||
private readonly Mock<IActionService<UnzipPasswordProtectedFileRequest>> _mockUnzipPasswordProtectedFileService;
|
||||
private readonly Mock<IActionService<CreateDirectoryRequest>> _mockCreateDirectoryService;
|
||||
private readonly Mock<IActionService<RenameDirectoryRequest>> _mockRenameDirectoryService;
|
||||
private readonly Mock<IActionService<BulkOperationRequest<MoveFileRequest>>> _mockBulkMoveFileService;
|
||||
private readonly Mock<IActionService<EncryptFileDataRequest>> _mockEncryptFileDataService;
|
||||
private readonly Mock<IActionService<DecryptFileDataRequest>> _mockDecryptFileDataService;
|
||||
private readonly Mock<IActionService<WriteFileRequest>> _mockWriteFileDataService;
|
||||
private readonly Mock<IActionService<DeleteDirectoryRequest>> _mockDeleteDirectoryService;
|
||||
private readonly Mock<IActionService<DeleteEmptyDirectoryRequest>> _mockDeleteEmptyDirectoriesService;
|
||||
private readonly Mock<IDirectFileService> _mockDirectFileService;
|
||||
|
||||
public FileOperationsControllerTest()
|
||||
{
|
||||
_mockFileOperationsService = new Mock<IQueueFileOperationsService>();
|
||||
_mockMoveFileService = new Mock<IActionService<MoveFileRequest>>();
|
||||
_mockCopyFileService = new Mock<IActionService<CopyFileRequest>>();
|
||||
_mockModifyFileService = new Mock<IActionService<ModifyFileRequest>>();
|
||||
_mockDeleteFileService = new Mock<IActionService<DeleteFileRequest>>();
|
||||
_mockRenameFileService = new Mock<IActionService<RenameFileRequest>>();
|
||||
_mockZipDirectoryService = new Mock<IActionService<ZipDirectoryRequest>>();
|
||||
_mockUnzipFileService = new Mock<IActionService<UnzipFileRequest>>();
|
||||
_mockUnzipPasswordProtectedFileService = new Mock<IActionService<UnzipPasswordProtectedFileRequest>>();
|
||||
_mockCreateDirectoryService = new Mock<IActionService<CreateDirectoryRequest>>();
|
||||
_mockRenameDirectoryService = new Mock<IActionService<RenameDirectoryRequest>>();
|
||||
_mockBulkMoveFileService = new Mock<IActionService<BulkOperationRequest<MoveFileRequest>>>();
|
||||
_mockEncryptFileDataService = new Mock<IActionService<EncryptFileDataRequest>>();
|
||||
_mockDecryptFileDataService = new Mock<IActionService<DecryptFileDataRequest>>();
|
||||
_mockWriteFileDataService = new Mock<IActionService<WriteFileRequest>>();
|
||||
_mockDeleteDirectoryService = new Mock<IActionService<DeleteDirectoryRequest>>();
|
||||
_mockDeleteEmptyDirectoriesService = new Mock<IActionService<DeleteEmptyDirectoryRequest>>();
|
||||
_mockDirectFileService = new Mock<IDirectFileService>();
|
||||
|
||||
_controller = new FileOperationsController(
|
||||
_mockFileOperationsService.Object,
|
||||
_mockMoveFileService.Object,
|
||||
_mockCopyFileService.Object,
|
||||
_mockModifyFileService.Object,
|
||||
_mockDeleteFileService.Object,
|
||||
_mockRenameFileService.Object,
|
||||
_mockZipDirectoryService.Object,
|
||||
_mockUnzipFileService.Object,
|
||||
_mockUnzipPasswordProtectedFileService.Object,
|
||||
_mockCreateDirectoryService.Object,
|
||||
_mockRenameDirectoryService.Object,
|
||||
_mockBulkMoveFileService.Object,
|
||||
_mockEncryptFileDataService.Object,
|
||||
_mockDecryptFileDataService.Object,
|
||||
_mockWriteFileDataService.Object,
|
||||
_mockDeleteDirectoryService.Object,
|
||||
_mockDeleteEmptyDirectoriesService.Object,
|
||||
_mockDirectFileService.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetFile_OK()
|
||||
{
|
||||
var bytes = new byte[1];
|
||||
_mockDirectFileService.Setup(service => service.GetFileBytes(It.IsAny<string>())).Returns(bytes);
|
||||
|
||||
// act
|
||||
var result = _controller.GetFile("\\\\fakeit\\file.csv");
|
||||
Assert.NotNull(result);
|
||||
var okResult = result as FileContentResult;
|
||||
|
||||
// assert
|
||||
Assert.NotNull(okResult);
|
||||
_mockDirectFileService.Verify(service => service.GetFileBytes(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetFile_BadRequest_Pre()
|
||||
{
|
||||
var bytes = new byte[1];
|
||||
_mockDirectFileService.Setup(service => service.GetFileBytes(It.IsAny<string>())).Returns(bytes);
|
||||
|
||||
// act
|
||||
var result = _controller.GetFile(" ");
|
||||
Assert.NotNull(result);
|
||||
var badResult = result as BadRequestObjectResult;
|
||||
|
||||
// assert
|
||||
Assert.NotNull(badResult);
|
||||
Assert.Equal(400, badResult.StatusCode);
|
||||
_mockDirectFileService.Verify(service => service.GetFileBytes(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetFile_BadRequest_Post()
|
||||
{
|
||||
_mockDirectFileService.Setup(service => service.GetFileBytes(It.IsAny<string>()))
|
||||
.Throws<ArgumentException>();
|
||||
|
||||
// act
|
||||
var result = _controller.GetFile("\\\\fakeit\\file.csv");
|
||||
Assert.NotNull(result);
|
||||
var badResult = result as BadRequestObjectResult;
|
||||
|
||||
// assert
|
||||
Assert.NotNull(badResult);
|
||||
Assert.Equal(400, badResult.StatusCode);
|
||||
_mockDirectFileService.Verify(service => service.GetFileBytes(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
// Post tests
|
||||
[Fact]
|
||||
public async Task MoveFilePost_OK()
|
||||
{
|
||||
// arrange
|
||||
var request = new MoveFileRequest()
|
||||
{
|
||||
SourcePath = "",
|
||||
SourceFile = "",
|
||||
DestinationPath = ""
|
||||
};
|
||||
|
||||
var validRequestResponse = new RequestResponse() { MessageStack = new List<string>(), IsSuccessful = true };
|
||||
_mockMoveFileService.Setup(service => service.PreQueueValidation(It.IsAny<MoveFileRequest>())).Returns(validRequestResponse);
|
||||
|
||||
// act
|
||||
var result = await _controller.MoveFile(request);
|
||||
Assert.NotNull(result);
|
||||
var okResult = result as OkResult;
|
||||
|
||||
// assert
|
||||
Assert.NotNull(okResult);
|
||||
Assert.Equal(200, okResult.StatusCode);
|
||||
}
|
||||
|
||||
// Post tests
|
||||
[Fact]
|
||||
public async Task MoveFilePost_InvalidRequest()
|
||||
{
|
||||
// arrange
|
||||
var request = new MoveFileRequest() { };
|
||||
var validRequestResponse = new RequestResponse() { MessageStack = new List<string>() { "Invalid" }, IsSuccessful = false };
|
||||
_mockMoveFileService.Setup(service => service.PreQueueValidation(It.IsAny<MoveFileRequest>())).Returns(validRequestResponse);
|
||||
// act
|
||||
var result = await _controller.MoveFile(request);
|
||||
|
||||
Assert.NotNull(result);
|
||||
var badRequest = result as BadRequestObjectResult;
|
||||
Assert.Equal(400, badRequest.StatusCode);
|
||||
Assert.Equal($"Request is invalid. Response: {String.Join("\n ", validRequestResponse.MessageStack.ToArray())}", badRequest.Value);
|
||||
}
|
||||
|
||||
// Post tests
|
||||
[Fact]
|
||||
public async Task CopyFilePost_OK()
|
||||
{
|
||||
// arrange
|
||||
var request = new CopyFileRequest()
|
||||
{
|
||||
SourcePath = "",
|
||||
SourceFile = "",
|
||||
DestinationPath = ""
|
||||
};
|
||||
|
||||
var validRequestResponse = new RequestResponse() { MessageStack = new List<string>(), IsSuccessful = true };
|
||||
_mockCopyFileService.Setup(service => service.PreQueueValidation(It.IsAny<CopyFileRequest>())).Returns(validRequestResponse);
|
||||
|
||||
// act
|
||||
var result = await _controller.CopyFile(request);
|
||||
Assert.NotNull(result);
|
||||
var okResult = result as OkResult;
|
||||
|
||||
// assert
|
||||
Assert.NotNull(okResult);
|
||||
Assert.Equal(200, okResult.StatusCode);
|
||||
}
|
||||
|
||||
// Post tests
|
||||
[Fact]
|
||||
public async Task CopyFilePost_InvalidRequest()
|
||||
{
|
||||
// arrange
|
||||
var request = new CopyFileRequest() { };
|
||||
var validRequestResponse = new RequestResponse() { MessageStack = new List<string>() { "Invalid" }, IsSuccessful = false };
|
||||
_mockCopyFileService.Setup(service => service.PreQueueValidation(It.IsAny<CopyFileRequest>())).Returns(validRequestResponse);
|
||||
// act
|
||||
var result = await _controller.CopyFile(request);
|
||||
|
||||
Assert.NotNull(result);
|
||||
var badRequest = result as BadRequestObjectResult;
|
||||
Assert.Equal(400, badRequest.StatusCode);
|
||||
Assert.Equal($"Request is invalid. Response: {String.Join("\n ", validRequestResponse.MessageStack.ToArray())}", badRequest.Value);
|
||||
}
|
||||
|
||||
// Post tests
|
||||
[Fact]
|
||||
public async Task UnzipPasswordProtectedFilePost_OK()
|
||||
{
|
||||
// arrange
|
||||
var request = new UnzipPasswordProtectedFileRequest()
|
||||
{
|
||||
SourceDirectory = "",
|
||||
PasswordProtectedZipFileName = "",
|
||||
Password = "",
|
||||
DestinationPath = ""
|
||||
};
|
||||
|
||||
var validRequestResponse = new RequestResponse() { MessageStack = new List<string>(), IsSuccessful = true };
|
||||
_mockUnzipPasswordProtectedFileService.Setup(service => service.PreQueueValidation(It.IsAny<UnzipPasswordProtectedFileRequest>())).Returns(validRequestResponse);
|
||||
|
||||
// act
|
||||
var result = await _controller.UnzipPasswordProtectedFile(request);
|
||||
|
||||
// assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(200, (result as OkResult).StatusCode);
|
||||
}
|
||||
|
||||
// Post tests
|
||||
[Fact]
|
||||
public async Task UnzipPasswordProtectedFilePost_InvalidRequest()
|
||||
{
|
||||
// arrange
|
||||
var request = new UnzipPasswordProtectedFileRequest() { };
|
||||
var validRequestResponse = new RequestResponse() { MessageStack = new List<string>() { "Invalid" }, IsSuccessful = false };
|
||||
_mockUnzipPasswordProtectedFileService.Setup(service => service.PreQueueValidation(It.IsAny<UnzipPasswordProtectedFileRequest>())).Returns(validRequestResponse);
|
||||
// act
|
||||
var result = await _controller.UnzipPasswordProtectedFile(request);
|
||||
|
||||
Assert.NotNull(result);
|
||||
var badRequest = result as BadRequestObjectResult;
|
||||
Assert.Equal(400, badRequest.StatusCode);
|
||||
Assert.Equal($"Request is invalid. Response: {String.Join("\n ", validRequestResponse.MessageStack.ToArray())}", badRequest.Value);
|
||||
}
|
||||
|
||||
// Post tests
|
||||
[Fact]
|
||||
public async Task HandleRequestResponsePost_CopyFileRequest_OK()
|
||||
{
|
||||
// arrange
|
||||
var request = new CopyFileRequest()
|
||||
{
|
||||
SourcePath = "",
|
||||
SourceFile = "",
|
||||
DestinationPath = ""
|
||||
};
|
||||
|
||||
var validRequestResponse = new RequestResponse() { MessageStack = new List<string>(), IsSuccessful = true };
|
||||
_mockCopyFileService.Setup(service => service.PreQueueValidation(It.IsAny<CopyFileRequest>())).Returns(validRequestResponse);
|
||||
|
||||
// act
|
||||
var result = await _controller.HandleRequestResponse<CopyFileRequest>(request, FileOperationType.Copy, _mockCopyFileService.Object);
|
||||
Assert.NotNull(result);
|
||||
var okResult = result as OkResult;
|
||||
|
||||
// assert
|
||||
Assert.NotNull(okResult);
|
||||
Assert.Equal(200, okResult.StatusCode);
|
||||
}
|
||||
|
||||
// Post tests
|
||||
[Fact]
|
||||
public async Task HandleRequestResponsePost_CreateDirectoryRequest_OK()
|
||||
{
|
||||
// arrange
|
||||
var request = new CreateDirectoryRequest()
|
||||
{
|
||||
DirectoryName = "",
|
||||
DirectoryPath = ""
|
||||
};
|
||||
|
||||
var validRequestResponse = new RequestResponse() { MessageStack = new List<string>(), IsSuccessful = true };
|
||||
_mockCreateDirectoryService.Setup(service => service.PreQueueValidation(It.IsAny<CreateDirectoryRequest>())).Returns(validRequestResponse);
|
||||
|
||||
// act
|
||||
var result = await _controller.HandleRequestResponse<CreateDirectoryRequest>(request, FileOperationType.CreateDirectory,
|
||||
_mockCreateDirectoryService.Object);
|
||||
Assert.NotNull(result);
|
||||
var okResult = result as OkResult;
|
||||
|
||||
// assert
|
||||
Assert.NotNull(okResult);
|
||||
Assert.Equal(200, okResult.StatusCode);
|
||||
}
|
||||
}
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
using LCU.Library.Internal.Exceptions;
|
||||
using LCU.Api.Internal.FileOperations.Controllers;
|
||||
using LCU.Library.Internal.FileOperationsModels.Models;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.Api.Internal.FileOperations.Services.QueueServices;
|
||||
|
||||
namespace LCU.Api.Internal.FileOperationsTests.Controllers
|
||||
{
|
||||
public class IndexFileControllerTest
|
||||
{
|
||||
private IndexFileController _controller;
|
||||
private Mock<IQueueFileOperationsService> _mockQueueFileOperationsService;
|
||||
|
||||
public IndexFileControllerTest()
|
||||
{
|
||||
_mockQueueFileOperationsService = new Mock<IQueueFileOperationsService>();
|
||||
_controller = new IndexFileController(_mockQueueFileOperationsService.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task BatchPdfParser_OK()
|
||||
{
|
||||
var request = new ExtractIndexFileDataRequest()
|
||||
{
|
||||
IndexFilePath = "\\test\test",
|
||||
IndexFileName = "Test.csv"
|
||||
};
|
||||
_mockQueueFileOperationsService.Setup(service => service.QueueFileOperations(It.IsAny<ExtractIndexFileDataRequest>(), It.IsAny<FileOperationType>())).Verifiable();
|
||||
|
||||
var result = await _controller.QueueExtractIndexFileData(request);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var acceptedResult = result as AcceptedResult;
|
||||
Assert.NotNull(acceptedResult);
|
||||
Assert.Equal(202, acceptedResult!.StatusCode);
|
||||
_mockQueueFileOperationsService.Verify();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExtractIndexFileDataRequest_ServiceException_InternalServerError()
|
||||
{
|
||||
var request = new ExtractIndexFileDataRequest()
|
||||
{
|
||||
IndexFilePath = "\\test\test",
|
||||
IndexFileName = "Test.csv"
|
||||
};
|
||||
_mockQueueFileOperationsService.Setup(service => service.QueueFileOperations(It.IsAny<ExtractIndexFileDataRequest>(), It.IsAny<FileOperationType>()))
|
||||
.Throws(new ServiceException("Thrown From Unit Test")).Verifiable();
|
||||
|
||||
var result = await _controller.QueueExtractIndexFileData(request);
|
||||
Assert.NotNull(result);
|
||||
var statusResult = result as ObjectResult;
|
||||
Assert.NotNull(statusResult);
|
||||
Assert.Equal(500, statusResult!.StatusCode);
|
||||
_mockQueueFileOperationsService.Verify();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExtractIndexFileDataRequest_UnexpectedException_InternalServerError()
|
||||
{
|
||||
var request = new ExtractIndexFileDataRequest()
|
||||
{
|
||||
IndexFilePath = "\\test\test",
|
||||
IndexFileName = "Test.csv"
|
||||
};
|
||||
_mockQueueFileOperationsService.Setup(service => service.QueueFileOperations(It.IsAny<ExtractIndexFileDataRequest>(), It.IsAny<FileOperationType>()))
|
||||
.Throws(new Exception("Thrown From Unit Test")).Verifiable();
|
||||
|
||||
var result = await _controller.QueueExtractIndexFileData(request);
|
||||
Assert.NotNull(result);
|
||||
var statusResult = result as StatusCodeResult;
|
||||
Assert.NotNull(statusResult);
|
||||
Assert.Equal(500, statusResult!.StatusCode);
|
||||
_mockQueueFileOperationsService.Verify();
|
||||
}
|
||||
}
|
||||
}
|
||||
+330
@@ -0,0 +1,330 @@
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
using LCU.Library.Internal.Exceptions;
|
||||
using LCU.Api.Internal.FileOperations.Controllers;
|
||||
using LCU.Api.Internal.FileOperations.Services;
|
||||
using LCU.Library.Internal.FileOperationsModels.Models;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
using LCU.Library.Internal.FileOperationsModels.Models.HtmlToPdfModels;
|
||||
using LCU.Api.Internal.FileOperations.Services.QueueServices;
|
||||
using LCU.Api.Internal.FileOperations.Services.PdfServices;
|
||||
|
||||
namespace LCU.Api.Internal.FileOperationsTests.Controllers
|
||||
{
|
||||
public class PdfControllerTest
|
||||
{
|
||||
private PdfController _pdfController;
|
||||
private Mock<IQueueFileOperationsService> _mockQueueFileOperationsService;
|
||||
private Mock<IPdfParserService> _mockPdfParserService;
|
||||
private Mock<IBatchPdfParserService> _mockBatchPdfParserService;
|
||||
private Mock<IDirectFileService> _mockDirectFileService;
|
||||
private Mock<IHtmlToPdfService> _mockHtmlToPdfService;
|
||||
|
||||
public PdfControllerTest()
|
||||
{
|
||||
_mockQueueFileOperationsService = new Mock<IQueueFileOperationsService>();
|
||||
_mockPdfParserService = new Mock<IPdfParserService>();
|
||||
_mockBatchPdfParserService = new Mock<IBatchPdfParserService>();
|
||||
_mockDirectFileService = new Mock<IDirectFileService>();
|
||||
_mockHtmlToPdfService = new Mock<IHtmlToPdfService>();
|
||||
_pdfController = new PdfController(_mockQueueFileOperationsService.Object,
|
||||
_mockPdfParserService.Object,
|
||||
_mockBatchPdfParserService.Object,
|
||||
_mockDirectFileService.Object,
|
||||
_mockHtmlToPdfService.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task BatchPdfParser_OK()
|
||||
{
|
||||
var batchPdfParserRequest = new BatchParsePdfRequest()
|
||||
{
|
||||
RootPath = "\\test\test",
|
||||
PdfName = "Test.pdf",
|
||||
BatchPdfs = new List<BatchPdf>()
|
||||
{
|
||||
new BatchPdf
|
||||
{
|
||||
PageStart = 1,
|
||||
PageStop = 2
|
||||
}
|
||||
}
|
||||
};
|
||||
var requestResponse = new RequestResponse
|
||||
{
|
||||
IsSuccessful = true
|
||||
};
|
||||
_mockBatchPdfParserService.Setup(service => service.IsRequestValid(batchPdfParserRequest, It.IsAny<RequestResponse>()))
|
||||
.Returns(requestResponse).Verifiable();
|
||||
_mockQueueFileOperationsService.Setup(service => service.QueueFileOperations(It.IsAny<BatchParsePdfRequest>(), It.IsAny<FileOperationType>())).Verifiable();
|
||||
|
||||
var result = await _pdfController.QueueBatchPdfParser(batchPdfParserRequest);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var acceptedResult = result as AcceptedResult;
|
||||
Assert.NotNull(acceptedResult);
|
||||
Assert.Equal(202, acceptedResult!.StatusCode);
|
||||
_mockBatchPdfParserService.Verify();
|
||||
_mockQueueFileOperationsService.Verify();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task BatchParsePdfRequest_ServiceException_InternalServerError()
|
||||
{
|
||||
var batchPdfParserRequest = new BatchParsePdfRequest()
|
||||
{
|
||||
RootPath = "\\test\test",
|
||||
PdfName = "Test.pdf",
|
||||
BatchPdfs = new List<BatchPdf>()
|
||||
{
|
||||
new BatchPdf
|
||||
{
|
||||
PageStart = 1,
|
||||
PageStop = 2
|
||||
}
|
||||
}
|
||||
};
|
||||
var requestResponse = new RequestResponse
|
||||
{
|
||||
IsSuccessful = true
|
||||
};
|
||||
_mockBatchPdfParserService.Setup(service => service.IsRequestValid(batchPdfParserRequest, It.IsAny<RequestResponse>()))
|
||||
.Returns(requestResponse).Verifiable();
|
||||
_mockQueueFileOperationsService.Setup(service => service.QueueFileOperations(It.IsAny<BatchParsePdfRequest>(), It.IsAny<FileOperationType>()))
|
||||
.Throws(new ServiceException("Thrown From Unit Test")).Verifiable();
|
||||
|
||||
var result = await _pdfController.QueueBatchPdfParser(batchPdfParserRequest);
|
||||
Assert.NotNull(result);
|
||||
var statusResult = result as ObjectResult;
|
||||
Assert.NotNull(statusResult);
|
||||
Assert.Equal(500, statusResult!.StatusCode);
|
||||
_mockBatchPdfParserService.Verify();
|
||||
_mockQueueFileOperationsService.Verify();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task BatchParsePdfRequest_UnexpectedException_InternalServerError()
|
||||
{
|
||||
var batchPdfParserRequest = new BatchParsePdfRequest()
|
||||
{
|
||||
RootPath = "\\test\test",
|
||||
PdfName = "Test.pdf",
|
||||
BatchPdfs = new List<BatchPdf>()
|
||||
{
|
||||
new BatchPdf
|
||||
{
|
||||
PageStart = 1,
|
||||
PageStop = 2
|
||||
}
|
||||
}
|
||||
};
|
||||
var requestResponse = new RequestResponse
|
||||
{
|
||||
IsSuccessful = true
|
||||
};
|
||||
_mockBatchPdfParserService.Setup(service => service.IsRequestValid(batchPdfParserRequest, It.IsAny<RequestResponse>()))
|
||||
.Returns(requestResponse).Verifiable();
|
||||
_mockQueueFileOperationsService.Setup(service => service.QueueFileOperations(It.IsAny<BatchParsePdfRequest>(), It.IsAny<FileOperationType>()))
|
||||
.Throws(new Exception("Thrown From Unit Test")).Verifiable();
|
||||
|
||||
var result = await _pdfController.QueueBatchPdfParser(batchPdfParserRequest);
|
||||
Assert.NotNull(result);
|
||||
var statusResult = result as StatusCodeResult;
|
||||
Assert.NotNull(statusResult);
|
||||
Assert.Equal(500, statusResult!.StatusCode);
|
||||
_mockBatchPdfParserService.Verify();
|
||||
_mockQueueFileOperationsService.Verify();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParsePdf_OK()
|
||||
{
|
||||
var parsePdfRequest = new ParsePdfRequest()
|
||||
{
|
||||
RootPath = "\\test\test",
|
||||
PdfName = "Test.pdf",
|
||||
PageStart = 1,
|
||||
PageStop = 2
|
||||
};
|
||||
var newPdfResponse = "test.pdf";
|
||||
_mockPdfParserService.Setup(service => service.ParsePdf(parsePdfRequest)).Returns(newPdfResponse).Verifiable();
|
||||
|
||||
var result = _pdfController.ParsePdf(parsePdfRequest);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.Equal(200, okResult!.StatusCode);
|
||||
_mockPdfParserService.Verify();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParsePdf_ServiceException_InternalServerError()
|
||||
{
|
||||
var parsePdfRequest = new ParsePdfRequest()
|
||||
{
|
||||
RootPath = "\\test\test",
|
||||
PdfName = "Test.pdf",
|
||||
PageStart = 1,
|
||||
PageStop = 2
|
||||
};
|
||||
_mockPdfParserService.Setup(service => service.ParsePdf(parsePdfRequest))
|
||||
.Throws(new ServiceException("Thrown From Unit Test")).Verifiable();
|
||||
|
||||
var result = _pdfController.ParsePdf(parsePdfRequest);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var statusResult = result as ObjectResult;
|
||||
Assert.NotNull(statusResult);
|
||||
Assert.Equal(500, statusResult!.StatusCode);
|
||||
_mockPdfParserService.Verify();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParsePdf_UnexpectedException_InternalServerError()
|
||||
{
|
||||
var parsePdfRequest = new ParsePdfRequest()
|
||||
{
|
||||
RootPath = "\\test\test",
|
||||
PdfName = "Test.pdf",
|
||||
PageStart = 1,
|
||||
PageStop = 2
|
||||
};
|
||||
_mockPdfParserService.Setup(service => service.ParsePdf(parsePdfRequest))
|
||||
.Throws(new Exception("Thrown From Unit Test")).Verifiable();
|
||||
|
||||
var result = _pdfController.ParsePdf(parsePdfRequest);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var statusResult = result as StatusCodeResult;
|
||||
Assert.NotNull(statusResult);
|
||||
Assert.Equal(500, statusResult!.StatusCode);
|
||||
_mockPdfParserService.Verify();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetPdfConent_OK()
|
||||
{
|
||||
var pdfPath = "\\\\Test\\PdfPath\\test.pdf";
|
||||
var btyes = new byte[23122321];
|
||||
_mockDirectFileService.Setup(service => service.GetFileBytes(pdfPath)).Returns(btyes).Verifiable();
|
||||
|
||||
var result = _pdfController.GetPdfContent(pdfPath);
|
||||
var okResult = result as FileContentResult;
|
||||
Assert.NotNull(okResult);
|
||||
_mockDirectFileService.Verify();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetPdfConent_UnexpectedException_InternalServerError()
|
||||
{
|
||||
var pdfPath = "\\\\Test\\PdfPath\\test.pdf";
|
||||
_mockDirectFileService.Setup(service => service.GetFileBytes(pdfPath))
|
||||
.Throws(new Exception("Thrown From Unit Test")).Verifiable();
|
||||
|
||||
var result = _pdfController.GetPdfContent(pdfPath);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var statusResult = result as StatusCodeResult;
|
||||
Assert.NotNull(statusResult);
|
||||
Assert.Equal(500, statusResult!.StatusCode);
|
||||
_mockPdfParserService.Verify();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetPdfConent_ArgumentException_InternalServerError()
|
||||
{
|
||||
var pdfPath = "\\\\Test\\PdfPath\\test.pdf";
|
||||
_mockDirectFileService.Setup(service => service.GetFileBytes(pdfPath))
|
||||
.Throws(new ArgumentException("Thrown From Unit Test")).Verifiable();
|
||||
|
||||
var result = _pdfController.GetPdfContent(pdfPath);
|
||||
Assert.NotNull(result);
|
||||
var statusResult = result as BadRequestObjectResult;
|
||||
Assert.NotNull(statusResult);
|
||||
Assert.Equal(400, statusResult!.StatusCode);
|
||||
_mockPdfParserService.Verify();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ConvertHtmlToPdf_OK()
|
||||
{
|
||||
var htmlToPdfRequest = new HtmlToPdfRequest()
|
||||
{
|
||||
HtmlTemplateFilePath = "\\Test",
|
||||
BodyTagValues = new List<TagValue>
|
||||
{
|
||||
new TagValue
|
||||
{
|
||||
Tag = "Test Tag",
|
||||
Value = "Test Value"
|
||||
}
|
||||
}
|
||||
};
|
||||
var btyes = new byte[23122321];
|
||||
_mockHtmlToPdfService.Setup(service => service.ConvertHtmlToPdf(htmlToPdfRequest)).Returns(btyes).Verifiable();
|
||||
|
||||
var result = _pdfController.ConvertHtmlToPdf(htmlToPdfRequest);
|
||||
var okResult = result as FileContentResult;
|
||||
Assert.NotNull(okResult);
|
||||
_mockDirectFileService.Verify();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ConvertHtmlToPdf_ServiceExceptionException_InternalServerError()
|
||||
{
|
||||
var htmlToPdfRequest = new HtmlToPdfRequest()
|
||||
{
|
||||
HtmlTemplateFilePath = "\\Test",
|
||||
BodyTagValues = new List<TagValue>
|
||||
{
|
||||
new TagValue
|
||||
{
|
||||
Tag = "Test Tag",
|
||||
Value = "Test Value"
|
||||
}
|
||||
}
|
||||
};
|
||||
_mockHtmlToPdfService.Setup(service => service.ConvertHtmlToPdf(htmlToPdfRequest))
|
||||
.Throws(new ServiceException("Thrown From Unit Test")).Verifiable();
|
||||
|
||||
var result = _pdfController.ConvertHtmlToPdf(htmlToPdfRequest);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var statusResult = result as ObjectResult;
|
||||
Assert.NotNull(statusResult);
|
||||
Assert.Equal(500, statusResult!.StatusCode);
|
||||
_mockPdfParserService.Verify();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetConvertHtmlToPdf_UnexpectedExceptionException_InternalServerError()
|
||||
{
|
||||
var htmlToPdfRequest = new HtmlToPdfRequest()
|
||||
{
|
||||
HtmlTemplateFilePath = "\\Test",
|
||||
BodyTagValues = new List<TagValue>
|
||||
{
|
||||
new TagValue
|
||||
{
|
||||
Tag = "Test Tag",
|
||||
Value = "Test Value"
|
||||
}
|
||||
}
|
||||
};
|
||||
_mockHtmlToPdfService.Setup(service => service.ConvertHtmlToPdf(htmlToPdfRequest))
|
||||
.Throws(new Exception("Thrown From Unit Test")).Verifiable();
|
||||
|
||||
var result = _pdfController.ConvertHtmlToPdf(htmlToPdfRequest);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var statusResult = result as StatusCodeResult;
|
||||
Assert.NotNull(statusResult);
|
||||
Assert.Equal(500, statusResult!.StatusCode);
|
||||
_mockPdfParserService.Verify();
|
||||
}
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
|
||||
<PackageReference Include="Moq" Version="4.13.0" />
|
||||
<PackageReference Include="NUnit" Version="3.13.3" />
|
||||
<PackageReference Include="xunit" Version="2.4.0" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\LCU.Api.Internal.FileOperations\LCU.Api.Internal.FileOperations.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
using LCU.Api.Internal.FileOperations.Services;
|
||||
using LCU.Library.Internal.FileOperationsModels.Models;
|
||||
namespace LCU.Api.Internal.FileOperationsTests.Services;
|
||||
|
||||
public class DirectFileOperationsServiceTest
|
||||
{
|
||||
private readonly DirectFileOperationsService _directFileOperationsService;
|
||||
private Mock<IFileOperationsService> _mockFileOperationsService;
|
||||
|
||||
public DirectFileOperationsServiceTest()
|
||||
{
|
||||
_mockFileOperationsService = new Mock<IFileOperationsService>();
|
||||
_directFileOperationsService = new DirectFileOperationsService(_mockFileOperationsService.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleDirectFileOperationsRequest_Return_IsSuccessful_True()
|
||||
{
|
||||
var validRequestResponse = new RequestResponse() { MessageStack = new List<string>(), IsSuccessful = true };
|
||||
_mockFileOperationsService.Setup(service => service.PerformFileOperation(It.IsAny<QueueRequest>())).Returns(validRequestResponse);
|
||||
|
||||
var request = new MoveFileRequest()
|
||||
{
|
||||
SourcePath = "",
|
||||
SourceFile = "",
|
||||
DestinationPath = ""
|
||||
};
|
||||
|
||||
// act
|
||||
var result = await _directFileOperationsService.HandleDirectFileOperationsRequest(request, FileOperationType.Move);
|
||||
Assert.NotNull(result);
|
||||
Assert.True(validRequestResponse.IsSuccessful);
|
||||
_mockFileOperationsService.Verify(service => service.PerformFileOperation(It.IsAny<QueueRequest>()), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleDirectFileOperationsRequest_Return_IsSuccessful_False()
|
||||
{
|
||||
var validRequestResponse = new RequestResponse() { MessageStack = new List<string> { "test" }, IsSuccessful = false };
|
||||
_mockFileOperationsService.Setup(service => service.PerformFileOperation(It.IsAny<QueueRequest>())).Returns(validRequestResponse);
|
||||
|
||||
var request = new MoveFileRequest()
|
||||
{
|
||||
SourcePath = "",
|
||||
SourceFile = "",
|
||||
DestinationPath = ""
|
||||
};
|
||||
|
||||
// act
|
||||
var result = await _directFileOperationsService.HandleDirectFileOperationsRequest(request, FileOperationType.Move);
|
||||
Assert.NotNull(result);
|
||||
Assert.False(result.IsSuccessful);
|
||||
Assert.Single(result.MessageStack);
|
||||
_mockFileOperationsService.Verify(service => service.PerformFileOperation(It.IsAny<QueueRequest>()), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HandleDirectFileOperationsRequest_PerformFileOperation_ThrowsException()
|
||||
{
|
||||
var validRequestResponse = new RequestResponse() { MessageStack = new List<string>(), IsSuccessful = true };
|
||||
_mockFileOperationsService.Setup(service => service.PerformFileOperation(It.IsAny<QueueRequest>())).Throws(new Exception("Test"));
|
||||
|
||||
var request = new MoveFileRequest()
|
||||
{
|
||||
SourcePath = "",
|
||||
SourceFile = "",
|
||||
DestinationPath = ""
|
||||
};
|
||||
|
||||
// act
|
||||
Assert.ThrowsAsync<ArgumentNullException>(async () => await _directFileOperationsService.HandleDirectFileOperationsRequest(request, FileOperationType.Move));
|
||||
_mockFileOperationsService.Verify(service => service.PerformFileOperation(It.IsAny<QueueRequest>()), Times.Once);
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
using LCU.Api.Internal.FileOperations.Services;
|
||||
using System;
|
||||
using Xunit;
|
||||
|
||||
namespace LCU.Api.Internal.FileOperationsTests.Services
|
||||
{
|
||||
public class DirectFileServiceTest
|
||||
{
|
||||
private readonly DirectFileService _directFileService;
|
||||
|
||||
public DirectFileServiceTest()
|
||||
{
|
||||
_directFileService = new DirectFileService();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Sir_Throws_A_Lot()
|
||||
{
|
||||
Assert.Throws<ArgumentException>(
|
||||
() => { _directFileService.GetFileBytes(" "); });
|
||||
Assert.Throws<ArgumentException>(
|
||||
() => { _directFileService.GetFileBytes("C:\\secret.txt"); });
|
||||
Assert.Throws<ArgumentException>(
|
||||
() => { _directFileService.GetFileBytes("asdf"); });
|
||||
}
|
||||
}
|
||||
}
|
||||
+126
@@ -0,0 +1,126 @@
|
||||
using Moq;
|
||||
using Xunit;
|
||||
using LCU.Api.Internal.FileOperations.Services;
|
||||
using LCU.Api.Internal.FileOperations.Services.FileActionServices;
|
||||
using LCU.Library.Internal.FileOperationsModels.Models;
|
||||
using LCU.Api.Internal.FileOperations.Configurations;
|
||||
using LCU.Api.Internal.FileOperations.Services.QueueServices;
|
||||
using LCU.Library.Internal.LCUServiceFactory.Services;
|
||||
using System;
|
||||
namespace LCU.Api.Internal.FileOperationsTests.Services;
|
||||
|
||||
public class FileOperationsServiceTest
|
||||
{
|
||||
private readonly FileOperationsService _fileOperationsService;
|
||||
private readonly Mock<ILcuServiceFactory<IFileActionService>> _mockServiceFactory;
|
||||
private Mock<IQueueFileOperationsService> _mockQueueFileOperationsService;
|
||||
|
||||
public FileOperationsServiceTest()
|
||||
{
|
||||
var apiConfiguration = new ApiConfiguration()
|
||||
{
|
||||
AttemptsLimit = 2
|
||||
};
|
||||
_mockQueueFileOperationsService = new Mock<IQueueFileOperationsService>();
|
||||
_mockServiceFactory = new Mock<ILcuServiceFactory<IFileActionService>>();
|
||||
_fileOperationsService = new FileOperationsService(
|
||||
_mockQueueFileOperationsService.Object,
|
||||
apiConfiguration,
|
||||
_mockServiceFactory.Object);
|
||||
;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Basic_Construct_Test()
|
||||
{
|
||||
Assert.NotNull(_fileOperationsService);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ShouldPerformFileOperationsAgain_AttempsLessThenLimit_True()
|
||||
{
|
||||
var request = new QueueRequest()
|
||||
{
|
||||
Attempts = 0
|
||||
};
|
||||
var requestResponse = new RequestResponse()
|
||||
{
|
||||
IsSuccessful = false
|
||||
};
|
||||
var result = _fileOperationsService.ShouldPerformFileOperationsAgain(request, requestResponse);
|
||||
|
||||
Assert.True(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ShouldPerformFileOperationsAgain_AttempsGreaterThenLimit_False()
|
||||
{
|
||||
var request = new QueueRequest()
|
||||
{
|
||||
Attempts = 3
|
||||
};
|
||||
|
||||
var requestResponse = new RequestResponse()
|
||||
{
|
||||
IsSuccessful = false
|
||||
};
|
||||
var result = _fileOperationsService.ShouldPerformFileOperationsAgain(request, requestResponse);
|
||||
|
||||
Assert.False(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PerformFileOperation_IsSuccessful()
|
||||
{
|
||||
QueueRequest request = null;
|
||||
|
||||
var result = _fileOperationsService.PerformFileOperation(request);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.Single(result.MessageStack);
|
||||
Assert.True(result.IsSuccessful);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PerformFileOperation_NullRequest_IsSuccessful()
|
||||
{
|
||||
var request = new QueueRequest()
|
||||
{
|
||||
Attempts = 3,
|
||||
FileOperationType = FileOperationType.Move
|
||||
};
|
||||
|
||||
var response = new RequestResponse();
|
||||
|
||||
var mockedFileActionService = new Mock<IFileActionService>();
|
||||
_mockServiceFactory.Setup(x => x.GetService(request.FileOperationType)).Returns(mockedFileActionService.Object);
|
||||
mockedFileActionService.Setup(x => x.ExecuteAction(request)).Returns(response);
|
||||
|
||||
var result = _fileOperationsService.PerformFileOperation(request);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.Empty(result.MessageStack);
|
||||
Assert.True(result.IsSuccessful);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PerformFileOperation_ServiceFactoryException_IsNotSuccessful()
|
||||
{
|
||||
var request = new QueueRequest()
|
||||
{
|
||||
Attempts = 3,
|
||||
FileOperationType = FileOperationType.Move
|
||||
};
|
||||
|
||||
var response = new RequestResponse();
|
||||
|
||||
var mockedFileActionService = new Mock<IFileActionService>();
|
||||
_mockServiceFactory.Setup(x => x.GetService(request.FileOperationType)).Throws(new Exception("Failure"));
|
||||
|
||||
var result = _fileOperationsService.PerformFileOperation(request);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.Single(result.MessageStack);
|
||||
Assert.False(result.IsSuccessful);
|
||||
}
|
||||
}
|
||||
+128
@@ -0,0 +1,128 @@
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
using LCU.Library.Internal.FileOperationsModels.Models;
|
||||
using LCU.Api.Internal.FileOperations.Validations;
|
||||
namespace LCU.Api.Internal.FileOperationsTests.Services.Validations;
|
||||
|
||||
public class FileValidationTest
|
||||
{
|
||||
[Fact]
|
||||
public void IsSourceEmpty_SourceEmpty_ReturnIsValid_False()
|
||||
{
|
||||
// arrange
|
||||
var sourcePath = "";
|
||||
var responseRequest = new RequestResponse();
|
||||
|
||||
// act
|
||||
responseRequest = FileValidation.ValidateSourceNotEmpty(sourcePath, responseRequest);
|
||||
|
||||
// assert
|
||||
Assert.False(responseRequest.IsSuccessful);
|
||||
Assert.Equal("Source is empty and is required.", responseRequest.MessageStack.FirstOrDefault());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsSourceEmpty_SourceNotEmpty_ReturnIsValid_True()
|
||||
{
|
||||
// arrange
|
||||
var sourcePath = "TESTSource";
|
||||
var responseRequest = new RequestResponse();
|
||||
|
||||
// act
|
||||
responseRequest = FileValidation.ValidateSourceNotEmpty(sourcePath, responseRequest);
|
||||
|
||||
// assert
|
||||
Assert.True(responseRequest.IsSuccessful);
|
||||
Assert.Empty(responseRequest.MessageStack);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsDestinationEmpty_DestinationEmpty_ReturnIsValid_False()
|
||||
{
|
||||
// arrange
|
||||
var sourcePath = "";
|
||||
var responseRequest = new RequestResponse();
|
||||
|
||||
// act
|
||||
responseRequest = FileValidation.ValidateDestinationNotEmpty(sourcePath, responseRequest);
|
||||
|
||||
// assert
|
||||
Assert.False(responseRequest.IsSuccessful);
|
||||
Assert.Equal("Destination is empty and is required.", responseRequest.MessageStack.FirstOrDefault());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsDestinationEmpty_DestinationNotEmpty_ReturnIsValid_True()
|
||||
{
|
||||
// arrange
|
||||
var destinationPath = "TESTDestination";
|
||||
var responseRequest = new RequestResponse();
|
||||
|
||||
// act
|
||||
responseRequest = FileValidation.ValidateDestinationNotEmpty(destinationPath, responseRequest);
|
||||
|
||||
// assert
|
||||
Assert.True(responseRequest.IsSuccessful);
|
||||
Assert.Empty(responseRequest.MessageStack);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsFilenameEmpty_FilenameEmpty_ReturnIsValid_False()
|
||||
{
|
||||
// arrange
|
||||
var filename = "";
|
||||
var responseRequest = new RequestResponse();
|
||||
|
||||
// act
|
||||
responseRequest = FileValidation.ValidateFilenameNotEmpty(filename, responseRequest);
|
||||
|
||||
// assert
|
||||
Assert.False(responseRequest.IsSuccessful);
|
||||
Assert.Equal("Filename is empty and is required.", responseRequest.MessageStack.FirstOrDefault());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsFilenameEmpty_FilenameNotEmpty_ReturnIsValid_True()
|
||||
{
|
||||
// arrange
|
||||
var filename = "TESTFilename";
|
||||
var responseRequest = new RequestResponse();
|
||||
|
||||
// act
|
||||
responseRequest = FileValidation.ValidateDestinationNotEmpty(filename, responseRequest);
|
||||
|
||||
// assert
|
||||
Assert.True(responseRequest.IsSuccessful);
|
||||
Assert.Empty(responseRequest.MessageStack);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsFilenameValid_FilenameNotValid_ReturnIsValid_False()
|
||||
{
|
||||
// arrange
|
||||
var filename = "/**";
|
||||
var responseRequest = new RequestResponse();
|
||||
|
||||
// act
|
||||
responseRequest = FileValidation.ValidateFilename(filename, responseRequest);
|
||||
|
||||
// assert
|
||||
Assert.False(responseRequest.IsSuccessful);
|
||||
Assert.Equal("File name is invalid.", responseRequest.MessageStack.FirstOrDefault());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsFilenameValid_FilenameValid_ReturnIsValid_True()
|
||||
{
|
||||
// arrange
|
||||
var filename = "TESTFilename";
|
||||
var responseRequest = new RequestResponse();
|
||||
|
||||
// act
|
||||
responseRequest = FileValidation.ValidateFilename(filename, responseRequest);
|
||||
|
||||
// assert
|
||||
Assert.True(responseRequest.IsSuccessful);
|
||||
Assert.Empty(responseRequest.MessageStack);
|
||||
}
|
||||
}
|
||||
+144
@@ -0,0 +1,144 @@
|
||||
using LCU.Library.Internal.FileOperationsModels.Models.NameSettings;
|
||||
using LCU.Library.Internal.FileOperationsModels.Shared;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Xunit;
|
||||
|
||||
namespace LCU.Api.Internal.FileOperationsTests.Shared
|
||||
{
|
||||
public class DynamicNameBuilderTest
|
||||
{
|
||||
public DynamicNameBuilderTest()
|
||||
{
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EmptyFileNameSettings_Return_FileName()
|
||||
{
|
||||
// arrange
|
||||
var name = "testfile.txt";
|
||||
var settings = new DynamicNameSetting();
|
||||
|
||||
// act
|
||||
var result = DynamicNameBuilder.BuildDynamicName(name, settings);
|
||||
|
||||
// assert
|
||||
Assert.Equal(name, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NullFileNameSettings_Return_FileName()
|
||||
{
|
||||
// arrange
|
||||
var name = "testfile.txt";
|
||||
DynamicNameSetting settings = null;
|
||||
|
||||
// act
|
||||
var result = DynamicNameBuilder.BuildDynamicName(name, settings);
|
||||
|
||||
// assert
|
||||
Assert.Equal(name, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Return_FileName_dd_MM()
|
||||
{
|
||||
// arrange
|
||||
var name = "testfile_{TestDate}.txt";
|
||||
var settings = new DynamicNameSetting();
|
||||
|
||||
var dateFormatSetting = new DateFormatSetting();
|
||||
dateFormatSetting.Tag = "{TestDate}";
|
||||
dateFormatSetting.DateFormat = "dd_MM";
|
||||
settings.DateFormatSettings = new List<DateFormatSetting>();
|
||||
settings.DateFormatSettings.Add(dateFormatSetting);
|
||||
|
||||
// act
|
||||
var result = DynamicNameBuilder.BuildDynamicName(name, settings);
|
||||
|
||||
// assert
|
||||
Assert.Equal($"testfile_{DateTime.Now:dd_MM}.txt", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Minus_One_Day_Return_FileName_dd_MM()
|
||||
{
|
||||
// arrange
|
||||
var name = "testfile_{TestDate}.txt";
|
||||
var settings = new DynamicNameSetting();
|
||||
settings.DaysFromToday = -1;
|
||||
|
||||
var dateFormatSetting = new DateFormatSetting();
|
||||
dateFormatSetting.Tag = "{TestDate}";
|
||||
dateFormatSetting.DateFormat = "dd_MM";
|
||||
settings.DateFormatSettings = new List<DateFormatSetting>();
|
||||
settings.DateFormatSettings.Add(dateFormatSetting);
|
||||
|
||||
// act
|
||||
var result = DynamicNameBuilder.BuildDynamicName(name, settings);
|
||||
|
||||
// assert
|
||||
Assert.Equal($"testfile_{DateTime.Now.AddDays(-1):dd_MM}.txt", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Multiple_Formats_sepratedby_dashs_Return_FileName_dd_MM_yyyy()
|
||||
{
|
||||
// arrange
|
||||
var name = "testfile_{TestDate}-{TestDate2}-{TestDate3}.txt";
|
||||
var settings = new DynamicNameSetting();
|
||||
settings.DateFormatSettings = new List<DateFormatSetting>();
|
||||
|
||||
var dateFormatSetting1 = new DateFormatSetting();
|
||||
dateFormatSetting1.Tag = "{TestDate}";
|
||||
dateFormatSetting1.DateFormat = "dd";
|
||||
settings.DateFormatSettings.Add(dateFormatSetting1);
|
||||
|
||||
var dateFormatSetting2 = new DateFormatSetting();
|
||||
dateFormatSetting2.Tag = "{TestDate2}";
|
||||
dateFormatSetting2.DateFormat = "MM";
|
||||
settings.DateFormatSettings.Add(dateFormatSetting2);
|
||||
|
||||
var dateFormatSetting3 = new DateFormatSetting();
|
||||
dateFormatSetting3.Tag = "{TestDate3}";
|
||||
dateFormatSetting3.DateFormat = "yyyy";
|
||||
settings.DateFormatSettings.Add(dateFormatSetting3);
|
||||
|
||||
// act
|
||||
var result = DynamicNameBuilder.BuildDynamicName(name, settings);
|
||||
|
||||
// assert
|
||||
Assert.Equal($"testfile_{DateTime.Now:dd}-{DateTime.Now:MM}-{DateTime.Now:yyyy}.txt", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Multiple_Formats_nosepration_Return_FileName_ddMMyyyy()
|
||||
{
|
||||
// arrange
|
||||
var fileName = "testfile_{TestDate}{TestDate2}{TestDate3}.txt";
|
||||
var settings = new DynamicNameSetting();
|
||||
settings.DateFormatSettings = new List<DateFormatSetting>();
|
||||
|
||||
var dateFormatSetting1 = new DateFormatSetting();
|
||||
dateFormatSetting1.Tag = "{TestDate}";
|
||||
dateFormatSetting1.DateFormat = "dd";
|
||||
settings.DateFormatSettings.Add(dateFormatSetting1);
|
||||
|
||||
var dateFormatSetting2 = new DateFormatSetting();
|
||||
dateFormatSetting2.Tag = "{TestDate2}";
|
||||
dateFormatSetting2.DateFormat = "MM";
|
||||
settings.DateFormatSettings.Add(dateFormatSetting2);
|
||||
|
||||
var dateFormatSetting3 = new DateFormatSetting();
|
||||
dateFormatSetting3.Tag = "{TestDate3}";
|
||||
dateFormatSetting3.DateFormat = "yyyy";
|
||||
settings.DateFormatSettings.Add(dateFormatSetting3);
|
||||
|
||||
// act
|
||||
var result = DynamicNameBuilder.BuildDynamicName(fileName, settings);
|
||||
|
||||
// assert
|
||||
Assert.Equal($"testfile_{DateTime.Now:dd}{DateTime.Now:MM}{DateTime.Now:yyyy}.txt", result);
|
||||
}
|
||||
}
|
||||
}
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
using LCU.Library.Internal.FileOperationsModels.Models.NameSettings;
|
||||
using LCU.Library.Internal.FileOperationsModels.Shared;
|
||||
using System.Collections.Generic;
|
||||
using Xunit;
|
||||
|
||||
namespace LCU.Api.Internal.FileOperationsTests.Shared
|
||||
{
|
||||
public class RegexNameHandlerTest
|
||||
{
|
||||
|
||||
[Fact]
|
||||
public void BuildFileList_NoRegex_Return_SingleFileName()
|
||||
{
|
||||
// arrange
|
||||
var name = "testfile.txt";
|
||||
var path = "\\TEST";
|
||||
var settings = new DynamicNameSetting();
|
||||
|
||||
// act
|
||||
var result = RegexNameHandler.BuildFileList(path, name, settings);
|
||||
|
||||
// assert
|
||||
Assert.Single(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BuildRegexName_Return_FileName_OneRegex_Replaced()
|
||||
{
|
||||
// arrange
|
||||
var name = "testfile_{Regex01}.txt";
|
||||
var settings = new DynamicNameSetting();
|
||||
settings.RegexSettings = new List<RegexSetting>();
|
||||
var regexTest = new RegexSetting()
|
||||
{
|
||||
Tag = "{Regex01}",
|
||||
Regex = "\\d*"
|
||||
};
|
||||
settings.RegexSettings.Add(regexTest);
|
||||
|
||||
// act
|
||||
var result = RegexNameHandler.BuildRegexName(name, settings);
|
||||
|
||||
// assert
|
||||
Assert.Equal("testfile_\\d*.txt", result.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BuildRegexName_Return_FileName_TwoRegex_Replaced()
|
||||
{
|
||||
// arrange
|
||||
var name = "testfile_{Regex01}_Test_{Regex02}.txt";
|
||||
var settings = new DynamicNameSetting();
|
||||
settings.RegexSettings = new List<RegexSetting>();
|
||||
var regexTest1 = new RegexSetting()
|
||||
{
|
||||
Tag = "{Regex01}",
|
||||
Regex = "\\d*"
|
||||
};
|
||||
settings.RegexSettings.Add(regexTest1);
|
||||
|
||||
var regexTest2 = new RegexSetting()
|
||||
{
|
||||
Tag = "{Regex02}",
|
||||
Regex = "\\w*"
|
||||
};
|
||||
settings.RegexSettings.Add(regexTest2);
|
||||
|
||||
// act
|
||||
var result = RegexNameHandler.BuildRegexName(name, settings);
|
||||
|
||||
// assert
|
||||
Assert.Equal("testfile_\\d*_Test_\\w*.txt", result.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReplaceTagWithRegex_Return_FileName_OneRegex_Replaced()
|
||||
{
|
||||
// arrange
|
||||
var name = "testfile_{Regex01}.txt";
|
||||
var tag = "{Regex01}";
|
||||
var regex = "\\d*";
|
||||
|
||||
// act
|
||||
var result = RegexNameHandler.ReplaceTagWithRegex(name, tag, regex);
|
||||
|
||||
// assert
|
||||
Assert.Equal("testfile_\\d*.txt", result);
|
||||
}
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!-- additional settings used during the dotnet test execution step in the azure dev ops pipeline -->
|
||||
|
||||
<RunSettings>
|
||||
|
||||
<DataCollectionRunSettings>
|
||||
<DataCollectors>
|
||||
<DataCollector friendlyName="Code Coverage" uri="datacollector://Microsoft/CodeCoverage/2.0" assemblyQualifiedName="Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector, Microsoft.VisualStudio.TraceCollector, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<Configuration>
|
||||
<CodeCoverage>
|
||||
|
||||
|
||||
<CompanyNames>
|
||||
<Exclude>
|
||||
<CompanyName>.*microsoft.*</CompanyName>
|
||||
</Exclude>
|
||||
</CompanyNames>
|
||||
|
||||
</CodeCoverage>
|
||||
</Configuration>
|
||||
</DataCollector>
|
||||
|
||||
</DataCollectors>
|
||||
</DataCollectionRunSettings>
|
||||
|
||||
</RunSettings>
|
||||
Reference in New Issue
Block a user