Files
monorepo/LCU.API.Internal.FTP/LCU.Api.Internal.FTPTests/Controllers/SftpControllerTest.cs
T
2026-03-24 15:28:37 -05:00

65 lines
1.9 KiB
C#

using Microsoft.AspNetCore.Mvc;
using Moq;
using Xunit;
using LCU.Api.Internal.FTP.Controllers;
using LCU.Api.Internal.FTP.Services;
using LCU.Api.Internal.FTPLib.Models;
using LCU.Api.Internal.FTP.Services.FtpOpertionServices;
namespace LCU.Api.Internal.FTPTests.Controllers;
public class SftpControllerTest
{
private readonly SftpController controller;
private readonly Mock<IQueueFtpService> _mockFtpService;
private readonly Mock<IWinScpListDirectoryService> _winScpListDirectoryService;
public SftpControllerTest()
{
_mockFtpService = new Mock<IQueueFtpService>();
_winScpListDirectoryService = new Mock<IWinScpListDirectoryService>();
controller = new SftpController(_mockFtpService.Object, _winScpListDirectoryService.Object);
}
// Post tests
[Fact]
public void Post_OK()
{
// arrange
var request = new SftpRequest()
{
Protocol = ProtocolType.Sftp,
HostName = "Test Host",
UserName = "Test UserName",
Password = "Test Password",
LocalFilePath = "Test LocalFilePath",
RemoteFilePath = "Test RemoteFilePath"
};
Assert.Equal(22, request.PortNumber);
// act
var result = controller.Post(request);
Assert.NotNull(result);
var okResult = result as OkResult;
// assert
Assert.NotNull(okResult);
Assert.Equal(200, okResult.StatusCode);
}
// Post tests
[Fact]
public void Post_InvalidSftp_NoHost()
{
// arrange
var request = new SftpRequest() { };
// act
var result = controller.Post(request);
Assert.NotNull(result);
var badRequest = result as BadRequestObjectResult;
Assert.Equal(400, badRequest.StatusCode);
Assert.Equal("Sftp request can not be created into a valid session options.", badRequest.Value);
}
}