コード例 #1
0
ファイル: KondutoTest.cs プロジェクト: wmaschette/dotnet-sdk
        public void UpdateHTTPErrorTest()
        {
            foreach (int code in HTTP_STATUSES)
            {
                try
                {
                    var fakeResponseHandler = new FakeResponseHandler();

                    var message = new HttpResponseMessage((HttpStatusCode)code);
                    message.Content = new StringContent("{}");

                    fakeResponseHandler.AddFakeResponse(konduto.KondutoPutOrderUrl(ORDER_ID), message);
                    konduto.__MessageHandler = fakeResponseHandler;

                    konduto.Analyze(KondutoOrderFactory.basicOrder());
                    Assert.Fail("Exception expected");
                }
                catch (KondutoHTTPException e)
                {
                    //Ok
                }
                catch (Exception e)
                {
                    Assert.Fail("KondutoHTTPException was expected");
                }
            }
        }
コード例 #2
0
ファイル: KondutoTest.cs プロジェクト: wmaschette/dotnet-sdk
        public void AnalyzeSuccessfullyTest()
        {
            var fakeResponseHandler = new FakeResponseHandler();
            var message             = new HttpResponseMessage(HttpStatusCode.OK);

            message.Content = new StringContent(ANALYZE_ORDER_RESPONSE.ToString());

            fakeResponseHandler.AddFakeResponse(konduto.KondutoPostOrderUrl(), message);
            konduto.__MessageHandler = fakeResponseHandler;

            KondutoOrder orderToSend   = KondutoOrderFactory.basicOrder();
            String       s             = orderToSend.ToJson();
            KondutoOrder orderResponse = null;

            Assert.IsTrue(orderToSend.Recommendation == KondutoRecommendation.none, "basic order should have no recommendation");
            Assert.IsTrue(orderToSend.Score == null, "basic order should have no score");
            Assert.IsNull(orderToSend.Geolocation, "basic order should have no geolocation");
            Assert.IsNull(orderToSend.Device, "basic order should have no device");
            Assert.IsNull(orderToSend.NavigationInfo, "basic order should have no navigation info");
            Assert.IsTrue(orderToSend.Analyze, "basic order should have analyze set to true");

            try
            {
                orderResponse = konduto.Analyze(orderToSend); // do analyze
            }
            catch (KondutoInvalidEntityException e)
            {
                Assert.Fail("order should be valid");
            }
            catch (KondutoUnexpectedAPIResponseException e)
            {
                Assert.Fail("server should respond with status 200");
            }
            catch (KondutoHTTPException e)
            {
                Assert.Fail("server should respond with status 200");
            }

            Double?actualScore = ORDER_FROM_FILE.Score;
            KondutoRecommendation?actualRecommendation = ORDER_FROM_FILE.Recommendation;
            KondutoGeolocation    actualGeolocation    = ORDER_FROM_FILE.Geolocation;
            KondutoDevice         actualDevice         = ORDER_FROM_FILE.Device;
            KondutoNavigationInfo actualNavigationInfo = ORDER_FROM_FILE.NavigationInfo;

            Assert.IsTrue(orderResponse.Geolocation.Equals(actualGeolocation));
            Assert.AreEqual(orderResponse.Recommendation, actualRecommendation);
            Assert.AreEqual(orderResponse.Device, actualDevice);
            Assert.AreEqual(orderResponse.NavigationInfo, actualNavigationInfo);
            Assert.AreEqual(orderResponse.Score, actualScore);
        }
コード例 #3
0
        public void SerializationTestWithSeller()
        {
            KondutoOrder order = KondutoOrderFactory.completeOrder();

            order.Seller = KondutoSellerFactory.Create();

            try
            {
                order.ToJson();
                //ok
            }
            catch (KondutoInvalidEntityException e)
            {
                Assert.Fail("order should be invalid");
            }
        }
コード例 #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");
        }
コード例 #5
0
        public void SerializationTestWithShoppingAndFlight()
        {
            KondutoOrder order = KondutoOrderFactory.completeOrder();

            order.Travel = KondutoFlightFactory.CreateFlight();

            try
            {
                order.ToJson();
                Assert.Fail("order should be invalid");
            }
            catch (KondutoInvalidEntityException e)
            {
                //ok
            }

            order              = KondutoOrderFactory.completeOrder();
            order.Travel       = KondutoFlightFactory.CreateFlight();
            order.ShoppingCart = null;
            //ok
        }
コード例 #6
0
ファイル: KondutoTest.cs プロジェクト: wmaschette/dotnet-sdk
        public void SendOrderToKondutoButDoNotAnalyzeTest()
        {
            var fakeResponseHandler = new FakeResponseHandler();
            var message             = new HttpResponseMessage(HttpStatusCode.OK);

            message.Content = new StringContent(NOT_ANALYZE_ORDER_RESPONSE.ToString());

            fakeResponseHandler.AddFakeResponse(konduto.KondutoPostOrderUrl(), message);
            konduto.__MessageHandler = fakeResponseHandler;

            KondutoOrder orderToSend = KondutoOrderFactory.basicOrder();

            orderToSend.Analyze = false;

            Assert.IsFalse(orderToSend.Analyze, "order analyze should be false");

            try
            {
                orderToSend = konduto.Analyze(orderToSend); // do analyze
            }
            catch (KondutoInvalidEntityException e)
            {
                Assert.Fail("order should be valid");
            }
            catch (KondutoHTTPException e)
            {
                Assert.Fail("server should respond with status 200");
            }
            catch (KondutoUnexpectedAPIResponseException e)
            {
                Assert.Fail("server should respond with status 200");
            }

            Assert.IsTrue(orderToSend.Score == null);
            Assert.IsTrue(orderToSend.Recommendation == KondutoRecommendation.none);
        }