diff --git a/CHANGELOG b/CHANGELOG index 65c81e0..db803af 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,9 @@ = Worldpay CNP CHANGELOG +==Version 12.27.1 (October 09, 2024) +* Change: Enhanced de-serialization to handle error responses due to gateway-timeout + ==Version 12.27.0 (October 19, 2022) Note: It contains changes from cnpAPI v12.25, v12.26 & v12.27. In case you need any feature supported by cnpAPI v12.25, v12.26 & v12.27, please use SDK version 12.27.0 diff --git a/CnpSdkForNet/CnpSdkForNet/CnpOnline.cs b/CnpSdkForNet/CnpSdkForNet/CnpOnline.cs index 8295741..a6da2c7 100644 --- a/CnpSdkForNet/CnpSdkForNet/CnpOnline.cs +++ b/CnpSdkForNet/CnpSdkForNet/CnpOnline.cs @@ -120,7 +120,7 @@ private cnpOnlineRequest CreateRequest(transactionRequest transaction) } else if (transaction is depositTransactionReversal) { - request.depositTransactionReversal = (depositTransactionReversal) transaction; + request.depositTransactionReversal = (depositTransactionReversal)transaction; } else if (transaction is refundTransactionReversal) { @@ -289,23 +289,23 @@ private cnpOnlineRequest CreateRequest(transactionRequest transaction) } else if (transaction is fastAccessFunding) { - request.fastAccessFunding = (fastAccessFunding) transaction; + request.fastAccessFunding = (fastAccessFunding)transaction; } else if (transaction is payFacCredit) { - request.payFacCredit = (payFacCredit) transaction; + request.payFacCredit = (payFacCredit)transaction; } else if (transaction is payFacDebit) { - request.payFacDebit = (payFacDebit) transaction; + request.payFacDebit = (payFacDebit)transaction; } else if (transaction is physicalCheckCredit) { - request.physicalCheckCredit = (physicalCheckCredit) transaction; + request.physicalCheckCredit = (physicalCheckCredit)transaction; } else if (transaction is physicalCheckDebit) { - request.physicalCheckDebit = (physicalCheckDebit) transaction; + request.physicalCheckDebit = (physicalCheckDebit)transaction; } else if (transaction is payoutOrgCredit) { @@ -317,33 +317,33 @@ private cnpOnlineRequest CreateRequest(transactionRequest transaction) } else if (transaction is reserveCredit) { - request.reserveCredit = (reserveCredit) transaction; + request.reserveCredit = (reserveCredit)transaction; } else if (transaction is reserveDebit) { - request.reserveDebit = (reserveDebit) transaction; + request.reserveDebit = (reserveDebit)transaction; } else if (transaction is submerchantCredit) { - request.submerchantCredit = (submerchantCredit) transaction; + request.submerchantCredit = (submerchantCredit)transaction; } else if (transaction is submerchantDebit) { - request.submerchantDebit = (submerchantDebit) transaction; + request.submerchantDebit = (submerchantDebit)transaction; } else if (transaction is vendorCredit) { - request.vendorCredit = (vendorCredit) transaction; + request.vendorCredit = (vendorCredit)transaction; } else if (transaction is translateToLowValueTokenRequest) { - request.translateToLowValueTokenRequest = (translateToLowValueTokenRequest) transaction; + request.translateToLowValueTokenRequest = (translateToLowValueTokenRequest)transaction; } else if (transaction is vendorDebit) { request.vendorDebit = (vendorDebit)transaction; } - else if (transaction is customerDebit) + else if (transaction is customerDebit) { request.customerDebit = (customerDebit)transaction; } @@ -361,15 +361,15 @@ private cnpOnlineRequest CreateRequest(transactionRequest transaction) public authorizationResponse Authorize(authorization auth) { - var cnpResponse = SendRequest(response => response, auth); + var cnpResponse = SendRequest(response => response, auth); var authResponse = cnpResponse.authorizationResponse; return authResponse; } public authReversalResponse AuthReversal(authReversal reversal) { - - var cnpResponse = SendRequest(response => response, reversal); + + var cnpResponse = SendRequest(response => response, reversal); var reversalResponse = cnpResponse.authReversalResponse; return reversalResponse; } @@ -382,14 +382,14 @@ public Task AuthReversalAsync(authReversal reversal, Cance return authReversalResponse; }, reversal, cancellationToken); } - + public depositTransactionReversalResponse DepositTransactionReversal(depositTransactionReversal reversal) - { - var cnpResponse = SendRequest(response => response, reversal); + { + var cnpResponse = SendRequest(response => response, reversal); var reversalResponse = cnpResponse.depositTransactionReversalResponse; return reversalResponse; } - + public Task DepositTransactionReversalAsync(depositTransactionReversal reversal, CancellationToken cancellationToken) { return SendRequestAsync(response => @@ -417,7 +417,7 @@ public Task RefundTransactionReversalAsync(re public giftCardAuthReversalResponse GiftCardAuthReversal(giftCardAuthReversal giftCard) { - var cnpResponse = SendRequest(response => response, giftCard); + var cnpResponse = SendRequest(response => response, giftCard); var giftCardReversalResponse = cnpResponse.giftCardAuthReversalResponse; return giftCardReversalResponse; } @@ -442,21 +442,21 @@ public Task CaptureAsync(capture capture, CancellationToken can public captureResponse Capture(capture capture) { - var cnpResponse = SendRequest(response => response, capture); + var cnpResponse = SendRequest(response => response, capture); var captureResponse = cnpResponse.captureResponse; return captureResponse; } public giftCardCaptureResponse GiftCardCapture(giftCardCapture giftCardCapture) { - var cnpResponse = SendRequest(response => response, giftCardCapture); + var cnpResponse = SendRequest(response => response, giftCardCapture); var giftCaptureResponse = cnpResponse.giftCardCaptureResponse; return giftCaptureResponse; } public Task GiftCardCaptureAsync(giftCardCapture giftCardCapture, CancellationToken cancellationToken) { - + return SendRequestAsync(response => { var giftCardCaptureResponse = response.giftCardCaptureResponse; @@ -491,7 +491,7 @@ public Task CreditAsync(credit credit, CancellationToken cancell { return SendRequestAsync(response => { - var creditResponse= response.creditResponse; + var creditResponse = response.creditResponse; return creditResponse; }, credit, cancellationToken); } @@ -546,7 +546,7 @@ public echeckRedepositResponse EcheckRedeposit(echeckRedeposit echeckRedeposit) public Task EcheckSaleAsync(echeckSale echeckSale, CancellationToken cancellationToken) { - + return SendRequestAsync(response => { var echeckSalesResponse = response.echeckSalesResponse; @@ -635,7 +635,7 @@ public voidResponse DoVoid(voidTxn v) public Task DoVoidAsync(voidTxn v, CancellationToken cancellationToken) { return SendRequestAsync(response => - { + { var voidResponse = response.voidResponse; return voidResponse; }, v, cancellationToken); @@ -794,7 +794,7 @@ public Task QueryTransactionAsync(queryTransacti return SendRequestAsync(response => { var res = response.queryTransactionResponse ?? - (transactionTypeWithReportGroup) response.queryTransactionUnavailableResponse; + (transactionTypeWithReportGroup)response.queryTransactionUnavailableResponse; return res; }, queryTransaction, cancellationToken); } @@ -803,7 +803,7 @@ public transactionTypeWithReportGroup QueryTransaction(queryTransaction queryTra { var cnpResponse = SendRequest(response => response, queryTransaction); var transactionResponse = cnpResponse.queryTransactionResponse ?? - (transactionTypeWithReportGroup) cnpResponse.queryTransactionUnavailableResponse; + (transactionTypeWithReportGroup)cnpResponse.queryTransactionUnavailableResponse; return transactionResponse; } @@ -829,7 +829,7 @@ public fastAccessFundingResponse FastAccessFunding(fastAccessFunding fastAccessF var fastAccessFundingResponse = cnpResponse.fastAccessFundingResponse; return fastAccessFundingResponse; } - + public payFacCreditResponse PayFacCredit(payFacCredit payFacCredit) { var cnpResponse = SendRequest(response => response, payFacCredit); @@ -857,7 +857,7 @@ public Task PayFacDebitAsync(payFacDebit payFacDebit, Cance { return SendRequestAsync(response => { - var payFacDebitResponse = response.payFacDebitResponse; + var payFacDebitResponse = response.payFacDebitResponse; return payFacDebitResponse; }, payFacDebit, cancellationToken); } @@ -1091,35 +1091,18 @@ private cnpOnlineResponse SendToCnp(cnpOnlineRequest request) { throw new WebException("Could not retrieve response from server for given request"); } + if (!xmlResponse.IsSuccessStatusCode) + { + throw new CnpOnlineException(ProcessErrorResponseHttpStatusCode(xmlResponse)); + } try { - var cnpOnlineResponse = DeserializeObject(xmlResponse); + var cnpOnlineResponse = DeserializeObject(xmlResponse.Content.ReadAsStringAsync().Result); if (_config.ContainsKey("printxml") && Convert.ToBoolean(_config["printxml"])) { - Console.WriteLine(cnpOnlineResponse.response); - - } - if (!"0".Equals(cnpOnlineResponse.response)) - { - if ("2".Equals(cnpOnlineResponse.response) || "3".Equals(cnpOnlineResponse.response)) - { - throw new CnpInvalidCredentialException(cnpOnlineResponse.message); - } - else if ("4".Equals(cnpOnlineResponse.response)) - { - throw new CnpConnectionLimitExceededException(cnpOnlineResponse.message); - } - else if ("5".Equals(cnpOnlineResponse.response)) - { - throw new CnpObjectionableContentException(cnpOnlineResponse.message); - } - else - { - throw new CnpOnlineException(cnpOnlineResponse.message); - } } - return cnpOnlineResponse; + return HandleCnpOnlineResponse(cnpOnlineResponse); } catch (InvalidOperationException ioe) { @@ -1138,20 +1121,23 @@ private async Task SendRequestAsync(Func getResponse private async Task SendToCnpAsync(cnpOnlineRequest request, CancellationToken cancellationToken) { string xmlRequest = request.Serialize(); - string xmlResponse = await _communication.HttpPostAsync(xmlRequest, cancellationToken).ConfigureAwait(false); + System.Net.Http.HttpResponseMessage xmlResponse = await _communication.HttpPostAsync(xmlRequest, cancellationToken).ConfigureAwait(false); return DeserializeResponse(xmlResponse); } - private cnpOnlineResponse DeserializeResponse(string xmlResponse) + private cnpOnlineResponse DeserializeResponse(System.Net.Http.HttpResponseMessage xmlResponse) { try { - cnpOnlineResponse cnpOnlineResponse = DeserializeObject(xmlResponse); - if ("1".Equals(cnpOnlineResponse.response)) + if (xmlResponse.IsSuccessStatusCode) { - throw new CnpOnlineException(cnpOnlineResponse.message); + cnpOnlineResponse cnpOnlineResponse = DeserializeObject(xmlResponse.Content.ReadAsStringAsync().Result); + return HandleCnpOnlineResponse(cnpOnlineResponse); + } + else + { + throw new CnpOnlineException(ProcessErrorResponseHttpStatusCode(xmlResponse)); } - return cnpOnlineResponse; } catch (InvalidOperationException ioe) { @@ -1159,6 +1145,39 @@ private cnpOnlineResponse DeserializeResponse(string xmlResponse) } } + private string ProcessErrorResponseHttpStatusCode(System.Net.Http.HttpResponseMessage xmlResponseErrorMessage) + { + switch (xmlResponseErrorMessage.StatusCode) + { + case HttpStatusCode.GatewayTimeout: + return "The request was timed out while processing transaction. Please refer iQ before retrying the transaction." + + xmlResponseErrorMessage.Content.ReadAsStringAsync().Result; + default: + return "An error has occurred. Please share following while reaching Worldpay Support. " + + xmlResponseErrorMessage.Content.ReadAsStringAsync().Result; + } + } + + private cnpOnlineResponse HandleCnpOnlineResponse(cnpOnlineResponse cnpOnlineResponse) + { + switch (cnpOnlineResponse.response) + { + case "0": + return cnpOnlineResponse; + case "1": + throw new CnpOnlineException(cnpOnlineResponse.message); + case "2": + case "3": + throw new CnpInvalidCredentialException(cnpOnlineResponse.message); + case "4": + throw new CnpConnectionLimitExceededException(cnpOnlineResponse.message); + case "5": + throw new CnpObjectionableContentException(cnpOnlineResponse.message); + default: + throw new CnpOnlineException(cnpOnlineResponse.message); + } + } + public static string SerializeObject(cnpOnlineRequest req) { var serializer = new XmlSerializer(typeof(cnpOnlineRequest)); @@ -1230,12 +1249,12 @@ public interface ICnpOnline Task GiftCardAuthReversalAsync(giftCardAuthReversal giftCard, CancellationToken cancellationToken); giftCardCaptureResponse GiftCardCapture(giftCardCapture giftCardCapture); Task GiftCardCaptureAsync(giftCardCapture giftCardCapture, CancellationToken cancellationToken); - + payFacCreditResponse PayFacCredit(payFacCredit payFacCredit); Task PayFacCreditAsync(payFacCredit payFacCredit, CancellationToken cancellationToken); payFacDebitResponse PayFacDebit(payFacDebit payFacDebit); Task PayFacDebitAsync(payFacDebit payFacDebit, CancellationToken cancellationToken); - + physicalCheckCreditResponse PhysicalCheckCredit(physicalCheckCredit physicalCheckCredit); Task PhysicalCheckCreditAsync(physicalCheckCredit physicalCheckCredit, CancellationToken cancellationToken); physicalCheckDebitResponse PhysicalCheckDebit(physicalCheckDebit physicalCheckDebit); @@ -1245,18 +1264,18 @@ public interface ICnpOnline Task PayoutOrgCreditAsync(payoutOrgCredit payoutOrgCredit, CancellationToken cancellationToken); payoutOrgDebitResponse PayoutOrgDebit(payoutOrgDebit payoutOrgDebit); Task PayoutOrgDebitAsync(payoutOrgDebit payoutOrgDebit, CancellationToken cancellationToken); - + reserveCreditResponse ReserveCredit(reserveCredit reserveCredit); Task ReserveCreditAsync(reserveCredit reserveCredit, CancellationToken cancellationToken); reserveDebitResponse ReserveDebit(reserveDebit reserveDebit); Task ReserveDebitAsync(reserveDebit reserveDebit, CancellationToken cancellationToken); - + submerchantCreditResponse SubmerchantCredit(submerchantCredit submerchantCredit); Task SubmerchantCreditAsync(submerchantCredit submerchantCredit, CancellationToken cancellationToken); submerchantDebitResponse SubmerchantDebit(submerchantDebit submerchantDebit); Task SubmerchantDebitAsync(submerchantDebit submerchantDebit, CancellationToken cancellationToken); - + vendorCreditResponse VendorCredit(vendorCredit vendorCredit); Task VendorCreditAsync(vendorCredit vendorCredit, CancellationToken cancellationToken); vendorDebitResponse VendorDebit(vendorDebit vendorDebit); diff --git a/CnpSdkForNet/CnpSdkForNet/CnpSdkForNet.csproj b/CnpSdkForNet/CnpSdkForNet/CnpSdkForNet.csproj index eac420d..1ada1f6 100644 --- a/CnpSdkForNet/CnpSdkForNet/CnpSdkForNet.csproj +++ b/CnpSdkForNet/CnpSdkForNet/CnpSdkForNet.csproj @@ -3,7 +3,7 @@ netstandard2.0 true dotNetSDKKey.snk - 12.27.0 + 12.27.1 Vantiv.CnpSdkForNet FIS Copyright © FIS 2020 diff --git a/CnpSdkForNet/CnpSdkForNet/CnpVersion.cs b/CnpSdkForNet/CnpSdkForNet/CnpVersion.cs index 4bde18d..a5691f5 100644 --- a/CnpSdkForNet/CnpSdkForNet/CnpVersion.cs +++ b/CnpSdkForNet/CnpSdkForNet/CnpVersion.cs @@ -9,6 +9,6 @@ namespace Cnp.Sdk public class CnpVersion { public const String CurrentCNPXMLVersion = "12.27"; - public const String CurrentCNPSDKVersion = "12.27.0"; + public const String CurrentCNPSDKVersion = "12.27.1"; } } diff --git a/CnpSdkForNet/CnpSdkForNet/Communications.cs b/CnpSdkForNet/CnpSdkForNet/Communications.cs index 5a88b12..6480e1c 100644 --- a/CnpSdkForNet/CnpSdkForNet/Communications.cs +++ b/CnpSdkForNet/CnpSdkForNet/Communications.cs @@ -215,7 +215,7 @@ public void Log(string logMessage, string logFile) /// The XML to send to the API /// /// The XML response on success, null otherwise - public async Task HttpPostAsync(string xmlRequest, CancellationToken cancellationToken) + public async Task HttpPostAsync(string xmlRequest, CancellationToken cancellationToken) { // First, read values from the config that we need that relate to logging _config.TryGetValue("logFile", out var logFile); @@ -250,7 +250,7 @@ public async Task HttpPostAsync(string xmlRequest, CancellationToken can Log(xmlResponse, logFile); } - return xmlResponse; + return response; } catch (Exception) { @@ -265,7 +265,7 @@ public async Task HttpPostAsync(string xmlRequest, CancellationToken can /// /// The XML to send to the API /// The XML response as a string on success, or null otherwise - public virtual string HttpPost(string xmlRequest) + public virtual HttpResponseMessage HttpPost(string xmlRequest) { var source = new CancellationTokenSource(); var asyncTask = Task.Run(() => HttpPostAsync(xmlRequest, source.Token), source.Token); diff --git a/CnpSdkForNet/CnpSdkForNetTest/Unit/TestAdvancedFraudCheck.cs b/CnpSdkForNet/CnpSdkForNetTest/Unit/TestAdvancedFraudCheck.cs index b238f10..540bd9b 100644 --- a/CnpSdkForNet/CnpSdkForNetTest/Unit/TestAdvancedFraudCheck.cs +++ b/CnpSdkForNet/CnpSdkForNetTest/Unit/TestAdvancedFraudCheck.cs @@ -3,6 +3,8 @@ using System.Collections.Generic; using Moq; using System.Text.RegularExpressions; +using System.Net.Http; +using System.Net; namespace Cnp.Sdk.Test.Unit { @@ -10,7 +12,7 @@ namespace Cnp.Sdk.Test.Unit class TestAdvancedFraudCheck { - private CnpOnline cnp; + private CnpOnline cnp; [OneTimeSetUp] public void SetUpCnp() @@ -29,7 +31,7 @@ public void TestNoCustomAttributes() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*123\r\n.*", RegexOptions.Singleline))) - .Returns("742802348034313000000Approvedpass42triggered_rule_default"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("742802348034313000000Approvedpass42triggered_rule_default") }); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -51,7 +53,7 @@ public void TestCustomAttribute1() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex("..*123\r\nabc\r\n.*", RegexOptions.Singleline))) - .Returns("742802348034313000000Approvedpass42triggered_rule_default"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("742802348034313000000Approvedpass42triggered_rule_default") }); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -74,7 +76,7 @@ public void TestCustomAttribute2() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex("..*123\r\nabc\r\ndef\r\n.*", RegexOptions.Singleline))) - .Returns("742802348034313000000Approvedpass42triggered_rule_default"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("742802348034313000000Approvedpass42triggered_rule_default") }); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -98,7 +100,7 @@ public void TestCustomAttribute3() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex("..*123\r\nabc\r\ndef\r\nghi\r\n.*", RegexOptions.Singleline))) - .Returns("742802348034313000000Approvedpass42triggered_rule_default"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("742802348034313000000Approvedpass42triggered_rule_default") }); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -123,7 +125,7 @@ public void TestCustomAttribute4() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex("..*123\r\nabc\r\ndef\r\nghi\r\njkl\r\n.*", RegexOptions.Singleline))) - .Returns("742802348034313000000Approvedpass42triggered_rule_default"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("742802348034313000000Approvedpass42triggered_rule_default") }); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -149,7 +151,7 @@ public void TestCustomAttribute5() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex("..*123\r\nabc\r\ndef\r\nghi\r\njkl\r\nmno\r\n.*", RegexOptions.Singleline))) - .Returns("742802348034313000000Approvedpass42triggered_rule_default"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("742802348034313000000Approvedpass42triggered_rule_default") }); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -175,7 +177,7 @@ public void TestAdvancedFraudChecksTypeWebSessionId() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex("..*ajhgsdjh\r\nabc\r\ndef\r\nghi\r\njkl\r\nmno\r\n.*", RegexOptions.Singleline))) - .Returns("742802348034313000000Approvedpass42triggered_rule_default"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("742802348034313000000Approvedpass42triggered_rule_default") }); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); diff --git a/CnpSdkForNet/CnpSdkForNetTest/Unit/TestAuthReversal.cs b/CnpSdkForNet/CnpSdkForNetTest/Unit/TestAuthReversal.cs index 262de56..cce0dfa 100644 --- a/CnpSdkForNet/CnpSdkForNetTest/Unit/TestAuthReversal.cs +++ b/CnpSdkForNet/CnpSdkForNetTest/Unit/TestAuthReversal.cs @@ -3,6 +3,8 @@ using NUnit.Framework; using Moq; using System.Text.RegularExpressions; +using System.Net.Http; +using System.Net; namespace Cnp.Sdk.Test.Unit @@ -32,7 +34,7 @@ public void TestSurchargeAmount() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*2\r\n1\r\nnote.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -51,7 +53,7 @@ public void TestSurchargeAmount_Optional() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*2\r\nnote.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -71,7 +73,7 @@ public void TestAuthReversalWithLocation() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*2\r\n1\r\nnote.*", RegexOptions.Singleline))) - .Returns("123sandbox"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123sandbox")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -103,7 +105,7 @@ public void TestAuthReversalWithAdditionalCofData() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*2\r\n1\r\nnote.*", RegexOptions.Singleline))) - .Returns("123sandbox"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123sandbox")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); diff --git a/CnpSdkForNet/CnpSdkForNetTest/Unit/TestAuthorization.cs b/CnpSdkForNet/CnpSdkForNetTest/Unit/TestAuthorization.cs index 4e68044..ff64248 100644 --- a/CnpSdkForNet/CnpSdkForNetTest/Unit/TestAuthorization.cs +++ b/CnpSdkForNet/CnpSdkForNetTest/Unit/TestAuthorization.cs @@ -2,6 +2,8 @@ using NUnit.Framework; using Moq; using System.Text.RegularExpressions; +using System.Net.Http; +using System.Net; namespace Cnp.Sdk.Test.Unit @@ -31,7 +33,7 @@ public void TestFraudFilterOverride() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*true.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); var mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -57,7 +59,7 @@ public void TestContactShouldSendEmailForEmail_NotZip() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*12345.*gdake@cnp.com.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); var mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -83,7 +85,7 @@ public void Test3dsAttemptedShouldNotSayItem() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*2.*3dsAttempted.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); var mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -109,7 +111,7 @@ public void Test3dsAuthenticatedShouldNotSayItem() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*2.*3dsAuthenticated.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); var mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -132,7 +134,7 @@ public void TestSecondaryAmount() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*2\r\n1\r\necommerce.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); var mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -155,7 +157,7 @@ public void TestSurchargeAmount() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*2\r\n1\r\necommerce.*", RegexOptions.Singleline))) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); var mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -177,7 +179,7 @@ public void TestSurchargeAmount_Optional() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*2\r\necommerce.*", RegexOptions.Singleline))) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); var mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -204,7 +206,7 @@ public void TestMethodOfPaymentAllowsGiftCard() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*\r\nGC\r\n414100000000000000\r\n1210\r\n.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); var mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -241,7 +243,7 @@ public void TestMethodOfPaymentApplepayAndWallet() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*?applepay.*?.*?user.*?.*?.*?123.*?.*?.*?", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); var mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -271,7 +273,7 @@ public void TestRecurringRequest() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*true\r\n\r\n\r\nabc123\r\n12\r\n\r\n\r\n.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); var mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -298,7 +300,7 @@ public void TestDebtRepayment() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*true\r\ntrue\r\n.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); var mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -372,7 +374,7 @@ public void TestSimpleAuthWithFraudCheck() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*.*192.168.1.1.*.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); var mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -419,7 +421,7 @@ public void TestSimpleAuthWithBillMeLaterRequest() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*.*\r\nPresence\r\nData\r\n.*.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); var mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -464,7 +466,7 @@ public void TestAuthWithAdvancedFraud() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsAny() )) - .Returns("123\"ReviewStatus\"800"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123\"ReviewStatus\"800")}); var mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -528,7 +530,7 @@ public void TestAuthWithPosCatLevelEnum() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsAny() )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); var mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -582,7 +584,7 @@ public void TestOriginalTransaction() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*?123456789.*?12.*?", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); var mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -606,7 +608,7 @@ public void TestOriginalTransactionWithPin() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*\r\nMC\r\n414100000000000000\r\n1210\r\n1234\r\n.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); var mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -627,7 +629,7 @@ public void TestAuthWithMCC() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*2\r\necommerce\r\n0111.*", RegexOptions.Singleline))) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); var mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -650,7 +652,7 @@ public void TestAuthorizationWithLocation() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*2\r\n1\r\necommerce.*", RegexOptions.Singleline))) - .Returns("123sandbox"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123sandbox")}); var mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -700,7 +702,7 @@ public void TestSimpleAuthWithRetailerAddressAndAdditionalCOFdata() ///new testc var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*01867-4456.*mikasa@cnp.com.*s1234.*www.google.com.*BiWeekly.*PHONE\r\nNot Approved\r\nfalse.*", RegexOptions.Singleline))) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); var mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -755,7 +757,7 @@ public void TestAuthWithFsErrorCode_OverridePolicy_ProdEnrolled_MercAcctStatus_F var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*01867-4456.*mikasa@cnp.com.*s1234.*www.google.com.*BiWeekly.*PHONE\r\nNot Approved\r\nfalse.*", RegexOptions.Singleline))) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); var mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -818,7 +820,7 @@ public void AuthWithLodgingInfoPropertyAddressChanges() ///new testcase 12.25 var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*01867-4456.*mikasa@cnp.com.*s1234.*www.google.com.*BiWeekly.*PHONE\r\nNot Approved\r\nfalse.*", RegexOptions.Singleline))) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); var mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -883,7 +885,7 @@ public void AuthWithLodgingInfoPropertyAddressChanges() ///new testcase 12.25 var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*TR0001.*IC.*Indigo.*TI2022.*1.*1\r\nC2011583.*", RegexOptions.Singleline))) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); var mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); diff --git a/CnpSdkForNet/CnpSdkForNetTest/Unit/TestCancelSubscription.cs b/CnpSdkForNet/CnpSdkForNetTest/Unit/TestCancelSubscription.cs index 8612e21..e7a26d5 100644 --- a/CnpSdkForNet/CnpSdkForNetTest/Unit/TestCancelSubscription.cs +++ b/CnpSdkForNet/CnpSdkForNetTest/Unit/TestCancelSubscription.cs @@ -3,6 +3,8 @@ using NUnit.Framework; using Moq; using System.Text.RegularExpressions; +using System.Net.Http; +using System.Net; namespace Cnp.Sdk.Test.Unit @@ -27,7 +29,7 @@ public void TestSimple() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*\r\n12345\r\n\r\n.*?.*", RegexOptions.Singleline) )) - .Returns("12345"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("12345")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -43,7 +45,7 @@ public void TestCancelSubscriptionWithLocation() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*\r\n12345\r\n\r\n.*?.*", RegexOptions.Singleline))) - .Returns("12345"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("12345")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); diff --git a/CnpSdkForNet/CnpSdkForNetTest/Unit/TestCapture.cs b/CnpSdkForNet/CnpSdkForNetTest/Unit/TestCapture.cs index 9ef8677..c624f64 100644 --- a/CnpSdkForNet/CnpSdkForNetTest/Unit/TestCapture.cs +++ b/CnpSdkForNet/CnpSdkForNetTest/Unit/TestCapture.cs @@ -3,6 +3,8 @@ using NUnit.Framework; using Moq; using System.Text.RegularExpressions; +using System.Net.Http; +using System.Net; namespace Cnp.Sdk.Test.Unit @@ -32,7 +34,7 @@ public void TestSimpleCapture() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*2\r\nnote\r\n1234.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -52,7 +54,7 @@ public void TestSurchargeAmount() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*2\r\n1\r\nnote.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -71,7 +73,7 @@ public void TestSurchargeAmount_Optional() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*2\r\nnote.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -91,7 +93,7 @@ public void TestCaptureWithLocation() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*2\r\nnote\r\n1234.*", RegexOptions.Singleline))) - .Returns("123sandbox"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123sandbox")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -152,7 +154,7 @@ public void TestCaptureWithLocation() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*TR0001.*IC.*Indigo.*TI2022.*1.*1\r\nC2011583.*", RegexOptions.Singleline))) - .Returns("123sandbox"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123sandbox")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); diff --git a/CnpSdkForNet/CnpSdkForNetTest/Unit/TestCaptureGivenAuth.cs b/CnpSdkForNet/CnpSdkForNetTest/Unit/TestCaptureGivenAuth.cs index d91c667..0c9862d 100644 --- a/CnpSdkForNet/CnpSdkForNetTest/Unit/TestCaptureGivenAuth.cs +++ b/CnpSdkForNet/CnpSdkForNetTest/Unit/TestCaptureGivenAuth.cs @@ -3,6 +3,8 @@ using NUnit.Framework; using Moq; using System.Text.RegularExpressions; +using System.Net.Http; +using System.Net; namespace Cnp.Sdk.Test.Unit @@ -31,7 +33,7 @@ public void TestSecondaryAmount() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*2\r\n1\r\necommerce.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -50,7 +52,7 @@ public void TestSurchargeAmount() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*2\r\n1\r\necommerce.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -68,7 +70,7 @@ public void TestSurchargeAmount_Optional() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*2\r\necommerce.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -85,7 +87,7 @@ public void TestDebtRepayment_True() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*\r\ntrue\r\n.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -102,7 +104,7 @@ public void TestDebtRepayment_False() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*\r\nfalse\r\n.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -118,7 +120,7 @@ public void TestDebtRepayment_Optional() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*\r\n.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -138,7 +140,7 @@ public void TestProcessingType() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*2\r\necommerce\r\ninitialRecurring\r\nabc123\r\n1234.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -159,7 +161,7 @@ public void TestUndefinedProcessingType() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*2\r\necommerce\r\nabc123\r\n1234.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -178,7 +180,7 @@ public void TestCaptureAuthWithMCC() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*2\r\necommerce\r\n0111.*", RegexOptions.Singleline))) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -197,7 +199,7 @@ public void TestCaptureGivenAuthWithLocation() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*2\r\n1\r\necommerce.*", RegexOptions.Singleline))) - .Returns("123sandbox"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123sandbox")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -244,7 +246,7 @@ public void TestSimpleCaptureGivenAuthWithRetailerAddressAndAdditionalCOFdata() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*01867-4456.*mikasa@cnp.com.*s1234.*www.google.com.*BiWeekly.*false.*", RegexOptions.Singleline))) - .Returns("123sandbox"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123sandbox")}); var mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -308,7 +310,7 @@ public void TestSimpleCaptureGivenAuthWithRetailerAddressAndAdditionalCOFdata() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*TR0001.*IC.*Indigo.*TI2022.*1.*1\r\nC2011583.*", RegexOptions.Singleline))) - .Returns("123sandbox"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123sandbox")}); var mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); diff --git a/CnpSdkForNet/CnpSdkForNetTest/Unit/TestCnpOnline.cs b/CnpSdkForNet/CnpSdkForNetTest/Unit/TestCnpOnline.cs index 8adad69..cf1a05c 100644 --- a/CnpSdkForNet/CnpSdkForNetTest/Unit/TestCnpOnline.cs +++ b/CnpSdkForNet/CnpSdkForNetTest/Unit/TestCnpOnline.cs @@ -2,6 +2,7 @@ using NUnit.Framework; using Moq; using System.Text.RegularExpressions; +using System.Net.Http; using System.Net; namespace Cnp.Sdk.Test.Unit @@ -41,7 +42,7 @@ public void TestAuth() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*.*4100000000000002.*.*.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -61,7 +62,7 @@ public void TestAuthReversal() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*?12345678000.*?.*?", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -81,7 +82,7 @@ public void TestCapture() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*?123456000.*?.*?", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -110,7 +111,7 @@ public void TestCaptureGivenAuth() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*?.*?4100000000000001.*?.*?.*?", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -134,7 +135,7 @@ public void TestCredit() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*?.*?4100000000000001.*?.*?.*?", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -152,7 +153,7 @@ public void TestEcheckCredit() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*?123456789101112.*?.*?", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -169,7 +170,7 @@ public void TestEcheckRedeposit() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*?123456.*?.*?", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -201,7 +202,7 @@ public void TestEcheckSale() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*?.*?12345657890.*?.*?.*?", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -233,7 +234,7 @@ public void TestEcheckVerification() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*?.*?12345657890.*?.*?.*?", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -257,7 +258,7 @@ public void TestForceCapture() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*?.*?4100000000000001.*?.*?.*?", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -281,7 +282,7 @@ public void TestSale() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*?.*?4100000000000002.*?.*?.*?", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -325,7 +326,7 @@ public void TestToken() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*?1233456789103801.*?.*?", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -345,7 +346,7 @@ public void TestActivate() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*?2.*?.*?", RegexOptions.Singleline) )) - .Returns(@" + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(@" @@ -361,7 +362,7 @@ public void TestActivate() 1234 -"); +")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -383,7 +384,7 @@ public void TestDeactivate() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*?2.*?.*?", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -402,7 +403,7 @@ public void TestLoad() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*?2.*?.*?", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -421,7 +422,7 @@ public void TestUnload() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*?2.*?.*?", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -440,7 +441,7 @@ public void TestBalanceInquiry() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*?2.*?.*?", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -457,7 +458,7 @@ public void TestCreatePlan() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*?theCode.*?.*?", RegexOptions.Singleline) )) - .Returns("theCode"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("theCode")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -474,7 +475,7 @@ public void TestUpdatePlan() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*?theCode.*?.*?", RegexOptions.Singleline) )) - .Returns("theCode"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("theCode")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -499,7 +500,7 @@ public void TestCnpOnlineException() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*?.*?4100000000000002.*?.*?.*?", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -530,7 +531,7 @@ public void TestInvalidOperationException() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*?.*?4100000000000002.*?.*?.*?", RegexOptions.Singleline) )) - .Returns("no xml"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("no xml") }); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -560,7 +561,7 @@ public void TestDefaultReportGroup() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*?.*?.*?4100000000000002.*?.*?.*?", RegexOptions.Singleline) )) - .Returns(""); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -568,6 +569,37 @@ public void TestDefaultReportGroup() Assert.AreEqual("Default Report Group", authorize.reportGroup); } + [Test] + public void TestTimeoutException() + { + 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 = "4100000000000002"; + card.expDate = "1210"; + authorization.card = card; + + var mock = new Mock(); + + mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*?.*?4100000000000002.*?.*?.*?", RegexOptions.Singleline))) + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.GatewayTimeout, Content = new StringContent("ErrorAn error occurred while processing your request.

Reference #221.2b962a17.1722911327.18e1a491

https://errors.edgesuite.net/221.2b%2a17.1722911327$#46;18e1a491

") }); + + Communications mockedCommunication = mock.Object; + cnp.SetCommunication(mockedCommunication); + try + { + cnp.Authorize(authorization); + } + catch (CnpOnlineException e) + { + Assert.IsTrue(e.Message.Contains("The request was timed out while processing transaction. Please refer iQ before retrying the transaction")); + } + } + [Test] public void TestSetMerchantSdk() { diff --git a/CnpSdkForNet/CnpSdkForNetTest/Unit/TestCredit.cs b/CnpSdkForNet/CnpSdkForNetTest/Unit/TestCredit.cs index 45481be..8f2f98e 100644 --- a/CnpSdkForNet/CnpSdkForNetTest/Unit/TestCredit.cs +++ b/CnpSdkForNet/CnpSdkForNetTest/Unit/TestCredit.cs @@ -3,6 +3,8 @@ using NUnit.Framework; using Moq; using System.Text.RegularExpressions; +using System.Net.Http; +using System.Net; namespace Cnp.Sdk.Test.Unit @@ -32,7 +34,7 @@ public void TestActionReasonOnOrphanedRefund() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*SUSPECT_FRAUD.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -53,7 +55,7 @@ public void TestOrderSource_Set() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*2.*ecommerce.*.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -73,7 +75,7 @@ public void TestSecondaryAmount_Orphan() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*3\r\n2\r\n1\r\necommerce.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -93,7 +95,7 @@ public void TestSecondaryAmount_Tied() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*3\r\n2\r\n1\r\n123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -113,7 +115,7 @@ public void TestSurchargeAmount_Tied() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*3\r\n2\r\n1\r\n123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -132,7 +134,7 @@ public void TestSurchargeAmount_TiedOptional() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*3\r\n2\r\n123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -152,7 +154,7 @@ public void TestSurchargeAmount_Orphan() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*3\r\n2\r\n1\r\necommerce.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -171,7 +173,7 @@ public void TestSurchargeAmount_OrphanOptional() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*3\r\n2\r\necommerce.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -192,7 +194,7 @@ public void TestPos_Tied() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*3\r\n2\r\n\r\nabc123\r\n.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -211,7 +213,7 @@ public void TestPos_TiedOptional() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*3\r\n2\r\n.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -235,7 +237,7 @@ public void TestCreditWithPin() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*1234.*.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -255,7 +257,7 @@ public void TestCreditWithMCC() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*3\r\n2\r\necommerce\r\n0111.*", RegexOptions.Singleline))) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -275,7 +277,7 @@ public void TestCreditWithLocation() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*SUSPECT_FRAUD.*", RegexOptions.Singleline))) - .Returns("123sandbox"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123sandbox")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -307,7 +309,7 @@ public void TestCreditWithAdditionalCofData() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*SUSPECT_FRAUD.*", RegexOptions.Singleline))) - .Returns("123sandbox"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123sandbox")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -368,7 +370,7 @@ public void TestCreditWithAdditionalCofData() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*TR0001.*IC.*Indigo.*TI2022.*1.*1\r\nC2011583.*", RegexOptions.Singleline))) - .Returns("123sandbox"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123sandbox")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); diff --git a/CnpSdkForNet/CnpSdkForNetTest/Unit/TestDepositTransactionReversal.cs b/CnpSdkForNet/CnpSdkForNetTest/Unit/TestDepositTransactionReversal.cs index 45e89c8..1c6b312 100644 --- a/CnpSdkForNet/CnpSdkForNetTest/Unit/TestDepositTransactionReversal.cs +++ b/CnpSdkForNet/CnpSdkForNetTest/Unit/TestDepositTransactionReversal.cs @@ -3,6 +3,8 @@ using NUnit.Framework; using Moq; using System.Text.RegularExpressions; +using System.Net.Http; +using System.Net; namespace Cnp.Sdk.Test.Unit @@ -31,7 +33,7 @@ public void TestSurchargeAmount() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*2\r\n1\r\n.*", RegexOptions.Singleline))) - .Returns("3"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("3")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -49,7 +51,7 @@ public void TestSurchargeAmount_Optional() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*2\r\n.*", RegexOptions.Singleline))) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -68,7 +70,7 @@ public void TestTransactionReversalWithLocation() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*2\r\n1\r\n.*", RegexOptions.Singleline))) - .Returns("123sandbox"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123sandbox")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -128,7 +130,7 @@ public void TestTransactionReversalWithLocation() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*TR0001.*IC.*Indigo.*TI2022.*1.*1\r\nC2011583.*", RegexOptions.Singleline))) - .Returns("123sandbox"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123sandbox")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); diff --git a/CnpSdkForNet/CnpSdkForNetTest/Unit/TestEcheckRedeposit.cs b/CnpSdkForNet/CnpSdkForNetTest/Unit/TestEcheckRedeposit.cs index b05c749..c593272 100644 --- a/CnpSdkForNet/CnpSdkForNetTest/Unit/TestEcheckRedeposit.cs +++ b/CnpSdkForNet/CnpSdkForNetTest/Unit/TestEcheckRedeposit.cs @@ -3,6 +3,8 @@ using NUnit.Framework; using Moq; using System.Text.RegularExpressions; +using System.Net.Http; +using System.Net; namespace Cnp.Sdk.Test.Unit @@ -33,7 +35,7 @@ public void TestMerchantData() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*1.*.*camp.*affil.*mgi.*.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -54,7 +56,7 @@ public void TestEcheckRedepositWithLocation() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*1.*.*camp.*affil.*mgi.*.*", RegexOptions.Singleline))) - .Returns("123sandbox"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123sandbox")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); diff --git a/CnpSdkForNet/CnpSdkForNetTest/Unit/TestEcheckVerification.cs b/CnpSdkForNet/CnpSdkForNetTest/Unit/TestEcheckVerification.cs index e14f0cd..120189a 100644 --- a/CnpSdkForNet/CnpSdkForNetTest/Unit/TestEcheckVerification.cs +++ b/CnpSdkForNet/CnpSdkForNetTest/Unit/TestEcheckVerification.cs @@ -3,6 +3,8 @@ using NUnit.Framework; using Moq; using System.Text.RegularExpressions; +using System.Net.Http; +using System.Net; namespace Cnp.Sdk.Test.Unit @@ -38,7 +40,7 @@ public void TestMerchantData() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*1.*2.*camp.*affil.*mgi.*.*", RegexOptions.Singleline) )) - .Returns("123sandbox"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123sandbox")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); diff --git a/CnpSdkForNet/CnpSdkForNetTest/Unit/TestEcheckVoid.cs b/CnpSdkForNet/CnpSdkForNetTest/Unit/TestEcheckVoid.cs index ee17b28..db4c370 100644 --- a/CnpSdkForNet/CnpSdkForNetTest/Unit/TestEcheckVoid.cs +++ b/CnpSdkForNet/CnpSdkForNetTest/Unit/TestEcheckVoid.cs @@ -3,6 +3,8 @@ using NUnit.Framework; using Moq; using System.Text.RegularExpressions; +using System.Net.Http; +using System.Net; namespace Cnp.Sdk.Test.Unit @@ -28,7 +30,7 @@ public void TestFraudFilterOverride() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*123456789.*", RegexOptions.Singleline) )) - .Returns("123sandbox"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123sandbox")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); diff --git a/CnpSdkForNet/CnpSdkForNetTest/Unit/TestForceCapture.cs b/CnpSdkForNet/CnpSdkForNetTest/Unit/TestForceCapture.cs index d4903a9..8d38521 100644 --- a/CnpSdkForNet/CnpSdkForNetTest/Unit/TestForceCapture.cs +++ b/CnpSdkForNet/CnpSdkForNetTest/Unit/TestForceCapture.cs @@ -3,6 +3,8 @@ using NUnit.Framework; using Moq; using System.Text.RegularExpressions; +using System.Net.Http; +using System.Net; namespace Cnp.Sdk.Test.Unit @@ -31,7 +33,7 @@ public void TestSecondaryAmount() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*2\r\n1\r\necommerce.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -50,7 +52,7 @@ public void TestSurchargeAmount() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*2\r\n1\r\necommerce.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -69,7 +71,7 @@ public void TestSurchargeAmount_Optional() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*2\r\necommerce.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -86,7 +88,7 @@ public void TestDebtRepayment_True() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*\r\ntrue\r\n.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -103,7 +105,7 @@ public void TestDebtRepayment_False() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*\r\nfalse\r\n.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -119,7 +121,7 @@ public void TestDebtRepayment_Optional() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*\r\n.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -139,7 +141,7 @@ public void TestProcessingType() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*2\r\necommerce\r\ninitialRecurring.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -159,7 +161,7 @@ public void TestUndefinedProcessingType() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*2\r\necommerce.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -178,7 +180,7 @@ public void TestForceCaptureWithMCC() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*2\r\necommerce\r\n0111.*", RegexOptions.Singleline))) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -198,7 +200,7 @@ public void TestForceCaptureWithLocation() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*2\r\n1\r\necommerce.*", RegexOptions.Singleline))) - .Returns("123sandbox"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123sandbox")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -259,7 +261,7 @@ public void TestForceCaptureWithLocation() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*TR0001.*IC.*Indigo.*TI2022.*1.*1\r\nC2011583.*", RegexOptions.Singleline))) - .Returns("123sandbox"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123sandbox")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); diff --git a/CnpSdkForNet/CnpSdkForNetTest/Unit/TestGiftCard.cs b/CnpSdkForNet/CnpSdkForNetTest/Unit/TestGiftCard.cs index 9e82c72..0e7a7e7 100644 --- a/CnpSdkForNet/CnpSdkForNetTest/Unit/TestGiftCard.cs +++ b/CnpSdkForNet/CnpSdkForNetTest/Unit/TestGiftCard.cs @@ -3,6 +3,8 @@ using NUnit.Framework; using Moq; using System.Text.RegularExpressions; +using System.Net.Http; +using System.Net; namespace Cnp.Sdk.Test.Unit { @@ -33,7 +35,7 @@ public void TestGiftCardAuthReversalSimple() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*123456789\r\nabc123\r\n500\r\n2017-01-01T00:00:00Z\r\n123\r\n123456.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -57,7 +59,7 @@ public void TestGiftCardAuthReversalWithCard() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*\r\nGC\r\n414100000000000000\r\n1210\r\n.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -85,7 +87,7 @@ public void TestGiftCardCaptureSimple() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*123456000\r\n106\r\n\r\nGC\r\n414100000000000000\r\n1210\r\n\r\nabc123\r\n43534345\r\n2017-01-01T00:00:00Z.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -109,7 +111,7 @@ public void TestGiftCardCreditTxnId() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*123456000\r\n106\r\n\r\nGC\r\n4100000000000000\r\n1210\r.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -134,7 +136,7 @@ public void TestGiftCardCreditOrderId() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*2111\r\n106\r\necheckppd\r\n\r\nGC\r\n4100000000000000\r\n1210\r.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -159,7 +161,7 @@ public void TestGiftCardCreditWithLocation() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*2111\r\n106\r\necheckppd\r\n\r\nGC\r\n4100000000000000\r\n1210\r.*", RegexOptions.Singleline))) - .Returns("123sandbox"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123sandbox")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); diff --git a/CnpSdkForNet/CnpSdkForNetTest/Unit/TestGiftCardParentReversal.cs b/CnpSdkForNet/CnpSdkForNetTest/Unit/TestGiftCardParentReversal.cs index b249023..d5f3b04 100644 --- a/CnpSdkForNet/CnpSdkForNetTest/Unit/TestGiftCardParentReversal.cs +++ b/CnpSdkForNet/CnpSdkForNetTest/Unit/TestGiftCardParentReversal.cs @@ -3,6 +3,8 @@ using NUnit.Framework; using Moq; using System.Text.RegularExpressions; +using System.Net.Http; +using System.Net; namespace Cnp.Sdk.Test.Unit { @@ -40,7 +42,7 @@ public void DepositReversal() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*123456000\r\n\r\nGC\r\n414100000000000000\r\n1210\r\n1234\r\n\r\n123\r\n123\r\n2017-01-01T00:00:00Z\r\n123\r\n123456.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -69,7 +71,7 @@ public void RefundReversal() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*123456000\r\n\r\nGC\r\n414100000000000000\r\n1210\r\n1234\r\n\r\n123\r\n123\r\n2017-01-01T00:00:00Z\r\n123\r\n123456.*", RegexOptions.Singleline) )) - .Returns("123sandbox"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123sandbox")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -100,7 +102,7 @@ public void ActivateReversal() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*123456000\r\n123\r\n\r\nGC\r\n414100000000000000\r\n1210\r\n1234\r\n\r\n123\r\n123\r\n2017-01-01T00:00:00Z\r\n123\r\n123456.*", RegexOptions.Singleline) )) - .Returns("123sandbox"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123sandbox")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -131,7 +133,7 @@ public void DeactivateReversal() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*123456000\r\n\r\nGC\r\n414100000000000000\r\n1210\r\n1234\r\n\r\n123\r\n2017-01-01T00:00:00Z\r\n123\r\n123456.*", RegexOptions.Singleline) )) - .Returns("123sandbox"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123sandbox")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -163,7 +165,7 @@ public void LoadReversal() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*123456000\r\n\r\nGC\r\n414100000000000000\r\n1210\r\n1234\r\n\r\n123\r\n123\r\n2017-01-01T00:00:00Z\r\n123\r\n123456.*", RegexOptions.Singleline) )) - .Returns("123sandbox"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123sandbox")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -195,7 +197,7 @@ public void UnloadReversal() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*123456000\r\n\r\nGC\r\n414100000000000000\r\n1210\r\n1234\r\n\r\n123\r\n123\r\n2017-01-01T00:00:00Z\r\n123\r\n123456.*", RegexOptions.Singleline) )) - .Returns("123sandbox"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123sandbox")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); diff --git a/CnpSdkForNet/CnpSdkForNetTest/Unit/TestQueryTransactionRequest.cs b/CnpSdkForNet/CnpSdkForNetTest/Unit/TestQueryTransactionRequest.cs index 8491d46..9fb303c 100644 --- a/CnpSdkForNet/CnpSdkForNetTest/Unit/TestQueryTransactionRequest.cs +++ b/CnpSdkForNet/CnpSdkForNetTest/Unit/TestQueryTransactionRequest.cs @@ -3,6 +3,8 @@ using NUnit.Framework; using Moq; using System.Text.RegularExpressions; +using System.Net.Http; +using System.Net; namespace Cnp.Sdk.Test.Unit @@ -47,7 +49,7 @@ public void TestQueryTransactionResponse() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*0002015-12-03T10:30:02Original transaction found756027696701750GenericOrderId0002015-04-14T12:04:592015-04-14Approved055858756027696701751GenericOrderId0002015-04-14T12:04:592015-04-14Approved055858000Deposit approvedsandbox"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("0002015-12-03T10:30:02Original transaction found756027696701750GenericOrderId0002015-04-14T12:04:592015-04-14Approved055858756027696701751GenericOrderId0002015-04-14T12:04:592015-04-14Approved055858000Deposit approvedsandbox")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -89,7 +91,7 @@ public void TestQueryTransactionUnavailableResponse() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*1522015-12-03T14:45:31Original transaction found but response not yet availablesandbox"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("1522015-12-03T14:45:31Original transaction found but response not yet availablesandbox")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); diff --git a/CnpSdkForNet/CnpSdkForNetTest/Unit/TestRefundTransactionReversal.cs b/CnpSdkForNet/CnpSdkForNetTest/Unit/TestRefundTransactionReversal.cs index 534eb1b..67629c3 100644 --- a/CnpSdkForNet/CnpSdkForNetTest/Unit/TestRefundTransactionReversal.cs +++ b/CnpSdkForNet/CnpSdkForNetTest/Unit/TestRefundTransactionReversal.cs @@ -3,6 +3,8 @@ using NUnit.Framework; using Moq; using System.Text.RegularExpressions; +using System.Net.Http; +using System.Net; namespace Cnp.Sdk.Test.Unit @@ -31,7 +33,7 @@ public void TestSurchargeAmount() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*2\r\n1\r\n.*", RegexOptions.Singleline))) - .Returns("3"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("3")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -49,7 +51,7 @@ public void TestSurchargeAmount_Optional() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*2\r\n.*", RegexOptions.Singleline))) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -68,7 +70,7 @@ public void TestTransactionReversalWithLocation() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*2\r\n1\r\n.*", RegexOptions.Singleline))) - .Returns("123sandbox"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123sandbox")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -128,7 +130,7 @@ public void TestTransactionReversalWithLocation() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*TR0001.*IC.*Indigo.*TI2022.*1.*1\r\nC2011583.*", RegexOptions.Singleline))) - .Returns("123sandbox"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123sandbox")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); diff --git a/CnpSdkForNet/CnpSdkForNetTest/Unit/TestRegisterTokenRequest.cs b/CnpSdkForNet/CnpSdkForNetTest/Unit/TestRegisterTokenRequest.cs index 923dc2a..a07d5e2 100644 --- a/CnpSdkForNet/CnpSdkForNetTest/Unit/TestRegisterTokenRequest.cs +++ b/CnpSdkForNet/CnpSdkForNetTest/Unit/TestRegisterTokenRequest.cs @@ -4,6 +4,8 @@ using NUnit.Framework; using Moq; using System.Text.RegularExpressions; +using System.Net.Http; +using System.Net; namespace Cnp.Sdk.Test.Unit @@ -30,7 +32,7 @@ public void TestSimpleRequest() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*4100000000000001.*.*", RegexOptions.Singleline) )) - .Returns("4801Token Successfully Registered2012-10-10T10:17:03sandbox"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("4801Token Successfully Registered2012-10-10T10:17:03sandbox")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -51,7 +53,7 @@ public void TestCanContainCardValidationNum() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*4100000000000001.*123.*.*", RegexOptions.Singleline) )) - .Returns("4801Token Successfully Registered2012-10-10T10:17:03"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("4801Token Successfully Registered2012-10-10T10:17:03")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -78,7 +80,7 @@ public void TestSimpleRequestWithApplepay() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*.*?user.*?.*?.*", RegexOptions.Singleline) )) - .Returns("4801Token Successfully Registered2012-10-10T10:17:03"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("4801Token Successfully Registered2012-10-10T10:17:03")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); diff --git a/CnpSdkForNet/CnpSdkForNetTest/Unit/TestSale.cs b/CnpSdkForNet/CnpSdkForNetTest/Unit/TestSale.cs index a340446..e12663b 100644 --- a/CnpSdkForNet/CnpSdkForNetTest/Unit/TestSale.cs +++ b/CnpSdkForNet/CnpSdkForNetTest/Unit/TestSale.cs @@ -3,6 +3,8 @@ using NUnit.Framework; using Moq; using System.Text.RegularExpressions; +using System.Net.Http; +using System.Net; namespace Cnp.Sdk.Test.Unit @@ -32,7 +34,7 @@ public void TestFraudFilterOverride() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*false.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -51,7 +53,7 @@ public void TestSurchargeAmount() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*2\r\n1\r\necommerce.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -69,7 +71,7 @@ public void TestSurchargeAmount_Optional() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*2\r\necommerce.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -96,7 +98,7 @@ public void TestRecurringRequest() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*true\r\n\r\n\r\nabc123\r\n12\r\n\r\n.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -146,7 +148,7 @@ public void TestRecurringRequest_Optional() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*true\r\n.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -172,7 +174,7 @@ public void Test_CnpInternalRecurringRequest() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex("true\r\n\r\n123\r\n456\r\n.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -194,7 +196,7 @@ public void Test_CnpInternalRecurringRequest_Optional() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*true\r\n.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -211,7 +213,7 @@ public void TestDebtRepayment_True() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*\r\ntrue\r\n.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -228,7 +230,7 @@ public void TestDebtRepayment_False() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*\r\nfalse\r\n.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -244,7 +246,7 @@ public void TestDebtRepayment_Optional() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*\r\n.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -263,7 +265,7 @@ public void TestSecondaryAmount() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*2\r\n1\r\necommerce.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -294,7 +296,7 @@ public void TestApplepayAndWallet() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*?.*?user.*?.*?123.*?.*?.*?", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -319,7 +321,7 @@ public void SimpleSaleWithDirectDebit() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*\r\nMerchant\r\nFirstRecurring\r\n123456789123456789\r\n.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -342,7 +344,7 @@ public void SimpleSaleWithProcessTypeNetIdTranAmt() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*accountFunding\r\nTest\r\n123.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -365,7 +367,7 @@ public void SimpleSaleWithIdealResponse() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*\r\nUS\r\n.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -388,7 +390,7 @@ public void SimpleSaleWithGiropayResponse() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*\r\nUS\r\n.*", RegexOptions.Singleline) )) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -411,7 +413,7 @@ public void SimpleSaleWithSofortResponse() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*\r\nUS\r\n.*", RegexOptions.Singleline))) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -430,7 +432,7 @@ public void TestSaleWithMCC() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*2\r\necommerce\r\n0111.*", RegexOptions.Singleline))) - .Returns("123"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -450,7 +452,7 @@ public void TestSaleWithLocation() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*false.*", RegexOptions.Singleline))) - .Returns("123sandbox"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123sandbox")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -499,7 +501,7 @@ public void TestSimpleSaleWithRetailerAddressAndAdditionalCOFdata() ///new testc var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*01867-4456.*mikasa@cnp.com.*s1234.*www.google.com.*BiWeekly.*PHONE\r\nNot Approved\r\nfalse.*", RegexOptions.Singleline))) - .Returns("123sandbox"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123sandbox")}); var mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -555,7 +557,7 @@ public void TestSaleWithFsErrorCode_OverridePolicy_ProdEnrolled_MercAcctStatus_F var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*01867-4456.*mikasa@cnp.com.*s1234.*www.google.com.*BiWeekly.*PHONE\r\nNot Approved\r\nfalse.*", RegexOptions.Singleline))) - .Returns("123sandbox"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123sandbox")}); var mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -626,7 +628,7 @@ public void TestSaleWithLodgingInfoPropertyAddressChanges() ///new testcase 12.2 var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*01867-4456.*mikasa@cnp.com.*s1234.*www.google.com.*BiWeekly.*PHONE\r\nNot Approved\r\nfalse.*", RegexOptions.Singleline))) - .Returns("123sandbox"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123sandbox")}); var mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -691,7 +693,7 @@ public void TestSaleWithLodgingInfoPropertyAddressChanges() ///new testcase 12.2 var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*TR0001.*IC.*Indigo.*TI2022.*1.*1\r\nC2011583.*", RegexOptions.Singleline))) - .Returns("123sandbox"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("123sandbox")}); var mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); diff --git a/CnpSdkForNet/CnpSdkForNetTest/Unit/TestUpdateCardValidationNumOnToken.cs b/CnpSdkForNet/CnpSdkForNetTest/Unit/TestUpdateCardValidationNumOnToken.cs index a13989b..414944d 100644 --- a/CnpSdkForNet/CnpSdkForNetTest/Unit/TestUpdateCardValidationNumOnToken.cs +++ b/CnpSdkForNet/CnpSdkForNetTest/Unit/TestUpdateCardValidationNumOnToken.cs @@ -3,6 +3,8 @@ using NUnit.Framework; using Moq; using System.Text.RegularExpressions; +using System.Net.Http; +using System.Net; namespace Cnp.Sdk.Test.Unit @@ -32,7 +34,7 @@ public void TestSimpleRequest() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*12344.*1111222233334444.*321.*.*", RegexOptions.Singleline) )) - .Returns("412344801Token Successfully Registered2012-10-10T10:17:03sandbox"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("412344801Token Successfully Registered2012-10-10T10:17:03sandbox")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -56,7 +58,7 @@ public void TestOrderIdIsOptional() mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*1111222233334444.*321.*.*", RegexOptions.Singleline) )) //mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*", RegexOptions.Singleline) )) - .Returns("4801Token Successfully Registered2012-10-10T10:17:03"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("4801Token Successfully Registered2012-10-10T10:17:03")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); diff --git a/CnpSdkForNet/CnpSdkForNetTest/Unit/TestUpdateSubscription.cs b/CnpSdkForNet/CnpSdkForNetTest/Unit/TestUpdateSubscription.cs index efd6679..a3be945 100644 --- a/CnpSdkForNet/CnpSdkForNetTest/Unit/TestUpdateSubscription.cs +++ b/CnpSdkForNet/CnpSdkForNetTest/Unit/TestUpdateSubscription.cs @@ -3,6 +3,8 @@ using NUnit.Framework; using Moq; using System.Text.RegularExpressions; +using System.Net.Http; +using System.Net; namespace Cnp.Sdk.Test.Unit @@ -44,7 +46,7 @@ public void TestSimple() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*\r\n12345\r\nabcdefg\r\n\r\nGreg Dake.*?\r\n\r\nVI.*?\r\n2002-10-09\r\n\r\n.*?.*", RegexOptions.Singleline) )) - .Returns("456000Approved2013-09-0412345"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("456000Approved2013-09-0412345")}); var mockedCommunication = mock.Object; _cnp.SetCommunication(mockedCommunication); @@ -83,7 +85,7 @@ public void TestWithToken() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*\r\n12345\r\nabcdefg\r\n\r\nGreg Dake.*?\r\n.*?0123456789012345678\r\n\r\n2002-10-09\r\n\r\n.*?.*", RegexOptions.Singleline) )) - .Returns("456000Approved2013-09-0412345"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("456000Approved2013-09-0412345")}); var mockedCommunication = mock.Object; _cnp.SetCommunication(mockedCommunication); diff --git a/CnpSdkForNet/CnpSdkForNetTest/Unit/TestVoid.cs b/CnpSdkForNet/CnpSdkForNetTest/Unit/TestVoid.cs index 6ef7fbf..af492e7 100644 --- a/CnpSdkForNet/CnpSdkForNetTest/Unit/TestVoid.cs +++ b/CnpSdkForNet/CnpSdkForNetTest/Unit/TestVoid.cs @@ -3,6 +3,8 @@ using NUnit.Framework; using Moq; using System.Text.RegularExpressions; +using System.Net.Http; +using System.Net; namespace Cnp.Sdk.Test.Unit @@ -28,7 +30,7 @@ public void TestRecyclingDataOnVoidResponse() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*", RegexOptions.Singleline))) - .Returns("1230002013-01-31T15:48:092013-01-31Approved456sandbox"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("1230002013-01-31T15:48:092013-01-31Approved456sandbox")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication); @@ -47,7 +49,7 @@ public void TestRecyclingDataOnVoidResponseIsOptional() var mock = new Mock(); mock.Setup(Communications => Communications.HttpPost(It.IsRegex(".*", RegexOptions.Singleline) )) - .Returns("1230002013-01-31T15:48:092013-01-31Approved"); + .Returns(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("1230002013-01-31T15:48:092013-01-31Approved")}); Communications mockedCommunication = mock.Object; cnp.SetCommunication(mockedCommunication);