using LCU.API.Internal.CoreSoapApiWrapper.CoreSoapUtilities; using LCU.API.Internal.CoreSoapApiWrapper.DataAccess; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; using System; namespace LCU.API.Internal.CoreSoapApiWrapperTest.DataAccess { [TestClass] public class AccountDaoTest { private AccountDao _dao; private Mock _mockCoreSoapRequest; public AccountDaoTest() { _mockCoreSoapRequest = new Mock(); _dao = new AccountDao(_mockCoreSoapRequest.Object); } [TestMethod] public void FindAccountByAccountNumber_OK() { var response = new AccountDetailInquiryResponse { WasSuccessful = true }; _mockCoreSoapRequest.Setup(x => x.SubmitRequest(It.Is(req => req.AccountNumber == 100L && req.AvailableMethodCode.Equals("ABHP") && req.IsExternalEntity == false && req.IsGetRTXNData == false))).Returns(response).Verifiable(); var result = _dao.FindAccountByAccountNumber(100L); _mockCoreSoapRequest.Verify(); Assert.IsNotNull(result); Assert.IsTrue((bool)result.WasSuccessful); } [TestMethod] public void FindAccountByAccountNumber_Exception() { _mockCoreSoapRequest.Setup(x => x.SubmitRequest(It.IsAny())).Throws(new Exception("Error thrown in unit test.")).Verifiable(); Assert.ThrowsException(() => _dao.FindAccountByAccountNumber(100L)); _mockCoreSoapRequest.Verify(); } [TestMethod] public void SendAccountMaintenanceRequest_OK() { var maintenanceRequest = new AccountMaintenanceRequest { Accounts = new[]{ new MaintenanceAccount { AccountNumber = 123456, DeliveryMethodCode = "PRNT" } } }; var maintenanceResponse = new AccountMaintenanceResponse { WasSuccessful = true }; _mockCoreSoapRequest.Setup(x => x.SubmitRequest(maintenanceRequest)).Returns(maintenanceResponse).Verifiable(); var result = _dao.SendAccountMaintenanceRequest(maintenanceRequest); Assert.IsNotNull(result); Assert.IsTrue((bool)result.WasSuccessful); _mockCoreSoapRequest.Verify(); } [TestMethod] public void SendAccountMaintenanceRequest_Exception() { var maintenanceRequest = new AccountMaintenanceRequest { Accounts = new[]{ new MaintenanceAccount { AccountNumber = 123456, DeliveryMethodCode = "PRNT" } } }; _mockCoreSoapRequest.Setup(x => x.SubmitRequest(maintenanceRequest)).Throws(new Exception("Error thrown in unit test.")).Verifiable(); Assert.ThrowsException(() => _dao.SendAccountMaintenanceRequest(maintenanceRequest)); _mockCoreSoapRequest.Verify(); } [TestMethod] public void SendAccountNickNameUpdateRequest_OK() { var maintenanceRequest = new AccountMaintenanceRequest { Accounts = new[]{ new MaintenanceAccount { AccountNumber = 123456, AccountDescription = "TestSuccess" } } }; var maintenanceResponse = new AccountMaintenanceResponse { WasSuccessful = true }; _mockCoreSoapRequest.Setup(x => x.SubmitRequest(maintenanceRequest)).Returns(maintenanceResponse).Verifiable(); var result = _dao.SendAccountMaintenanceRequest(maintenanceRequest); Assert.IsNotNull(result); Assert.IsTrue((bool)result.WasSuccessful); _mockCoreSoapRequest.Verify(); } [TestMethod] public void SendAccountNickNameUpdateRequest_Exception() { var maintenanceRequest = new AccountMaintenanceRequest { Accounts = new[]{ new MaintenanceAccount { AccountNumber = 123456, AccountDescription = "TestException" } } }; _mockCoreSoapRequest.Setup(x => x.SubmitRequest(maintenanceRequest)).Throws(new Exception("Error thrown in unit test.")).Verifiable(); Assert.ThrowsException(() => _dao.SendAccountMaintenanceRequest(maintenanceRequest)); _mockCoreSoapRequest.Verify(); } [TestMethod] public void SendAccountCreditReportTypeUpdateRequest_OK() { var maintenanceRequest = new AccountMaintenanceRequest { Accounts = new[]{ new MaintenanceAccount { AccountNumber = 123456, IsAccountMaintenance = true, AccountLoanDetail = new AccountLoanDetail() { AccountLoanInformation = new AccountLoanInformation() { CreditReportTypeCode = "EXCL" } } } } }; var maintenanceResponse = new AccountMaintenanceResponse { WasSuccessful = true }; _mockCoreSoapRequest.Setup(x => x.SubmitRequest(maintenanceRequest)).Returns(maintenanceResponse).Verifiable(); var result = _dao.SendAccountMaintenanceRequest(maintenanceRequest); Assert.IsNotNull(result); Assert.IsTrue((bool)result.WasSuccessful); _mockCoreSoapRequest.Verify(); } [TestMethod] public void SendAccountCreditReportTypeUpdateRequest_Exception() { var maintenanceRequest = new AccountMaintenanceRequest { Accounts = new[]{ new MaintenanceAccount { AccountNumber = 123456, IsAccountMaintenance = true, AccountLoanDetail = new AccountLoanDetail() { AccountLoanInformation = new AccountLoanInformation() { CreditReportTypeCode = "EXCL" } } } } }; _mockCoreSoapRequest.Setup(x => x.SubmitRequest(maintenanceRequest)).Throws(new Exception("Error thrown in unit test.")).Verifiable(); Assert.ThrowsException(() => _dao.SendAccountMaintenanceRequest(maintenanceRequest)); _mockCoreSoapRequest.Verify(); } } }