Adding
This commit is contained in:
+70
@@ -0,0 +1,70 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using LCU.Library.Internal.DataCleanUpModel.Entities;
|
||||
using LCU.Api.Internal.DataCleanUpLib.Persistence;
|
||||
|
||||
namespace LCU.Api.Internal.DataCleanUpTest.RepositoryTests;
|
||||
|
||||
public class DbContextTestSet
|
||||
{
|
||||
public IReadOnlyCollection<Ltv_DataCleanUp>? Ltv_DataCleanUps { get; set; }
|
||||
|
||||
}
|
||||
|
||||
public abstract class DbContextFromJsonTest
|
||||
{
|
||||
private const string RepositoryFolder = "Repositories";
|
||||
private const string LtvFileName = "loanToValue_repo";
|
||||
public DbContextTestSet GetTestRecords()
|
||||
{
|
||||
var testSet = new DbContextTestSet();
|
||||
|
||||
// Get the absolute path to the JSON file
|
||||
var basePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory);
|
||||
var path = $"{ basePath}//{RepositoryFolder}//{LtvFileName}.json";
|
||||
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
throw new ArgumentException($"Could not find file at path: {path}");
|
||||
}
|
||||
|
||||
var fileData = File.ReadAllText(path);
|
||||
var allData = JObject.Parse(fileData);
|
||||
|
||||
var data = allData["Ltv_DataCleanUps"];
|
||||
testSet.Ltv_DataCleanUps = data.ToObject<List<Ltv_DataCleanUp>>();
|
||||
|
||||
return testSet;
|
||||
}
|
||||
|
||||
public AppDbContext GetBlankContext()
|
||||
{
|
||||
var options = new DbContextOptionsBuilder<AppDbContext>()
|
||||
.UseInMemoryDatabase(Guid.NewGuid().ToString())
|
||||
.Options;
|
||||
return new AppDbContext(options);
|
||||
}
|
||||
|
||||
public AppDbContext GetContextWithData()
|
||||
{
|
||||
var options = new DbContextOptionsBuilder<AppDbContext>()
|
||||
.UseInMemoryDatabase(Guid.NewGuid().ToString())
|
||||
.Options;
|
||||
var context = new AppDbContext(options);
|
||||
|
||||
var testData = GetTestRecords();
|
||||
AddTo(context.LtvDataCleanUp, testData.Ltv_DataCleanUps);
|
||||
|
||||
context.SaveChanges();
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
private static void AddTo<T>(DbSet<T> collection, IEnumerable<T> range) where T : class
|
||||
{
|
||||
if (range != null) collection.AddRange(range);
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
using LCU.Api.Internal.DataCleanUpLib.Repositories;
|
||||
using LCU.Api.Internal.DataCleanUpTest.RepositoryTests;
|
||||
using Xunit;
|
||||
using Moq;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using LCU.Api.Internal.DataCleanUp.Configuration;
|
||||
|
||||
namespace LCU.Api.Internal.DataCleanUpTest.Repositories;
|
||||
public class UpdateAccountLoanToValueRepositoryTest : DbContextFromJsonTest
|
||||
{
|
||||
private readonly LtvDataCleanUpRepository _ltvRepository;
|
||||
private readonly Mock<DataCleanupDefaults> _mockDataCleanupDefaults;
|
||||
|
||||
|
||||
public UpdateAccountLoanToValueRepositoryTest()
|
||||
|
||||
{
|
||||
var dbContext = GetContextWithData();
|
||||
_mockDataCleanupDefaults = new Mock<DataCleanupDefaults>();
|
||||
_mockDataCleanupDefaults.Object.LtvExcludedMinorAccountTypes = new List <string>()
|
||||
{
|
||||
"DL01", "DL02", "DL03", "DL04", "DL05", "DL06", "DL07", "DL08", "DL09", "DL10", "DL11", "DL12", "DL13", "DL14", "DL15", "DL16"
|
||||
};
|
||||
|
||||
_ltvRepository = new LtvDataCleanUpRepository(dbContext);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void ExcludedListAsync_Return_1() //DL01 minor account type is filtered
|
||||
{
|
||||
var resultsBasic = await _ltvRepository.ListMinorAccountTypeAsync(_mockDataCleanupDefaults.Object.LtvExcludedMinorAccountTypes);
|
||||
|
||||
//Assert
|
||||
Assert.NotNull(resultsBasic);
|
||||
Assert.Single(resultsBasic);
|
||||
Assert.Equal("SV01", resultsBasic.First().MinorType);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"Ltv_DataCleanUps": [
|
||||
{
|
||||
"AccountNumber": "1111111",
|
||||
"Ltv": ".1",
|
||||
"MinorType": "DL01"
|
||||
},
|
||||
{
|
||||
"AccountNumber": "2222222",
|
||||
"Ltv": ".2",
|
||||
"MinorType": "SV01"
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user