using Moq; using Microsoft.VisualStudio.TestTools.UnitTesting; using System.Net.Sockets; using System.Collections.Generic; using LCU.API.Internal.CoreSoapApiWrapper.CoreSoapUtilities; using LCU.API.Internal.CoreSoapApiWrapper.DataAccess; using LCU.API.Internal.CoreSoapApiWrapper.Models; using Cmc = LCU.API.Internal.CoreSoapApiWrapper.Models.Cmc; namespace LCU.API.Internal.CoreSoapApiWrapperTest.DataAccess { [TestClass] public class IndirectLoanDaoTest { private IndirectLoanDao _dao; private Mock _mockSoapConfiguration; private Mock _mockCoreCmcConnection; public IndirectLoanDaoTest() { _mockSoapConfiguration = new Mock(); _mockCoreCmcConnection = new Mock(); _mockSoapConfiguration.Object.IPAddress = "10.10.3.26"; _mockSoapConfiguration.Object.PortId = 2500; _mockSoapConfiguration.Object.RequestType = "16340"; _mockSoapConfiguration.Object.SocketApplicationId = "7726"; _mockSoapConfiguration.Object.SocketDeviceId = "FULL"; _mockSoapConfiguration.Object.AuthenticationType = "2"; _mockSoapConfiguration.Object.SocketTimeout = 10000; _dao = new IndirectLoanDao(_mockSoapConfiguration.Object); } [TestMethod] public void UpdateDealerOriginalBalance_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 }; _mockCoreCmcConnection.Setup(x => x.CreateSocketTransactionRequest(It.IsAny())).Returns(transaction); var result = _dao.UpdateDealerOriginalBalance(transaction); Assert.IsNotNull(result); } [TestMethod] public void UpdateDealerOriginalBalance_Exception() { var accountValue = new Cmc.Account() { AcctNbr = "11111111111111" }; 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, Passwd = "TESTTOKENSTRING" }; var requestsBase = new List(); requestsBase.Add(accountRequest); var input = new Cmc.Input() { UserAuthentication = userAuthentication, Requests = requestsBase }; var transaction = new Cmc.Transaction() { //this will cause the socket send to timeout and throw an exception }; Assert.ThrowsException(() => _dao.UpdateDealerOriginalBalance(transaction)); } } }