Files
2026-03-13 09:28:55 -05:00

158 lines
6.3 KiB
C#

using Moq;
using NUnit.Framework;
using LCU.Api.Internal.DataCleanUp.Services;
using LCU.Api.Internal.DataCleanUp.DataAccess;
using System.Collections.Generic;
using System.Threading.Tasks;
using LCU.Library.Internal.DataCleanUpModel.Enum;
using LCU.Library.Internal.DataCleanUpModel.Models;
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.CoreResponses;
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.CoreRequests;
using LCU.Api.Internal.DataCleanUp.Configuration;
namespace LCU.Api.Internal.DataCleanUpTest.Services;
public class AddFundsToVipSavingsAccountsServiceTest
{
private AddFundsToVipSavingsAccountsService _addFundsToVipSavingsAccountsService;
private Mock<ICoreApiWrapperService> _mockCoreApiWrapperService;
private Mock<ICoreApiWrapperDao> _mockCoreApiWrapperDao;
private SavingsMissingRequirementsDefaults _savingsMissingRequirementsDefaults;
[SetUp]
public void Setup()
{
_savingsMissingRequirementsDefaults = new SavingsMissingRequirementsDefaults()
{
FundsToAccountDefaults = new FundsToAccountDefaults()
{
Description = "Vip Savings",
TransactionAmount = 5.00,
TransactionTypeCode = "DEP",
FundsDefaults = new FundsDefaults()
{
ClearingCategoryCode = "IMED",
FundAmount = 5.00,
FundTypeCode = "EL",
FundTypeDetailCode = "INTR"
}
}
};
_mockCoreApiWrapperDao = new Mock<ICoreApiWrapperDao>();
_mockCoreApiWrapperService = new Mock<ICoreApiWrapperService>();
_addFundsToVipSavingsAccountsService = new AddFundsToVipSavingsAccountsService(_mockCoreApiWrapperService.Object, _savingsMissingRequirementsDefaults);
}
[Test]
public async Task CleanUpVipSavings_Success()
{
//Set Up Object
var listAccounts = new List<string>() { "1111111" };
_mockCoreApiWrapperService.Setup(x => x.GetVipSavingsToFund()).ReturnsAsync(listAccounts);
//Set Up Response
var basicResponse = new BasicResponse()
{
Success = true,
Errors = new List<string>()
};
var basicResponseList = new List<BasicResponse>() { basicResponse };
_mockCoreApiWrapperService.Setup(x => x.PostFundsToAccount(It.IsAny<string>(), It.IsAny<double>()))
.ReturnsAsync(basicResponseList);
var testRequest = new DataCleanUpRequest()
{
CleanUpType = CleanUpTypes.AddFundsToVipSavingsAccounts
};
var result = await _addFundsToVipSavingsAccountsService.CleanUp(testRequest);
Assert.NotNull(result);
Assert.AreEqual(testRequest, result.Request);
Assert.IsTrue(result.Successful);
Assert.IsEmpty(result.ResponseStack);
_mockCoreApiWrapperService.Verify(x => x.GetVipSavingsToFund(), Times.Once);
_mockCoreApiWrapperService.Verify(x => x.PostFundsToAccount(It.IsAny<string>(), It.IsAny<double>()), Times.Once);
}
[Test]
public async Task CleanUp_GetVipSavings_Null_Fail()
{
//Set Up Object
List<string> listAccounts = null;
_mockCoreApiWrapperService.Setup(x => x.GetVipSavingsToFund()).ReturnsAsync(listAccounts);
var testRequest = new DataCleanUpRequest()
{
CleanUpType = CleanUpTypes.AddFundsToVipSavingsAccounts
};
var result = await _addFundsToVipSavingsAccountsService.CleanUp(testRequest);
Assert.NotNull(result);
Assert.AreEqual(testRequest, result.Request);
Assert.IsFalse(result.Successful);
Assert.AreEqual(1, result.ResponseStack.Count);
_mockCoreApiWrapperService.Verify(x => x.GetVipSavingsToFund(), Times.Once);
_mockCoreApiWrapperDao.Verify(x => x.PostFundsToAccount(It.IsAny<List<FundsToAccountRequest>>()), Times.Never);
}
[Test]
public async Task CleanUp_UpdateResult_Null_Fail()
{
//Set Up Objects
var listAccounts = new List<string>(){"1111111"};
_mockCoreApiWrapperService.Setup(x => x.GetVipSavingsToFund()).ReturnsAsync(listAccounts);
List<BasicResponse>? basicResponseList = null;
_mockCoreApiWrapperService.Setup(x => x.PostFundsToAccount(It.IsAny<string>(), It.IsAny<double>()))
.ReturnsAsync(basicResponseList);
var testRequest = new DataCleanUpRequest()
{
CleanUpType = CleanUpTypes.AddFundsToVipSavingsAccounts
};
var result = await _addFundsToVipSavingsAccountsService.CleanUp(testRequest);
Assert.NotNull(result);
Assert.AreEqual(testRequest, result.Request);
Assert.IsFalse(result.Successful);
Assert.AreEqual(1, result.ResponseStack.Count);
_mockCoreApiWrapperService.Verify(x => x.GetVipSavingsToFund(), Times.Once);
_mockCoreApiWrapperService.Verify(x => x.PostFundsToAccount(It.IsAny<string>(), It.IsAny<double>()), Times.Once);
}
[Test]
public async Task CleanUp_BasicResponse_Return_NotSuccessful_Fail()
{
//Set Up Objects
var listAccounts = new List<string>(){"1111111"};
_mockCoreApiWrapperService.Setup(x => x.GetVipSavingsToFund()).ReturnsAsync(listAccounts);
var basicResponse = new BasicResponse()
{
Success = false,
Errors = new List<string>() { "Error has occured" }
};
var basicResponseList = new List<BasicResponse>() { basicResponse };
_mockCoreApiWrapperService.Setup(x => x.PostFundsToAccount(It.IsAny<string>(), It.IsAny<double>()))
.ReturnsAsync(basicResponseList);
var testRequest = new DataCleanUpRequest()
{
CleanUpType = CleanUpTypes.AddFundsToVipSavingsAccounts
};
var result = await _addFundsToVipSavingsAccountsService.CleanUp(testRequest);
Assert.NotNull(result);
Assert.AreEqual(testRequest, result.Request);
Assert.IsFalse(result.Successful);
Assert.AreEqual(1, result.ResponseStack.Count);
_mockCoreApiWrapperService.Verify(x => x.GetVipSavingsToFund(), Times.Once);
_mockCoreApiWrapperService.Verify(x => x.PostFundsToAccount(It.IsAny<string>(), It.IsAny<double>()), Times.Once);
}
}