233 lines
10 KiB
C#
233 lines
10 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.CoreApiUtilities;
|
|
using LCU.Library.Internal.CoreApiWrapperLib.CoreDbUtilities;
|
|
using LCU.Library.Internal.CoreApiWrapperLib.DataAccess;
|
|
using LCU.Library.Internal.CoreApiWrapperLib.Utilities;
|
|
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels;
|
|
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.CoreRequests;
|
|
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.Transaction;
|
|
using LCU.Library.Internal.LcuHttpClient.HttpRequest;
|
|
|
|
namespace LCU.Api.Internal.CoreApiWrapperTest.DataAccess
|
|
{
|
|
public class TransactionDaoTest
|
|
{
|
|
private TransactionDao _transactionDao;
|
|
private Mock<ICoreRequest> _mockCoreRequest;
|
|
private CoreConfiguration _coreConfiguration;
|
|
private ApiSecurityConfiguration _apiSecurityConfiguration;
|
|
private Mock<ICoreDbExecution> _mockCoreDbExecution;
|
|
private Mock<IPostRequest> _mockPostRequest;
|
|
|
|
[SetUp]
|
|
public void SetUp()
|
|
{
|
|
_mockCoreRequest = new Mock<ICoreRequest>();
|
|
_mockCoreDbExecution = new Mock<ICoreDbExecution>();
|
|
_mockPostRequest = new Mock<IPostRequest>();
|
|
|
|
_coreConfiguration = new CoreConfiguration()
|
|
{
|
|
CoreSoapApiConfiguration = new CoreSoapApiConfiguration()
|
|
{
|
|
CoreSoapEndpointConfiguration = new CoreSoapEndpointConfiguration()
|
|
{
|
|
PostMonetaryTransactions = "TEST/MonetaryTransaction/PostMonetaryTransactions"
|
|
}
|
|
},
|
|
CoreApiConfiguration = new CoreApiConfiguration()
|
|
{
|
|
CoreEndPointConfiguration = new CoreEndPointConfiguration()
|
|
{
|
|
AccountsTransactionHistoryQueryAccountNumber = "test/AccountsTransactionHistoryQueryAccountNumber"
|
|
}
|
|
}
|
|
};
|
|
|
|
_apiSecurityConfiguration = new ApiSecurityConfiguration()
|
|
{
|
|
InternalApiKeySet = new Dictionary<string, string>()
|
|
{
|
|
["CoreSoapApiWrapper"] = "TEST"
|
|
}
|
|
};
|
|
|
|
_transactionDao = new TransactionDao(_mockCoreRequest.Object,
|
|
_coreConfiguration,
|
|
_apiSecurityConfiguration,
|
|
_mockCoreDbExecution.Object,
|
|
_mockPostRequest.Object);
|
|
}
|
|
|
|
[Test]
|
|
public async Task AddMonetaryTransactions_Returns_Two()
|
|
{
|
|
var response = new List<MonetaryTransactionResponse>()
|
|
{
|
|
new()
|
|
{
|
|
WasSuccessful = true
|
|
},
|
|
new()
|
|
{
|
|
WasSuccessful = true
|
|
}
|
|
};
|
|
|
|
_mockPostRequest.Setup(x => x.Async<List<GroupedMonetaryTransactionRequest>, List<MonetaryTransactionResponse>>(It.IsAny<Uri>(),
|
|
It.IsAny<List<GroupedMonetaryTransactionRequest>>(),
|
|
It.IsAny<Dictionary<string, string>>(),
|
|
It.IsAny<int>(),
|
|
It.IsAny<int>()))
|
|
.ReturnsAsync(response).Verifiable();
|
|
|
|
var groupRequest = new GroupedMonetaryTransactionRequest()
|
|
{
|
|
ParentRequestNumber = "1",
|
|
MonetaryTransactionRequests =
|
|
[
|
|
new MonetaryTransactionRequest()
|
|
{
|
|
AccountNumber = 19617805142,
|
|
ApprovalPersonNumber = 5225,
|
|
RequestNumber = "1",
|
|
OverrideCashBoxNumber = 800,
|
|
TransactionTypeCode = "DEXP",
|
|
Description = "",
|
|
BalanceTypes =
|
|
[
|
|
new BalanceType1()
|
|
{
|
|
BalanceCategoryCode = "UPFR",
|
|
BalanceTypeCode = "DLR",
|
|
BalanceTypeAmount = 1.27
|
|
}
|
|
],
|
|
FundBalanceTypes =
|
|
[
|
|
new FundBalanceType()
|
|
{
|
|
FundBalanceAmount = 1.27,
|
|
FundTypeCode = "EL",
|
|
FundTypeDetailCode = "IMED"
|
|
}
|
|
],
|
|
Funds =
|
|
[
|
|
new Fund()
|
|
{
|
|
ClearingCategoryCode = "IMED",
|
|
FundAmount = 1.27,
|
|
FundTypeCode = "EL",
|
|
FundTypeDetailCode = "INTR",
|
|
NumberOfItems = 1
|
|
}
|
|
]
|
|
},
|
|
new MonetaryTransactionRequest()
|
|
{
|
|
AccountNumber = 19617805142,
|
|
TransactionAmount = -1.27,
|
|
ApprovalPersonNumber = 5225,
|
|
RequestNumber = "2",
|
|
ParentRequestNumber = "1",
|
|
OverrideCashBoxNumber = 800,
|
|
TransactionTypeCode = "DRIR",
|
|
Description = "",
|
|
BalanceTypes =
|
|
[
|
|
new()
|
|
{
|
|
BalanceCategoryCode = "UPFR",
|
|
BalanceTypeCode = "DLR",
|
|
BalanceTypeAmount = -1.27
|
|
}
|
|
],
|
|
Funds =
|
|
[
|
|
new Fund()
|
|
{
|
|
ClearingCategoryCode = "IMED",
|
|
FundAmount = -1.27,
|
|
FundTypeCode = "EL",
|
|
FundTypeDetailCode = "INTR",
|
|
NumberOfItems = 1
|
|
}
|
|
]
|
|
}
|
|
]
|
|
};
|
|
var listGroupRequest = new List<GroupedMonetaryTransactionRequest> { groupRequest };
|
|
|
|
var results = await _transactionDao.AddMonetaryTransactions(listGroupRequest);
|
|
Assert.IsNotNull(results);
|
|
Assert.AreEqual(2, results.Count);
|
|
_mockPostRequest.Verify();
|
|
}
|
|
|
|
[Test]
|
|
public void AddMonetaryTransactions_Exception()
|
|
{
|
|
var listGroupRequest = new List<GroupedMonetaryTransactionRequest> { new() };
|
|
var endpoint = HttpUtilities.BuildHttpsUri(_coreConfiguration.CoreSoapApiConfiguration.CoreSoapApiWrapperHost,
|
|
_coreConfiguration.CoreSoapApiConfiguration.CoreSoapEndpointConfiguration.PostMonetaryTransactions);
|
|
|
|
_mockPostRequest.Setup(x => x.Async<List<GroupedMonetaryTransactionRequest>, List<MonetaryTransactionResponse>>(endpoint,
|
|
It.IsAny<List<GroupedMonetaryTransactionRequest>>(),
|
|
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 _transactionDao.AddMonetaryTransactions(listGroupRequest));
|
|
_mockPostRequest.Verify();
|
|
}
|
|
|
|
[Test]
|
|
public async Task FindTransactionHistoryById_Return_Two()
|
|
{
|
|
var messageBody = new List<TransactionHistory>()
|
|
{
|
|
new TransactionHistory()
|
|
{
|
|
AccountNumber = 1234555,
|
|
ActivityDateTime = Convert.ToDateTime("1/1/2021")
|
|
},
|
|
new TransactionHistory()
|
|
{
|
|
AccountNumber = 1234555,
|
|
ActivityDateTime = Convert.ToDateTime("1/2/2021")
|
|
}
|
|
};
|
|
|
|
var messageHeader = new CoreMessageHeader() { };
|
|
var returnValue = new CoreApiMessage<IEnumerable<TransactionHistory>>(messageHeader, messageBody);
|
|
|
|
_mockCoreRequest
|
|
.Setup(x => x.PostRequestObject<CoreApiMessage<IEnumerable<TransactionHistory>>>(It.IsAny<string>(),
|
|
It.IsAny<Dictionary<string, string>>(),
|
|
It.IsAny<string>()))
|
|
.ReturnsAsync(returnValue).Verifiable();
|
|
|
|
|
|
var coreRequestParameters = new CoreRequestParameters() { };
|
|
var transactionHistoryRequest = new TransactionHistoryRequest() { };
|
|
|
|
var results = await _transactionDao.FindTransactionHistoryById(coreRequestParameters, transactionHistoryRequest, "dfasdfasdp-adfsdafafd-asfsadf");
|
|
|
|
var resultsList = results.ToList();
|
|
Assert.NotNull(results);
|
|
Assert.AreEqual(2, resultsList.Count);
|
|
Assert.True(resultsList.Any(x => x.AccountNumber == 1234555));
|
|
|
|
_mockCoreRequest.Verify();
|
|
}
|
|
}
|
|
} |