Пример #1
0
        public void TestCreatePaymentRejected()
        {
            // an exception is thrown after logging the response

            TestLogger logger = new TestLogger();

            using (MockServer host = new MockServer(Port, "/v2/1/payments", (request, response, arg3) =>
            {
                AssignResponse((HttpStatusCode)402, new Dictionary <string, string>(), response);

                return(createPaymentFailureRejectedJson);
            }))
                using (IClient client = CreateClient())
                {
                    client.EnableLogging(logger);

                    AmountOfMoney amountOfMoney = new AmountOfMoney();
                    amountOfMoney.CurrencyCode = "EUR";
                    amountOfMoney.Amount       = 2345L;

                    Address billingAddress = new Address();
                    billingAddress.CountryCode = "BE";

                    Customer customer = new Customer();
                    customer.BillingAddress = billingAddress;

                    Order order = new Order();
                    order.AmountOfMoney = amountOfMoney;
                    order.Customer      = customer;

                    Card card = new Card();
                    card.Cvv        = "123";
                    card.CardNumber = "1234567890123452";
                    card.ExpiryDate = "1230";

                    CardPaymentMethodSpecificInput paymentMethodSpecificInput = new CardPaymentMethodSpecificInput();
                    paymentMethodSpecificInput.PaymentProductId = 1;
                    paymentMethodSpecificInput.Card             = card;

                    CreatePaymentRequest request = new CreatePaymentRequest();
                    request.Order = order;
                    request.CardPaymentMethodSpecificInput = paymentMethodSpecificInput;

                    Assert.CatchAsync(typeof(DeclinedPaymentException), async() => await client.WithNewMerchant("1").Payments.CreatePayment(request)
                                      .ConfigureAwait(false));
                }
            Assert.That(logger.Entries, Has.Count.EqualTo(2));

            TestLoggerEntry requestEntry = logger.Entries.First();

            Assert.That(requestEntry.Message, Is.Not.Null);
            Assert.That(requestEntry.Thrown, Is.Null);

            TestLoggerEntry responseEntry = logger.Entries.ElementAt(1);

            Assert.That(responseEntry.Message, Is.Not.Null);
            Assert.That(responseEntry.Thrown, Is.Null);

            AssertRequestAndResponse(requestEntry.Message, responseEntry.Message, createPaymentFailureRejectedRequest, createPaymentFailureRejectedResponse);
        }
Пример #2
0
        public void TestLoggingUnknownServerError()
        {
            // an exception is thrown after logging the response

            TestLogger logger = new TestLogger();

            using (MockServer host = new MockServer(Port, "/v2/1/services/testconnection", (request, response, arg3) =>
            {
                AssignResponse((HttpStatusCode)500, new Dictionary <string, string>(), response);

                return(unknownServerErrorJson);
            }))
                using (IClient client = CreateClient())
                {
                    client.EnableLogging(logger);

                    Assert.CatchAsync(typeof(PaymentPlatformException), async() => await client.WithNewMerchant("1").Services.TestConnection()
                                      .ConfigureAwait(false));
                }

            Assert.That(logger.Entries, Has.Count.EqualTo(2));

            TestLoggerEntry requestEntry = logger.Entries.First();

            Assert.NotNull(requestEntry.Message);
            Assert.Null(requestEntry.Thrown);

            TestLoggerEntry responseEntry = logger.Entries.ElementAt(1);

            Assert.NotNull(responseEntry.Message);
            Assert.Null(responseEntry.Thrown);

            AssertRequestAndResponse(requestEntry.Message, responseEntry.Message, testConnectionRequest, unknownServerErrorResponse);
        }
Пример #3
0
        public async Task TestDeleteToken()
        {
            // POST with no request body and a void response

            TestLogger logger = new TestLogger();

            using (MockServer host = new MockServer(Port, "/v2/1/tokens/5678", (request, response, arg3) =>
            {
                AssignResponse((HttpStatusCode)204, new Dictionary <string, string>(), response, contentType: null);
                return(null);
            }))
                using (IClient client = CreateClient())
                {
                    client.EnableLogging(logger);
                    await client.WithNewMerchant("1").Tokens.DeleteToken("5678")
                    .ConfigureAwait(false);
                }
            Assert.That(logger.Entries, Has.Count.EqualTo(2));

            TestLoggerEntry requestEntry = logger.Entries.First();

            Assert.NotNull(requestEntry.Message);
            Assert.Null(requestEntry.Thrown);

            TestLoggerEntry responseEntry = logger.Entries.ElementAt(1);

            Assert.NotNull(responseEntry.Message);
            Assert.Null(responseEntry.Thrown);

            AssertRequestAndResponse(requestEntry.Message, responseEntry.Message, deleteTokenRequest, deleteTokenResponse);
        }
Пример #4
0
        public async Task TestLoggingTestConnection()
        {
            // GET with no query params
            TestLogger logger = new TestLogger();

            using (MockServer host = new MockServer(Port, "/v2/1/services/testconnection", (request, response, arg3) =>
            {
                AssignResponse((HttpStatusCode)200, new Dictionary <string, string>(), response);

                return(testConnectionJson);
            }))
                using (IClient client = CreateClient())
                {
                    client.EnableLogging(logger);

                    TestConnection response = await client.WithNewMerchant("1").Services.TestConnection()
                                              .ConfigureAwait(false);

                    Assert.That(response, Is.Not.Null);
                    Assert.That("OK", Is.EqualTo(response.Result));
                }
            Assert.That(logger.Entries, Has.Count.EqualTo(2));

            TestLoggerEntry requestEntry = logger.Entries.First();

            Assert.That(requestEntry.Message, Is.Not.Null);
            Assert.That(requestEntry.Thrown, Is.Null);

            TestLoggerEntry responseEntry = logger.Entries.ElementAt(1);

            Assert.That(responseEntry.Message, Is.Not.Null);
            Assert.That(responseEntry.Thrown, Is.Null);

            AssertRequestAndResponse(requestEntry.Message, responseEntry.Message, testConnectionRequest, testConnectionResponse);
        }
Пример #5
0
        public void TestLogErrorOnly()
        {
            // logging is enabled after the request is logged but before the error is logged

            TestLogger logger = new TestLogger();

            using (Client client = CreateClient(1, 100))
                using (MockServer host = new MockServer(Port, "/v1/1234/services/testconnection", (request, response, arg3) =>
                {
                    AssignResponse((HttpStatusCode)200, new Dictionary <string, string>(), response);
                    client.EnableLogging(logger);
                    System.Threading.Thread.Sleep(500);

                    return(testConnectionJson);
                }))
                {
                    Assert.That(async() => await client.Merchant("1234").Services().Testconnection(),
                                Throws.Exception.TypeOf(typeof(CommunicationException))
                                .And.InnerException.TypeOf(typeof(TaskCanceledException)));
                }

            Assert.That(logger.Entries, Has.Count.EqualTo(1));

            TestLoggerEntry errorEntry = logger.Entries.First();

            Assert.NotNull(errorEntry.Message);
            Assert.NotNull(errorEntry.Thrown);

            AssertError(errorEntry.Message);
        }
Пример #6
0
        public async Task TestLogResponseOnly()
        {
            // logging is disabled after the request is logged but before the response is logged

            TestLogger logger = new TestLogger();

            using (Client client = CreateClient())
                using (MockServer host = new MockServer(Port, "/v1/1234/services/testconnection", (request, response, arg3) =>
                {
                    AssignResponse((HttpStatusCode)200, new Dictionary <string, string>(), response);
                    client.EnableLogging(logger);

                    return(testConnectionJson);
                }))
                {
                    TestConnection response = await client.Merchant("1234").Services().Testconnection();

                    Assert.NotNull(response);
                    Assert.AreEqual("OK", response.Result);
                }

            Assert.That(logger.Entries, Has.Count.EqualTo(1));

            TestLoggerEntry requestEntry = logger.Entries.First();

            Assert.NotNull(requestEntry.Message);
            Assert.Null(requestEntry.Thrown);

            AssertResponse(requestEntry.Message, testConnectionResponse);
        }
Пример #7
0
        public void TestNonJson()
        {
            // an exception is thrown after logging the response

            TestLogger logger = new TestLogger();

            using (MockServer host = new MockServer(Port, "/v1/1234/services/testconnection", (request, response, arg3) =>
            {
                AssignResponse((HttpStatusCode)404, new Dictionary <string, string>(), response, contentType: "text/html");

                return(notFoundHtml);
            }))
                using (Client client = CreateClient())
                {
                    client.EnableLogging(logger);

                    Assert.CatchAsync(typeof(NotFoundException), async() => await client.Merchant("1234").Services().Testconnection());
                }
            Assert.That(logger.Entries, Has.Count.EqualTo(2));

            TestLoggerEntry requestEntry = logger.Entries.First();

            Assert.NotNull(requestEntry.Message);
            Assert.Null(requestEntry.Thrown);

            TestLoggerEntry responseEntry = logger.Entries.ElementAt(1);

            Assert.NotNull(responseEntry.Message);
            Assert.Null(responseEntry.Thrown);

            AssertRequestAndResponse(requestEntry.Message, responseEntry.Message, testConnectionRequest, notFoundResponse);
        }
        public async Task TestLoggingConvertAmount()
        {
            // GET with query params

            TestLogger logger = new TestLogger();

            using (MockServer host = new MockServer(Port, "/v1/1234/services/convert/amount", (request, response, arg3) =>
            {
                AssignResponse((HttpStatusCode)200, new Dictionary <string, string>(), response);

                return(convertAmountJson);
            }))
                using (Client client = CreateClient())
                {
                    client.EnableLogging(logger);
                    ConvertAmountParams query = new ConvertAmountParams();
                    query.Amount = 1000L;
                    query.Source = "EUR";
                    query.Target = "USD";
                    ConvertAmount response = await client.Merchant("1234").Services().ConvertAmount(query);

                    Assert.NotNull(response);
                    Assert.NotNull(response.ConvertedAmount);
                }

            Assert.That(logger.Entries, Has.Count.EqualTo(2));

            TestLoggerEntry requestEntry = logger.Entries.First();

            Assert.NotNull(requestEntry.Message);
            Assert.Null(requestEntry.Thrown);

            TestLoggerEntry responseEntry = logger.Entries.ElementAt(1);

            Assert.NotNull(responseEntry.Message);
            Assert.Null(responseEntry.Thrown);

            AssertRequestAndResponse(requestEntry.Message, responseEntry.Message, convertAmountRequest, convertAmountResponse);
        }
        public async Task TestLoggingCreatePaymentUnicode()
        {
            // POST with a success (201) response
            TestLogger logger = new TestLogger();

            using (MockServer host = new MockServer(Port, "/v1/1234/payments", (request, response, arg3) =>
            {
                AssignResponse((HttpStatusCode)201, new Dictionary <string, string>(), response, "http://localhost/v1/1234/payments/000000123410000595980000100001");

                return(createPaymentUnicodeJson);
            }))
                using (Client client = CreateClient())
                {
                    client.EnableLogging(logger);

                    AmountOfMoney amountOfMoney = new AmountOfMoney();
                    amountOfMoney.CurrencyCode = "CAD";
                    amountOfMoney.Amount       = 2345L;

                    Address billingAddress = new Address();
                    billingAddress.CountryCode = "CA";

                    Customer customer = new Customer();
                    customer.BillingAddress = billingAddress;

                    Order order = new Order();
                    order.AmountOfMoney = amountOfMoney;
                    order.Customer      = customer;

                    Card card = new Card();
                    card.Cvv        = "123";
                    card.CardNumber = "1234567890123456";
                    card.ExpiryDate = "1220";

                    CardPaymentMethodSpecificInput paymentMethodSpecificInput = new CardPaymentMethodSpecificInput();
                    paymentMethodSpecificInput.PaymentProductId = 1;
                    paymentMethodSpecificInput.Card             = card;

                    CreatePaymentRequest request = new CreatePaymentRequest();
                    request.Order = order;
                    request.CardPaymentMethodSpecificInput = paymentMethodSpecificInput;

                    CreatePaymentResponse response = await client.Merchant("1234").Payments().Create(request);

                    Assert.NotNull(response);
                    Assert.NotNull(response.Payment);
                    Assert.NotNull(response.Payment.Id);
                }
            Assert.That(logger.Entries, Has.Count.EqualTo(2));

            TestLoggerEntry requestEntry = logger.Entries.First();

            Assert.That(requestEntry.Message, Is.Not.Null);
            Assert.That(requestEntry.Thrown, Is.Null);

            TestLoggerEntry responseEntry = logger.Entries.ElementAt(1);

            Assert.That(responseEntry.Message, Is.Not.Null);
            Assert.That(responseEntry.Thrown, Is.Null);

            AssertRequestAndResponse(requestEntry.Message, responseEntry.Message, createPaymentUnicodeRequest, createPaymentUnicodeResponse);
        }