Files
2026-04-20 14:47:24 -05:00

114 lines
4.0 KiB
C#

using System.Collections.Generic;
using System.Linq;
using LCU.API.Collections.RepoApi.Domain.FloorPricing;
using LCU.API.Collections.RepoApi.Domain.FloorPricing.Strategies;
using LCU.API.Collections.RepoApi.Services;
using LCU.Shared.Collections.RepoApiLib.Models;
using LCU.Shared.Collections.RepoApiLib.WebServices.NADA;
using Moq;
using Xunit;
namespace LCU.API.Collections.RepoApiTests.Services
{
public class FloorPricingServiceTest
{
private readonly Mock<IVehicleFloorPricingParametersService> mockFloorPriceService;
private readonly Mock<ICollateralValueService> mockCollateralValueService;
private readonly Mock<IImsAutoFileDataService> mockImsAutoFileDataService;
private readonly Mock<IFloorPricingStrategyFactory> mockStrategyFactory;
private readonly FloorPricingService service;
public FloorPricingServiceTest()
{
mockFloorPriceService = new Mock<IVehicleFloorPricingParametersService>();
mockCollateralValueService = new Mock<ICollateralValueService>();
mockImsAutoFileDataService = new Mock<IImsAutoFileDataService>();
mockStrategyFactory = new Mock<IFloorPricingStrategyFactory>();
service = new FloorPricingService(
mockStrategyFactory.Object,
mockFloorPriceService.Object,
mockImsAutoFileDataService.Object,
mockCollateralValueService.Object);
}
[Fact]
public void Full_Calculate_Floor_Price_OK()
{
// arrange
var strategies = new List<IFloorPricingStrategy>()
{
new AutoImsSuggestedValue(),
new NadaMmrConditionValue()
};
FloorPriceCalculationParams fpcParams = new FloorPriceCalculationParams();
mockStrategyFactory.Setup(x => x.GetFloorPricingStrategies()).Returns(strategies);
// act
var results = service.GetCalculatedFloorPrices(fpcParams);
// Assert
Assert.NotNull(results);
Assert.True(results.Any());
}
[Fact]
public void Select_Floor_Price_OK()
{
// arrange
List<FloorPriceCalculationResult> results = new List<FloorPriceCalculationResult>()
{
new FloorPriceCalculationResult()
{
Success = true,
FloorPrice = 1000,
StrategyName = "a",
ResultWeight = 100
},
new FloorPriceCalculationResult()
{
Success = false,
FloorPrice = 0,
StrategyName = "b",
ResultWeight = 1001
},
new FloorPriceCalculationResult()
{
Success = true,
FloorPrice = 0,
StrategyName = "c",
ResultWeight = -1
},
new FloorPriceCalculationResult()
{
Success = true,
FloorPrice = 1200,
StrategyName = "d",
ResultWeight = 101
}
};
var strategies = new List<IFloorPricingStrategy>()
{
new AutoImsSuggestedValue(),
new NadaMmrConditionValue()
};
mockStrategyFactory.Setup(x => x.GetFloorPricingStrategies()).Returns(strategies);
// act
var result = service.SelectBestFloorPrice(results);
// Assert
Assert.NotNull(result);
Assert.Equal(1200, result.FloorPrice);
}
[Fact]
public void Failed_NADA_Soap_Request_CollateralValuation_Not_Null()
{
mockCollateralValueService.Setup(x => x.GetCollateralValue("", 0, 0)).Throws<System.ServiceModel.FaultException>();
var results = service.GetCollateralValuation("",0,0);
Assert.NotNull(results);
}
}
}