using LCU.API.Internal.CoreSoapApiWrapper.CoreSoapUtilities; using LCU.API.Internal.CoreSoapApiWrapper.DataAccess; using LCU.API.Internal.CoreSoapApiWrapper.Models; using LCU.API.Internal.CoreSoapApiWrapper.Models.Requests; using LCU.API.Internal.CoreSoapApiWrapper.Services; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; using System; using System.Collections.Generic; namespace LCU.API.Internal.CoreSoapApiWrapperTest.Services { [TestClass] public class MonetaryTranscationServiceTest { private MonetaryTransactionService _service; private Mock _mockDao; private Mock _mockSoapConfiguration; public MonetaryTranscationServiceTest() { _mockDao = new Mock(); _mockSoapConfiguration = new Mock(); _mockSoapConfiguration.Object.ApprovalPersonNumber = "5225"; _mockSoapConfiguration.Object.OverrideCashBoxNumber = "800"; _service = new MonetaryTransactionService(_mockDao.Object, _mockSoapConfiguration.Object); } [TestMethod] public void AddMonetaryTransactionsRequest_OK() { var groupRequest = new GroupedMonetaryTransactionRequest() { MonetaryTransactionRequests = new List() { new MonetaryTransactionRequest() { AccountNumber = 19618756535, RequestNumber = "1", TransactionTypeCode = "DEXP", FundBalanceTypes = new FundBalanceType[1] { new FundBalanceType() { FundBalanceAmount = 1.25, FundTypeCode = "EL", FundTypeDetailCode = "IMED" } }, BalanceTypes = new BalanceType1[1] { new BalanceType1() { BalanceCategoryCode = "UPFR", BalanceTypeCode = "DLR", BalanceTypeAmount = 1.25 } }, Funds = new Fund[1] { new Fund() { ClearingCategoryCode = "IMED", FundAmount = 1.25, FundTypeCode = "EL", FundTypeDetailCode = "INTR", NumberOfItems = 1 } } }, new MonetaryTransactionRequest() { AccountNumber = 19617805142, TransactionAmount = -1.25, ParentRequestNumber = "1", RequestNumber = "2", TransactionTypeCode = "DRIR", Description = "", BalanceTypes = new BalanceType1[1] { new BalanceType1() { BalanceCategoryCode = "UPFR", BalanceTypeCode = "DLR", BalanceTypeAmount = -1.25 } }, Funds = new Fund[1] { new Fund() { ClearingCategoryCode = "IMED", FundAmount = -1.25, FundTypeCode = "EL", FundTypeDetailCode = "INTR", NumberOfItems = 1 } } } } }; var response = new MonetaryTransactionResponse() { WasSuccessful = true }; var listResponse = new List { response }; var listGroupRequest = new List { groupRequest }; _mockDao.Setup(x => x.AddMonetaryTransactions(groupRequest.MonetaryTransactionRequests)).Returns(listResponse).Verifiable(); var result = _service.AddMonetaryTransactions(listGroupRequest); Assert.IsNotNull(result); _mockDao.Verify(); } [TestMethod] public void AddMonetaryTransactionsRequest_Exception() { var groupRequest = new GroupedMonetaryTransactionRequest() { MonetaryTransactionRequests = new List() { new MonetaryTransactionRequest() { AccountNumber = 19618756535, RequestNumber = "1", TransactionTypeCode = "DEXP", FundBalanceTypes = new FundBalanceType[1] { new FundBalanceType() { FundBalanceAmount = 1.25, FundTypeCode = "EL", FundTypeDetailCode = "IMED" } }, BalanceTypes = new BalanceType1[1] { new BalanceType1() { BalanceCategoryCode = "UPFR", BalanceTypeCode = "DLR", BalanceTypeAmount = 1.25 } }, Funds = new Fund[1] { new Fund() { ClearingCategoryCode = "IMED", FundAmount = 1.25, FundTypeCode = "EL", FundTypeDetailCode = "INTR", NumberOfItems = 1 } } }, new MonetaryTransactionRequest() { AccountNumber = 19617805142, TransactionAmount = -1.25, ParentRequestNumber = "1", RequestNumber = "2", TransactionTypeCode = "DRIR", Description = "", BalanceTypes = new BalanceType1[1] { new BalanceType1() { BalanceCategoryCode = "UPFR", BalanceTypeCode = "DLR", BalanceTypeAmount = -1.25 } }, Funds = new Fund[1] { new Fund() { ClearingCategoryCode = "IMED", FundAmount = -1.25, FundTypeCode = "EL", FundTypeDetailCode = "INTR", NumberOfItems = 1 } } } } }; var response = new MonetaryTransactionResponse() { WasSuccessful = false }; var listResponse = new List { response }; var listGroupRequest = new List { groupRequest }; _mockDao.Setup(x => x.AddMonetaryTransactions(groupRequest.MonetaryTransactionRequests)).Throws(new Exception("Error thrown in unit test.")).Verifiable(); Assert.ThrowsException(() => _service.AddMonetaryTransactions(listGroupRequest)); _mockDao.Verify(); } } }