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 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 SendThreeDSecureInvalidResponseHashTest() { //get sample response XML ThreeDSecureResponse fromXmlResponse = new ThreeDSecureResponse().FromXml(Resources._3ds_verify_enrolled_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 ThreeDSecureRequest request = new ThreeDSecureRequest(); //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); realexClient.Send(request); //shouldn't get this far Assert.Fail("RealexException should have been thrown before this point."); }
public void Init() { _config = new HttpConfiguration { Endpoint = "https://test.realexpayments.com/epage-remote.cgi" }; _client = new RealexClient("Po8lRRT67a", _config); _handler = new FakeResponseHandler(); }
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."); }