273 lines
9.7 KiB
C#
273 lines
9.7 KiB
C#
using Moq;
|
|
using NUnit.Framework;
|
|
using Newtonsoft.Json;
|
|
using System.Linq;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using LCU.Api.Internal.DataCleanUp.Configuration;
|
|
using LCU.Api.Internal.DataCleanUp.Models;
|
|
using LCU.Api.Internal.DataCleanUp.Services;
|
|
using LCU.Library.Internal.DataCleanUpModel.Models;
|
|
using LCU.Library.Internal.DataCleanUpModel.Enum;
|
|
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.CoreResponses;
|
|
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.Accounts;
|
|
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.CoreRequests;
|
|
|
|
namespace LCU.Api.Internal.DataCleanUpTest.Services;
|
|
|
|
public class AddFundsToIndirectSavingsAccountsServiceTest
|
|
{
|
|
private AddFundsToIndirectSavingsAccountsService _addFundsToIndirectSavingsAccountsService;
|
|
private Mock<ICoreApiWrapperService> _mockCoreApiWrapperService;
|
|
private Mock<IFileOperationsService> _mockFileOperationsService;
|
|
private DataCleanUpConfiguration _dataCleanUpConfiguration;
|
|
private IndirectSavingsRequirementsDefaults _indirectSavingsRequirementsDefaults;
|
|
private DataCleanUpResult _dataCleanUpResult;
|
|
|
|
[SetUp]
|
|
public void Setup()
|
|
{
|
|
_dataCleanUpConfiguration = new DataCleanUpConfiguration()
|
|
{
|
|
TimeZone = "America/Chicago"
|
|
};
|
|
|
|
_indirectSavingsRequirementsDefaults = new IndirectSavingsRequirementsDefaults()
|
|
{
|
|
Description = "test",
|
|
GLAccountNumber = "123445",
|
|
TransactionAmount = 5.00,
|
|
TransactionTypeCode = "test",
|
|
TransactionTypeCodeDeposit = "test",
|
|
TransactionTypeCodeGL = "test",
|
|
FundsDefaults = new FundsDefaults()
|
|
{
|
|
ClearingCategoryCode = "IMED",
|
|
FundAmount = 5.00,
|
|
FundTypeCode = "EL",
|
|
FundTypeDetailCode = "INTR"
|
|
},
|
|
FundingCoreRequests = new FundingCoreRequests()
|
|
{
|
|
AccountStatusTypes = new List<string>() { "APPR" },
|
|
BranchCodeTypes = new List<long>() { 1310 },
|
|
MajorAccountTypes = new List<string>() { "SAV" },
|
|
MinorAccountTypes = new List<string>() { "SV01", "BS01" }
|
|
}
|
|
};
|
|
|
|
_mockCoreApiWrapperService = new Mock<ICoreApiWrapperService>();
|
|
_mockFileOperationsService = new Mock<IFileOperationsService>();
|
|
_addFundsToIndirectSavingsAccountsService = new AddFundsToIndirectSavingsAccountsService(_mockCoreApiWrapperService.Object,
|
|
_mockFileOperationsService.Object,
|
|
_indirectSavingsRequirementsDefaults,
|
|
_dataCleanUpConfiguration);
|
|
}
|
|
|
|
[Test]
|
|
public async Task HandleCleanUp_Ok()
|
|
{
|
|
var indirectRequest = new IndirectFundingRequest()
|
|
{
|
|
Filename = "Test",
|
|
SummaryFileDestinationPath = "Test"
|
|
};
|
|
|
|
var dataCleanUpRequest = new DataCleanUpRequest()
|
|
{
|
|
CleanUpType = CleanUpTypes.AddFundsToIndirectSavingsAccounts,
|
|
DataCleanUpPayload = JsonConvert.SerializeObject(indirectRequest)
|
|
};
|
|
|
|
var response = new List<AccountsByMajorMinorBranchAndStatusResponse>()
|
|
{
|
|
new AccountsByMajorMinorBranchAndStatusResponse()
|
|
{
|
|
AccountNumber = 1,
|
|
BranchCode = 1,
|
|
Name = "Test"
|
|
}
|
|
};
|
|
|
|
var basicResponse = new BasicResponse()
|
|
{
|
|
Success = true,
|
|
Errors = new List<string>()
|
|
};
|
|
|
|
var basicResponseList = new List<BasicResponse>() { basicResponse };
|
|
|
|
_mockCoreApiWrapperService.Setup(x => x.GetAccountsByMajorMinorBranchAndStatus(It.IsAny<AccountsByMajorMinorBranchAndStatusRequest>()))
|
|
.ReturnsAsync(response);
|
|
|
|
_mockCoreApiWrapperService.Setup(x => x.PostFundsToAccount(It.IsAny<List<FundsToAccountRequest>>()))
|
|
.ReturnsAsync(basicResponseList).Verifiable();
|
|
|
|
var result = await _addFundsToIndirectSavingsAccountsService.CleanUp(dataCleanUpRequest);
|
|
|
|
_mockCoreApiWrapperService.Verify(x => x.PostFundsToAccount(It.IsAny<List<FundsToAccountRequest>>()), Times.Exactly(1));
|
|
|
|
Assert.AreEqual(0, result.ResponseStack.Count());
|
|
Assert.AreEqual(true, result.Successful);
|
|
}
|
|
|
|
[Test]
|
|
public async Task HandleCleanUp_WithError()
|
|
{
|
|
var accountToBeFunded = new AccountsByMajorMinorBranchAndStatusResponse()
|
|
{
|
|
BranchCode = 1,
|
|
AccountNumber = 1,
|
|
Name = "Test"
|
|
};
|
|
|
|
var response = new List<AccountsByMajorMinorBranchAndStatusResponse>()
|
|
{
|
|
new AccountsByMajorMinorBranchAndStatusResponse()
|
|
{
|
|
AccountNumber = 1,
|
|
BranchCode = 1,
|
|
Name = "Test"
|
|
}
|
|
};
|
|
|
|
var testRequest = new DataCleanUpRequest()
|
|
{
|
|
CleanUpType = CleanUpTypes.AddFundsToIndirectSavingsAccounts,
|
|
DataCleanUpPayload = null
|
|
};
|
|
|
|
_dataCleanUpResult = new DataCleanUpResult(testRequest, true, new List<string>());
|
|
|
|
_mockCoreApiWrapperService.Setup(x => x.GetAccountsByMajorMinorBranchAndStatus(It.IsAny<AccountsByMajorMinorBranchAndStatusRequest>()))
|
|
.ReturnsAsync(response);
|
|
|
|
var result = await _addFundsToIndirectSavingsAccountsService.HandleSavingsToFundsRequest(_dataCleanUpResult, accountToBeFunded);
|
|
|
|
Assert.AreEqual(1, result.ResponseStack.Count());
|
|
Assert.AreEqual(false, result.Successful);
|
|
}
|
|
|
|
[Test]
|
|
public async Task HandleExportResultsFile_Ok_NoErrors()
|
|
{
|
|
var indirectRequest = new IndirectFundingRequest()
|
|
{
|
|
Filename = "Test",
|
|
SummaryFileDestinationPath = "Test"
|
|
};
|
|
|
|
var indirectSavingsAccountSummaryList = new List<IndirectSavingsAccountsSummary>
|
|
{
|
|
new IndirectSavingsAccountsSummary
|
|
{
|
|
AccountNumber = "1",
|
|
BranchCode = "1",
|
|
AmountFunded = _indirectSavingsRequirementsDefaults.FundsDefaults.FundAmount.ToString(),
|
|
ErrorMessage = string.Empty,
|
|
Name = "Test",
|
|
}
|
|
};
|
|
|
|
var summaryTotalResults = new IndirectSavingsAccountResult
|
|
{
|
|
TotalAccountsFunded = "1",
|
|
TotalAccountsNotFunded = "0"
|
|
};
|
|
|
|
await _addFundsToIndirectSavingsAccountsService.HandleExportResultsAddFundsToSavingsAccounts(indirectRequest);
|
|
|
|
Assert.AreEqual(0, indirectSavingsAccountSummaryList.Where(x => x.ErrorMessage == null).Count());
|
|
Assert.AreEqual(summaryTotalResults.TotalAccountsFunded, indirectSavingsAccountSummaryList.Count().ToString());
|
|
}
|
|
|
|
[Test]
|
|
public async Task HandleExportResultsFile_Ok_WithErrors()
|
|
{
|
|
var indirectRequest = new IndirectFundingRequest()
|
|
{
|
|
Filename = "Test",
|
|
SummaryFileDestinationPath = "Test"
|
|
};
|
|
|
|
var indirectSavingsAccountSummaryList = new List<IndirectSavingsAccountsSummary>
|
|
{
|
|
new IndirectSavingsAccountsSummary
|
|
{
|
|
AccountNumber = "1",
|
|
BranchCode = "1",
|
|
AmountFunded = _indirectSavingsRequirementsDefaults.FundsDefaults.FundAmount.ToString(),
|
|
ErrorMessage = "There was a problem funding the account",
|
|
Name = "Test",
|
|
}
|
|
};
|
|
|
|
var summaryTotalResults = new IndirectSavingsAccountResult
|
|
{
|
|
TotalAccountsFunded = "0",
|
|
TotalAccountsNotFunded = "1"
|
|
};
|
|
|
|
await _addFundsToIndirectSavingsAccountsService.HandleExportResultsAddFundsToSavingsAccounts(indirectRequest);
|
|
|
|
Assert.AreEqual(1, indirectSavingsAccountSummaryList.Where(x => x.ErrorMessage != null).Count());
|
|
Assert.AreEqual(summaryTotalResults.TotalAccountsNotFunded, indirectSavingsAccountSummaryList.Count().ToString());
|
|
}
|
|
|
|
[Test]
|
|
public async Task HandleCreatingAccountSummary_Ok_NoErrors()
|
|
{
|
|
var accountToBeFunded = new AccountsByMajorMinorBranchAndStatusResponse()
|
|
{
|
|
BranchCode = 1,
|
|
AccountNumber = 1,
|
|
Name = "Test"
|
|
};
|
|
|
|
var testRequest = new DataCleanUpRequest()
|
|
{
|
|
CleanUpType = CleanUpTypes.AddFundsToIndirectSavingsAccounts,
|
|
DataCleanUpPayload = null
|
|
};
|
|
|
|
_dataCleanUpResult = new DataCleanUpResult(testRequest, true, new List<string>());
|
|
|
|
var result = _addFundsToIndirectSavingsAccountsService.HandleCreatingAccountSummary(accountToBeFunded, _dataCleanUpResult);
|
|
|
|
Assert.IsNotNull(result);
|
|
Assert.AreEqual(true, _dataCleanUpResult.Successful);
|
|
}
|
|
|
|
[Test]
|
|
public async Task HandleCreatingAccountSummary_Ok_WithErrors()
|
|
{
|
|
var accountToBeFunded = new AccountsByMajorMinorBranchAndStatusResponse()
|
|
{
|
|
BranchCode = 1,
|
|
AccountNumber = 1,
|
|
Name = "Test"
|
|
};
|
|
|
|
var testRequest = new DataCleanUpRequest()
|
|
{
|
|
CleanUpType = CleanUpTypes.AddFundsToIndirectSavingsAccounts,
|
|
DataCleanUpPayload = null
|
|
};
|
|
|
|
var errorList = new List<string>()
|
|
{
|
|
"There was an error"
|
|
};
|
|
|
|
_dataCleanUpResult = new DataCleanUpResult(testRequest, false, errorList);
|
|
|
|
var result = _addFundsToIndirectSavingsAccountsService.HandleCreatingAccountSummary(accountToBeFunded, _dataCleanUpResult);
|
|
|
|
Assert.IsNotNull(result);
|
|
Assert.AreEqual(false, _dataCleanUpResult.Successful);
|
|
Assert.IsNotNull(result.ErrorMessage);
|
|
}
|
|
}
|
|
|
|
|