348 lines
13 KiB
C#
348 lines
13 KiB
C#
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using Xunit;
|
|
using System.Linq;
|
|
using LCU.API.Collections.CollectionsApiLib.Models;
|
|
using LCU.Shared.Collections.RepoApiLib.Models;
|
|
using LCU.Shared.Collections.RepoApiLib.Persistence;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace LCU.API.Collections.RepoApiTests.Repository
|
|
{
|
|
public class RepoAccountRepository : DbContextFromJson
|
|
{
|
|
private readonly AppDbContext _dbContext;
|
|
|
|
public RepoAccountRepository()
|
|
{
|
|
_dbContext = GetSqliteContextWithData(@"Repository/repo_account_repository_data.json");
|
|
|
|
}
|
|
|
|
[Fact]
|
|
public async void ListAccounts_Filter_Closed_Ok()
|
|
{
|
|
|
|
var repoAccountRepos = new Shared.Collections.RepoApiLib.Repositories.RepoAccountRepository(_dbContext);
|
|
// act
|
|
var result = await repoAccountRepos.ListAsync(new List<int?> { }, 0, 10, null, null, null, true);
|
|
|
|
// Assert
|
|
Assert.NotNull(result);
|
|
Assert.Equal(2, result.Total);
|
|
Assert.True(result.Items.ToList().Exists(x => (x.RepoId == 2)));
|
|
Assert.True(result.Items.ToList().Exists(x => (x.RepoId == 1)));
|
|
Assert.False(result.Items.ToList().Exists(x => (x.RepoId == 3 || x.RepoId == 4)));
|
|
Assert.DoesNotContain(result.Items, x => x.DateClosed != null);
|
|
}
|
|
|
|
[Fact]
|
|
public async void FindAccount_Async_Missing_Ok()
|
|
{
|
|
var repoAccountRepos = new Shared.Collections.RepoApiLib.Repositories.RepoAccountRepository(_dbContext);
|
|
// act
|
|
var result = await repoAccountRepos.FindByAccountNoAsync("123456-999");
|
|
|
|
// Assert
|
|
Assert.NotNull(result);
|
|
Assert.Empty(result);
|
|
}
|
|
|
|
[Fact]
|
|
public async void ListAccounts_Filter_By_RepoCompanyID_Ok()
|
|
{
|
|
|
|
var repoAccountRepos = new Shared.Collections.RepoApiLib.Repositories.RepoAccountRepository(_dbContext);
|
|
// act
|
|
var result = await repoAccountRepos.ListAsync(new List<int?> { }, 0, 10, null, null, 4, null);
|
|
|
|
// Assert
|
|
Assert.NotNull(result);
|
|
Assert.Equal(1, result.Total);
|
|
Assert.Contains(result.Items, x => x.RepoId == 2);
|
|
Assert.DoesNotContain(result.Items, x => x.RepoId == 1 || x.RepoId == 3 || x.RepoId == 4);
|
|
}
|
|
|
|
[Fact]
|
|
public async void ListAccounts_Filter_By_AuctionHouseID_Ok()
|
|
{
|
|
|
|
var repoAccountRepos = new Shared.Collections.RepoApiLib.Repositories.RepoAccountRepository(_dbContext);
|
|
// act
|
|
var result = await repoAccountRepos.ListAsync(new List<int?> { }, 0, 10, null, "1259", null, null);
|
|
|
|
// Assert
|
|
Assert.NotNull(result);
|
|
Assert.Equal(1, result.Total);
|
|
Assert.Contains(result.Items, x => x.RepoId == 2);
|
|
Assert.DoesNotContain(result.Items, x => x.RepoId == 1 || x.RepoId == 3 || x.RepoId == 4);
|
|
}
|
|
|
|
[Fact]
|
|
public async void ListAccounts_Filter_By_Status_Ok()
|
|
{
|
|
var repoAccountRepos = new Shared.Collections.RepoApiLib.Repositories.RepoAccountRepository(_dbContext);
|
|
// act
|
|
var result = await repoAccountRepos.ListAsync(new List<int?> { }, 0, 10, "SOLD", null, null, null);
|
|
|
|
// Assert
|
|
Assert.NotNull(result);
|
|
Assert.Equal(1, result.Total);
|
|
Assert.Contains(result.Items, x => x.RepoId == 4);
|
|
Assert.DoesNotContain(result.Items, x => x.RepoId == 1 || x.RepoId == 2 || x.RepoId == 3);
|
|
}
|
|
|
|
[Fact]
|
|
public async void ListAccounts_Filter_By_Combination_RepoCompany_AuctionHouse_Ok()
|
|
{
|
|
var repoAccountRepos = new Shared.Collections.RepoApiLib.Repositories.RepoAccountRepository(_dbContext);
|
|
// act
|
|
var result = await repoAccountRepos.ListAsync(new List<int?> { }, 0, 10, null, "1259", 4, null);
|
|
|
|
// Assert
|
|
Assert.NotNull(result);
|
|
Assert.Equal(1, result.Total);
|
|
Assert.Contains(result.Items, x => x.RepoId == 2);
|
|
Assert.DoesNotContain(result.Items, x => x.RepoId == 1 || x.RepoId == 3 || x.RepoId == 4);
|
|
}
|
|
|
|
[Fact]
|
|
public async void ListAccounts_Filter_By_Combination_Open_AuctionHouse_Ok()
|
|
{
|
|
var repoAccountRepos = new Shared.Collections.RepoApiLib.Repositories.RepoAccountRepository(_dbContext);
|
|
// act
|
|
var result = await repoAccountRepos.ListAsync(new List<int?> { }, 0, 10, "PSKP", null, null, true);
|
|
|
|
// Assert
|
|
Assert.NotNull(result);
|
|
Assert.Equal(1, result.Total);
|
|
Assert.Contains(result.Items, x => x.RepoId == 1);
|
|
Assert.DoesNotContain(result.Items, x => x.RepoId == 2 || x.RepoId == 3 || x.RepoId == 4);
|
|
}
|
|
|
|
[Fact]
|
|
public async void ListAccounts_Filter_To_Null_OK()
|
|
{
|
|
var repoAccountRepos = new Shared.Collections.RepoApiLib.Repositories.RepoAccountRepository(_dbContext);
|
|
// act
|
|
var result = await repoAccountRepos.ListAsync(new List<int?> { }, 0, 10, "PSKP", "1259", 4, true);
|
|
|
|
// Assert
|
|
Assert.NotNull(result);
|
|
Assert.Empty(result.Items);
|
|
Assert.Equal(0, result.Total);
|
|
}
|
|
|
|
[Fact]
|
|
public async void ListAccounts_Filter_To_Doesnt_Exist_OK()
|
|
{
|
|
var repoAccountRepos = new Shared.Collections.RepoApiLib.Repositories.RepoAccountRepository(_dbContext);
|
|
// act
|
|
var result = await repoAccountRepos.ListAsync(new List<int?> { }, 0, 10, "THISDOESNTEXIST", null, null, null);
|
|
|
|
// Assert
|
|
Assert.NotNull(result);
|
|
Assert.Empty(result.Items);
|
|
Assert.Equal(0, result.Total);
|
|
}
|
|
|
|
[Fact]
|
|
public async void ListAccounts_All_Paged_Result__OK()
|
|
{
|
|
var repoAccountRepos = new Shared.Collections.RepoApiLib.Repositories.RepoAccountRepository(_dbContext);
|
|
|
|
//act
|
|
var result = await repoAccountRepos.ListAsync(new List<int?> { }, 0, 2, null, null, null, true);
|
|
|
|
// Assert
|
|
Assert.NotNull(result);
|
|
Assert.Equal(2,result.Items.Count());
|
|
Assert.Equal(2, result.Total);
|
|
}
|
|
|
|
[Fact]
|
|
public async void ListAccounts_All__OK()
|
|
{
|
|
var repoAccountRepos = new Shared.Collections.RepoApiLib.Repositories.RepoAccountRepository(_dbContext);
|
|
|
|
//act
|
|
var result = await repoAccountRepos.ListAsync(new List<int?> { }, 0, 10, null, null, null, true);
|
|
|
|
// Assert
|
|
Assert.NotNull(result);
|
|
Assert.Equal(2,result.Items.Count());
|
|
Assert.Equal(2, result.Total);
|
|
}
|
|
|
|
[Fact]
|
|
public async void SaveAccount_OK()
|
|
{
|
|
var options = new DbContextOptionsBuilder<AppDbContext>()
|
|
.UseInMemoryDatabase(Guid.NewGuid().ToString())
|
|
.Options;
|
|
var context = new AppDbContext(options);
|
|
|
|
var repoAccountRepos = new Shared.Collections.RepoApiLib.Repositories.RepoAccountRepository(context);
|
|
|
|
var repo = new RepoAccount()
|
|
{
|
|
AccountNo = "123456-789",
|
|
Balance = 1000,
|
|
Branch = 5,
|
|
Collector = "Test",
|
|
DaysDelinquent = 5,
|
|
AccountTypeCode = "L1",
|
|
LoanNo = 789,
|
|
DelinquentAmount = 500,
|
|
CurrentDelinquentAmount = 500,
|
|
LstPmtAmt = 200,
|
|
MemberNo = 123456,
|
|
OrigAmount = 1000,
|
|
O4RDate = DateTime.Today,
|
|
PrimaryIndividualId = "777777",
|
|
SubStatus = "XXX",
|
|
Status = "O4R",
|
|
Borrowers = new List<Borrower>()
|
|
{
|
|
new Borrower()
|
|
{
|
|
IndividualId = "77777",
|
|
IndividualName = "Test Borrower",
|
|
OwnershipType = 6
|
|
}
|
|
},
|
|
Collaterals = new List<Collateral>()
|
|
{
|
|
new Collateral()
|
|
{
|
|
BodyStyle = "Coupe",
|
|
Description = "2019 Subaru BRZ Ts",
|
|
Make = "Subaru",
|
|
Model = "BRZ",
|
|
Vin = "1234567AAAGHZJP11",
|
|
Year = 2019,
|
|
VehicleType = 1,
|
|
Inoperable = false
|
|
}
|
|
},
|
|
ReferenceId = 555,
|
|
AccountLastProcessed = DateTime.Today
|
|
};
|
|
|
|
Assert.Equal(0, repo.RepoId);
|
|
|
|
//act
|
|
var result = await repoAccountRepos.AddAsync(repo);
|
|
context.SaveChanges();
|
|
|
|
// Assert
|
|
Assert.NotNull(result);
|
|
Assert.NotNull(result.Collaterals);
|
|
Assert.NotNull(result.Borrowers);
|
|
Assert.NotEqual(0, result.RepoId);
|
|
Assert.NotEqual(0, result.Collaterals.First().CollateralId);
|
|
Assert.Equal(result.RepoId, result.Borrowers.First().RepoId);
|
|
Assert.Equal(result.RepoId, result.Collaterals.First().RepoId);
|
|
}
|
|
|
|
[Fact]
|
|
public async void UpdateAccount_OK()
|
|
{
|
|
var options = new DbContextOptionsBuilder<AppDbContext>()
|
|
.UseInMemoryDatabase(Guid.NewGuid().ToString())
|
|
.Options;
|
|
var context = new AppDbContext(options);
|
|
|
|
var repoAccountRepository = new Shared.Collections.RepoApiLib.Repositories.RepoAccountRepository(context);
|
|
|
|
var repo = new RepoAccount()
|
|
{
|
|
AccountNo = "123456-789",
|
|
Balance = 1000,
|
|
Branch = 5,
|
|
Collector = "Test",
|
|
DaysDelinquent = 5,
|
|
AccountTypeCode = "L1",
|
|
LoanNo = 789,
|
|
DelinquentAmount = 500,
|
|
CurrentDelinquentAmount = 500,
|
|
LstPmtAmt = 200,
|
|
OrigAmount = 1000,
|
|
O4RDate = DateTime.Today,
|
|
PrimaryIndividualId = "777777",
|
|
SubStatus = "XXX",
|
|
Status = "O4R",
|
|
Borrowers = new List<Borrower>()
|
|
{
|
|
new Borrower()
|
|
{
|
|
IndividualId = "77777",
|
|
IndividualName = "Test Borrower",
|
|
OwnershipType = 6
|
|
}
|
|
},
|
|
Collaterals = new List<Collateral>()
|
|
{
|
|
new Collateral()
|
|
{
|
|
BodyStyle = "Coupe",
|
|
Description = "2019 Subaru BRZ Ts",
|
|
Make = "Subaru",
|
|
Model = "BRZ",
|
|
Vin = "1234567AAAGHZJP11",
|
|
Year = 2019,
|
|
VehicleType = 1,
|
|
Inoperable = false,
|
|
RepoCompanySelections = new List<RepoCompanySelection>()
|
|
{
|
|
new RepoCompanySelection()
|
|
{
|
|
RepoCompanyId = 7,
|
|
DateTimeCreated = DateTime.Now,
|
|
RepoCompanyAssignmentDate = DateTime.Now,
|
|
RepoType = RepoType.Involuntary
|
|
}
|
|
}
|
|
}
|
|
},
|
|
ReferenceId = 999,
|
|
AccountLastProcessed = null
|
|
};
|
|
var result = await repoAccountRepository.AddAsync(repo);
|
|
context.SaveChanges();
|
|
|
|
// Assert
|
|
Assert.NotNull(result);
|
|
Assert.Equal("1000", result.Balance.ToString());
|
|
Assert.Equal(1, result.Collaterals.Count);
|
|
Assert.Equal(999, result.ReferenceId);
|
|
|
|
//act
|
|
result.Balance = 7299;
|
|
result.Collaterals.Add(new Collateral()
|
|
{
|
|
BodyStyle = "Coupe",
|
|
Description = "2019 Subaru BRZ Ts",
|
|
Make = "Subaru",
|
|
Model = "BRZ",
|
|
Vin = "1234567AAAGHZJP22",
|
|
Year = 2019,
|
|
VehicleType = 1,
|
|
Inoperable = false
|
|
});
|
|
result.AccountLastProcessed = DateTime.Now;
|
|
// repoAccountRepos.Update(result);
|
|
_dbContext.SaveChanges();
|
|
|
|
var resultNew = await repoAccountRepository.FindByIdAsync(result.RepoId);
|
|
// Assert
|
|
Assert.NotNull(resultNew);
|
|
Assert.NotNull(resultNew.AccountLastProcessed);
|
|
Assert.Equal("7299", resultNew.Balance.ToString());
|
|
Assert.Equal(2, resultNew.Collaterals.Count);
|
|
Assert.Equal(999, resultNew.ReferenceId);
|
|
}
|
|
}
|
|
}
|