示例#1
0
        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);
            }
        }
示例#2
0
        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);
        }