Esempio n. 1
0
        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");
                }
            }
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
        }