Ejemplo n.º 1
0
        public void CaptureSale_With_Opcional_Parameters_Send_Corrrectly_ApiService()
        {
            var paymentId = Guid.NewGuid();

            var validCaptureSaleResponse = ValidCaptureSaleResponse();

            _mockRestClient.Setup(m => m.Execute <CaptureResponse>(It.IsAny <IRestRequest>())).Returns(new RestResponse <CaptureResponse>()
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new JsonSerializer().Serialize(validCaptureSaleResponse),
                Data       = validCaptureSaleResponse
            });

            _service.Capture(paymentId, MerchantAuthenticationHelper.CreateMerchantAuthentication(), CaptureTransationHelper.CreateValidCaptureRequest());

            _mockRestClient.Verify(m => m.Execute <CaptureResponse>(It.IsAny <RestRequest>()), Times.Once);

            _mockRestClient.Verify(m => m.Execute <CaptureResponse>(It.Is <RestRequest>(request => request.Method == Method.PUT)), Times.Once);

            _mockRestClient.Verify(m => m.Execute <CaptureResponse>(It.Is <RestRequest>(request => request.Resource == @"sales/{paymentId}/capture")), Times.Once);

            _mockRestClient.Verify(m => m.Execute <CaptureResponse>(It.Is <RestRequest>(request => request.Parameters.Any(
                                                                                            param => param.Type == ParameterType.UrlSegment && param.Name == "paymentId" && param.Value.ToString() == paymentId.ToString()))), Times.Once);

            _mockRestClient.Verify(m => m.Execute <CaptureResponse>(It.Is <RestRequest>(request => request.Parameters.Any(
                                                                                            param => param.Type == ParameterType.QueryString && param.Name == "amount" && param.Value.ToString() == CaptureTransationHelper.CreateValidCaptureRequest().Amount.ToString()))), Times.Once);

            _mockRestClient.Verify(m => m.Execute <CaptureResponse>(It.Is <RestRequest>(request => request.Parameters.Any(
                                                                                            param => param.Type == ParameterType.QueryString && param.Name == "serviceTaxAmount" && param.Value.ToString() == CaptureTransationHelper.CreateValidCaptureRequest().ServiceTaxAmount.ToString()))), Times.Once);
        }
Ejemplo n.º 2
0
        public void CaptureSale_Capture_Valid_Transaction()
        {
            var validCreditCardCaptureResponse = ValidCaptureSaleResponse();

            _mockRestClient.Setup(m => m.Execute <CaptureResponse>(It.IsAny <IRestRequest>())).Returns(new RestResponse <CaptureResponse>()
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new JsonSerializer().Serialize(validCreditCardCaptureResponse),
                Data       = validCreditCardCaptureResponse
            });

            _service.RestClient = _mockRestClient.Object;

            var response = _service.Capture(Guid.NewGuid(), MerchantAuthenticationHelper.CreateMerchantAuthentication(), CaptureTransationHelper.CreateValidCaptureRequest());

            response.ErrorDataCollection.Should().BeNull();
            response.HttpStatus.Should().Be(HttpStatusCode.OK);
            response.ReasonCode.Should().Be(0);
            response.ReasonMessage.Should().Be("Successful");
            response.Status.Should().Be(10);
            response.Links.Count.Should().BeGreaterThan(0);
        }
Ejemplo n.º 3
0
        public void CaptureSale_Error_Transaction()
        {
            var errorCreditCardCaptureResponse = new CaptureResponse
            {
                HttpStatus          = HttpStatusCode.BadRequest,
                Links               = null,
                ReasonCode          = 0,
                Status              = 0,
                ReasonMessage       = null,
                ErrorDataCollection = new List <Error>()
                {
                    new Error
                    {
                        Code    = 500,
                        Message = "Internal Server Error"
                    }
                }
            };

            _mockRestClient.Setup(m => m.Execute <CaptureResponse>(It.IsAny <IRestRequest>())).Returns(new RestResponse <CaptureResponse>()
            {
                StatusCode = HttpStatusCode.BadRequest,
                Content    = new JsonSerializer().Serialize(errorCreditCardCaptureResponse),
                Data       = errorCreditCardCaptureResponse
            });

            var response = _service.Capture(Guid.NewGuid(), MerchantAuthenticationHelper.CreateMerchantAuthentication(), CaptureTransationHelper.CreateValidCaptureRequest());

            response.ErrorDataCollection.Count.Should().BeGreaterThan(0);
            response.HttpStatus.Should().Be(HttpStatusCode.BadRequest);
            response.ReasonCode.Should().Be(0);
            response.ReasonMessage.Should().BeNull();
            response.Status.Should().Be(0);
            response.Links.Should().BeNull();
        }