188 lines
7.5 KiB
C#
188 lines
7.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using LCU.API.Collections.RepoApi.Services;
|
|
using LCU.API.Collections.RepoApi.Services.AutoIms;
|
|
using LCU.Shared.Collections.RepoApiLib.Models;
|
|
using LCU.Shared.Collections.RepoApiLib.Models.AutoIms;
|
|
using LCU.Shared.Collections.RepoApiLib.Models.Results;
|
|
using LCU.Shared.Collections.RepoApiLib.Repositories;
|
|
using Moq;
|
|
using Xunit;
|
|
|
|
namespace LCU.API.Collections.RepoApiTests.Processor
|
|
{
|
|
public class AutoImsImporterServiceTest
|
|
{
|
|
private readonly IAutoImsImporterService autoImsImporterService;
|
|
private readonly Mock<IAuctionAssignmentRepository> mockAuctionAssignmentRepository;
|
|
private readonly Mock<IAuctionAssignmentService> mockAuctionAssignmentService;
|
|
private readonly Mock<IAutoImsNoteProcessorService> mockAutoImsNoteProcessorService;
|
|
private readonly Mock<IAutoImsAuctionProcessorService> mockAutoImsAuctionProcessorService;
|
|
|
|
private readonly Mock<IFloorPricingService> _mockFloorPricingService;
|
|
|
|
public AutoImsImporterServiceTest()
|
|
{
|
|
mockAuctionAssignmentRepository = new Mock<IAuctionAssignmentRepository>();
|
|
|
|
mockAutoImsNoteProcessorService = new Mock<IAutoImsNoteProcessorService>();
|
|
mockAutoImsAuctionProcessorService = new Mock<IAutoImsAuctionProcessorService>();
|
|
_mockFloorPricingService = new Mock<IFloorPricingService>();
|
|
mockAuctionAssignmentService = new Mock<IAuctionAssignmentService>();
|
|
|
|
autoImsImporterService =
|
|
new AutoImsImporterService(mockAuctionAssignmentRepository.Object,
|
|
mockAutoImsNoteProcessorService.Object,
|
|
mockAutoImsAuctionProcessorService.Object,
|
|
_mockFloorPricingService.Object,
|
|
mockAuctionAssignmentService.Object);
|
|
}
|
|
|
|
[Fact]
|
|
public void Basic_Construct_Test()
|
|
{
|
|
Assert.NotNull(autoImsImporterService);
|
|
}
|
|
|
|
[Fact]
|
|
public void Import_Data_Files_Test()
|
|
{
|
|
mockAutoImsAuctionProcessorService.Setup(x => x.ImportSingleAutoImsAuction(It.IsAny<ImsAutoFileData>()))
|
|
.Returns(
|
|
new ImportResultRow());
|
|
|
|
Assert.NotNull(autoImsImporterService);
|
|
var results = autoImsImporterService.ImportDataFile(CreateDummyImsData());
|
|
Assert.NotNull(results);
|
|
Assert.Equal(2, results.Count());
|
|
mockAutoImsAuctionProcessorService.Verify(x => x.ImportSingleAutoImsAuction(It.IsAny<ImsAutoFileData>()),
|
|
Times.Exactly(2));
|
|
}
|
|
|
|
[Fact]
|
|
public void Import_Notes_Test()
|
|
{
|
|
mockAutoImsNoteProcessorService.Setup(x => x.ImportSingleNoteRow(It.IsAny<AuctionAssignmentNote>()))
|
|
.Returns(new AuctionAssignmentNote());
|
|
|
|
Assert.NotNull(autoImsImporterService);
|
|
var results = autoImsImporterService.ImportNotesToDatabase(CreateDummyNotes());
|
|
Assert.NotNull(results);
|
|
Assert.Equal(2, results.Count());
|
|
mockAutoImsNoteProcessorService.Verify(x => x.ImportSingleNoteRow(It.IsAny<AuctionAssignmentNote>()),
|
|
Times.Exactly(2));
|
|
}
|
|
|
|
[Fact]
|
|
public void Set_All_Floors_Test()
|
|
{
|
|
var mockReadyForFloor = new PagedResult<AuctionAssignment>()
|
|
{
|
|
Total = 0,
|
|
Items = new List<AuctionAssignment>()
|
|
{
|
|
new AuctionAssignment()
|
|
{
|
|
RepoId = 111,
|
|
CollateralVIN = "12312321312"
|
|
}
|
|
}
|
|
};
|
|
var floorPriceResult = new FloorPriceCalculationResultSet()
|
|
{
|
|
PrimaryResult = new FloorPriceCalculationResult()
|
|
{
|
|
FloorPrice = 1000,
|
|
Success = true,
|
|
ResultWeight = 99,
|
|
StrategyName = "Guessing"
|
|
}
|
|
};
|
|
mockAuctionAssignmentRepository.Setup(x => x.ListReadyForFloorPriceAsync()).ReturnsAsync(mockReadyForFloor);
|
|
_mockFloorPricingService.Setup(x => x.DetermineFloorPrice(It.IsAny<int>()))
|
|
.Returns(floorPriceResult);
|
|
mockAuctionAssignmentService.Setup(x => x.UpdateAsync(It.IsAny<AuctionAssignment>()))
|
|
.ReturnsAsync(new AuctionAssignment());
|
|
|
|
Assert.NotNull(autoImsImporterService);
|
|
autoImsImporterService.SetAllAvailableFloors();
|
|
mockAuctionAssignmentRepository.Verify(x => x.ListReadyForFloorPriceAsync(), Times.Exactly(1));
|
|
_mockFloorPricingService.Verify(x => x.DetermineFloorPrice(It.IsAny<int>()),
|
|
Times.Exactly(1));
|
|
mockAuctionAssignmentService.Verify(x => x.UpdateAsync(It.IsAny<AuctionAssignment>()),
|
|
Times.Exactly(1));
|
|
}
|
|
|
|
[Fact]
|
|
public void Set_All_Floors_Test_NULL_AuctionAssignments()
|
|
{
|
|
var mockReadyForFloor = new PagedResult<AuctionAssignment>()
|
|
{
|
|
// null on purpose.
|
|
};
|
|
var floorPriceResult = new FloorPriceCalculationResultSet()
|
|
{
|
|
PrimaryResult = new FloorPriceCalculationResult()
|
|
{
|
|
FloorPrice = 1000,
|
|
Success = true,
|
|
ResultWeight = 99,
|
|
StrategyName = "Guessing"
|
|
}
|
|
};
|
|
mockAuctionAssignmentRepository.Setup(x => x.ListReadyForFloorPriceAsync()).ReturnsAsync(mockReadyForFloor);
|
|
_mockFloorPricingService.Setup(x => x.DetermineFloorPrice(It.IsAny<int>()))
|
|
.Returns(floorPriceResult);
|
|
mockAuctionAssignmentService.Setup(x => x.UpdateAsync(It.IsAny<AuctionAssignment>()))
|
|
.ReturnsAsync(new AuctionAssignment());
|
|
|
|
Assert.NotNull(autoImsImporterService);
|
|
autoImsImporterService.SetAllAvailableFloors();
|
|
mockAuctionAssignmentRepository.Verify(x => x.ListReadyForFloorPriceAsync(), Times.Exactly(1));
|
|
_mockFloorPricingService.Verify(x => x.DetermineFloorPrice(It.IsAny<int>()),
|
|
Times.Never);
|
|
mockAuctionAssignmentService.Verify(x => x.UpdateAsync(It.IsAny<AuctionAssignment>()), Times.Never);
|
|
}
|
|
|
|
private IEnumerable<ImsAutoFileData> CreateDummyImsData()
|
|
{
|
|
return new[]
|
|
{
|
|
new ImsAutoFileData()
|
|
{
|
|
},
|
|
new ImsAutoFileData()
|
|
{
|
|
}
|
|
};
|
|
}
|
|
|
|
private IEnumerable<AuctionAssignmentNote> CreateDummyNotes()
|
|
{
|
|
return new[]
|
|
{
|
|
new AuctionAssignmentNote()
|
|
{
|
|
Text = "test1",
|
|
AuctionCustomerNo = "123456-789",
|
|
DateWritten = DateTime.Today,
|
|
Origin = "testing",
|
|
Writer = "tester",
|
|
Type = "XX",
|
|
AuctionAssignmentId = 12345
|
|
},
|
|
new AuctionAssignmentNote()
|
|
{
|
|
Text = "test2",
|
|
AuctionCustomerNo = "223456-789",
|
|
DateWritten = DateTime.Today,
|
|
Origin = "testing",
|
|
Writer = "tester",
|
|
Type = "XX",
|
|
AuctionAssignmentId = 12346
|
|
}
|
|
};
|
|
}
|
|
}
|
|
} |