276 lines
14 KiB
C#
276 lines
14 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Moq;
|
|
using NUnit.Framework;
|
|
using LCU.Library.Internal.ApiSecurity.Models;
|
|
using LCU.Library.Internal.CoreApiWrapperLib.Configuration;
|
|
using LCU.Library.Internal.CoreApiWrapperLib.CoreDbUtilities;
|
|
using LCU.Library.Internal.CoreApiWrapperLib.DataAccess;
|
|
using LCU.Library.Internal.CoreApiWrapperLib.Utilities;
|
|
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.IndirectLoan;
|
|
using LCU.Library.Internal.LcuHttpClient.HttpRequest;
|
|
|
|
namespace LCU.Api.Internal.CoreApiWrapperTest.DataAccess
|
|
{
|
|
public class IndirectLoanDaoTest
|
|
{
|
|
private IndirectLoanDao _indirectLoanDao;
|
|
private Mock<ICoreDbExecution> _mockCoreDbExecution;
|
|
private CoreConfiguration _coreConfiguration;
|
|
private ApiSecurityConfiguration _apiSecurityConfiguration;
|
|
private Mock<IPutRequest> _mockPutRequest;
|
|
|
|
[SetUp]
|
|
public void SetUp()
|
|
{
|
|
_mockPutRequest = new Mock<IPutRequest>();
|
|
|
|
_coreConfiguration = new CoreConfiguration()
|
|
{
|
|
CoreSoapApiConfiguration = new CoreSoapApiConfiguration()
|
|
{
|
|
CoreSoapEndpointConfiguration = new CoreSoapEndpointConfiguration()
|
|
{
|
|
PutDealerOriginalBalance = "TEST/IndirectLoan/PutDealerOriginalBalance"
|
|
}
|
|
}
|
|
};
|
|
|
|
_apiSecurityConfiguration = new ApiSecurityConfiguration()
|
|
{
|
|
InternalApiKeySet = new Dictionary<string, string>()
|
|
{
|
|
["CoreSoapApiWrapper"] = "TEST"
|
|
}
|
|
};
|
|
|
|
_mockCoreDbExecution = new Mock<ICoreDbExecution>();
|
|
_indirectLoanDao = new IndirectLoanDao(_mockCoreDbExecution.Object,
|
|
_coreConfiguration,
|
|
_apiSecurityConfiguration,
|
|
_mockPutRequest.Object);
|
|
}
|
|
|
|
[Test]
|
|
public async Task GetIndirectLoanByAccountNumber_OK()
|
|
{
|
|
_mockCoreDbExecution
|
|
.Setup(x => x.ExecuteQuery<IndirectLoanDetail, object>(It.IsAny<string>(), It.IsAny<object>()))
|
|
.ReturnsAsync(new List<IndirectLoanDetail>()
|
|
{
|
|
new IndirectLoanDetail() {LoanNumber = "1234"}
|
|
}).Verifiable();
|
|
|
|
var results = await _indirectLoanDao.FindByAccountNumber(1234);
|
|
|
|
Assert.NotNull(results);
|
|
Assert.AreEqual(1, results.Count());
|
|
_mockCoreDbExecution.Verify(x =>
|
|
x.ExecuteQuery<IndirectLoanDetail, object>(It.Is<string>(str => str.Contains(":AcctNbr")),
|
|
It.Is<object>(obj =>
|
|
obj.GetHashCode().Equals(new { AcctNbr = 1234 }.GetHashCode()))));
|
|
}
|
|
|
|
[Test]
|
|
public async Task GetIndirectLoanByAccountNumber_Exception()
|
|
{
|
|
_mockCoreDbExecution
|
|
.Setup(x => x.ExecuteQuery<IndirectLoanDetail, object>(It.IsAny<string>(), It.IsAny<object>()))
|
|
.ThrowsAsync(new Exception("Yikes"));
|
|
|
|
Assert.ThrowsAsync<Exception>(async () =>
|
|
await _indirectLoanDao.FindByAccountNumber(1234));
|
|
|
|
_mockCoreDbExecution.Verify(x =>
|
|
x.ExecuteQuery<IndirectLoanDetail, object>(It.Is<string>(str => str.Contains(":AcctNbr")),
|
|
It.Is<object>(obj =>
|
|
obj.GetHashCode().Equals(new { AcctNbr = 1234 }.GetHashCode()))));
|
|
}
|
|
|
|
[Test]
|
|
public async Task GetIndirectLoansByPostedDate_OK()
|
|
{
|
|
_mockCoreDbExecution
|
|
.Setup(x => x.ExecuteQuery<IndirectLoanDetail, object>(It.IsAny<string>(), It.IsAny<object>()))
|
|
.ReturnsAsync(new List<IndirectLoanDetail>()
|
|
{
|
|
new IndirectLoanDetail { LoanNumber = "1" },
|
|
new IndirectLoanDetail { LoanNumber = "2" },
|
|
new IndirectLoanDetail { LoanNumber = "3" }
|
|
}).Verifiable();
|
|
|
|
var results = await _indirectLoanDao.FindByPostedDate(DateTime.Parse("2021-05-01T11:00:00"));
|
|
|
|
Assert.NotNull(results);
|
|
Assert.AreEqual(3, results.Count());
|
|
_mockCoreDbExecution.Verify(x =>
|
|
x.ExecuteQuery<IndirectLoanDetail, object>(It.Is<string>(str => str.Contains(":newerThanDateTime")),
|
|
It.Is<object>(obj =>
|
|
obj.GetHashCode().Equals(new { newerThanDateTime = "2021-05-01 11:00:00" }.GetHashCode()))));
|
|
}
|
|
|
|
[Test]
|
|
public async Task GetIndirectLoansByPostedDate_Exception()
|
|
{
|
|
_mockCoreDbExecution
|
|
.Setup(x => x.ExecuteQuery<IndirectLoanDetail, object>(It.IsAny<string>(), It.IsAny<object>()))
|
|
.ThrowsAsync(new Exception("Yikes"));
|
|
|
|
Assert.ThrowsAsync<Exception>(async () =>
|
|
await _indirectLoanDao.FindByPostedDate(DateTime.Parse("2021-05-01T11:00:00")));
|
|
|
|
//Parameters are passed in using Anonymous Object,Verify they are expected object using HashCode. Obj.Equals has issues with Anonymous Objects.
|
|
_mockCoreDbExecution.Verify(x =>
|
|
x.ExecuteQuery<IndirectLoanDetail, object>(It.Is<string>(str => str.Contains(":newerThanDateTime")),
|
|
It.Is<object>(obj =>
|
|
obj.GetHashCode().Equals(new { newerThanDateTime = "2021-05-01 11:00:00" }.GetHashCode()))));
|
|
}
|
|
|
|
[Test]
|
|
public async Task GetClosedIndirectLoansByPostedDate_OK()
|
|
{
|
|
_mockCoreDbExecution
|
|
.Setup(x => x.ExecuteQuery<ClosedIndirectLoan, object>(It.IsAny<string>(), It.IsAny<object>()))
|
|
.ReturnsAsync(new List<ClosedIndirectLoan>()
|
|
{
|
|
new ClosedIndirectLoan { LoanNumber = "1" },
|
|
new ClosedIndirectLoan { LoanNumber = "2" },
|
|
new ClosedIndirectLoan { LoanNumber = "3" }
|
|
}).Verifiable();
|
|
|
|
var results = await _indirectLoanDao.FindClosedByPostedDate(DateTime.Parse("2021-05-01T11:00:00"));
|
|
|
|
Assert.NotNull(results);
|
|
Assert.AreEqual(3, results.Count());
|
|
_mockCoreDbExecution.Verify(x =>
|
|
x.ExecuteQuery<ClosedIndirectLoan, object>(It.Is<string>(str => str.Contains(":newerThanDateTime") && str.Contains("CLS")),
|
|
It.Is<object>(obj =>
|
|
obj.GetHashCode().Equals(new { newerThanDateTime = "2021-05-01 11:00:00" }.GetHashCode()))));
|
|
}
|
|
|
|
[Test]
|
|
public async Task GetClosedIndirectLoansByPostedDate_Exception()
|
|
{
|
|
_mockCoreDbExecution
|
|
.Setup(x => x.ExecuteQuery<ClosedIndirectLoan, object>(It.IsAny<string>(), It.IsAny<object>()))
|
|
.ThrowsAsync(new Exception("Yikes"));
|
|
|
|
Assert.ThrowsAsync<Exception>(async () =>
|
|
await _indirectLoanDao.FindClosedByPostedDate(DateTime.Parse("2021-05-01T11:00:00")));
|
|
|
|
//Parameters are passed in using Anonymous Object,Verify they are expected object using HashCode. Obj.Equals has issues with Anonymous Objects.
|
|
_mockCoreDbExecution.Verify(x =>
|
|
x.ExecuteQuery<ClosedIndirectLoan, object>(It.Is<string>(str => str.Contains(":newerThanDateTime") && str.Contains("CLS")),
|
|
It.Is<object>(obj =>
|
|
obj.GetHashCode().Equals(new { newerThanDateTime = "2021-05-01 11:00:00" }.GetHashCode()))));
|
|
}
|
|
|
|
[Test]
|
|
public async Task GetClosedIndirectLoansWithDetailByPostedDate_OK()
|
|
{
|
|
_mockCoreDbExecution
|
|
.Setup(x => x.ExecuteQuery<IndirectLoanDetail, object>(It.IsAny<string>(), It.IsAny<object>()))
|
|
.ReturnsAsync(new List<IndirectLoanDetail>()
|
|
{
|
|
new IndirectLoanDetail { LoanNumber = "1" },
|
|
new IndirectLoanDetail { LoanNumber = "2" },
|
|
new IndirectLoanDetail { LoanNumber = "3" }
|
|
}).Verifiable();
|
|
|
|
var results = await _indirectLoanDao.FindClosedWithDetailByPostedDate(DateTime.Parse("2021-05-01T11:00:00"));
|
|
|
|
Assert.NotNull(results);
|
|
Assert.AreEqual(3, results.Count());
|
|
_mockCoreDbExecution.Verify(x =>
|
|
x.ExecuteQuery<IndirectLoanDetail, object>(It.Is<string>(str => str.Contains(":newerThanDateTime") && str.Contains("CLS")),
|
|
It.Is<object>(obj =>
|
|
obj.GetHashCode().Equals(new { newerThanDateTime = "2021-05-01 11:00:00" }.GetHashCode()))));
|
|
}
|
|
|
|
[Test]
|
|
public async Task GetClosedIndirectLoansWithDetailByPostedDate_Exception()
|
|
{
|
|
_mockCoreDbExecution
|
|
.Setup(x => x.ExecuteQuery<IndirectLoanDetail, object>(It.IsAny<string>(), It.IsAny<object>()))
|
|
.ThrowsAsync(new Exception("Yikes"));
|
|
|
|
Assert.ThrowsAsync<Exception>(async () =>
|
|
await _indirectLoanDao.FindClosedWithDetailByPostedDate(DateTime.Parse("2021-05-01T11:00:00")));
|
|
|
|
//Parameters are passed in using Anonymous Object,Verify they are expected object using HashCode. Obj.Equals has issues with Anonymous Objects.
|
|
_mockCoreDbExecution.Verify(x =>
|
|
x.ExecuteQuery<IndirectLoanDetail, object>(It.Is<string>(str => str.Contains(":newerThanDateTime") && str.Contains("CLS")),
|
|
It.Is<object>(obj =>
|
|
obj.GetHashCode().Equals(new { newerThanDateTime = "2021-05-01 11:00:00" }.GetHashCode()))));
|
|
}
|
|
|
|
[Test]
|
|
public async Task UpdateDealerOriginalBalance_Ok()
|
|
{
|
|
var accountNumber = "111111111111";
|
|
var response = new UpdateDealerOriginalBalanceResponse();
|
|
var responseList = new List<UpdateDealerOriginalBalanceResponse> { response }; //no errors in response
|
|
var endpoint = HttpUtilities.BuildHttpsUri(_coreConfiguration.CoreSoapApiConfiguration.CoreSoapApiWrapperHost,
|
|
_coreConfiguration.CoreSoapApiConfiguration.CoreSoapEndpointConfiguration.PutDealerOriginalBalance + $"?accountNumber={accountNumber}");
|
|
_mockPutRequest.Setup(x => x.Async<string, List<UpdateDealerOriginalBalanceResponse>>(endpoint,
|
|
null,
|
|
It.IsAny<Dictionary<string, string>>(),
|
|
It.IsAny<int>(),
|
|
It.IsAny<int>()))
|
|
.ReturnsAsync(responseList).Verifiable();
|
|
|
|
var results = await _indirectLoanDao.UpdateDealerOriginalBalance(accountNumber);
|
|
Assert.IsNotNull(results);
|
|
Assert.AreEqual("", results.ToList().Where(x => x.AccountNumber == "111111111111"));
|
|
_mockPutRequest.Verify();
|
|
}
|
|
|
|
[Test]
|
|
public async Task UpdateDealerOriginalBalance_Ok_WithErrors()
|
|
{
|
|
var accountNumber ="111111111111";
|
|
var response = new UpdateDealerOriginalBalanceResponse()
|
|
{
|
|
AccountNumber = "111111111111",
|
|
ErrorMessage = "Error: This account is not valid for update."
|
|
};
|
|
|
|
var responseList = new List<UpdateDealerOriginalBalanceResponse> { response }; //error for second account
|
|
var endpoint = HttpUtilities.BuildHttpsUri(_coreConfiguration.CoreSoapApiConfiguration.CoreSoapApiWrapperHost,
|
|
_coreConfiguration.CoreSoapApiConfiguration.CoreSoapEndpointConfiguration.PutDealerOriginalBalance + $"?accountNumber={accountNumber}");
|
|
_mockPutRequest.Setup(x => x.Async<string, List<UpdateDealerOriginalBalanceResponse>>(endpoint,
|
|
null,
|
|
It.IsAny<Dictionary<string, string>>(),
|
|
It.IsAny<int>(),
|
|
It.IsAny<int>()))
|
|
.ReturnsAsync(responseList).Verifiable();
|
|
|
|
var results = await _indirectLoanDao.UpdateDealerOriginalBalance(accountNumber);
|
|
Assert.IsNotNull(results);
|
|
Assert.AreEqual(1, results.Count());
|
|
Assert.AreEqual("111111111111", results.ToList().Where(x => x.AccountNumber == "111111111111").FirstOrDefault().AccountNumber);
|
|
_mockPutRequest.Verify();
|
|
}
|
|
|
|
[Test]
|
|
public void UpdateDealerOriginalBalance_Exception()
|
|
{
|
|
var accountNumber = "111111111111";
|
|
var endpoint = HttpUtilities.BuildHttpsUri(_coreConfiguration.CoreSoapApiConfiguration.CoreSoapApiWrapperHost,
|
|
_coreConfiguration.CoreSoapApiConfiguration.CoreSoapEndpointConfiguration.PutDealerOriginalBalance + $"?accountNumber={accountNumber}");
|
|
_mockPutRequest.Setup(x => x.Async<string, List<UpdateDealerOriginalBalanceResponse>>(endpoint,
|
|
null,
|
|
It.IsAny<Dictionary<string, string>>(),
|
|
It.IsAny<int>(),
|
|
It.IsAny<int>()))
|
|
.Throws(new Exception("Error thrown in unit test.")).Verifiable();
|
|
|
|
Assert.ThrowsAsync<Exception>(async () => await _indirectLoanDao.UpdateDealerOriginalBalance(accountNumber));
|
|
_mockPutRequest.Verify();
|
|
}
|
|
|
|
}
|
|
}
|