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 _mockDao; private Mock _mockSoapConfiguration; private Mock _mockCoreCmcConnection; private const string AuthTypeToken = "3"; public IndirectLoanServiceTest() { _mockDao = new Mock(); _mockSoapConfiguration = new Mock(); _mockCoreCmcConnection = new Mock(); _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(); requestsBase.Add(accountRequest); var input = new Cmc.Input() { UserAuthentication = userAuthentication, Requests = requestsBase }; var outputResponse = new Cmc.Response() { SuccessYN = "Y", Errors = new List() }; var output = new Cmc.Output() { Responses = new List() { outputResponse } }; var transaction = new Cmc.Transaction() { Input = input, CommitRollbackYN = "Y", Output = output }; var account = "11111111111"; var response = new UpdateDealerOriginalBalanceResponse(); _mockCoreCmcConnection.Setup(x => x.CreateSocketTransactionRequest(It.IsAny())).Returns(transaction); _mockDao.Setup(x => x.UpdateDealerOriginalBalance(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(); requestsBase.Add(accountRequest); var input = new Cmc.Input() { UserAuthentication = userAuthentication, Requests = requestsBase }; var outputResponse = new Cmc.Response() { SuccessYN = "Y", //Errors = new List() }; var output = new Cmc.Output() { Responses = new List() { outputResponse } }; var transaction = new Cmc.Transaction() { Input = input, CommitRollbackYN = "Y", Output = output }; var account = "11111111111111"; _mockCoreCmcConnection.Setup(x => x.CreateSocketTransactionRequest(It.IsAny())).Returns(transaction); _mockDao.Setup(x => x.UpdateDealerOriginalBalance(transaction)).Throws(new Exception("Error thrown in unit test.")).Verifiable(); Assert.ThrowsException(() => _service.UpdateDealerOriginalBalances(account)); _mockDao.Verify(); } } }