Adding
This commit is contained in:
+363
@@ -0,0 +1,363 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using LCU.API.Collections.RepoApi.Services;
|
||||
using LCU.Shared.Collections.RepoApiLib.Models;
|
||||
using LCU.Shared.Collections.RepoApiLib.Repositories;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
namespace LCU.API.Collections.RepoApiTests.Services
|
||||
{
|
||||
public class FactoidServiceTest
|
||||
{
|
||||
private IFactoidService _factoidService;
|
||||
private Mock<IReportingRepository> _mockReportingRepository;
|
||||
private Mock<IRepoAccountRepository> _mockRepoAccountRepository;
|
||||
private Mock<IImsAutoFileDataRepository> _mockImsAutoFileDataRepository;
|
||||
|
||||
public FactoidServiceTest()
|
||||
{
|
||||
_mockReportingRepository = new Mock<IReportingRepository>();
|
||||
_mockRepoAccountRepository = new Mock<IRepoAccountRepository>();
|
||||
_mockImsAutoFileDataRepository = new Mock<IImsAutoFileDataRepository>();
|
||||
_factoidService = new FactoidService(_mockReportingRepository.Object, _mockRepoAccountRepository.Object,
|
||||
_mockImsAutoFileDataRepository.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Find_Auction_Index()
|
||||
{
|
||||
// arrange
|
||||
var auctionHouses = new List<string>()
|
||||
{
|
||||
"Gross Active Balance", "a1", "a2", "No Auction"
|
||||
};
|
||||
|
||||
// act
|
||||
var result = _factoidService.FindAuctionIndex(auctionHouses, "A1");
|
||||
var result2 = _factoidService.FindAuctionIndex(auctionHouses, null);
|
||||
var result3 = _factoidService.FindAuctionIndex(auctionHouses, "A3");
|
||||
|
||||
// assert
|
||||
Assert.Equal(1, result);
|
||||
Assert.Equal(3, result2);
|
||||
Assert.Equal(3, result3);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Get_All_Accounts_O4R_Ok()
|
||||
{
|
||||
// arrange
|
||||
_mockReportingRepository.Setup(x => x.GetAllAccountsInO4R()).ReturnsAsync(new List<RepoAccount>()
|
||||
{
|
||||
new RepoAccount(),
|
||||
new RepoAccount()
|
||||
});
|
||||
|
||||
// act
|
||||
var result = await _factoidService.GetAllAccountsO4R();
|
||||
|
||||
// assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal("Accounts", result.Name);
|
||||
Assert.Equal("Total Accounts in O4R", result.Description);
|
||||
Assert.Equal("fa-car", result.FontAwesomeIcon);
|
||||
Assert.Equal("2", result.CumulativeValue);
|
||||
Assert.Equal(2, result.Records.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Get_Percent_Floor_Price_Ok()
|
||||
{
|
||||
// arrange
|
||||
var fakeAutoIms = new List<ImsAutoFileData>()
|
||||
{
|
||||
new ImsAutoFileData() {GrossPercentFloor = 50, RepoId = 111},
|
||||
new ImsAutoFileData() {GrossPercentFloor = 100, RepoId = 111}
|
||||
};
|
||||
var fakeAccounts = new List<RepoAccount>()
|
||||
{
|
||||
new RepoAccount(),
|
||||
new RepoAccount()
|
||||
};
|
||||
var highDate = DateTime.Parse("12/31/2019");
|
||||
var lowDate = DateTime.Parse("11/01/2019");
|
||||
_mockImsAutoFileDataRepository
|
||||
.Setup(x => x.GetImsSoldRecordsForPeriod(It.IsAny<DateTime>(), It.IsAny<DateTime>()))
|
||||
.ReturnsAsync(fakeAutoIms);
|
||||
|
||||
_mockRepoAccountRepository.Setup(
|
||||
x => x.FindByRepoIdAsync(It.IsAny<List<string>>()))
|
||||
.ReturnsAsync(fakeAccounts);
|
||||
|
||||
// act
|
||||
var result = await _factoidService.GetPercentFloorPrice(lowDate, highDate);
|
||||
|
||||
// assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal("Percentage of Floor", result.Name);
|
||||
Assert.Equal("Last 30 Days", result.Description);
|
||||
Assert.Equal("fa-money", result.FontAwesomeIcon);
|
||||
Assert.Equal("75%", result.CumulativeValue);
|
||||
Assert.Equal(2, result.Records.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Get_Recently_Redeemed_Ok()
|
||||
{
|
||||
// arrange
|
||||
var fakeAccounts = new List<RepoAccount>()
|
||||
{
|
||||
new RepoAccount(),
|
||||
new RepoAccount()
|
||||
};
|
||||
var highDate = DateTime.Parse("12/31/2019");
|
||||
var lowDate = DateTime.Parse("11/01/2019");
|
||||
|
||||
_mockRepoAccountRepository.Setup(
|
||||
x => x.FindByStatusChangeInPeriod(It.IsAny<string>(), It.IsAny<DateTime>(), It.IsAny<DateTime>(),
|
||||
It.IsAny<string>()))
|
||||
.ReturnsAsync(fakeAccounts);
|
||||
|
||||
// act
|
||||
var result = await _factoidService.GetRecentlyRedeemed(lowDate, highDate);
|
||||
|
||||
// assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal("Recently Redeemed", result.Name);
|
||||
Assert.Equal("Last 30 Days", result.Description);
|
||||
Assert.Equal("fa-calendar", result.FontAwesomeIcon);
|
||||
Assert.Equal("2", result.CumulativeValue);
|
||||
Assert.Equal(2, result.Records.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetAvgDaysO4RToREPO_Ok()
|
||||
{
|
||||
// Arrange
|
||||
var fakeAccounts = new List<RepoAccount>()
|
||||
{
|
||||
new RepoAccount()
|
||||
{
|
||||
RepoStatusChanges = new List<RepoStatusChange>()
|
||||
{
|
||||
new RepoStatusChange()
|
||||
{
|
||||
StatusFrom = "REHO",
|
||||
StatusTo = "O4R",
|
||||
ChangedDate = DateTime.Parse("10/01/2019")
|
||||
},
|
||||
new RepoStatusChange()
|
||||
{
|
||||
StatusFrom = "O4R",
|
||||
StatusTo = "REPO",
|
||||
ChangedDate = DateTime.Parse("10/21/2019")
|
||||
}
|
||||
}
|
||||
},
|
||||
new RepoAccount()
|
||||
{
|
||||
RepoStatusChanges = new List<RepoStatusChange>()
|
||||
{
|
||||
new RepoStatusChange()
|
||||
{
|
||||
StatusFrom = "REDEEMED",
|
||||
StatusTo = "O4R",
|
||||
ChangedDate = DateTime.Parse("10/15/2019")
|
||||
},
|
||||
new RepoStatusChange()
|
||||
{
|
||||
StatusFrom = "O4R",
|
||||
StatusTo = "REDEEMED",
|
||||
ChangedDate = DateTime.Parse("10/20/2019")
|
||||
},
|
||||
new RepoStatusChange()
|
||||
{
|
||||
StatusFrom = "REDEEMED",
|
||||
StatusTo = "O4R",
|
||||
ChangedDate = DateTime.Parse("10/21/2019")
|
||||
},
|
||||
new RepoStatusChange()
|
||||
{
|
||||
StatusFrom = "REDEEMED",
|
||||
StatusTo = "REPO",
|
||||
ChangedDate = DateTime.Parse("10/31/2019")
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
var highDate = DateTime.Parse("12/31/2019");
|
||||
var lowDate = DateTime.Parse("11/01/2019");
|
||||
|
||||
_mockRepoAccountRepository.Setup(
|
||||
x => x.FindByStatusChangeInPeriod(It.IsAny<string>(), It.IsAny<DateTime>(), It.IsAny<DateTime>(),
|
||||
It.IsAny<string>()))
|
||||
.ReturnsAsync(fakeAccounts);
|
||||
|
||||
// act
|
||||
var result = await _factoidService.GetAvgDaysO4RToREPO(lowDate, highDate);
|
||||
|
||||
// assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal("Avg. Days O4R to Repo", result.Name);
|
||||
Assert.Equal("Last 30 Days", result.Description);
|
||||
Assert.Equal("fa-calendar", result.FontAwesomeIcon);
|
||||
Assert.Equal("15", result.CumulativeValue);
|
||||
Assert.Equal(2, result.Records.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetAvgDaysO4RToREPO_Does_Not_Divide_By_Zero_No_Accounts()
|
||||
{
|
||||
// Arrange
|
||||
var fakeAccounts = new List<RepoAccount>();
|
||||
var highDate = DateTime.Parse("12/31/2019");
|
||||
var lowDate = DateTime.Parse("11/01/2019");
|
||||
|
||||
_mockRepoAccountRepository.Setup(
|
||||
x => x.FindByStatusChangeInPeriod(It.IsAny<string>(), It.IsAny<DateTime>(), It.IsAny<DateTime>(),
|
||||
It.IsAny<string>()))
|
||||
.ReturnsAsync(fakeAccounts);
|
||||
|
||||
// act
|
||||
var result = await _factoidService.GetAvgDaysO4RToREPO(lowDate, highDate);
|
||||
|
||||
// assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal("Avg. Days O4R to Repo", result.Name);
|
||||
Assert.Equal("Last 30 Days", result.Description);
|
||||
Assert.Equal("fa-calendar", result.FontAwesomeIcon);
|
||||
Assert.Equal("N/A", result.CumulativeValue);
|
||||
Assert.Equal(0, result.Records.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetCurrentInventory_Success()
|
||||
{
|
||||
// Arrange
|
||||
_mockRepoAccountRepository.Setup(repo => repo.FindByCurrentStatus(It.IsAny<string>())).ReturnsAsync(
|
||||
new List<RepoAccount>()
|
||||
{
|
||||
new RepoAccount()
|
||||
{
|
||||
Collaterals = new List<Collateral>()
|
||||
{
|
||||
new Collateral(),
|
||||
new Collateral()
|
||||
}
|
||||
},
|
||||
new RepoAccount()
|
||||
{
|
||||
Collaterals = new List<Collateral>()
|
||||
{
|
||||
new Collateral()
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Act
|
||||
var result = await _factoidService.GetCurrentInventory();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal("3", result.CumulativeValue);
|
||||
Assert.Equal(2, result.Records.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetAvgDaysDelqToO4R_Success()
|
||||
{
|
||||
// Arrange
|
||||
var fakeAccounts = new List<RepoAccount>()
|
||||
{
|
||||
new RepoAccount()
|
||||
{
|
||||
DaysDelinquent = 125
|
||||
},
|
||||
new RepoAccount()
|
||||
{
|
||||
DaysDelinquent = 25
|
||||
},
|
||||
new RepoAccount()
|
||||
};
|
||||
|
||||
_mockRepoAccountRepository.Setup(
|
||||
x => x.FindByStatusChangeInPeriod(It.IsAny<string>(), It.IsAny<DateTime>(), It.IsAny<DateTime>(),
|
||||
It.IsAny<string>()))
|
||||
.ReturnsAsync(fakeAccounts);
|
||||
|
||||
// act
|
||||
var result = await _factoidService.GetGetAvgDaysDelqToO4R(It.IsAny<DateTime>(), It.IsAny<DateTime>());
|
||||
|
||||
// assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal("Avg. Days Dlqt To O4R", result.Name);
|
||||
Assert.Equal("Last 30 Days", result.Description);
|
||||
Assert.Equal("fa-calendar", result.FontAwesomeIcon);
|
||||
Assert.Equal("75", result.CumulativeValue);
|
||||
Assert.Equal(2, result.Records.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetAvgDaysRepoToSold_Success()
|
||||
{
|
||||
// Arrange
|
||||
var fakeAccounts = new List<RepoAccount>()
|
||||
{
|
||||
new RepoAccount()
|
||||
{
|
||||
RepoStatusChanges = new List<RepoStatusChange>()
|
||||
{
|
||||
new RepoStatusChange()
|
||||
{
|
||||
StatusFrom = "REPO",
|
||||
StatusTo = "SOLD",
|
||||
ChangedDate = DateTime.Parse("10/21/2019")
|
||||
},
|
||||
new RepoStatusChange()
|
||||
{
|
||||
StatusFrom = "O4R",
|
||||
StatusTo = "REPO",
|
||||
ChangedDate = DateTime.Parse("10/01/2019")
|
||||
}
|
||||
}
|
||||
},
|
||||
new RepoAccount()
|
||||
{
|
||||
RepoStatusChanges = new List<RepoStatusChange>()
|
||||
{
|
||||
new RepoStatusChange()
|
||||
{
|
||||
StatusFrom = "REPO",
|
||||
StatusTo = "SOLD",
|
||||
ChangedDate = DateTime.Parse("10/01/2019")
|
||||
},
|
||||
new RepoStatusChange()
|
||||
{
|
||||
StatusFrom = "O4R",
|
||||
StatusTo = "REPO",
|
||||
ChangedDate = DateTime.Parse("09/01/2019")
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
_mockRepoAccountRepository.Setup(
|
||||
x => x.FindByStatusChangeInPeriod(It.IsAny<string>(), It.IsAny<DateTime>(), It.IsAny<DateTime>(),
|
||||
It.IsAny<string>()))
|
||||
.ReturnsAsync(fakeAccounts);
|
||||
|
||||
// act
|
||||
var result = await _factoidService.GetGetAvgDaysRepoToSold(It.IsAny<DateTime>(), It.IsAny<DateTime>());
|
||||
|
||||
// assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal("Avg. Days Repo to Sold", result.Name);
|
||||
Assert.Equal("Last 30 Days", result.Description);
|
||||
Assert.Equal("fa-calendar", result.FontAwesomeIcon);
|
||||
Assert.Equal("25", result.CumulativeValue);
|
||||
Assert.Equal(2, result.Records.Count);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user