Adding
This commit is contained in:
+274
@@ -0,0 +1,274 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using NUnit.Framework;
|
||||
using AutoMapper;
|
||||
using Moq;
|
||||
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels;
|
||||
using LCU.Api.Internal.CoreApiWrapper.Mappers;
|
||||
using LCU.Api.Internal.CoreApiWrapper.Services;
|
||||
using LCU.Library.Internal.CoreApiWrapperModel.Constants;
|
||||
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.Accounts;
|
||||
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.Loans;
|
||||
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.CoreRequests;
|
||||
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.Properties;
|
||||
|
||||
namespace LCU.Api.Internal.CoreApiWrapperTest.Service
|
||||
{
|
||||
public class LoanServiceTest
|
||||
{
|
||||
private readonly LoanService _loanService;
|
||||
private readonly IMapper _mapper;
|
||||
private readonly Mock<IAccountService> _mockAccountService;
|
||||
private readonly Mock<IPropertyService> _mockPropertyService;
|
||||
private readonly Mock<IAccountHistoryService> _mockAccountHistoryService;
|
||||
|
||||
public LoanServiceTest()
|
||||
{
|
||||
|
||||
if (_mapper == null)
|
||||
{
|
||||
var mappingConfig = new MapperConfiguration(mc =>
|
||||
{
|
||||
mc.AddProfile(new LoanDetailMapper());
|
||||
mc.AddProfile(new CollateralDetailMapper());
|
||||
mc.AddProfile(new OtherCollateralMapper());
|
||||
mc.AddProfile(new VehicleMapper());
|
||||
});
|
||||
IMapper mapper = mappingConfig.CreateMapper();
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
_mockAccountService = new Mock<IAccountService>();
|
||||
_mockPropertyService = new Mock<IPropertyService>();
|
||||
_mockAccountHistoryService = new Mock<IAccountHistoryService>();
|
||||
_loanService = new LoanService(_mapper, _mockAccountService.Object, _mockPropertyService.Object, _mockAccountHistoryService.Object);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetLoanDetail_Returns_FilledOutAccount_WrittenOffStatus()
|
||||
{
|
||||
var testAccountRolesInfos = new List<AccountRolesInfo>()
|
||||
{
|
||||
new AccountRolesInfo()
|
||||
{
|
||||
AccountRoleDescription = AccountRoleConstants.LoanOfficer
|
||||
},
|
||||
new AccountRolesInfo()
|
||||
{
|
||||
PersonNumber = 1,
|
||||
RoleName = "Tester One"
|
||||
},
|
||||
new AccountRolesInfo()
|
||||
{
|
||||
PersonNumber = 2,
|
||||
RoleName = "Tester Two"
|
||||
}
|
||||
};
|
||||
|
||||
var testLoanInfo = new LoanInfo()
|
||||
{
|
||||
NextDueDate = Convert.ToDateTime("1/1/2021"),
|
||||
CurrentDueDate = Convert.ToDateTime("1/1/2020")
|
||||
};
|
||||
|
||||
var account = new Account()
|
||||
{
|
||||
MemberAgreementNumber = 100,
|
||||
AccountNumber = 1000143,
|
||||
ReportingForPersonNumber = 1,
|
||||
CurrentAccountStatusDescription = AccountStatusConstants.CoreChargeOffAccount,
|
||||
CurrentAccountStatusDateTime = Convert.ToDateTime("1/1/2021"),
|
||||
Balance = 100.10M,
|
||||
AccountRolesInfo = testAccountRolesInfos,
|
||||
LoanInfo = testLoanInfo
|
||||
|
||||
};
|
||||
_mockAccountService.Setup(x => x.GetAccountDetails(It.IsAny<CoreRequestParameters>(),
|
||||
It.IsAny<AcctNbrRequest>())).ReturnsAsync(account);
|
||||
|
||||
_mockAccountHistoryService.Setup(x => x.GetChargeoffDateTimesByAccountNumber(It.IsAny<string>())).ReturnsAsync(new List<DateTime>() { Convert.ToDateTime("1/1/2021") });
|
||||
|
||||
var testLoanId = 1000143;
|
||||
var result = await _loanService.GetLoanDetail(testLoanId);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.AreEqual(2, result.IndividualId.Length);
|
||||
Assert.AreEqual(1, result.IndividualId[0]);
|
||||
Assert.AreEqual(2, result.Borrowers.Count);
|
||||
Assert.AreEqual(AccountRoleConstants.Borrower, result.Borrowers.FirstOrDefault().Type);
|
||||
Assert.AreEqual(1, result.Borrowers.FirstOrDefault().IndividualId);
|
||||
Assert.AreEqual("Tester One", result.Borrowers.FirstOrDefault().Name);
|
||||
Assert.AreEqual(AccountStatusConstants.WrittenOffStatus, result.Status);
|
||||
Assert.AreEqual(Convert.ToDateTime("1/1/2021"), result.WrittenOffDate);
|
||||
Assert.AreEqual(Convert.ToDateTime("1/1/2020"), result.NextDueDate);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetLoanDetail_Returns_FilledOutAccount_OpenStatus()
|
||||
{
|
||||
var testAccountRolesInfos = new List<AccountRolesInfo>()
|
||||
{
|
||||
new AccountRolesInfo()
|
||||
{
|
||||
AccountRoleDescription = AccountRoleConstants.LoanOfficer
|
||||
},
|
||||
new AccountRolesInfo()
|
||||
{
|
||||
PersonNumber = 1,
|
||||
RoleName = "Tester One"
|
||||
},
|
||||
new AccountRolesInfo()
|
||||
{
|
||||
PersonNumber = 2,
|
||||
RoleName = "Tester Two"
|
||||
}
|
||||
};
|
||||
|
||||
var testLoanInfo = new LoanInfo()
|
||||
{
|
||||
NextDueDate = Convert.ToDateTime("1/1/2021"),
|
||||
CurrentDueDate = Convert.ToDateTime("1/1/2020")
|
||||
};
|
||||
|
||||
var account = new Account()
|
||||
{
|
||||
MemberAgreementNumber = 100,
|
||||
AccountNumber = 1000143,
|
||||
ReportingForPersonNumber = 1,
|
||||
CurrentAccountStatusDescription = AccountStatusConstants.CoreActiveAccount,
|
||||
Balance = 100.10M,
|
||||
AccountRolesInfo = testAccountRolesInfos,
|
||||
LoanInfo = testLoanInfo
|
||||
|
||||
};
|
||||
_mockAccountService.Setup(x => x.GetAccountDetails(It.IsAny<CoreRequestParameters>(),
|
||||
It.IsAny<AcctNbrRequest>())).ReturnsAsync(account);
|
||||
|
||||
var testLoanId = 1000143;
|
||||
var result = await _loanService.GetLoanDetail(testLoanId);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.AreEqual(2, result.IndividualId.Length);
|
||||
Assert.AreEqual(1, result.IndividualId[0]);
|
||||
Assert.AreEqual(2, result.Borrowers.Count);
|
||||
Assert.AreEqual(AccountRoleConstants.Borrower, result.Borrowers.FirstOrDefault().Type);
|
||||
Assert.AreEqual(1, result.Borrowers.FirstOrDefault().IndividualId);
|
||||
Assert.AreEqual("Tester One", result.Borrowers.FirstOrDefault().Name);
|
||||
Assert.AreEqual(AccountStatusConstants.OpenStatus, result.Status);
|
||||
Assert.AreEqual(DateTime.MinValue, result.WrittenOffDate);
|
||||
Assert.AreEqual(Convert.ToDateTime("1/1/2020"), result.NextDueDate);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetLoanDetail_Exception()
|
||||
{
|
||||
_mockAccountService.Setup(x => x.GetAccountDetails(It.IsAny<CoreRequestParameters>(),
|
||||
It.IsAny<AcctNbrRequest>())).Throws(new Exception());
|
||||
|
||||
var testLoanId = 1000143;
|
||||
Assert.ThrowsAsync<Exception>(async () => await _loanService.GetLoanDetail(testLoanId));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetCollateralDetails_Returns_CollateralDetails_OneVehicle_OneNoneVehicle()
|
||||
{
|
||||
var testProperty1 = new Property()
|
||||
{
|
||||
TypeCode= "AUTU",
|
||||
Value = 100,
|
||||
Make ="Test Make",
|
||||
Model = "Test Model",
|
||||
PropertyNumber = 1,
|
||||
PropertyId = "dfjadf12083213"
|
||||
};
|
||||
var testProperty2 = new Property()
|
||||
{
|
||||
TypeCode = "TEST",
|
||||
Value = 1000,
|
||||
PropertyId = "2"
|
||||
};
|
||||
List<Property> testProperties = new List<Property>() { testProperty1, testProperty2 };
|
||||
_mockPropertyService.Setup(x => x.GetAccountProperties(It.IsAny<long>())).ReturnsAsync(testProperties);
|
||||
|
||||
var testLoanId = 1000143;
|
||||
var results = await _loanService.GetCollateralDetails(testLoanId);
|
||||
|
||||
Assert.NotNull(results);
|
||||
Assert.AreEqual(2, results.Count());
|
||||
var resultVehicle = results.FirstOrDefault(p => p.Vehicle != null);
|
||||
Assert.NotNull(resultVehicle);
|
||||
Assert.AreEqual("Test Make", resultVehicle.Vehicle.Make);
|
||||
Assert.AreEqual("Test Model", resultVehicle.Vehicle.Model);
|
||||
Assert.AreEqual("dfjadf12083213", resultVehicle.Vehicle.VIN);
|
||||
Assert.AreEqual(1, resultVehicle.CollateralId);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetCollateralDetails_Returns_CollateralDetails_AllNoneVehicle()
|
||||
{
|
||||
var testProperty1 = new Property()
|
||||
{
|
||||
TypeCode = "TEST 1",
|
||||
Value = 10001.99,
|
||||
PropertyId = "1"
|
||||
};
|
||||
var testProperty2 = new Property()
|
||||
{
|
||||
TypeCode = "TEST 2",
|
||||
Value = 10002.01,
|
||||
PropertyId = "2"
|
||||
};
|
||||
List<Property> testProperties = new List<Property>() { testProperty1, testProperty2 };
|
||||
_mockPropertyService.Setup(x => x.GetAccountProperties(It.IsAny<long>())).ReturnsAsync(testProperties);
|
||||
|
||||
var testLoanId = 1000143;
|
||||
var results = await _loanService.GetCollateralDetails(testLoanId);
|
||||
|
||||
Assert.NotNull(results);
|
||||
Assert.AreEqual(2, results.Count());
|
||||
var resultVehicle = results.FirstOrDefault(p => p.Vehicle != null);
|
||||
Assert.Null(resultVehicle);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetCollateralDetails_Exception()
|
||||
{
|
||||
_mockPropertyService.Setup(x => x.GetAccountProperties(It.IsAny<long>())).Throws(new Exception());
|
||||
|
||||
var testLoanId = 1000143;
|
||||
Assert.ThrowsAsync<Exception>(async () => await _loanService.GetCollateralDetails( testLoanId));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetPropertyInformation_OkAsync()
|
||||
{
|
||||
var testProperty1 = new Property()
|
||||
{
|
||||
PropertyNumber = 1000
|
||||
};
|
||||
var testProperty2 = new Property()
|
||||
{
|
||||
PropertyNumber = 1001
|
||||
};
|
||||
List<Property> testProperties = new List<Property>() { testProperty1, testProperty2 };
|
||||
_mockPropertyService.Setup(x => x.GetAccountProperties(It.IsAny<long>())).ReturnsAsync(testProperties);
|
||||
|
||||
var testLoanId = 1000143;
|
||||
var results = await _loanService.GetPropertyInformation(testLoanId);
|
||||
|
||||
Assert.NotNull(results);
|
||||
Assert.AreEqual(2, results.Count());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetPropertyInformation_Exception()
|
||||
{
|
||||
_mockPropertyService.Setup(x => x.GetAccountProperties(It.IsAny<long>())).Throws(new Exception());
|
||||
|
||||
var testaccountId = 1000;
|
||||
Assert.ThrowsAsync<Exception>(async () => await _loanService.GetPropertyInformation(testaccountId));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user