Files
2026-03-13 12:58:13 -05:00

162 lines
6.0 KiB
C#

using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using System;
using System.Collections.Generic;
using LCU.API.Internal.CoreSoapApiWrapper.DataAccess;
using LCU.API.Internal.CoreSoapApiWrapper.Models;
using LCU.API.Internal.CoreSoapApiWrapper.Services;
using LCU.API.Internal.CoreSoapApiWrapper.CoreSoapUtilities;
using LCU.API.Internal.CoreSoapApiWrapper.Models.Response;
using Cmc = LCU.API.Internal.CoreSoapApiWrapper.Models.Cmc;
namespace LCU.API.Internal.CoreSoapApiWrapperTest.Services
{
[TestClass]
public class IndirectLoanServiceTest
{
private IndirectLoanService _service;
private Mock<IIndirectLoanDao> _mockDao;
private Mock<SoapConfiguration> _mockSoapConfiguration;
private Mock<ICoreCmcConnection> _mockCoreCmcConnection;
private const string AuthTypeToken = "3";
public IndirectLoanServiceTest()
{
_mockDao = new Mock<IIndirectLoanDao>();
_mockSoapConfiguration = new Mock<SoapConfiguration>();
_mockCoreCmcConnection = new Mock<ICoreCmcConnection>();
_mockSoapConfiguration.Object.RequestType = "16370";
_mockSoapConfiguration.Object.IPAddress = "10.10.0.00";
_mockSoapConfiguration.Object.PortId = 2500;
_mockSoapConfiguration.Object.RequestType = "16340";
_mockSoapConfiguration.Object.SocketApplicationId = "7726";
_mockSoapConfiguration.Object.SocketDeviceId = "FULL";
_mockSoapConfiguration.Object.AuthenticationType = "2";
_mockSoapConfiguration.Object.SocketTimeout = 10000;
_service = new IndirectLoanService(_mockDao.Object, _mockCoreCmcConnection.Object, _mockSoapConfiguration.Object);
}
[TestMethod]
public void UpdateDealerOriginalBalancesRequest_OK()
{
var accountValue = new Cmc.Account()
{
AcctNbr = "11111111111"
};
var accountRequest = new Cmc.AccountRequest()
{
Account = accountValue,
ReqTypCd = _mockSoapConfiguration.Object.RequestType
};
var userAuthentication = new Cmc.UserAuthentication()
{
AuthTyp = _mockSoapConfiguration.Object.AuthenticationType,
ApplNbr = _mockSoapConfiguration.Object.SocketApplicationId,
PhysAddr = _mockSoapConfiguration.Object.SocketDeviceId,
UserId = "LOANORIG"
//Passwd = "TESTTOKENSTRING" use without token for testing
};
var requestsBase = new List<Cmc.AccountRequest>();
requestsBase.Add(accountRequest);
var input = new Cmc.Input<Cmc.AccountRequest>()
{
UserAuthentication = userAuthentication,
Requests = requestsBase
};
var outputResponse = new Cmc.Response()
{
SuccessYN = "Y",
Errors = new List<Cmc.Error>()
};
var output = new Cmc.Output()
{
Responses = new List<Cmc.Response>() { outputResponse }
};
var transaction = new Cmc.Transaction<Cmc.AccountRequest>()
{
Input = input,
CommitRollbackYN = "Y",
Output = output
};
var account = "11111111111";
var response = new UpdateDealerOriginalBalanceResponse();
_mockCoreCmcConnection.Setup(x => x.CreateSocketTransactionRequest<Cmc.AccountRequest>(It.IsAny<Cmc.AccountRequest>())).Returns(transaction);
_mockDao.Setup(x => x.UpdateDealerOriginalBalance<Cmc.AccountRequest>(transaction)).Returns(transaction).Verifiable();
var result = _service.UpdateDealerOriginalBalances(account);
Assert.IsNotNull(result);
_mockCoreCmcConnection.Verify();
_mockDao.Verify();
}
[TestMethod]
public void UpdateDealerOriginalBalancesRequest_Exception()
{
var accountValue = new Cmc.Account()
{
AcctNbr = "11111111111"
};
var accountRequest = new Cmc.AccountRequest()
{
Account = accountValue,
ReqTypCd = _mockSoapConfiguration.Object.RequestType
};
var userAuthentication = new Cmc.UserAuthentication()
{
AuthTyp = _mockSoapConfiguration.Object.AuthenticationType,
ApplNbr = _mockSoapConfiguration.Object.SocketApplicationId,
PhysAddr = _mockSoapConfiguration.Object.SocketDeviceId,
UserId = "LOANORIG"
//Passwd = "TESTTOKENSTRING" use without token for testing
};
var requestsBase = new List<Cmc.AccountRequest>();
requestsBase.Add(accountRequest);
var input = new Cmc.Input<Cmc.AccountRequest>()
{
UserAuthentication = userAuthentication,
Requests = requestsBase
};
var outputResponse = new Cmc.Response()
{
SuccessYN = "Y",
//Errors = new List<Cmc.Error>()
};
var output = new Cmc.Output()
{
Responses = new List<Cmc.Response>() { outputResponse }
};
var transaction = new Cmc.Transaction<Cmc.AccountRequest>()
{
Input = input,
CommitRollbackYN = "Y",
Output = output
};
var account = "11111111111111";
_mockCoreCmcConnection.Setup(x => x.CreateSocketTransactionRequest<Cmc.AccountRequest>(It.IsAny<Cmc.AccountRequest>())).Returns(transaction);
_mockDao.Setup(x => x.UpdateDealerOriginalBalance<Cmc.AccountRequest>(transaction)).Throws(new Exception("Error thrown in unit test.")).Verifiable();
Assert.ThrowsException<Exception>(() => _service.UpdateDealerOriginalBalances(account));
_mockDao.Verify();
}
}
}