Files
monorepo/LCU.API.Collections.RepoApi-old/LCU.API.Collections.RepoApiTests/Services/VehicleFloorPricingParameterServiceTest.cs
T
2026-04-20 14:47:24 -05:00

193 lines
9.0 KiB
C#

using System;
using System.Collections.Generic;
using System.Text;
using Xunit;
using Moq;
using LCU.Shared.Collections.RepoApiLib.Repositories;
using RabbitMQ.Client;
using LCU.API.Collections.RepoApi.Services;
using LCU.API.Collections.RepoApi.Exceptions;
using LCU.Shared.Collections.RepoApiLib.Models;
using System.Threading.Tasks;
using System.Data.SqlClient;
namespace LCU.API.Collections.RepoApiTests.Services
{
public class VehicleFloorPricingParameterServiceTest
{
[Fact]
public async void ListAll_Exception()
{
var _mockFloorPricingParamRepo = new Mock<IVehicleFloorPricingParametersRepository>();
var _mockUnitOfWork = new Mock<IUnitOfWork>();
_mockFloorPricingParamRepo.Setup(repo => repo.ListAllAsync()).ThrowsAsync(new Exception("oops"));
VehicleFloorPricingParametersService vehicleFloorPricingService = new VehicleFloorPricingParametersService(_mockFloorPricingParamRepo.Object, _mockUnitOfWork.Object);
await Assert.ThrowsAsync<ServerErrorException>(async () => await vehicleFloorPricingService.ListAll());
}
[Fact]
public async void ListAll_OK()
{
var _mockFloorPricingParamRepo = new Mock<IVehicleFloorPricingParametersRepository>();
var _mockUnitOfWork = new Mock<IUnitOfWork>();
_mockFloorPricingParamRepo.Setup(repo => repo.ListAllAsync()).ReturnsAsync(new List<VehicleFloorPricingParameters>() { new VehicleFloorPricingParameters() { } });
VehicleFloorPricingParametersService vehicleFloorPricingService = new VehicleFloorPricingParametersService(_mockFloorPricingParamRepo.Object, _mockUnitOfWork.Object);
var res = await vehicleFloorPricingService.ListAll();
Assert.Single(res);
}
[Fact]
public async void Get_Exception()
{
var _mockFloorPricingParamRepo = new Mock<IVehicleFloorPricingParametersRepository>();
var _mockUnitOfWork = new Mock<IUnitOfWork>();
_mockFloorPricingParamRepo.Setup(repo => repo.FindByIdAsync(It.IsAny<int>())).ThrowsAsync(new Exception("oops"));
VehicleFloorPricingParametersService vehicleFloorPricingService = new VehicleFloorPricingParametersService(_mockFloorPricingParamRepo.Object, _mockUnitOfWork.Object);
await Assert.ThrowsAsync<ServerErrorException>(async () => await vehicleFloorPricingService.Get(5));
}
[Fact]
public async void Get_Ok()
{
var _mockFloorPricingParamRepo = new Mock<IVehicleFloorPricingParametersRepository>();
var _mockUnitOfWork = new Mock<IUnitOfWork>();
_mockFloorPricingParamRepo.Setup(repo => repo.FindByIdAsync(It.IsAny<int>())).ReturnsAsync(new VehicleFloorPricingParameters() { Id = 5 }) ;
VehicleFloorPricingParametersService vehicleFloorPricingService = new VehicleFloorPricingParametersService(_mockFloorPricingParamRepo.Object, _mockUnitOfWork.Object);
var res = await vehicleFloorPricingService.Get(5);
Assert.NotNull(res);
Assert.Equal(5, res.Id);
}
[Fact]
public async void Get_Null_Exception()
{
var _mockFloorPricingParamRepo = new Mock<IVehicleFloorPricingParametersRepository>();
var _mockUnitOfWork = new Mock<IUnitOfWork>();
_mockFloorPricingParamRepo.Setup(repo => repo.FindByIdAsync(It.IsAny<int>())).Returns(Task.FromResult<VehicleFloorPricingParameters>(null));
VehicleFloorPricingParametersService vehicleFloorPricingService = new VehicleFloorPricingParametersService(_mockFloorPricingParamRepo.Object, _mockUnitOfWork.Object);
await Assert.ThrowsAsync<NotFoundException>(async () => await vehicleFloorPricingService.Get(5));
}
[Fact]
public async void UpdateAsync_Existing_Null()
{
VehicleFloorPricingParameters parameters = new VehicleFloorPricingParameters {
Id = 5,
LowCondition = 1,
HighCondition = 5,
NADAFirstValue = "101.1",
NADASecondValue = "202.2",
MMRAdjustedValue = "303.3",
PercentageOf = 10,
ValuationServiceType = 5
};
var _mockFloorPricingParamRepo = new Mock<IVehicleFloorPricingParametersRepository>();
var _mockUnitOfWork = new Mock<IUnitOfWork>();
_mockFloorPricingParamRepo.Setup(repo => repo.FindByIdAsync(It.IsAny<int>())).Returns(Task.FromResult<VehicleFloorPricingParameters>(null));
_mockFloorPricingParamRepo.Setup(repo => repo.Update(It.Is<VehicleFloorPricingParameters>(param => param.Id == 5)));
VehicleFloorPricingParametersService vehicleFloorPricingService = new VehicleFloorPricingParametersService(_mockFloorPricingParamRepo.Object, _mockUnitOfWork.Object);
await Assert.ThrowsAsync<NotFoundException>(async () => await vehicleFloorPricingService.UpdateAsync(parameters));
}
[Fact]
public async void UpdateAsync_Ok()
{
VehicleFloorPricingParameters parameters = new VehicleFloorPricingParameters
{
Id = 5,
LowCondition = 1,
HighCondition = 3,
NADAFirstValue = "101.1",
NADASecondValue = "202.2",
MMRAdjustedValue = "303.3",
PercentageOf = 10,
ValuationServiceType = 4
};
var _mockFloorPricingParamRepo = new Mock<IVehicleFloorPricingParametersRepository>();
var _mockUnitOfWork = new Mock<IUnitOfWork>();
_mockFloorPricingParamRepo.Setup(repo => repo.FindByIdAsync(It.IsAny<int>())).ReturnsAsync(parameters);
_mockFloorPricingParamRepo.Setup(repo => repo.Update(It.Is<VehicleFloorPricingParameters>(param => param.Id == 5 && param.NADAFirstValue == "101.1")));
VehicleFloorPricingParametersService vehicleFloorPricingService = new VehicleFloorPricingParametersService(_mockFloorPricingParamRepo.Object, _mockUnitOfWork.Object);
var res = await vehicleFloorPricingService.UpdateAsync(parameters);
Assert.NotNull(res);
Assert.Equal(1, res.LowCondition);
Assert.Equal(3, res.HighCondition);
Assert.Equal("101.1", res.NADAFirstValue);
Assert.Equal("202.2", res.NADASecondValue);
Assert.Equal("303.3", res.MMRAdjustedValue);
Assert.Equal(10, res.PercentageOf);
Assert.Equal(4, res.ValuationServiceType);
}
[Fact]
public async void UpdateAsync_Existing_Exception()
{
VehicleFloorPricingParameters parameters = new VehicleFloorPricingParameters
{
Id = 5,
LowCondition = 1,
HighCondition = 5,
NADAFirstValue = "101.1",
NADASecondValue = "202.2",
MMRAdjustedValue = "303.3",
PercentageOf = 10,
ValuationServiceType = 5
};
var _mockFloorPricingParamRepo = new Mock<IVehicleFloorPricingParametersRepository>();
var _mockUnitOfWork = new Mock<IUnitOfWork>();
_mockFloorPricingParamRepo.Setup(repo => repo.FindByIdAsync(It.IsAny<int>())).ThrowsAsync(new Exception("oops"));
_mockFloorPricingParamRepo.Setup(repo => repo.Update(It.Is<VehicleFloorPricingParameters>(param => param.Id == 5)));
VehicleFloorPricingParametersService vehicleFloorPricingService = new VehicleFloorPricingParametersService(_mockFloorPricingParamRepo.Object, _mockUnitOfWork.Object);
await Assert.ThrowsAsync<ServerErrorException>(async () => await vehicleFloorPricingService.UpdateAsync(parameters));
}
[Fact]
public async void UpdateAsync_Update_Exception()
{
VehicleFloorPricingParameters parameters = new VehicleFloorPricingParameters
{
Id = 5,
LowCondition = 1,
HighCondition = 5,
NADAFirstValue = "101.1",
NADASecondValue = "202.2",
MMRAdjustedValue = "303.3",
PercentageOf = 10,
ValuationServiceType = 5
};
var _mockFloorPricingParamRepo = new Mock<IVehicleFloorPricingParametersRepository>();
var _mockUnitOfWork = new Mock<IUnitOfWork>();
_mockFloorPricingParamRepo.Setup(repo => repo.FindByIdAsync(It.IsAny<int>())).Returns(Task.FromResult<VehicleFloorPricingParameters>(parameters));
_mockFloorPricingParamRepo.Setup(repo => repo.Update(It.Is<VehicleFloorPricingParameters>(param => param.Id == 5))).Throws(new Exception("oops"));
VehicleFloorPricingParametersService vehicleFloorPricingService = new VehicleFloorPricingParametersService(_mockFloorPricingParamRepo.Object, _mockUnitOfWork.Object);
await Assert.ThrowsAsync<ServerErrorException>(async () => await vehicleFloorPricingService.UpdateAsync(parameters));
}
}
}