/// <summary> /// Puts the tracking response data into the common /// <see cref="TrackingData"/> format. /// </summary> /// <returns> /// Gets the <see cref="TrackingData"/> that contains the tracking /// information for this response. /// </returns> public static TrackingData GetCommonTrackingData(string xml) { _log.Debug("Processing DHL tracking response data: " + xml); try { var td = new TrackingData(); var xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xml); var response = GetResponseCode(xmlDoc); //Response code 0 = Package found if (response.Key != 0) { //Response code 1 = Not found, anything else should log the message if(response.Key != 1) _log.InfoFormat("Received a response code of {0} from DHL, message: {1}", response.Key, response.Value); return null; } td.Activity = getActivities(xmlDoc); td.TrackerName = TRACKER_NAME; td.UsageRequirements = DhlTracker.USAGE_REQUIREMENTS; return td; } catch (Exception ex) { throw new ResponseParseException(xml, ex); } }
private static TrackingData getSim2TrackingData() { var td = new TrackingData(); td.UsageRequirements = "The simulation tracker is for internal use only"; td.TrackerName = "Simulation Tracker"; td.EstimatedDelivery = DateTime.Parse("1-7-15"); td.Activity = new List<Activity>(); DateTime baseTime = DateTime.Now; baseTime = baseTime.AddMinutes(-baseTime.Minute); var activity = new Activity(); activity.Timestamp = baseTime.AddHours(-1); activity.ShortDescription = string.Format("Simulated activity at {0}", activity.Timestamp); activity.LocationDescription = "Simulated, SI"; td.Activity.Add(activity); activity = new Activity(); activity.Timestamp = baseTime; activity.ShortDescription = string.Format("Simulated activity at {0}", activity.Timestamp); activity.LocationDescription = "Simulated, SI"; td.Activity.Add(activity); return td; }
public void Non_Empty_Tracking_Number_Verify_Upstream_Tracker_Used() { var expectedTrackingData = new TrackingData(); _mockUpstreamTracker.Expect(x => x.GetTrackingData("abc")).Return(expectedTrackingData); var td = _t.GetTrackingData("abc"); Assert.AreEqual(td, expectedTrackingData); }
public TrackingDataEntity(string trackingNumber, TrackingData trackingData) { PartitionKey = trackingNumber; RowKey = DateTime.UtcNow.ToString("O"); TrackingNumber = trackingNumber; //What is the performance impact here? TrackingDataJson = JsonConvert.SerializeObject(trackingData); }
public void UsesTrackingNumberUtilities() { var downstreamTracker = MockRepository.GenerateMock<ITracker>(); var expectedTrackingData = new TrackingData(); downstreamTracker.Expect(x => x.GetTrackingData("abc123")).Return(expectedTrackingData); var t = new TrackingNumberStandardizerTracker(downstreamTracker); var actualTrackingData = t.GetTrackingData("abc 123"); downstreamTracker.VerifyAllExpectations(); }
public void UseDownstreamTracker() { var downstreamTracker = MockRepository.GenerateMock<ITracker>(); var expectedTrackingData = new TrackingData(); downstreamTracker.Expect(x => x.GetTrackingData("abc")).Return(expectedTrackingData); var t = new TrackingNumberStandardizerTracker(downstreamTracker); var actualTrackingData = t.GetTrackingData("abc"); Assert.AreEqual(expectedTrackingData, actualTrackingData); }
public void Pass_On_Valid_Tracking_Data() { var td = new TrackingData(); _eht = new ErrorHandlerTracker(_mockTracker); Expect.Call(_mockTracker.GetTrackingData("Pass_On_Valid_Tracking_Data")).Return(td); _mocks.ReplayAll(); Assert.AreEqual(td, _eht.GetTrackingData("Pass_On_Valid_Tracking_Data")); _mocks.VerifyAll(); }
public void One_Tracker_Verify_Pass_Through() { var td = new TrackingData(); Expect.Call(_mt1.GetTrackingData("abc")).Return(td); _mocks.ReplayAll(); _mt = new MultiTracker(new[] {_mt1}); Assert.AreEqual(td, _mt.GetTrackingData("abc")); _mocks.VerifyAll(); }
/// <summary> /// Gets simulated tracking data for certain tracking numbers. /// </summary> /// <param name="trackingNumber"> /// sim1: Passes back 2 activities, with basic tracking data. /// sim2: Passes back tracking data that has 2 activities that are updated /// every hour. This can be used to test RSS feeds or email data. /// </param> /// <returns></returns> public TrackingData GetTrackingData(string trackingNumber) { var td = new TrackingData(); if (trackingNumber == "sim1") return getSim1TrackingData(); if (trackingNumber == "sim2") return getSim2TrackingData(); if (trackingNumber == "sim3") return getSim3TrackingData(); return null; }
public void No_Tracking_Data_Available() { var td = new TrackingData(); Expect.Call(_mockTracker.GetTrackingData("abc")).Return(null).Repeat.Twice(); _mocks.ReplayAll(); _ct = new CacheTracker(_mockTracker); Assert.AreEqual(null, _ct.GetTrackingData("abc")); Assert.AreEqual(null, _ct.GetTrackingData("abc")); _mocks.VerifyAll(); }
public void Simple_Cache_Check() { var td = new TrackingData(); Expect.Call(_mockTracker.GetTrackingData("abc")).Return(td); _mocks.ReplayAll(); _ct = new CacheTracker(_mockTracker, TimeSpan.FromSeconds(10.0)); _ct.GetTrackingData("abc"); //This should use the passed in tracker _ct.GetTrackingData("abc"); //This should use the cache _mocks.VerifyAll(); }
public void Try_Default_Cache_Time() { var td = new TrackingData(); Expect.Call(_mockTracker.GetTrackingData("abc")).Return(td); _mocks.ReplayAll(); _ct = new CacheTracker(_mockTracker); _ct.GetTrackingData("abc"); //This should use the passed in tracker _ct.GetTrackingData("abc"); //This should use the cache _mocks.VerifyAll(); }
public void Two_Trackers_Both_Work_Verify_Return_First() { var td = new TrackingData(); var td2 = new TrackingData(); Expect.Call(_mt1.GetTrackingData("abc")).Return(td); Expect.Call(_mt2.GetTrackingData("abc")).Return(td2); _mocks.ReplayAll(); _mt = new MultiTracker(new[] {_mt1, _mt2}); Assert.AreEqual(td, _mt.GetTrackingData("abc")); _mocks.VerifyAll(); }
public void Cache_Expired_Recheck_Tracker() { var td = new TrackingData(); Expect.Call(_mockTracker.GetTrackingData("abc")).Return(td).Repeat.Twice(); _mocks.ReplayAll(); _ct = new CacheTracker(_mockTracker, TimeSpan.FromSeconds(1.0)); _ct.GetTrackingData("abc"); //This should use the passed in tracker Thread.Sleep(2000); _ct.GetTrackingData("abc"); //This should use ask the pass in tracker again _mocks.VerifyAll(); }
/// <summary> /// Converts the USPS XML response data into a <see cref="TrackingData"/> instance. /// </summary> /// <param name="xml"> /// The XML response from the API call. /// </param> /// <returns> /// The XML parsed into a <see cref="TrackingData"/> instance. /// </returns> public static TrackingData GetCommonTrackingData(string xml) { _log.Debug("Processing USPS tracking response data: " + xml); try { var td = new TrackingData(); td.Activity = GetActivities(xml); td.UsageRequirements = UsageRequirements; return td; } catch (Exception ex) { throw new ResponseParseException(xml, ex); } }
private void StoreTrackingData(string trackingNumber, TrackingData trackingData) { //If we don't have an internet connection (offline dev), don't use storage if (!System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable()) return; var trackingNumberCacheConnectionString = WebConfigurationManager.AppSettings["TrackingNumberCacheConnectionString"]; //Store some tracking numbers to test with var storageAccount = CloudStorageAccount.Parse(trackingNumberCacheConnectionString); var tableClient = storageAccount.CreateCloudTableClient(); var table = tableClient.GetTableReference("trackrequests"); //This only had to run 1 time //table.CreateIfNotExists(); var data = new TrackingDataEntity(trackingNumber, trackingData); var insert = TableOperation.InsertOrReplace(data); table.BeginExecute(insert, new AsyncCallback(InsertComplete), table); }
public void Test() { var baseTracker = A.Fake<ITracker>(); var geocodeDb = A.Fake<IGeocodeDb>(); var baseTrackingData = new TrackingData(); baseTrackingData.Activity.Add(new Activity {LocationDescription = "Green Bay, WI"}); baseTrackingData.Activity.Add(new Activity {LocationDescription = "Seattle, WA"}); A.CallTo(() => baseTracker.GetTrackingData("abc")).Returns(baseTrackingData); A.CallTo(() => geocodeDb.GetCity("Green Bay", "WI")).Returns(new CityRecord() {Latitude = 10, Longitude = 11}); A.CallTo(() => geocodeDb.GetCity("Seattle", "WA")).Returns(new CityRecord() { Latitude = 12, Longitude = 13 }); var gt = new GeocodingTracker(baseTracker, geocodeDb); var td = gt.GetTrackingData("abc"); Assert.AreEqual(10, td.Activity[0].Latitude); Assert.AreEqual(11, td.Activity[0].Longitude); Assert.AreEqual(12, td.Activity[1].Latitude); Assert.AreEqual(13, td.Activity[1].Longitude); }
private static TrackingData getSim1TrackingData() { var td = new TrackingData(); td.UsageRequirements = "The simulation tracker is for internal use only"; td.TrackerName = "Simulation Tracker"; td.EstimatedDelivery = DateTime.Parse("1-7-15"); td.Activity = new List<Activity>(); var activity = new Activity(); activity.Timestamp = DateTime.Parse("1-6-15 1:30 am"); activity.ShortDescription = "Picked Up"; activity.LocationDescription = "Atlanta, GA"; td.Activity.Add(activity); activity = new Activity(); activity.Timestamp = DateTime.Parse("1-6-15 2:53 pm"); activity.ShortDescription = "Processed"; activity.LocationDescription = "Richmond, VA"; td.Activity.Add(activity); return td; }
public void Two_Trackers_One_Works_Verify_Pass_Through_2() { var td = new TrackingData(); Expect.Call(_mt1.GetTrackingData("abc")).Return(null); Expect.Call(_mt2.GetTrackingData("abc")).Return(td); _mocks.ReplayAll(); _mt = new MultiTracker(new[] {_mt1, _mt2}); Assert.AreEqual(td, _mt.GetTrackingData("abc")); _mocks.VerifyAll(); }
/// <summary> /// Gets the tracking data for the specified tracking number. /// </summary> /// <param name="trackingNumber"> /// The tracking number to get tracking data for. /// </param> /// <returns> /// </returns> public TrackingData GetTrackingData(string trackingNumber) { //Only track it if it's a valid FedEx express or ground number if (!IsFedExExpress(trackingNumber) && !IsFedExGround(trackingNumber) && !IsFedExSmartPost(trackingNumber)) return null; var trackRequest = CreateTrackRequest(_key, _password, _accountNumber, _meterNumber, trackingNumber); //Note: If you get an exception creating the web service, open Reference.cs, and replace all [][]'s with [] //Reference: http://brianseekford.com/index.php/2010/05/06/fedex-integration-address-service-unable-to-generate-a-temporary-class-parsedelement/ //Reference: http://support.microsoft.com/kb/2486643 var resp = _trackService.track(trackRequest); var td = new TrackingData { TrackerName = "FedEx", }; //No activity, no data if(resp == null || resp.TrackDetails == null || resp.TrackDetails.Length == 0) return td; td.EstimatedDelivery = resp.TrackDetails[0].EstimatedDeliveryTimestamp; foreach (var evt in resp.TrackDetails[0].Events) { var a = new Activity(); a.LocationDescription = evt.Address.GetFriendlyAddressString(); a.ShortDescription = evt.EventDescription; a.Timestamp = evt.Timestamp; td.Activity.Add(a); } td.UsageRequirements = UsageRequirements; return td; }
public void SetUp() { _td = new TrackingData(); }
/// <summary> /// Puts the tracking response data into the common /// <see cref="TrackingData"/> format. /// </summary> /// <returns> /// Gets the <see cref="TrackingData"/> that contains the tracking /// information for this response. /// </returns> public static TrackingData GetCommonTrackingData(string xml) { _log.Debug("Processing UPS tracking response data: " + xml); try { var td = new TrackingData(); var xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xml); //Verify that the shipment information is available //in the XML, if it isn't, they must not have any //tracking data yet. var node = xmlDoc.SelectSingleNode("/TrackResponse/Shipment"); if (node == null) return null; node = xmlDoc.SelectSingleNode("/TrackResponse/Shipment/ScheduledDeliveryDate/text()"); if (node != null) td.EstimatedDelivery = UpsFormatConversions.parseUpsDate(node.Value); var nodes = xmlDoc.SelectNodes("/TrackResponse/Shipment/ReferenceNumber/Value/text()"); for (var i = 0; i < nodes.Count; i++) td.ReferenceNumbers.Add(nodes[i].Value); node = xmlDoc.SelectSingleNode("/TrackResponse/Shipment/Service/Description/text()"); if(node != null) td.ServiceType = node.Value; node = xmlDoc.SelectSingleNode("/TrackResponse/Shipment/Package/PackageWeight/Weight/text()"); if(node != null) td.Weight = decimal.Parse(node.Value); td.Activity = getActivities(xmlDoc); td.TrackerName = SHIPPER_NAME; td.UsageRequirements = USAGE_REQUIREMENTS; td.LastUpdated = DateTime.Now; return td; } catch (Exception ex) { throw new ResponseParseException(xml, ex); } }
public void SetUp() { _td = new TrackingData(); }