コード例 #1
0
        public void testDetectCouriers()
        {
            //get trackings of this number.
            List <Courier> couriers = connection.detectCouriers(trackingNumberToDetect);

            Assert.AreEqual(2, couriers.Count);
            //the couriers should be dpd or fedex
            Assert.IsTrue(Equals(couriers[0].slug, couriersDetected[0]) ||
                          Equals(couriers[1].slug, couriersDetected[0]));
            Assert.IsTrue(Equals(couriers[0].slug, couriersDetected[1]) ||
                          Equals(couriersDetected[1], couriers[1].slug));

            //if the trackingNumber doesn't match any courier defined, should give an error.

            try {
                List <Courier> couriers1 = connection.detectCouriers(trackingNumberToDetectError);
                Assert.AreEqual(0, couriers1.Count);
            }catch (Exception e) {
                Assert.AreEqual("{\"meta\":{\"code\":4005,\"message\":\"The value of `tracking_number` is invalid.\",\"type\":\"BadRequest\"},\"data\":{\"tracking\":{\"tracking_number\":\"asdq\"}}}", e.Message);
            }

            List <String> slugs = new List <String>();

            slugs.Add("dtdc");
            slugs.Add("ukrposhta");
            slugs.Add("usps");
            //   slugs.add("asdfasdfasdfasd");
            slugs.Add("dpd");
            List <Courier> couriers2 = connection.detectCouriers(trackingNumberToDetect, "28046", "", null, slugs);

            Assert.AreEqual(1, couriers2.Count);
        }