Adding
This commit is contained in:
+72
@@ -0,0 +1,72 @@
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using LCU.Api.Internal.Dispatcher.Controllers;
|
||||
using LCU.Library.Internal.DispatcherModels.Enums;
|
||||
using LCU.Api.Internal.Dispatcher.Services.DispatcherOperationServices;
|
||||
namespace LCU.Api.Internal.DispatcherTests.ControllerTests;
|
||||
|
||||
public class IngestionControllerTest
|
||||
{
|
||||
private readonly IngestionController controller;
|
||||
private readonly Mock<IIngestionService> _mockIngestionService;
|
||||
|
||||
public IngestionControllerTest()
|
||||
{
|
||||
_mockIngestionService = new Mock<IIngestionService>();
|
||||
controller = new IngestionController(_mockIngestionService.Object);
|
||||
}
|
||||
|
||||
// Post tests
|
||||
[Fact]
|
||||
public async Task MoveFilePost_OK()
|
||||
{
|
||||
// arrange
|
||||
var testTask = new WorkItem()
|
||||
{
|
||||
WorkItemId = 0,
|
||||
JobId = 0,
|
||||
Order = 1,
|
||||
SerializedPayload = "",
|
||||
Url = "",
|
||||
HttpMethod = HttpMethodType.Post
|
||||
};
|
||||
|
||||
var testJob = new Job()
|
||||
{
|
||||
JobId = 0,
|
||||
RequestingApplication = "",
|
||||
WorkItems = new List<WorkItem>() { testTask }
|
||||
};
|
||||
|
||||
// act
|
||||
var result = await controller.Post(testJob);
|
||||
Assert.NotNull(result);
|
||||
var okResult = result as OkResult;
|
||||
|
||||
// assert
|
||||
Assert.NotNull(okResult);
|
||||
Assert.Equal(200, okResult.StatusCode);
|
||||
}
|
||||
|
||||
// Post tests
|
||||
[Fact]
|
||||
public async Task MoveFilePost_NoWorkItems_BadRequest()
|
||||
{
|
||||
// arrange
|
||||
var testJob = new Job()
|
||||
{
|
||||
JobId = 0,
|
||||
RequestingApplication = "",
|
||||
WorkItems = new List<WorkItem>()
|
||||
};
|
||||
|
||||
// act
|
||||
var result = await controller.Post(testJob);
|
||||
|
||||
// assert
|
||||
Assert.NotNull(result);
|
||||
var badRequest = result as BadRequestObjectResult;
|
||||
Assert.Equal(400, badRequest.StatusCode);
|
||||
Assert.Equal("Workitems are required.", badRequest.Value);
|
||||
}
|
||||
}
|
||||
+132
@@ -0,0 +1,132 @@
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using LCU.Api.Internal.Dispatcher.Controllers;
|
||||
using LCU.Api.Internal.Dispatcher.Services;
|
||||
using LCU.Library.Internal.DispatcherModels.Models.Results;
|
||||
using LCU.Library.Internal.DispatcherModels.Models.Requests;
|
||||
|
||||
namespace LCU.Api.Internal.DispatcherTests.ControllerTests;
|
||||
|
||||
public class JobControllerTest
|
||||
{
|
||||
private readonly JobController controller;
|
||||
private readonly Mock<IJobService> _mockJobService;
|
||||
|
||||
public JobControllerTest()
|
||||
{
|
||||
_mockJobService = new Mock<IJobService>();
|
||||
controller = new JobController(_mockJobService.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void PagedFilter_Ok()
|
||||
{
|
||||
|
||||
// Arrange
|
||||
var filter = new Filter()
|
||||
{
|
||||
Limit = 2,
|
||||
Page = 1
|
||||
};
|
||||
|
||||
_mockJobService.Setup(service => service.GetFilteredJobs(filter))
|
||||
.ReturnsAsync(new PagedResult<Job>()
|
||||
{
|
||||
Total = 4,
|
||||
Items = new List<Job>()
|
||||
{
|
||||
new Job() {JobId = 1},
|
||||
new Job() {JobId = 2},
|
||||
new Job() {JobId = 3},
|
||||
new Job() {JobId = 4}
|
||||
}
|
||||
});
|
||||
|
||||
// Act
|
||||
var result = await controller.GetFilteredJobs(filter);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okObject = result as OkObjectResult;
|
||||
Assert.NotNull(okObject);
|
||||
|
||||
var pagedResponse = okObject.Value as PagedResponse<Job>;
|
||||
Assert.NotNull(pagedResponse);
|
||||
|
||||
Assert.Equal(4, pagedResponse.TotalItems);
|
||||
|
||||
Assert.Equal(1, pagedResponse.Items.ElementAt(0).JobId);
|
||||
Assert.Equal(2, pagedResponse.Items.ElementAt(1).JobId);
|
||||
|
||||
Assert.Equal(0, pagedResponse.PreviousPage);
|
||||
Assert.Equal(2, pagedResponse.NextPage);
|
||||
Assert.Equal(2, pagedResponse.TotalPages);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Copy_OK()
|
||||
{
|
||||
var jobId = DateTime.Now.Millisecond;
|
||||
var request = new CopyJobRequest
|
||||
{
|
||||
JobId = jobId,
|
||||
ChangeEnvironment = false
|
||||
};
|
||||
var response = new Job
|
||||
{
|
||||
JobId = DateTime.Now.Millisecond + 1
|
||||
};
|
||||
|
||||
_mockJobService.Setup(x => x.CopyJobAsync(request))
|
||||
.ReturnsAsync(response).Verifiable();
|
||||
|
||||
var result = await controller.Copy(request);
|
||||
Assert.NotNull(result);
|
||||
|
||||
Assert.IsType<OkObjectResult>(result);
|
||||
var status = result as OkObjectResult;
|
||||
Assert.NotNull(status);
|
||||
Assert.Equal(200, status.StatusCode);
|
||||
|
||||
var jobResponse = status.Value as Job;
|
||||
Assert.NotNull(jobResponse);
|
||||
Assert.NotEqual(request.JobId, jobResponse.JobId);
|
||||
Assert.NotEqual(0, jobResponse.JobId);
|
||||
_mockJobService.Verify();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Copy_BadRequest()
|
||||
{
|
||||
CopyJobRequest request = null;
|
||||
|
||||
var result = await controller.Copy(request);
|
||||
Assert.NotNull(result);
|
||||
|
||||
Assert.IsType<BadRequestObjectResult>(result);
|
||||
var status = result as BadRequestObjectResult;
|
||||
Assert.NotNull(status);
|
||||
Assert.Equal(400, status.StatusCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Copy_InternalServerError()
|
||||
{
|
||||
var request = new CopyJobRequest
|
||||
{
|
||||
JobId = DateTime.Now.Millisecond
|
||||
};
|
||||
_mockJobService.Setup(x => x.CopyJobAsync(request))
|
||||
.Throws(new Exception("Test")).Verifiable();
|
||||
|
||||
var result = await controller.Copy(request);
|
||||
Assert.NotNull(result);
|
||||
|
||||
Assert.IsType<StatusCodeResult>(result);
|
||||
var status = result as StatusCodeResult;
|
||||
Assert.NotNull(status);
|
||||
Assert.Equal(500, status.StatusCode);
|
||||
_mockJobService.Verify();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user