Files
monorepo/LCU.Api.Internal.CoreApiWrapper/LCU.Api.Internal.CoreApiWrapperTest/DataAccess/AccountDaoTest.cs
T
2026-03-31 14:32:23 -05:00

438 lines
18 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Moq;
using NUnit.Framework;
using LCU.Library.Internal.CoreApiWrapperLib.Configuration;
using LCU.Library.Internal.CoreApiWrapperLib.CoreApiUtilities;
using LCU.Library.Internal.CoreApiWrapperLib.CoreDbUtilities;
using LCU.Library.Internal.CoreApiWrapperLib.DataAccess;
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.Accounts;
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.CoreRequests;
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.CoreResponses;
using LCU.Library.Internal.ApiSecurity.Models;
using LCU.Library.Internal.LcuHttpClient.HttpRequest;
using LCU.Library.Internal.CoreApiWrapperLib.Utilities;
namespace LCU.Api.Internal.CoreApiWrapperTest.DataAccess
{
public class AccountDaoTest
{
private IAccountDao _accountDao;
private CoreConfiguration _coreConfiguration;
private ApiSecurityConfiguration _apiSecurityConfiguration;
private Mock<ICoreRequest> _mockCoreRequest;
private Mock<ICoreDbExecution> _mockCoreDbExecution;
private Mock<IPostRequest> _mockPostRequest;
private Mock<IPutRequest> _mockPutRequest;
[SetUp]
public void SetUp()
{
_mockCoreDbExecution = new Mock<ICoreDbExecution>();
_mockCoreRequest = new Mock<ICoreRequest>();
_mockPostRequest = new Mock<IPostRequest>();
_mockPutRequest = new Mock<IPutRequest>();
_coreConfiguration = new CoreConfiguration()
{
CoreSoapApiConfiguration = new CoreSoapApiConfiguration()
{
CoreSoapApiWrapperHost = "test.lcu-internal.com",
CoreSoapEndpointConfiguration = new CoreSoapEndpointConfiguration()
{
PutAccountAnalysisGroupMaintenanceRequest = "TEST/Account/AccountAnalysisGroupMaintenanceRequest"
}
}
};
_apiSecurityConfiguration = new ApiSecurityConfiguration()
{
InternalApiKeySet = new Dictionary<string, string>()
{
["CoreSoapApiWrapper"] = "TEST"
}
};
_accountDao = new AccountDao(_mockCoreRequest.Object,
_coreConfiguration,
_apiSecurityConfiguration,
_mockCoreDbExecution.Object,
_mockPostRequest.Object,
_mockPutRequest.Object);
}
[Test]
public async Task GetActivityAccountDetailsByAccountNumbers_OK()
{
_mockCoreDbExecution
.Setup(x => x.ExecuteQuery<ActivityAccountDetails, object>(It.IsAny<string>(), It.IsAny<object>()))
.ReturnsAsync(new List<ActivityAccountDetails>()
{
new() {AccountNumber = 1},
new() {AccountNumber = 2},
new() {AccountNumber = 3}
}).Verifiable();
var results = await _accountDao.GetActivityAccountDetailsByAccountNumbers(new List<string>() { "1", "2", "3" });
Assert.NotNull(results);
Assert.AreEqual(3,results.Count);
_mockCoreDbExecution.Verify(x =>
x.ExecuteQuery<ActivityAccountDetails, object>(It.Is<string>(str => str.Contains("ActivityAccountDetailsByAccountNbr") && str.Contains(":accountNumbers")),
It.IsAny<It.IsAnyType>()));
}
[Test]
public async Task GetActivityAccountDetailsByAccountNumbers_Exception()
{
_mockCoreDbExecution
.Setup(x => x.ExecuteQuery<ActivityAccountDetails, object>(It.IsAny<string>(), It.IsAny<object>()))
.ThrowsAsync(new Exception("Oops"));
Assert.ThrowsAsync<Exception>(async () =>
await _accountDao.GetActivityAccountDetailsByAccountNumbers(new List<string>() { "1", "2", "3" }));
_mockCoreDbExecution.Verify(x =>
x.ExecuteQuery<ActivityAccountDetails, object>(It.Is<string>(str => str.Contains("ActivityAccountDetailsByAccountNbr") && str.Contains(":accountNumbers")),
It.IsAny<It.IsAnyType>()));
}
[Test]
public async Task FindOwnersByAccountNumber_OK()
{
_mockCoreDbExecution
.Setup(x => x.ExecuteQuery<AccountOwnership, object>(It.IsAny<string>(), It.IsAny<object>()))
.ReturnsAsync(new List<AccountOwnership> { new AccountOwnership() { FirstName = "Tim" } }).Verifiable();
var result = await _accountDao.FindOwnersByAccountNumber(12345, new DateTime());
Assert.NotNull(result);
var firstResult = result.First();
Assert.AreEqual(firstResult.FirstName, "Tim");
_mockCoreDbExecution.Verify();
}
[Test]
public void FindOwnersByAccountNumber_Exception()
{
_mockCoreDbExecution
.Setup(x => x.ExecuteQuery<AccountOwnership, object>(It.IsAny<string>(), It.IsAny<object>()))
.ThrowsAsync(new Exception("Error thrown from unit test"));
Assert.ThrowsAsync<Exception>(async () => await _accountDao.FindOwnersByAccountNumber(12345, new DateTime()));
_mockCoreDbExecution.Verify();
}
[Test]
public async Task FindOwnersByPersonName_OK()
{
var firstName = "Tim";
var role = "OWN";
_mockCoreDbExecution
.Setup(x => x.ExecuteQuery<AccountOwnership, object>(It.IsAny<string>(), It.IsAny<object>()))
.ReturnsAsync(new List<AccountOwnership> { new AccountOwnership() { FirstName = firstName, Role = role } }).Verifiable();
var result = await _accountDao.FindPrimaryOwnersByPersonName(firstName);
Assert.NotNull(result);
var firstResult = result.First();
Assert.AreEqual(firstResult.FirstName, firstName);
Assert.AreEqual(firstResult.Role, role);
_mockCoreDbExecution.Verify();
}
[Test]
public void FindOwnersByPersonName_Exception()
{
_mockCoreDbExecution
.Setup(x => x.ExecuteQuery<AccountOwnership, object>(It.IsAny<string>(), It.IsAny<object>()))
.ThrowsAsync(new Exception("Error thrown from unit test"));
Assert.ThrowsAsync<Exception>(async () => await _accountDao.FindPrimaryOwnersByPersonName("Tim"));
_mockCoreDbExecution.Verify();
}
[Test]
public async Task FindOwnersByOrganizationName_OK()
{
var organizationName = "The Big Company";
_mockCoreDbExecution
.Setup(x => x.ExecuteQuery<AccountOwnership, object>(It.IsAny<string>(), It.IsAny<object>()))
.ReturnsAsync(new List<AccountOwnership> { new AccountOwnership() { OrganizationName = organizationName } }).Verifiable();
var result = await _accountDao.FindPrimaryOwnersByOrganizationName(organizationName);
Assert.NotNull(result);
var firstResult = result.First();
Assert.AreEqual(firstResult.OrganizationName, organizationName);
_mockCoreDbExecution.Verify();
}
[Test]
public void FindOwnersByOrganizationName_Exception()
{
_mockCoreDbExecution
.Setup(x => x.ExecuteQuery<AccountOwnership, object>(It.IsAny<string>(), It.IsAny<object>()))
.ThrowsAsync(new Exception("Error thrown from unit test"));
Assert.ThrowsAsync<Exception>(async () => await _accountDao.FindPrimaryOwnersByOrganizationName("The Big Company"));
_mockCoreDbExecution.Verify();
}
[Test]
public async Task FindAccountsForGroupAnalysisUpdate_OK()
{
_mockCoreDbExecution
.Setup(x => x.ExecuteQuery<string>(It.IsAny<string>()))
.ReturnsAsync(new List<string> { { "11111111" }, { "22222222" } }).Verifiable();
var result = await _accountDao.FindAccountsToUpdateAccountAnalysis();
Assert.NotNull(result);
Assert.AreEqual(result.First(), "11111111");
_mockCoreDbExecution.Verify();
}
[Test]
public async Task FindAccountsForGroupAnalysisUpdate_Exception()
{
_mockCoreDbExecution
.Setup(x => x.ExecuteQuery<string, object>(null, null))
.ThrowsAsync(new Exception("Error thrown from unit test"));
_mockCoreDbExecution.Verify();
var result = await _accountDao.FindAccountsToUpdateAccountAnalysis();
Assert.IsEmpty(result);
}
[Test]
public async Task UpdateAccountsForGroupAnalysisUpdate_OK()
{
var accountAnalysisGroupMaintenanceRequest = new AccountAnalysisGroupMaintenanceRequest()
{
AccountNumber = 123,
IsGenerateAnalysisStatement = true,
IsPrintAnalysisStatement = true,
IsUseForServiceCharge = true
};
var basicResponse = new BasicResponse()
{
Success = true
};
var endpoint = HttpUtilities.BuildHttpsUri(_coreConfiguration.CoreSoapApiConfiguration.CoreSoapApiWrapperHost,
_coreConfiguration.CoreSoapApiConfiguration.CoreSoapEndpointConfiguration.PutAccountAnalysisGroupMaintenanceRequest);
_mockPutRequest.Setup(x => x.Async<AccountAnalysisGroupMaintenanceRequest, BasicResponse>(endpoint,
It.IsAny<AccountAnalysisGroupMaintenanceRequest>(),
It.IsAny<Dictionary<string, string>>(),
It.IsAny<int>(),
It.IsAny<int>()))
.ReturnsAsync(basicResponse).Verifiable();
var result = await _accountDao.UpdateAccountAnalysis(accountAnalysisGroupMaintenanceRequest);
Assert.NotNull(result);
Assert.AreEqual(result.Success, true);
}
[Test]
public async Task UpdateAccountsForGroupAnalysisUpdate_Exception()
{
_mockCoreDbExecution
.Setup(x => x.ExecuteQuery<string, object>(null, null))
.ThrowsAsync(new Exception("Error thrown from unit test"));
_mockCoreDbExecution.Verify();
var result = await _accountDao.FindAccountsToUpdateAccountAnalysis();
Assert.IsEmpty(result);
}
[Test]
public async Task UpdateAccountNickName_OK()
{
var accountRequest = new AccountNickNameUpdateRequest()
{
AccountNumber = 123,
AccountDescription = "TestOk"
};
var basicResponse = new BasicResponse()
{
Success = true
};
var endpoint = HttpUtilities.BuildHttpsUri(_coreConfiguration.CoreSoapApiConfiguration.CoreSoapApiWrapperHost,
_coreConfiguration.CoreSoapApiConfiguration.CoreSoapEndpointConfiguration.PutAccountNickNameUpdateRequest);
_mockPutRequest.Setup(x => x.Async<AccountNickNameUpdateRequest, BasicResponse>(endpoint,
It.IsAny<AccountNickNameUpdateRequest>(),
It.IsAny<Dictionary<string, string>>(),
It.IsAny<int>(),
It.IsAny<int>()))
.ReturnsAsync(basicResponse).Verifiable();
var result = await _accountDao.UpdateAccountNickName(accountRequest);
Assert.NotNull(result);
Assert.AreEqual(result.Success, true);
}
[Test]
public async Task UpdateAccountNickName_Exception()
{
var accountRequest = new AccountNickNameUpdateRequest()
{
AccountNumber = 0,
AccountDescription = "TestError"
};
var result = await _accountDao.UpdateAccountNickName(accountRequest);
Assert.IsNull(result);
}
[Test]
public async Task UpdateAccountCreditReportType_OK()
{
var accountRequest = new AccountCreditReportTypeUpdateRequest()
{
AccountNumber = 123,
CreditReportType = "EXCL"
};
var basicResponse = new BasicResponse()
{
Success = true
};
var endpoint = HttpUtilities.BuildHttpsUri(_coreConfiguration.CoreSoapApiConfiguration.CoreSoapApiWrapperHost,
_coreConfiguration.CoreSoapApiConfiguration.CoreSoapEndpointConfiguration.PutAccountCreditReportTypeUpdateRequest);
_mockPutRequest.Setup(x => x.Async<AccountCreditReportTypeUpdateRequest, BasicResponse>(endpoint,
It.IsAny<AccountCreditReportTypeUpdateRequest>(),
It.IsAny<Dictionary<string, string>>(),
It.IsAny<int>(),
It.IsAny<int>()))
.ReturnsAsync(basicResponse).Verifiable();
var result = await _accountDao.UpdateAccountCreditReportType(accountRequest);
Assert.NotNull(result);
Assert.AreEqual(result.Success, true);
}
[Test]
public async Task UpdateAccountCreditReportType_Exception()
{
var accountRequest = new AccountCreditReportTypeUpdateRequest()
{
AccountNumber = 0,
CreditReportType = "EXCL"
};
var result = await _accountDao.UpdateAccountCreditReportType(accountRequest);
Assert.IsNull(result);
}
[Test]
public async Task GetAccountsByMajorMinorBranchAndStatus_OK()
{
var request = new AccountsByMajorMinorBranchAndStatusRequest()
{
BranchCodes = new List<long>()
{
1234,
1235
},
AccountStatuses = new List<string>()
{
"Status"
},
MajorTypes = new List<string>()
{
"Major"
},
MinorTypes = new List<string>()
{
"MinorOne",
"MinorTwo"
}
};
var response = new List<AccountsByMajorMinorBranchAndStatusResponse>()
{
new AccountsByMajorMinorBranchAndStatusResponse()
{
AccountNumber = 1234,
BranchCode = 987654321,
Name = "Test Name"
},
new AccountsByMajorMinorBranchAndStatusResponse()
{
AccountNumber = 5678,
BranchCode = 987654321,
Name = "Test Name Two"
}
};
_mockCoreDbExecution
.Setup(x => x.ExecuteQuery<AccountsByMajorMinorBranchAndStatusResponse, object>(It.IsAny<string>(), It.IsAny<object>()))
.ReturnsAsync(response).Verifiable();
var result = await _accountDao.GetAccountsByMajorMinorBranchAndStatus(request);
Assert.NotNull(result);
var firstResult = result.First();
Assert.AreEqual(firstResult.AccountNumber, 1234);
Assert.AreEqual(firstResult.Name, "Test Name");
_mockCoreDbExecution.Verify();
}
[Test]
public async Task UpdateAccountContractDate_OK()
{
var accountRequest = new AccountContractDateUpdateRequest
{
AccountNumber = 123,
ContractDate = DateTime.Now
};
var basicResponse = new BasicResponse()
{
Success = true
};
var endpoint = HttpUtilities.BuildHttpsUri(_coreConfiguration.CoreSoapApiConfiguration.CoreSoapApiWrapperHost,
_coreConfiguration.CoreSoapApiConfiguration.CoreSoapEndpointConfiguration.PutAccountContractDateUpdateRequest);
_mockPutRequest.Setup(x => x.Async<AccountContractDateUpdateRequest, BasicResponse>(endpoint,
It.IsAny<AccountContractDateUpdateRequest>(),
It.IsAny<Dictionary<string, string>>(),
It.IsAny<int>(),
It.IsAny<int>()))
.ReturnsAsync(basicResponse).Verifiable();
var result = await _accountDao.UpdateAccountContractDate(accountRequest);
Assert.NotNull(result);
Assert.AreEqual(result.Success, true);
}
[Test]
public async Task UpdateAccountContractDate_Exception()
{
var accountRequest = new AccountContractDateUpdateRequest
{
AccountNumber = 123,
ContractDate = DateTime.Now
};
var result = await _accountDao.UpdateAccountContractDate(accountRequest);
Assert.IsNull(result);
}
}
}