Пример #1
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);
        }
Пример #2
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");
        }