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 _mockCoreRequest; private CoreConfiguration _coreConfiguration; private ApiSecurityConfiguration _apiSecurityConfiguration; private Mock _mockCoreDbExecution; private Mock _mockPostRequest; [SetUp] public void SetUp() { _mockCoreRequest = new Mock(); _mockCoreDbExecution = new Mock(); _mockPostRequest = new Mock(); _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() { ["CoreSoapApiWrapper"] = "TEST" } }; _transactionDao = new TransactionDao(_mockCoreRequest.Object, _coreConfiguration, _apiSecurityConfiguration, _mockCoreDbExecution.Object, _mockPostRequest.Object); } [Test] public async Task AddMonetaryTransactions_Returns_Two() { var response = new List() { new() { WasSuccessful = true }, new() { WasSuccessful = true } }; _mockPostRequest.Setup(x => x.Async, List>(It.IsAny(), It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())) .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 { 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 { new() }; var endpoint = HttpUtilities.BuildHttpsUri(_coreConfiguration.CoreSoapApiConfiguration.CoreSoapApiWrapperHost, _coreConfiguration.CoreSoapApiConfiguration.CoreSoapEndpointConfiguration.PostMonetaryTransactions); _mockPostRequest.Setup(x => x.Async, List>(endpoint, It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())) .Throws(new Exception("Error thrown in unit test.")).Verifiable(); Assert.ThrowsAsync(async () => await _transactionDao.AddMonetaryTransactions(listGroupRequest)); _mockPostRequest.Verify(); } [Test] public async Task FindTransactionHistoryById_Return_Two() { var messageBody = new List() { 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>(messageHeader, messageBody); _mockCoreRequest .Setup(x => x.PostRequestObject>>(It.IsAny(), It.IsAny>(), It.IsAny())) .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(); } } }