示例#1
0
        /// <summary>
        /// Queries an order from Konduto's API.
        /// Syncronous
        /// @see <a href="http://docs.konduto.com">Konduto API Spec</a>
        /// </summary>
        /// <param name="orderId">the order identifier</param>
        /// <returns>a {@link KondutoOrder} instance</returns>
        /// <exception cref="KondutoHTTPException"></exception>
        /// <exception cref="KondutoUnexpectedAPIResponseException"></exception>
        public KondutoOrder GetOrder(String orderId)
        {
            HttpClient client = CreateHttpClient();

            this.requestBody = orderId;

            var response = client.GetAsync(KondutoGetOrderSuffix(orderId)).Result;

            if (response.IsSuccessStatusCode)
            {
                var responseContent = response.Content;

                String responseString = responseContent.ReadAsStringAsync().Result;
                this.responseBody = responseString;

                JObject getResponse = JsonConvert.DeserializeObject <JObject>(responseString);

                KondutoOrder order = null;

                JToken jt;
                if (getResponse.TryGetValue("order", out jt))
                {
                    order = KondutoModel.FromJson <KondutoOrder>(jt.ToString());
                }

                return(order);
            }
            else
            {
                throw KondutoHTTPExceptionFactory.buildException((int)response.StatusCode, response.Content.ReadAsStringAsync().Result);
            }
        }
示例#2
0
        public void Setup()
        {
            konduto = new Konduto(API_KEY);

            ANALYZE_ORDER_RESPONSE = JsonConvert.DeserializeObject <JObject>(
                Properties.Resources.konduto_order);

            JToken jt;

            ANALYZE_ORDER_RESPONSE.TryGetValue("order", out jt);
            ORDER_FROM_FILE = KondutoModel.FromJson <KondutoOrder>(jt.ToString());
            ORDER_ID        = ORDER_FROM_FILE.Id;

            NOT_ANALYZE_ORDER_RESPONSE = JsonConvert.DeserializeObject <JObject>(
                Properties.Resources.konduto_order_not_analyzed);
        }
示例#3
0
        public void SerializeTest()
        {
            KondutoDevice device     = KondutoDeviceFactory.Create();
            String        deviceJSON = KondutoUtils.LoadJson <KondutoDevice>(Properties.Resources.device).ToJson();

            try
            {
                Assert.AreEqual(deviceJSON, device.ToJson(), "serialization failed");
            }
            catch (KondutoInvalidEntityException e)
            {
                Assert.Fail("device should be valid");
            }

            Assert.AreEqual(KondutoModel.FromJson <KondutoDevice>(deviceJSON), device, "deserialization failed");
        }
示例#4
0
        public void SerializationTest()
        {
            KondutoOrder order     = KondutoOrderFactory.completeOrder();
            String       orderJSON = KondutoUtils.LoadJson <KondutoOrder>(Properties.Resources.order).ToJson();

            try
            {
                Assert.AreEqual(orderJSON, order.ToJson(), "serialization failed");
            }
            catch (KondutoInvalidEntityException e)
            {
                Assert.Fail("order should be valid");
            }

            KondutoOrder deserializedOrder = KondutoModel.FromJson <KondutoOrder>(orderJSON);

            Assert.IsTrue(order.Equals(deserializedOrder), "deserialization failed");
        }
        public void SerializationTest()
        {
            KondutoCustomer customer     = KondutoCustomerFactory.CompleteCustomer();
            String          customerJSON = KondutoUtils.LoadJson <KondutoCustomer>(Properties.Resources.customer).ToJson();

            try
            {
                var v = customer.ToJson();
                Assert.AreEqual(customerJSON, customer.ToJson(), "serialization failed");
            }
            catch (KondutoInvalidEntityException e) {
                Debug.WriteLine(e.Message);
            }

            KondutoCustomer deserializedCustomer = KondutoModel.FromJson <KondutoCustomer>(customerJSON);

            Assert.AreEqual(customer, deserializedCustomer, "deserialization failed");
        }
示例#6
0
        public void SerializationTest()
        {
            KondutoGeolocation geolocation = KondutoGeolocationFactory.Create();

            String geolocationJSON = KondutoUtils.LoadJson <KondutoGeolocation>(Properties.Resources.geolocation).ToJson();

            try
            {
                Assert.AreEqual(geolocationJSON, geolocation.ToJson(), "serialization failed");
            }
            catch (KondutoInvalidEntityException e)
            {
                Assert.Fail("geolocation should be valid");
            }

            KondutoGeolocation geolocationDeserialized = KondutoModel.FromJson <KondutoGeolocation>(geolocationJSON);

            Assert.AreEqual(geolocation, geolocationDeserialized, "deserialization failed");
        }
示例#7
0
        public void SerializeTest()
        {
            String        expectedJSON = KondutoUtils.LoadJson <KondutoTravel>(Properties.Resources.flight).ToJson();
            String        actualJSON   = null;
            KondutoTravel flight       = KondutoFlightFactory.CreateFlight();

            try
            {
                actualJSON = flight.ToJson();
            }
            catch (KondutoInvalidEntityException e)
            {
                Assert.Fail("flight should be valid");
            }

            Assert.AreEqual(expectedJSON, actualJSON, "flight serialization failed");
            KondutoTravel flightFromJSON = KondutoModel.FromJson <KondutoTravel>(expectedJSON);

            Assert.AreEqual(flight, flightFromJSON, "flight deserialization failed");
        }
        public void SerializationTest()
        {
            String        expectedJSON = KondutoUtils.LoadJson <KondutoSeller>(Properties.Resources.seller).ToJson();
            String        actualJSON   = null;
            KondutoSeller seller       = KondutoSellerFactory.Create();

            try
            {
                actualJSON = seller.ToJson();
            }
            catch (KondutoInvalidEntityException e)
            {
                Assert.Fail("seller should be valid");
            }

            Assert.AreEqual(expectedJSON, actualJSON, "seller serialization failed");
            KondutoSeller sellerFromJson = KondutoModel.FromJson <KondutoSeller>(expectedJSON);

            Assert.AreEqual(seller, sellerFromJson, "passenger deserialization failed");
        }
        public void SerializationTest()
        {
            KondutoNavigationInfo navigationInfo = KondutoNavigationInfoFactory.Create();

            String navigationInfoJSON = KondutoUtils.LoadJson <KondutoNavigationInfo>(Properties.Resources.navigation).ToJson();

            try
            {
                var c = navigationInfo.ToJson();
                Assert.AreEqual(navigationInfoJSON, navigationInfo.ToJson(), "serialization failed");
            }
            catch (KondutoInvalidEntityException e)
            {
                Assert.Fail("navigation info should be valid");
            }

            KondutoNavigationInfo navigationInfoDeserialized = KondutoModel.FromJson <KondutoNavigationInfo>(navigationInfoJSON);

            Assert.AreEqual(navigationInfoDeserialized, navigationInfo, "deserialization failed");
        }
示例#10
0
        public void SerializeTest()
        {
            String         expectedJSON = KondutoUtils.LoadJson <KondutoAddress>(Properties.Resources.address).ToJson();
            String         actualJSON   = null;
            KondutoAddress address      = KondutoAddressFactory.Create();

            try
            {
                actualJSON = address.ToJson();
            }
            catch (KondutoInvalidEntityException e)
            {
                Assert.Fail("address should be valid");
            }

            Assert.AreEqual(expectedJSON, actualJSON, "address serialization failed");
            KondutoAddress addressFromJSON = KondutoModel.FromJson <KondutoAddress>(expectedJSON);

            Assert.AreEqual(address, addressFromJSON, "address deserialization failed");
        }
示例#11
0
        public void CreditSerializeTest()
        {
            String expectedJSON = KondutoUtils.GetFirstJArrayElement(Properties.Resources.payments);
            String actualJSON   = null;
            KondutoCreditCardPayment payment = KondutoPaymentFactory.CreateCreditCardPayment();

            try
            {
                actualJSON = payment.ToJson();
            }
            catch (KondutoInvalidEntityException e)
            {
                Assert.Fail("address should be valid");
            }

            Assert.AreEqual(expectedJSON, actualJSON, "address serialization failed");

            KondutoCreditCardPayment paymentFromJSON = KondutoModel.FromJson <KondutoCreditCardPayment>(expectedJSON);

            Assert.AreEqual(payment, paymentFromJSON, "address deserialization failed");
        }
示例#12
0
        public void TransferSerializeTest()
        {
            JArray a                       = JArray.Parse(Properties.Resources.payments);
            String expectedJSON            = a[3].ToString();
            String actualJSON              = null;
            KondutoTransferPayment payment = KondutoPaymentFactory.CreateTransferPayment();

            try
            {
                actualJSON = payment.ToJson();
            }
            catch (KondutoInvalidEntityException e)
            {
                Assert.Fail("payment should be valid");
            }

            Assert.AreEqual(expectedJSON, actualJSON, "address serialization failed");

            KondutoTransferPayment paymentFromJSON = KondutoModel.FromJson <KondutoTransferPayment>(expectedJSON);

            Assert.AreEqual(payment, paymentFromJSON, "payment deserialization failed");
        }
 public KondutoInvalidEntityException(KondutoModel entity)
     : base(String.Format("{0} is invalid: {1}", entity.ToString(), entity.GetError()))
 {
 }
示例#14
0
 public void Deserializationtest()
 {
     Assert.IsTrue(greenTShirt.Equals(KondutoModel.FromJson <KondutoItem>(greenTShirtJSON)), "deserialization failed");
 }