public void TestDepthFormatting() { Earthquake quake = new Earthquake(); quake.Depth = 102.13; Assert.AreEqual("102", quake.FormattedDepth); Assert.AreEqual(102.0, quake.Depth); quake.Depth = 102.03; Assert.AreEqual("102", quake.FormattedDepth); Assert.AreEqual(102.0, quake.Depth); quake.Depth = 102.73; Assert.AreEqual("103", quake.FormattedDepth); Assert.AreEqual(103.0, quake.Depth); // Test fails - "bankers rounding" (round to nearest even number when .5) // is our only option as we don't have the overloads to specify what to // do in this situation. Sigh. //quake.Depth = 102.5; //Assert.AreEqual("103", quake.FormattedDepth); //Assert.AreEqual(103.0, quake.Depth); quake.Depth = 102.0; Assert.AreEqual("102", quake.FormattedDepth); Assert.AreEqual(102.0, quake.Depth); }
public IEnumerable<Earthquake> ParseJsonToQuakes(string json) { try { JObject o = JObject.Parse(json); List<Earthquake> quakes = new List<Earthquake>(30); foreach (var q in o["features"].Children()) { Earthquake quake = new Earthquake { Location = new GeoCoordinate(q["geometry"]["coordinates"].Values<double>().ElementAt(1), q["geometry"]["coordinates"].Values<double>().ElementAt(0)), Depth = (double)q["properties"]["depth"], Magnitude = (double)q["properties"]["magnitude"], Reference = (string)q["properties"]["publicid"], /* origintime=2012-08-13 05:25:24.727000 (that's in UTC) */ Date = DateTime.Parse((string)q["properties"]["origintime"] + "Z"), Agency = (string)q["properties"]["agency"], Status = (string)q["properties"]["status"] }; quakes.Add(quake); } return quakes.OrderByDescending(q => q.Date); } catch (Exception e) { throw new JsonException("Problem with JSON data", e); } }
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { string quakeQueryString = string.Empty; if (NavigationContext.QueryString.TryGetValue("quake", out quakeQueryString)) { quake = Earthquake.DeserializeFromQueryString(quakeQueryString); } else return; ContentPanel.DataContext = quake; QuakeMap.Center = quake.Location; Pushpin pin = new Pushpin { GeoCoordinate = quake.Location, Content = quake.FormattedMagnitude }; if (quake.Magnitude >= appSettings.MinimumWarningMagnitudeSetting) pin.Background = Application.Current.Resources["PhoneAccentBrush"] as SolidColorBrush; MapOverlay overlay = new MapOverlay(); overlay.Content = pin; overlay.GeoCoordinate = quake.Location; overlay.PositionOrigin = new Point(0, 1); MapLayer layer = new MapLayer(); layer.Add(overlay); QuakeMap.Layers.Add(layer); base.OnNavigatedTo(e); }
public void TestMagnitudeFormatting() { Earthquake quake = new Earthquake(); quake.Magnitude = 3.13; Assert.AreEqual("3.1", quake.FormattedMagnitude); Assert.AreEqual(3.1, quake.Magnitude); quake.Magnitude = 3.02; Assert.AreEqual("3.0", quake.FormattedMagnitude); Assert.AreEqual(3.0, quake.Magnitude); quake.Magnitude = 3.96; Assert.AreEqual("4.0", quake.FormattedMagnitude); Assert.AreEqual(4.0, quake.Magnitude); quake.Magnitude = 3.15; Assert.AreEqual("3.2", quake.FormattedMagnitude); Assert.AreEqual(3.2, quake.Magnitude); quake.Magnitude = 3.0; Assert.AreEqual("3.0", quake.FormattedMagnitude); Assert.AreEqual(3.0, quake.Magnitude); }
protected void NavigateToQuakePage(Earthquake quake) { string navUri = string.Format("/QuakeDisplayPage.xaml?quake={0}", quake.SerializeToQueryString()); NavigationService.Navigate(new Uri(navUri, UriKind.Relative)); }