public void setUpBeforeEachTest()
        {
            litle = new LitleRequest();

            mockXmlReader = new Mock<XmlReader>();
            mockXmlReader.SetupSequence(XmlReader => XmlReader.ReadToFollowing(It.IsAny<String>())).Returns(true).Returns(true).Returns(false);
            mockXmlReader.SetupSequence(XmlReader => XmlReader.ReadState).Returns(ReadState.Initial).Returns(ReadState.Interactive).Returns(ReadState.Closed);
        }
 public void setUpBeforeTest()
 {
     litle = new LitleRequest();
 }
        public void RFRBatch()
        {
            BatchRequest litleBatchRequest = new BatchRequest();
            litleBatchRequest.ID = "1234567A";

            AccountUpdate accountUpdate1 = new AccountUpdate();
            accountUpdate1.OrderId = "1111";
            CardType card = new CardType();
            card.Type = MethodOfPaymentTypeEnum.VI;
            card.Number = "4242424242424242";
            card.ExpDate = "1210";
            accountUpdate1.Card = card;

            litleBatchRequest.AddAccountUpdate(accountUpdate1);

            AccountUpdate accountUpdate2 = new AccountUpdate();
            accountUpdate2.OrderId = "1112";
            accountUpdate2.Card = card;

            litleBatchRequest.AddAccountUpdate(accountUpdate2);
            litle.AddBatch(litleBatchRequest);

            string batchName = litle.SendToLitle();
            litle.BlockAndWaitForResponse(batchName, estimatedResponseTime(0, 1 * 2));
            LitleResponse litleResponse = litle.ReceiveFromLitle(batchName);

            Assert.NotNull(litleResponse);

            BatchResponse litleBatchResponse = litleResponse.NextBatchResponse();
            Assert.NotNull(litleBatchResponse);
            while (litleBatchResponse != null)
            {
                AccountUpdateResponse accountUpdateResponse = litleBatchResponse.NextAccountUpdateResponse();
                Assert.NotNull(accountUpdateResponse);
                while (accountUpdateResponse != null)
                {
                    Assert.AreEqual("000", accountUpdateResponse.Response);

                    accountUpdateResponse = litleBatchResponse.NextAccountUpdateResponse();
                }
                litleBatchResponse = litleResponse.NextBatchResponse();
            }

            LitleRequest litleRfr = new LitleRequest();
            RfrRequest rfrRequest = new RfrRequest();
            AccountUpdateFileRequestData accountUpdateFileRequestData = new AccountUpdateFileRequestData();
            accountUpdateFileRequestData.MerchantId = Properties.Settings.Default.merchantId;
            accountUpdateFileRequestData.PostDay = DateTime.Now;
            rfrRequest.AccountUpdateFileRequestData = accountUpdateFileRequestData;

            litleRfr.AddRfrRequest(rfrRequest);

            string rfrBatchName = litleRfr.SendToLitle();

            try
            {
                litle.BlockAndWaitForResponse(rfrBatchName, 120000);
                LitleResponse litleRfrResponse = litle.ReceiveFromLitle(rfrBatchName);
                Assert.NotNull(litleRfrResponse);
                RFRResponse rfrResponse = litleRfrResponse.NextRFRResponse();
                Assert.NotNull(rfrResponse);
                while (rfrResponse != null)
                {
                    Assert.AreEqual("1", rfrResponse.Response);
                    Assert.AreEqual("The account update file is not ready yet.  Please try again later.", rfrResponse.Message);
                    rfrResponse = litleResponse.NextRFRResponse();
                }
            }
            catch (Exception)
            {
            }
        }
        public void InvalidCredientialsBatch()
        {
            LitleRequest litleIC = new LitleRequest(invalidConfig);

            BatchRequest litleBatchRequest = new BatchRequest();

            Authorization authorization = new Authorization();
            authorization.ReportGroup = "Planets";
            authorization.OrderId = "12344";
            authorization.Amount = 106;
            authorization.OrderSource = OrderSourceType.Ecommerce;
            CardType card = new CardType();
            card.Type = MethodOfPaymentTypeEnum.VI;
            card.Number = "4100000000000001";
            card.ExpDate = "1210";
            authorization.Card = card; //This needs to compile

            litleBatchRequest.AddAuthorization(authorization);

            Authorization authorization2 = new Authorization();
            authorization2.ReportGroup = "Planets";
            authorization2.OrderId = "12345";
            authorization2.Amount = 106;
            authorization2.OrderSource = OrderSourceType.Ecommerce;
            CardType card2 = new CardType();
            card2.Type = MethodOfPaymentTypeEnum.VI;
            card2.Number = "4242424242424242";
            card2.ExpDate = "1210";
            authorization2.Card = card2; //This needs to compile

            litleBatchRequest.AddAuthorization(authorization2);

            AuthReversal reversal = new AuthReversal();
            reversal.LitleTxnId = 12345678000L;
            reversal.Amount = 106;
            reversal.PayPalNotes = "Notes";

            litleBatchRequest.AddAuthReversal(reversal);

            AuthReversal reversal2 = new AuthReversal();
            reversal2.LitleTxnId = 12345678900L;
            reversal2.Amount = 106;
            reversal2.PayPalNotes = "Notes";

            litleBatchRequest.AddAuthReversal(reversal2);

            Capture capture = new Capture();
            capture.LitleTxnId = 123456000;
            capture.Amount = 106;
            capture.PayPalNotes = "Notes";

            litleBatchRequest.AddCapture(capture);

            Capture capture2 = new Capture();
            capture2.LitleTxnId = 123456700;
            capture2.Amount = 106;
            capture2.PayPalNotes = "Notes";

            litleBatchRequest.AddCapture(capture2);

            CaptureGivenAuth capturegivenauth = new CaptureGivenAuth();
            capturegivenauth.Amount = 106;
            capturegivenauth.OrderId = "12344";
            AuthInformation authInfo = new AuthInformation();
            DateTime authDate = new DateTime(2002, 10, 9);
            authInfo.AuthDate = authDate;
            authInfo.AuthCode = "543216";
            authInfo.AuthAmount = 12345;
            capturegivenauth.AuthInformation = authInfo;
            capturegivenauth.OrderSource = OrderSourceType.Ecommerce;
            capturegivenauth.Card = card;

            litleBatchRequest.AddCaptureGivenAuth(capturegivenauth);

            CaptureGivenAuth capturegivenauth2 = new CaptureGivenAuth();
            capturegivenauth2.Amount = 106;
            capturegivenauth2.OrderId = "12344";
            AuthInformation authInfo2 = new AuthInformation();
            authDate = new DateTime(2003, 10, 9);
            authInfo2.AuthDate = authDate;
            authInfo2.AuthCode = "543216";
            authInfo2.AuthAmount = 12345;
            capturegivenauth2.AuthInformation = authInfo;
            capturegivenauth2.OrderSource = OrderSourceType.Ecommerce;
            capturegivenauth2.Card = card2;

            litleBatchRequest.AddCaptureGivenAuth(capturegivenauth2);

            Credit creditObj = new Credit();
            creditObj.Amount = 106;
            creditObj.OrderId = "2111";
            creditObj.OrderSource = OrderSourceType.Ecommerce;
            creditObj.Card = card;

            litleBatchRequest.AddCredit(creditObj);

            Credit creditObj2 = new Credit();
            creditObj2.Amount = 106;
            creditObj2.OrderId = "2111";
            creditObj2.OrderSource = OrderSourceType.Ecommerce;
            creditObj2.Card = card2;

            litleBatchRequest.AddCredit(creditObj2);

            EcheckCredit echeckcredit = new EcheckCredit();
            echeckcredit.Amount = 12L;
            echeckcredit.OrderId = "12345";
            echeckcredit.OrderSource = OrderSourceType.Ecommerce;
            EcheckType echeck = new EcheckType();
            echeck.AccType = EcheckAccountTypeEnum.Checking;
            echeck.AccNum = "1099999903";
            echeck.RoutingNum = "011201995";
            echeck.CheckNum = "123455";
            echeckcredit.Echeck = echeck;
            Contact billToAddress = new Contact();
            billToAddress.Name = "Bob";
            billToAddress.City = "Lowell";
            billToAddress.State = "MA";
            billToAddress.Email = "litle.com";
            echeckcredit.BillToAddress = billToAddress;

            litleBatchRequest.AddEcheckCredit(echeckcredit);

            EcheckCredit echeckcredit2 = new EcheckCredit();
            echeckcredit2.Amount = 12L;
            echeckcredit2.OrderId = "12346";
            echeckcredit2.OrderSource = OrderSourceType.Ecommerce;
            EcheckType echeck2 = new EcheckType();
            echeck2.AccType = EcheckAccountTypeEnum.Checking;
            echeck2.AccNum = "1099999903";
            echeck2.RoutingNum = "011201995";
            echeck2.CheckNum = "123456";
            echeckcredit2.Echeck = echeck2;
            Contact billToAddress2 = new Contact();
            billToAddress2.Name = "Mike";
            billToAddress2.City = "Lowell";
            billToAddress2.State = "MA";
            billToAddress2.Email = "litle.com";
            echeckcredit2.BillToAddress = billToAddress2;

            litleBatchRequest.AddEcheckCredit(echeckcredit2);

            EcheckRedeposit echeckredeposit = new EcheckRedeposit();
            echeckredeposit.LitleTxnId = 123456;
            echeckredeposit.Echeck = echeck;

            litleBatchRequest.AddEcheckRedeposit(echeckredeposit);

            EcheckRedeposit echeckredeposit2 = new EcheckRedeposit();
            echeckredeposit2.LitleTxnId = 123457;
            echeckredeposit2.Echeck = echeck2;

            litleBatchRequest.AddEcheckRedeposit(echeckredeposit2);

            EcheckSale echeckSaleObj = new EcheckSale();
            echeckSaleObj.Amount = 123456;
            echeckSaleObj.OrderId = "12345";
            echeckSaleObj.OrderSource = OrderSourceType.Ecommerce;
            echeckSaleObj.Echeck = echeck;
            echeckSaleObj.BillToAddress = billToAddress;

            litleBatchRequest.AddEcheckSale(echeckSaleObj);

            EcheckSale echeckSaleObj2 = new EcheckSale();
            echeckSaleObj2.Amount = 123456;
            echeckSaleObj2.OrderId = "12346";
            echeckSaleObj2.OrderSource = OrderSourceType.Ecommerce;
            echeckSaleObj2.Echeck = echeck2;
            echeckSaleObj2.BillToAddress = billToAddress2;

            litleBatchRequest.AddEcheckSale(echeckSaleObj2);

            EcheckVerification echeckVerificationObject = new EcheckVerification();
            echeckVerificationObject.Amount = 123456;
            echeckVerificationObject.OrderId = "12345";
            echeckVerificationObject.OrderSource = OrderSourceType.Ecommerce;
            echeckVerificationObject.Echeck = echeck;
            echeckVerificationObject.BillToAddress = billToAddress;

            litleBatchRequest.AddEcheckVerification(echeckVerificationObject);

            EcheckVerification echeckVerificationObject2 = new EcheckVerification();
            echeckVerificationObject2.Amount = 123456;
            echeckVerificationObject2.OrderId = "12346";
            echeckVerificationObject2.OrderSource = OrderSourceType.Ecommerce;
            echeckVerificationObject2.Echeck = echeck2;
            echeckVerificationObject2.BillToAddress = billToAddress2;

            litleBatchRequest.AddEcheckVerification(echeckVerificationObject2);

            ForceCapture forcecapture = new ForceCapture();
            forcecapture.Amount = 106;
            forcecapture.OrderId = "12344";
            forcecapture.OrderSource = OrderSourceType.Ecommerce;
            forcecapture.Card = card;

            litleBatchRequest.AddForceCapture(forcecapture);

            ForceCapture forcecapture2 = new ForceCapture();
            forcecapture2.Amount = 106;
            forcecapture2.OrderId = "12345";
            forcecapture2.OrderSource = OrderSourceType.Ecommerce;
            forcecapture2.Card = card2;

            litleBatchRequest.AddForceCapture(forcecapture2);

            Sale saleObj = new Sale();
            saleObj.Amount = 106;
            saleObj.LitleTxnId = 123456;
            saleObj.OrderId = "12344";
            saleObj.OrderSource = OrderSourceType.Ecommerce;
            saleObj.Card = card;

            litleBatchRequest.AddSale(saleObj);

            Sale saleObj2 = new Sale();
            saleObj2.Amount = 106;
            saleObj2.LitleTxnId = 123456;
            saleObj2.OrderId = "12345";
            saleObj2.OrderSource = OrderSourceType.Ecommerce;
            saleObj2.Card = card2;

            litleBatchRequest.AddSale(saleObj2);

            RegisterTokenRequestType registerTokenRequest = new RegisterTokenRequestType();
            registerTokenRequest.OrderId = "12344";
            registerTokenRequest.AccountNumber = "1233456789103801";
            registerTokenRequest.ReportGroup = "Planets";

            litleBatchRequest.AddRegisterTokenRequest(registerTokenRequest);

            RegisterTokenRequestType registerTokenRequest2 = new RegisterTokenRequestType();
            registerTokenRequest2.OrderId = "12345";
            registerTokenRequest2.AccountNumber = "1233456789103801";
            registerTokenRequest2.ReportGroup = "Planets";

            litleBatchRequest.AddRegisterTokenRequest(registerTokenRequest2);

            litleIC.AddBatch(litleBatchRequest);

            string batchName = litleIC.SendToLitle();

            litleIC.BlockAndWaitForResponse(batchName, 60*1000*5);

            try
            {
                LitleResponse litleResponse = litleIC.ReceiveFromLitle(batchName);
                Assert.Fail("Fail to throw a connection exception");
            }
            catch (LitleOnlineException e)
            {
                Assert.AreEqual("Error occured while attempting to retrieve and save the file from SFTP", e.Message);
            }
        }
        public void testInitialization()
        {
            Dictionary<String, String> mockConfig = new Dictionary<string, string>();

            mockConfig["url"] = "https://www.mockurl.com";
            mockConfig["reportGroup"] = "Mock Report Group";
            mockConfig["username"] = "******";
            mockConfig["printxml"] = "false";
            mockConfig["timeout"] = "35";
            mockConfig["proxyHost"] = "www.mockproxy.com";
            mockConfig["merchantId"] = "MOCKID";
            mockConfig["password"] = "******";
            mockConfig["proxyPort"] = "3000";
            mockConfig["sftpUrl"] = "www.mockftp.com";
            mockConfig["sftpUsername"] = "******";
            mockConfig["sftpPassword"] = "******";
            mockConfig["knownHostsFile"] = "C:\\MockKnownHostsFile";
            mockConfig["onlineBatchUrl"] = "www.mockbatch.com";
            mockConfig["onlineBatchPort"] = "4000";
            mockConfig["requestDirectory"] = "C:\\MockRequests";
            mockConfig["responseDirectory"] = "C:\\MockResponses";

            litle = new LitleRequest(mockConfig);

            Assert.AreEqual("C:\\MockRequests\\Requests\\", litle.GetRequestDirectory());
            Assert.AreEqual("C:\\MockResponses\\Responses\\", litle.GetResponseDirectory());

            Assert.NotNull(litle.GetCommunication());
            Assert.NotNull(litle.GetLitleTime());
            Assert.NotNull(litle.GetLitleFile());
            Assert.NotNull(litle.GetLitleXmlSerializer());
        }
        public void PFIFInstructionTxnTest()
        {
            Dictionary<string, string> configOverride = new Dictionary<string, string>();
            configOverride["url"] = Properties.Settings.Default.url;
            configOverride["reportGroup"] = Properties.Settings.Default.reportGroup;
            configOverride["username"] = "******";
            configOverride["printxml"] = Properties.Settings.Default.printxml;
            configOverride["timeout"] = Properties.Settings.Default.timeout;
            configOverride["proxyHost"] = Properties.Settings.Default.proxyHost;
            configOverride["merchantId"] = "0180";
            configOverride["password"] = "******";
            configOverride["proxyPort"] = Properties.Settings.Default.proxyPort;
            configOverride["sftpUrl"] = Properties.Settings.Default.sftpUrl;
            configOverride["sftpUsername"] = Properties.Settings.Default.sftpUsername;
            configOverride["sftpPassword"] = Properties.Settings.Default.sftpPassword;
            configOverride["knownHostsFile"] = Properties.Settings.Default.knownHostsFile;
            configOverride["onlineBatchUrl"] = Properties.Settings.Default.onlineBatchUrl;
            configOverride["onlineBatchPort"] = Properties.Settings.Default.onlineBatchPort;
            configOverride["requestDirectory"] = Properties.Settings.Default.requestDirectory;
            configOverride["responseDirectory"] = Properties.Settings.Default.responseDirectory;

            LitleRequest litleOverride = new LitleRequest(configOverride);

            BatchRequest litleBatchRequest = new BatchRequest(configOverride);

            EcheckType echeck = new EcheckType();
            echeck.AccType = EcheckAccountTypeEnum.Corporate;
            echeck.AccNum = "1092969901";
            echeck.RoutingNum = "011075150";
            echeck.CheckNum = "123455";

            SubmerchantCredit submerchantCredit = new SubmerchantCredit();
            submerchantCredit.FundingSubmerchantId = "123456";
            submerchantCredit.SubmerchantName = "merchant";
            submerchantCredit.FundsTransferId = "123467";
            submerchantCredit.Amount = 106L;
            submerchantCredit.AccountInfo = echeck;
            litleBatchRequest.AddSubmerchantCredit(submerchantCredit);

            PayFacCredit payFacCredit = new PayFacCredit();
            payFacCredit.FundingSubmerchantId = "123456";
            payFacCredit.FundsTransferId = "123467";
            payFacCredit.Amount = 107L;
            litleBatchRequest.AddPayFacCredit(payFacCredit);

            ReserveCredit reserveCredit = new ReserveCredit();
            reserveCredit.FundingSubmerchantId = "123456";
            reserveCredit.FundsTransferId = "123467";
            reserveCredit.Amount = 107L;
            litleBatchRequest.AddReserveCredit(reserveCredit);

            VendorCredit vendorCredit = new VendorCredit();
            vendorCredit.FundingSubmerchantId = "123456";
            vendorCredit.VendorName = "merchant";
            vendorCredit.FundsTransferId = "123467";
            vendorCredit.Amount = 106L;
            vendorCredit.AccountInfo = echeck;
            litleBatchRequest.AddVendorCredit(vendorCredit);

            PhysicalCheckCredit physicalCheckCredit = new PhysicalCheckCredit();
            physicalCheckCredit.FundingSubmerchantId = "123456";
            physicalCheckCredit.FundsTransferId = "123467";
            physicalCheckCredit.Amount = 107L;
            litleBatchRequest.AddPhysicalCheckCredit(physicalCheckCredit);

            SubmerchantDebit submerchantDebit = new SubmerchantDebit();
            submerchantDebit.FundingSubmerchantId = "123456";
            submerchantDebit.SubmerchantName = "merchant";
            submerchantDebit.FundsTransferId = "123467";
            submerchantDebit.Amount = 106L;
            submerchantDebit.AccountInfo = echeck;
            litleBatchRequest.AddSubmerchantDebit(submerchantDebit);

            PayFacDebit payFacDebit = new PayFacDebit();
            payFacDebit.FundingSubmerchantId = "123456";
            payFacDebit.FundsTransferId = "123467";
            payFacDebit.Amount = 107L;
            litleBatchRequest.AddPayFacDebit(payFacDebit);

            ReserveDebit reserveDebit = new ReserveDebit();
            reserveDebit.FundingSubmerchantId = "123456";
            reserveDebit.FundsTransferId = "123467";
            reserveDebit.Amount = 107L;
            litleBatchRequest.AddReserveDebit(reserveDebit);

            VendorDebit vendorDebit = new VendorDebit();
            vendorDebit.FundingSubmerchantId = "123456";
            vendorDebit.VendorName = "merchant";
            vendorDebit.FundsTransferId = "123467";
            vendorDebit.Amount = 106L;
            vendorDebit.AccountInfo = echeck;
            litleBatchRequest.AddVendorDebit(vendorDebit);

            PhysicalCheckDebit physicalCheckDebit = new PhysicalCheckDebit();
            physicalCheckDebit.FundingSubmerchantId = "123456";
            physicalCheckDebit.FundsTransferId = "123467";
            physicalCheckDebit.Amount = 107L;
            litleBatchRequest.AddPhysicalCheckDebit(physicalCheckDebit);

            litleOverride.AddBatch(litleBatchRequest);

            LitleResponse litleResponse = litleOverride.SendToLitleWithStream();

            Assert.NotNull(litleResponse);
            Assert.AreEqual("0", litleResponse.Response);
            Assert.AreEqual("Valid Format", litleResponse.Message);

            BatchResponse litleBatchResponse = litleResponse.NextBatchResponse();
            while (litleBatchResponse != null)
            {
                SubmerchantCreditResponse submerchantCreditResponse = litleBatchResponse.NextSubmerchantCreditResponse();
                while (submerchantCreditResponse != null)
                {
                    Assert.AreEqual("000", submerchantCreditResponse.Response);
                    submerchantCreditResponse = litleBatchResponse.NextSubmerchantCreditResponse();
                }

                PayFacCreditResponse payFacCreditResponse = litleBatchResponse.NextPayFacCreditResponse();
                while (payFacCreditResponse != null)
                {
                    Assert.AreEqual("000", payFacCreditResponse.Response);
                    payFacCreditResponse = litleBatchResponse.NextPayFacCreditResponse();
                }

                VendorCreditResponse vendorCreditResponse = litleBatchResponse.NextVendorCreditResponse();
                while (vendorCreditResponse != null)
                {
                    Assert.AreEqual("000", vendorCreditResponse.Response);
                    vendorCreditResponse = litleBatchResponse.NextVendorCreditResponse();
                }

                ReserveCreditResponse reserveCreditResponse = litleBatchResponse.NextReserveCreditResponse();
                while (reserveCreditResponse != null)
                {
                    Assert.AreEqual("000", reserveCreditResponse.Response);
                    reserveCreditResponse = litleBatchResponse.NextReserveCreditResponse();
                }

                PhysicalCheckCreditResponse physicalCheckCreditResponse = litleBatchResponse.NextPhysicalCheckCreditResponse();
                while (physicalCheckCreditResponse != null)
                {
                    Assert.AreEqual("000", physicalCheckCreditResponse.Response);
                    physicalCheckCreditResponse = litleBatchResponse.NextPhysicalCheckCreditResponse();
                }

                SubmerchantDebitResponse submerchantDebitResponse = litleBatchResponse.NextSubmerchantDebitResponse();
                while (submerchantDebitResponse != null)
                {
                    Assert.AreEqual("000", submerchantDebitResponse.Response);
                    submerchantDebitResponse = litleBatchResponse.NextSubmerchantDebitResponse();
                }

                PayFacDebitResponse payFacDebitResponse = litleBatchResponse.NextPayFacDebitResponse();
                while (payFacDebitResponse != null)
                {
                    Assert.AreEqual("000", payFacDebitResponse.Response);
                    payFacDebitResponse = litleBatchResponse.NextPayFacDebitResponse();
                }

                VendorDebitResponse vendorDebitResponse = litleBatchResponse.NextVendorDebitResponse();
                while (vendorDebitResponse != null)
                {
                    Assert.AreEqual("000", vendorDebitResponse.Response);
                    vendorDebitResponse = litleBatchResponse.NextVendorDebitResponse();
                }

                ReserveDebitResponse reserveDebitResponse = litleBatchResponse.NextReserveDebitResponse();
                while (reserveDebitResponse != null)
                {
                    Assert.AreEqual("000", reserveDebitResponse.Response);
                    reserveDebitResponse = litleBatchResponse.NextReserveDebitResponse();
                }

                PhysicalCheckDebitResponse physicalCheckDebitResponse = litleBatchResponse.NextPhysicalCheckDebitResponse();
                while (physicalCheckDebitResponse != null)
                {
                    Assert.AreEqual("000", physicalCheckDebitResponse.Response);
                    physicalCheckDebitResponse = litleBatchResponse.NextPhysicalCheckDebitResponse();
                }

                litleBatchResponse = litleResponse.NextBatchResponse();
            }
        }