using System; using System.Collections.Generic; using System.Linq; using LCU.API.Collections.RepoApi.Services.Reporting; using LCU.Shared.Collections.RepoApiLib.Models.Reporting; using LCU.Shared.Collections.RepoApiLib.Repositories; using Moq; using Xunit; namespace LCU.API.Collections.RepoApiTests.Services { public class LandmarkReportingServiceTest { private LandmarkReportingService _landmarkReportingService; private Mock _mockRepository; public LandmarkReportingServiceTest() { _mockRepository = new Mock(); _landmarkReportingService = new LandmarkReportingService(_mockRepository.Object); } [Fact] public async void GetAvgDaysRepoToSold_Ok() { // Arrange var reportData = new List() { new StdReportEntry() { RepoId = 1, DateRepoed = DateTime.Parse("11/01/2019"), FilteredStatusChangeDate = DateTime.Parse("12/01/2019") }, new StdReportEntry() { RepoId = 2, DateRepoed = DateTime.Parse("11/15/2019"), FilteredStatusChangeDate = DateTime.Parse("11/25/2019") }, new StdReportEntry() { RepoId = 3 }, new StdReportEntry() { RepoId = 4, DateRepoed = DateTime.Parse("11/22/2019") }, new StdReportEntry() { RepoId = 5, FilteredStatusChangeDate = DateTime.Parse("12/21/2019") }, new StdReportEntry() { RepoId = 6, DateRepoed = DateTime.Parse("12/21/2019"), FilteredStatusChangeDate = DateTime.Parse("12/31/2019") }, }; _mockRepository.Setup(repo => repo.GetAccountsByStatusChangeInPeriod(It.IsAny(), It.IsAny(), It.IsAny())) .ReturnsAsync(reportData); // Act var result = await _landmarkReportingService.GetAvgDaysRepoToSoldReport(DateTime.Parse("11/01/2019"), DateTime.Parse("12/31/2019")); // Assert Assert.NotNull(result); Assert.Equal(6, result.DataTable.Rows.Count()); Assert.Equal(4, result.ReportTable.Cells.Length); Assert.Equal("All Sold Accounts", result.ReportTable.Cells[0, 0].Display); Assert.Equal("10", result.ReportTable.Cells[0, 1].Display); Assert.Equal("20", result.ReportTable.Cells[0, 2].Display); Assert.Equal("17", result.ReportTable.Cells[0, 3].Display); } [Fact] public async void GetRedemptionCountReport_Ok() { // Arrange var reportData = new List() { new StdReportEntry() { RepoId = 1, FilteredStatusChangeDate = DateTime.Parse("11/01/2019") }, new StdReportEntry() { RepoId = 1, FilteredStatusChangeDate = DateTime.Parse("11/02/2019") }, new StdReportEntry() { RepoId = 1, FilteredStatusChangeDate = DateTime.Parse("11/02/2019") }, new StdReportEntry() { RepoId = 5, FilteredStatusChangeDate = DateTime.Parse("12/01/2019") }, new StdReportEntry() { RepoId = 6, FilteredStatusChangeDate = DateTime.Parse("11/30/2019") }, }; _mockRepository.Setup(repo => repo.GetAccountsByStatusChangeInPeriod(It.IsAny(), It.IsAny(), It.IsAny())) .ReturnsAsync(reportData); // Act var result = await _landmarkReportingService.GetRedemptionCountReport(DateTime.Parse("11/01/2019"), DateTime.Parse("12/31/2019")); // Assert Assert.NotNull(result); Assert.Equal(5, result.DataTable.Rows.Count()); Assert.Equal(4, result.ReportTable.Cells.Length); Assert.Equal("All Redemptions", result.ReportTable.Cells[0, 0].Display); Assert.Equal("3", result.ReportTable.Cells[0, 1].Display); Assert.Equal("1", result.ReportTable.Cells[0, 2].Display); Assert.Equal("4", result.ReportTable.Cells[0, 3].Display); } [Fact] public async void GetAvgDaysDelqWhenAddedReport_Ok() { // Arrange var reportData = new List() { new StdReportEntry() { RepoId = 1, DaysDelqWhenAdded = 25, O4RDate = DateTime.Parse("11/01/2019") }, new StdReportEntry() { RepoId = 2, DaysDelqWhenAdded = 38, O4RDate = DateTime.Parse("11/02/2019") }, new StdReportEntry() { RepoId = 3, DaysDelqWhenAdded = 19, O4RDate = DateTime.Parse("11/02/2019") }, new StdReportEntry() { RepoId = 4, DaysDelqWhenAdded = 12, O4RDate = DateTime.Parse("12/01/2019") }, }; _mockRepository.Setup(repo => repo.GetAccountsByO4RDate(It.IsAny(), It.IsAny())) .ReturnsAsync(reportData); // Act var result = await _landmarkReportingService.GetAvgDaysDelqWhenAddedReport(DateTime.Parse("11/01/2019"), DateTime.Parse("12/31/2019")); // Assert Assert.NotNull(result); Assert.Equal(4, result.DataTable.Rows.Count()); Assert.Equal(4, result.ReportTable.Cells.Length); Assert.Equal("All Accounts", result.ReportTable.Cells[0, 0].Display); Assert.Equal("27", result.ReportTable.Cells[0, 1].Display); Assert.Equal("12", result.ReportTable.Cells[0, 2].Display); Assert.Equal("24", result.ReportTable.Cells[0, 3].Display); } [Fact] public async void GetCountOfSalesReport_Ok() { // Arrange var reportData = new List() { new StdReportEntry() { RepoId = 1, FilteredStatusChangeDate = DateTime.Parse("11/01/2019") }, new StdReportEntry() { RepoId = 2, FilteredStatusChangeDate = DateTime.Parse("11/02/2019") }, new StdReportEntry() { RepoId = 3, FilteredStatusChangeDate = DateTime.Parse("11/02/2019") }, new StdReportEntry() { RepoId = 4, FilteredStatusChangeDate = DateTime.Parse("12/01/2019") }, }; _mockRepository.Setup(repo => repo.GetAccountsByStatusChangeInPeriod(It.IsAny(), It.IsAny(), It.IsAny())) .ReturnsAsync(reportData); // Act var result = await _landmarkReportingService.GetCountOfSalesReport(DateTime.Parse("11/01/2019"), DateTime.Parse("12/31/2019")); // Assert Assert.NotNull(result); Assert.Equal(4, result.DataTable.Rows.Count()); Assert.Equal(4, result.ReportTable.Cells.Length); Assert.Equal("All Sold Accounts", result.ReportTable.Cells[0, 0].Display); Assert.Equal("3", result.ReportTable.Cells[0, 1].Display); Assert.Equal("1", result.ReportTable.Cells[0, 2].Display); Assert.Equal("4", result.ReportTable.Cells[0, 3].Display); } [Fact] public async void GetAvgSurplusReport_Ok() { // Arrange var reportData = new List() { new StdReportEntry() { RepoId = 1, GrossSalePrice = 3000, Balance = 3500, AuctionName = "Auction A", SoldDate = DateTime.Parse("11/01/2019") }, new StdReportEntry() { RepoId = 2, GrossSalePrice = 500, Balance = 1200, AuctionName = "Auction B", SoldDate = DateTime.Parse("11/02/2019") }, new StdReportEntry() { RepoId = 3, GrossSalePrice = 700, Balance = 650, AuctionName = "Auction B", SoldDate = DateTime.Parse("11/02/2019") }, new StdReportEntry() { RepoId = 4, GrossSalePrice = 8000, Balance = 4000, AuctionName = "Auction A", SoldDate = DateTime.Parse("12/01/2019") }, }; _mockRepository.Setup(repo => repo.GetAccountsByDateSoldInAutoIMS(It.IsAny(), It.IsAny())) .ReturnsAsync(reportData); // Act var result = await _landmarkReportingService.GetAvgSurplusReport(DateTime.Parse("11/01/2019"), DateTime.Parse("12/31/2019")); // Assert Assert.NotNull(result); Assert.Equal(4, result.DataTable.Rows.Count()); Assert.Equal(12, result.ReportTable.Cells.Length); Assert.Equal("All Sold Accounts", result.ReportTable.Cells[0, 0].Display); Assert.Equal("($383.33)", result.ReportTable.Cells[0, 1].Display); Assert.Equal("$4,000.00", result.ReportTable.Cells[0, 2].Display); Assert.Equal("$712.50", result.ReportTable.Cells[0, 3].Display); Assert.Equal("Auction A", result.ReportTable.Cells[1, 0].Display); Assert.Equal("($500.00)", result.ReportTable.Cells[1, 1].Display); Assert.Equal("$4,000.00", result.ReportTable.Cells[1, 2].Display); Assert.Equal("$1,750.00", result.ReportTable.Cells[1, 3].Display); Assert.Equal("Auction B", result.ReportTable.Cells[2, 0].Display); Assert.Equal("($325.00)", result.ReportTable.Cells[2, 1].Display); Assert.Equal("-", result.ReportTable.Cells[2, 2].Display); Assert.Equal("($325.00)", result.ReportTable.Cells[2, 3].Display); } [Fact] public async void GetRepoBalanceReport_Ok() { // Arrange var reportData = new List() { new StdReportEntry() { RepoId = 1, Balance = 300m, RepoCompany = "Company A", DateRepoed = DateTime.Parse("11/01/2019") }, new StdReportEntry() { RepoId = 2, Balance = 275.49005m, RepoCompany = "Company A", DateRepoed = DateTime.Parse("11/02/2019") }, new StdReportEntry() { RepoId = 3, Balance = 999.91m, RepoCompany = "Company B", DateRepoed = DateTime.Parse("11/02/2019") }, new StdReportEntry() { RepoId = 4, Balance = 100m, RepoCompany = "Company B", DateRepoed = DateTime.Parse("12/01/2019") }, new StdReportEntry() { RepoId = 5, Balance = 210m, DateRepoed = DateTime.Parse("12/11/2019") }, }; _mockRepository.Setup(repo => repo.GetAccountsByDateRepoed(It.IsAny(), It.IsAny())) .ReturnsAsync(reportData); // Act var result = await _landmarkReportingService.GetRepoBalanceReport(DateTime.Parse("11/01/2019"), DateTime.Parse("12/31/2019")); // Assert Assert.NotNull(result); Assert.Equal(5, result.DataTable.Rows.Count()); Assert.Equal(16, result.ReportTable.Cells.Length); Assert.Equal("All Companies", result.ReportTable.Cells[0, 0].Display); Assert.Equal("$1,575.40", result.ReportTable.Cells[0, 1].Display); Assert.Equal("$310.00", result.ReportTable.Cells[0, 2].Display); Assert.Equal("$1,885.40", result.ReportTable.Cells[0, 3].Display); Assert.Equal("Company A", result.ReportTable.Cells[1, 0].Display); Assert.Equal("$575.49", result.ReportTable.Cells[1, 1].Display); Assert.Equal("-", result.ReportTable.Cells[1, 2].Display); Assert.Equal("$575.49", result.ReportTable.Cells[1, 3].Display); Assert.Equal("Company B", result.ReportTable.Cells[2, 0].Display); Assert.Equal("$999.91", result.ReportTable.Cells[2, 1].Display); Assert.Equal("$100.00", result.ReportTable.Cells[2, 2].Display); Assert.Equal("$1,099.91", result.ReportTable.Cells[2, 3].Display); Assert.Equal("No Companies", result.ReportTable.Cells[3, 0].Display); Assert.Equal("-", result.ReportTable.Cells[3, 1].Display); Assert.Equal("$210.00", result.ReportTable.Cells[3, 2].Display); Assert.Equal("$210.00", result.ReportTable.Cells[3, 3].Display); } [Fact] public async void GetRedemptionBalanceReport_Ok() { // Arrange var reportData = new List() { new StdReportEntry() { RepoId = 1, Balance = 250, FilteredStatusChangeDate = DateTime.Parse("11/01/2019") }, new StdReportEntry() { RepoId = 2, Balance = 150, FilteredStatusChangeDate = DateTime.Parse("11/02/2019") }, new StdReportEntry() { RepoId = 3, Balance = 99.99m, FilteredStatusChangeDate = DateTime.Parse("11/02/2019") }, new StdReportEntry() { RepoId = 4, Balance = 1.49m, FilteredStatusChangeDate = DateTime.Parse("12/01/2019") }, }; _mockRepository.Setup(repo => repo.GetAccountsByStatusChangeInPeriod(It.IsAny(), It.IsAny(), It.IsAny())) .ReturnsAsync(reportData); // Act var result = await _landmarkReportingService.GetRedemptionBalanceReport(DateTime.Parse("11/01/2019"), DateTime.Parse("12/31/2019")); // Assert Assert.NotNull(result); Assert.Equal(4, result.DataTable.Rows.Count()); Assert.Equal(4, result.ReportTable.Cells.Length); Assert.Equal("All Redeemed Accounts", result.ReportTable.Cells[0, 0].Display); Assert.Equal("$499.99", result.ReportTable.Cells[0, 1].Display); Assert.Equal("$1.49", result.ReportTable.Cells[0, 2].Display); Assert.Equal("$501.48", result.ReportTable.Cells[0, 3].Display); } } }