public void SendWithShortErrorResponseTest() { //get sample response XML PaymentResponse fromXmlResponse = new PaymentResponse().FromXml(Resources.payment_response_basic_error_sample); //mock HttpResponse _handler.AddFakeResponse(HttpConfiguration.DEFAULT_ENDPOINT, new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(fromXmlResponse.ToXml()) }); //create empty request PaymentRequest request = new PaymentRequest(); //create configuration HttpConfiguration httpConfiguration = new HttpConfiguration(); httpConfiguration.OnlyAllowHttps = false; //mock HttpCLient instance HttpClient httpClientMock = new HttpClient(_handler); //execute send on client RealexClient realexClient = new RealexClient(SampleXmlValidationUtils.SECRET, httpConfiguration, httpClientMock); try { realexClient.Send(request); Assert.Fail("RealexException should have been thrown before this point."); } catch (RealexServerException ex) { //validate error SampleXmlValidationUtils.checkBasicResponseError(ex); } }
public void SendInvalidResponseHashTest() { //get sample response XML and add invlid hash PaymentResponse fromXmlResponse = new PaymentResponse().FromXml(Resources.payment_response_sample); fromXmlResponse.Hash = "invalid hash"; //mock HttpResponse _handler.AddFakeResponse(HttpConfiguration.DEFAULT_ENDPOINT, new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(fromXmlResponse.ToXml()) }); //create empty request PaymentRequest request = new PaymentRequest(); //create configuration HttpConfiguration httpConfiguration = new HttpConfiguration(); //mock HttpCLient instance HttpClient httpClientMock = new HttpClient(_handler); //execute send on client RealexClient realexClient = new RealexClient(SampleXmlValidationUtils.SECRET, httpConfiguration, httpClientMock); realexClient.Send(request); //shouldn't get this far Assert.Fail("RealexException should have been thrown before this point."); }
public void SendTest() { //get sample response XML PaymentResponse fromXmlResponse = new PaymentResponse().FromXml(Resources.payment_response_sample); //mock HttpResponse _handler.AddFakeResponse(HttpConfiguration.DEFAULT_ENDPOINT, new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(fromXmlResponse.ToXml()) }); //create empty request PaymentRequest request = new PaymentRequest(); //create configuration HttpConfiguration httpConfiguration = new HttpConfiguration(); httpConfiguration.OnlyAllowHttps = false; //mock HttpClient instance HttpClient httpClient = new HttpClient(_handler); //execute send on client RealexClient realexClient = new RealexClient(SampleXmlValidationUtils.SECRET, httpConfiguration, httpClient); PaymentResponse response = realexClient.Send(request); //validate response SampleXmlValidationUtils.checkUnmarshalledPaymentResponse(response); }
public void PaymentResponseXmlTest() { PaymentResponse response = new PaymentResponse(); response.Account = sx.ACCOUNT; response.AcquirerResponse = sx.ACQUIRER_RESPONSE; response.AuthCode = sx.AUTH_CODE; response.AuthTimeTaken = sx.AUTH_TIME_TAKEN; response.BatchId = sx.BATCH_ID.ToString(); CardIssuer cardIssuer = new CardIssuer(); cardIssuer.Bank = sx.BANK; cardIssuer.Country = sx.COUNTRY; cardIssuer.CountryCode = sx.COUNTRY_CODE; cardIssuer.Region = sx.REGION; response.CardIssuer = cardIssuer; response.CvnResult = sx.CVN_RESULT; response.MerchantId = sx.MERCHANT_ID; response.Message = sx.MESSAGE; response.OrderId = sx.ORDER_ID; response.PaymentsReference = sx.PASREF; response.Result = sx.RESULT_SUCCESS; response.Hash = sx.RESPONSE_HASH; response.Timestamp = sx.TIMESTAMP_RESPONSE; response.TimeTaken = sx.TIME_TAKEN; TssResult tssResult = new TssResult(); tssResult.Result = sx.TSS_RESULT; List <TssResultCheck> checks = new List <TssResultCheck>(); TssResultCheck check = new TssResultCheck(); check.Id = sx.TSS_RESULT_CHECK1_ID; check.Value = sx.TSS_RESULT_CHECK1_VALUE; checks.Add(check); check = new TssResultCheck(); check.Id = sx.TSS_RESULT_CHECK2_ID; check.Value = sx.TSS_RESULT_CHECK2_VALUE; checks.Add(check); tssResult.Checks = checks; response.TssResult = tssResult; response.AvsAddressResponse = sx.AVS_ADDRESS; response.AvsPostcodeResponse = sx.AVS_POSTCODE; //marshal to XML string xml = response.ToXml(); //unmarshal back to response PaymentResponse fromXmlResponse = new PaymentResponse().FromXml(xml); sx.checkUnmarshalledPaymentResponse(fromXmlResponse); }
public void SendWithErrorResponseInvalidCodeTest() { //get sample response XML PaymentResponse fromXmlResponse = new PaymentResponse().FromXml(Resources.payment_response_basic_error_sample); fromXmlResponse.Result = "invalid"; //mock HttpResponse _handler.AddFakeResponse(HttpConfiguration.DEFAULT_ENDPOINT, new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(fromXmlResponse.ToXml()) }); //create empty request PaymentRequest request = new PaymentRequest(); //create configuration HttpConfiguration httpConfiguration = new HttpConfiguration(); //mock HttpCLient instance HttpClient httpClientMock = new HttpClient(_handler); //execute send on client RealexClient realexClient = new RealexClient(SampleXmlValidationUtils.SECRET, httpConfiguration, httpClientMock); bool correctExceptionThrown = false; try { realexClient.Send(request); Assert.Fail("RealexException should have been thrown before this point."); } catch (RealexServerException) { Assert.Fail("Incorrect exception thrown. Expected RealexException as result code is invalid."); } catch (RealexException) { correctExceptionThrown = true; } Assert.IsTrue(correctExceptionThrown, "Incorrect exception thrown."); }