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 mockAuctionAssignmentRepository; private readonly Mock mockAuctionAssignmentService; private readonly Mock mockAutoImsNoteProcessorService; private readonly Mock mockAutoImsAuctionProcessorService; private readonly Mock _mockFloorPricingService; public AutoImsImporterServiceTest() { mockAuctionAssignmentRepository = new Mock(); mockAutoImsNoteProcessorService = new Mock(); mockAutoImsAuctionProcessorService = new Mock(); _mockFloorPricingService = new Mock(); mockAuctionAssignmentService = new Mock(); 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())) .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()), Times.Exactly(2)); } [Fact] public void Import_Notes_Test() { mockAutoImsNoteProcessorService.Setup(x => x.ImportSingleNoteRow(It.IsAny())) .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()), Times.Exactly(2)); } [Fact] public void Set_All_Floors_Test() { var mockReadyForFloor = new PagedResult() { Total = 0, Items = new List() { 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())) .Returns(floorPriceResult); mockAuctionAssignmentService.Setup(x => x.UpdateAsync(It.IsAny())) .ReturnsAsync(new AuctionAssignment()); Assert.NotNull(autoImsImporterService); autoImsImporterService.SetAllAvailableFloors(); mockAuctionAssignmentRepository.Verify(x => x.ListReadyForFloorPriceAsync(), Times.Exactly(1)); _mockFloorPricingService.Verify(x => x.DetermineFloorPrice(It.IsAny()), Times.Exactly(1)); mockAuctionAssignmentService.Verify(x => x.UpdateAsync(It.IsAny()), Times.Exactly(1)); } [Fact] public void Set_All_Floors_Test_NULL_AuctionAssignments() { var mockReadyForFloor = new PagedResult() { // 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())) .Returns(floorPriceResult); mockAuctionAssignmentService.Setup(x => x.UpdateAsync(It.IsAny())) .ReturnsAsync(new AuctionAssignment()); Assert.NotNull(autoImsImporterService); autoImsImporterService.SetAllAvailableFloors(); mockAuctionAssignmentRepository.Verify(x => x.ListReadyForFloorPriceAsync(), Times.Exactly(1)); _mockFloorPricingService.Verify(x => x.DetermineFloorPrice(It.IsAny()), Times.Never); mockAuctionAssignmentService.Verify(x => x.UpdateAsync(It.IsAny()), Times.Never); } private IEnumerable CreateDummyImsData() { return new[] { new ImsAutoFileData() { }, new ImsAutoFileData() { } }; } private IEnumerable 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 } }; } } }