コード例 #1
0
        public TrackingData GetTrackingData(string trackingNumber)
        {
            string requestXml  = TrackingRequest.GetTrackingRequest(trackingNumber, _username, _password);
            string responseXml = _postUtility.PostData(DEV_URL, requestXml);

            return(TrackingResponse.GetCommonTrackingData(responseXml));
        }
コード例 #2
0
ファイル: UspsTracker.cs プロジェクト: ytechie/SimpleTracking
        public void Test_Dev_Url_Request_Response_Process()
        {
            _tracker = new UspsTracker(_postUtil, "userName", "password", false);

            Expect.Call(_postUtil.PostData(null, null)).IgnoreArguments()
            .Constraints(Text.StartsWith("http://testing.shippingapis.com/ShippingAPITest.dll?API=TrackV2&XML=<TrackRequest"),
                         Is.Null())
            .Return(getSampleResponse("MultipleActivities.xml"));

            mocks.ReplayAll();

            TrackingData td = _tracker.GetTrackingData("9101805213907598388159");

            Assert.AreEqual(4, td.Activity.Count);

            mocks.VerifyAll();
        }
コード例 #3
0
        /// <summary>
        ///		Gets the DHL tracking details for a tracking number.
        /// </summary>
        /// <param name="trackingNumber">
        ///		The tracking number to retrieve tracking details for.
        /// </param>
        /// <returns>
        ///		The tracking data extracted from the tracking response.
        /// </returns>
        public TrackingData GetTrackingData(string trackingNumber)
        {
            if (!DhlTracker.IsValidTrackingNumber(trackingNumber))
            {
                return(null);
            }

            string requestString = string.Format("txtTrackNbrs={0}", trackingNumber);
            string responseXml   = _postUtility.PostData(POST_URL, requestString);

            return(ScreenScrapeResponse.GetCommonTrackingData(responseXml));
        }
コード例 #4
0
ファイル: UspsTracker.cs プロジェクト: ytechie/SimpleTracking
        /// <summary>
        ///		Gets the <see cref="TrackingData"/> for the specified tracking number
        ///		by calling the API and parsing the results.
        /// </summary>
        /// <param name="trackingNumber">
        ///		The tracking number to request tracking information for.
        /// </param>
        /// <returns>
        ///		A <see cref="TrackingData"/> instance that represents the information
        ///		returned from the API.
        /// </returns>
        public TrackingData GetTrackingData(string trackingNumber)
        {
            if (!IsUspsTrackingNumber(trackingNumber))
            {
                return(null);
            }

            string       requestXml  = TrackingRequest.GetTrackingRequest(trackingNumber, _userName, _password);
            string       requestUrl  = string.Format(_serviceUrl, requestXml);
            string       responseXml = _postUtility.PostData(requestUrl, null);
            TrackingData td          = TrackingResponse.GetCommonTrackingData(responseXml);

            return(td);
        }
コード例 #5
0
        public void Test_Overall_Request_Response_Process()
        {
            Expect.Call(_postUtil.PostData(null, null)).IgnoreArguments()
            .Constraints(Is.Equal("HTTPS://eCommerce.Airborne.com/APILandingTest.asp"), Is.NotNull())
            .Return(getSampleResponse("StandardResponse.xml"));

            mocks.ReplayAll();

            TrackingData td = _dt.GetTrackingData("12991078030");

            Assert.AreEqual(5, td.Activity.Count);

            mocks.VerifyAll();
        }
コード例 #6
0
        public void Test_Overall_Request_Response_Process()
        {
            Expect.Call(_postUtil.PostData(null, null)).IgnoreArguments()
            .Constraints(Is.Equal("http://track.dhl-usa.com/TrackByNbr.asp?nav=Tracknbr"), Is.Equal("txtTrackNbrs=12991078030"))
            .Return(getSampleResponse("ScreenScrape1.txt"));

            mocks.ReplayAll();

            TrackingData td = _dt.GetTrackingData("12991078030");

            Assert.AreEqual(11, td.Activity.Count);

            mocks.VerifyAll();
        }
コード例 #7
0
        /// <summary>
        ///		Posts string data to a URL and receive a string response.
        /// </summary>
        /// <param name="url">
        ///		The URL to post the data to.
        /// </param>
        /// <param name="postString">
        ///		String data to post to the remote server.
        /// </param>
        /// <returns>
        ///		The string response data from the post request.
        /// </returns>
        public string PostData(string url, string postString)
        {
            var    tryCount = 0;
            string response;

            do
            {
                tryCount++;

                //Delay the subsequent requests
                if (tryCount > 1)
                {
                    _threadSleeper.Sleep(TimeSpan.FromSeconds(1.0));
                }

                response = _poster.PostData(url, postString);
            } while (tryCount < 5 && (response.Length == 0 || response == "-1"));

            return(response);
        }