120 lines
4.5 KiB
C#
120 lines
4.5 KiB
C#
using System.Collections.Generic;
|
|
using LCU.API.Collections.RepoApi.Controllers;
|
|
using LCU.API.Collections.RepoApi.Models.Filters;
|
|
using LCU.API.Collections.RepoApi.Models.Requests;
|
|
using LCU.API.Collections.RepoApi.Models.Responses;
|
|
using LCU.API.Collections.RepoApi.Services;
|
|
using LCU.Shared.Collections.RepoApiLib.Models;
|
|
using LCU.Shared.Collections.RepoApiLib.Models.Results;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Moq;
|
|
using Xunit;
|
|
|
|
namespace LCU.API.Collections.RepoApiTests.Controllers
|
|
{
|
|
public class AuctionAssignmentControllerTest
|
|
{
|
|
private readonly AuctionAssignmentController controller;
|
|
private readonly Mock<IAuctionAssignmentService> mockAuctionAssignmentServiceService;
|
|
private readonly Mock<IFloorPricingService> mockloorPricingService;
|
|
private readonly Mock<IHttpContextAccessor> mockHttpContextAccessor;
|
|
|
|
public AuctionAssignmentControllerTest()
|
|
{
|
|
mockAuctionAssignmentServiceService = new Mock<IAuctionAssignmentService>();
|
|
mockloorPricingService = new Mock<IFloorPricingService>();
|
|
mockHttpContextAccessor = new Mock<IHttpContextAccessor>();
|
|
controller = new AuctionAssignmentController(
|
|
mockAuctionAssignmentServiceService.Object,
|
|
mockloorPricingService.Object,
|
|
mockHttpContextAccessor.Object
|
|
);
|
|
}
|
|
|
|
[Fact]
|
|
public async void Get_OK()
|
|
{
|
|
mockAuctionAssignmentServiceService.Setup(service => service.ListByFilterAsync(It.IsAny<AuctionAssignmentFilter>())).ReturnsAsync(
|
|
new PagedResult<AuctionAssignment>()
|
|
{
|
|
Total = 1,
|
|
Items = new List<AuctionAssignment>()
|
|
{
|
|
new AuctionAssignment()
|
|
}
|
|
});
|
|
|
|
var filter = new AuctionAssignmentFilter();
|
|
var result = await controller.Get(filter);
|
|
Assert.NotNull(result);
|
|
|
|
var okResult = result as OkObjectResult;
|
|
Assert.NotNull(okResult);
|
|
Assert.Equal(200, okResult.StatusCode);
|
|
|
|
var okValue = okResult.Value as PagedResponse<AuctionAssignment>;
|
|
Assert.NotNull(okValue);
|
|
Assert.Equal(1, okValue.TotalItems);
|
|
mockAuctionAssignmentServiceService.Verify(x => x.ListByFilterAsync(It.IsAny<AuctionAssignmentFilter>()), Times.Once);
|
|
}
|
|
|
|
[Fact]
|
|
public async void Post_OK()
|
|
{
|
|
mockAuctionAssignmentServiceService.Setup(service => service.SaveAsync(It.IsAny<AuctionAssignmentPostRequest>())).ReturnsAsync(
|
|
new AuctionAssignmentPostRequest()
|
|
{
|
|
AuctionAssignment = new AuctionAssignment()
|
|
{
|
|
CollateralVIN = "abcde",
|
|
}
|
|
});
|
|
|
|
//var controller = new AuctionAssignmentController(mockService.Object, mockAutoIms.Object);
|
|
var result = await controller.Post(new AuctionAssignmentPostRequest()
|
|
{
|
|
Collaterals = new List<Collateral>
|
|
{
|
|
new Collateral()
|
|
}
|
|
});
|
|
Assert.NotNull(result);
|
|
|
|
var okResult = result as OkObjectResult;
|
|
Assert.NotNull(okResult);
|
|
Assert.Equal(200, okResult.StatusCode);
|
|
|
|
var okValue = okResult.Value as AuctionAssignmentPostRequest;
|
|
Assert.NotNull(okValue);
|
|
Assert.Equal("abcde", okValue.AuctionAssignment.CollateralVIN);
|
|
mockAuctionAssignmentServiceService.Verify(x => x.SaveAsync(It.IsAny<AuctionAssignmentPostRequest>()), Times.Once);
|
|
}
|
|
|
|
[Fact]
|
|
public async void Bad_GetById_Fails()
|
|
{
|
|
var result = await controller.GetById(0);
|
|
Assert.NotNull(result);
|
|
|
|
var badRequest = result as BadRequestObjectResult;
|
|
Assert.NotNull(badRequest);
|
|
Assert.Equal(400, badRequest.StatusCode);
|
|
}
|
|
|
|
[Fact]
|
|
public async void Put_IdMismatch_Fails()
|
|
{
|
|
var auctionAssignmentToPut = new AuctionAssignment()
|
|
{
|
|
ID = 2
|
|
};
|
|
var result = await controller.Put(1, auctionAssignmentToPut);
|
|
Assert.NotNull(result);
|
|
|
|
var badRequest = result as BadRequestObjectResult;
|
|
Assert.NotNull(badRequest);
|
|
Assert.Equal(400, badRequest.StatusCode);
|
|
}
|
|
}
|
|
} |