/// <remarks>
 /// ScheduledAgent constructor, initializes the UnhandledException handler
 /// </remarks>
 public ScheduledAgent()
 {
     TileTitle = AppResources.LiveTileDefaultTitle;
     if (!_classInitialized)
     {
         _classInitialized = true;
         // Subscribe to the managed exception handler
         Deployment.Current.Dispatcher.BeginInvoke(delegate
         {
             Application.Current.UnhandledException += ScheduledAgent_UnhandledException;
         });
     }
     geonet = new GeonetAccessor(new HttpWebRequestFactory());
 }
 public void TestGetQuakesHandlesBadJson()
 {
     var response = new Mocks.HttpWebResponse
     {
         getResponseStream = () => new System.IO.MemoryStream(
             System.Text.Encoding.UTF8.GetBytes(badJson))
     };
     var request = new Mocks.HttpWebRequest
     {
         getResponse = () => response
     };
     GeonetAccessor geonet = new GeonetAccessor(new Mocks.HttpWebRequestFactory
     {
         create = _ => request
     });
     geonet.GetQuakesCompletedEvent += (sender, e) =>
     {
         Assert.AreEqual(geonet, sender);
         Assert.AreEqual(GeonetSuccessStatus.BadGeonetData, e.Status);
         Assert.AreEqual(0, e.Quakes.Count);
         EnqueueTestComplete();
     };
     geonet.GetQuakes();
 }
 public EarthquakeContainer(IHttpWebRequestFactory factory)
 {
     appSettings = new AppSettings();
     geonet = new GeonetAccessor(factory);
     geonet.GetQuakesCompletedEvent += QuakeListener;
 }
        public void TestGetQuakesUsesCorrectUrl()
        {
            AppSettings settings = new AppSettings();

            var response = new Mocks.HttpWebResponse
            {
                getResponseStream = () => new System.IO.MemoryStream(
                    System.Text.Encoding.UTF8.GetBytes(goodJson))
            };
            var request = new Mocks.HttpWebRequest
            {
                getResponse = () => response
            };

            // 'felt' quakes is used
            settings.UseGeonetAllQuakesEndpointSetting = false;
            GeonetAccessor geonet = new GeonetAccessor(new Mocks.HttpWebRequestFactory
            {
                create = (url) => {
                    Assert.AreEqual(GeonetEndpoints.FeltQuakes, url.AbsoluteUri);
                    return request;
                }
            });
            geonet.GetQuakes();

            // 'all' quakes is used
            settings.UseGeonetAllQuakesEndpointSetting = true;
            geonet = new GeonetAccessor(new Mocks.HttpWebRequestFactory
            {
                create = (url) =>
                {
                    Assert.AreEqual(GeonetEndpoints.AllQuakes, url.AbsoluteUri);
                    EnqueueTestComplete();
                    return request;
                }
            });
            geonet.GetQuakes();
        }
 public void TestGetQuakesHandlesNoConnection()
 {
     var request = new Mocks.HttpWebRequest
     {
         getResponse = () => { throw new WebException(); }
     };
     GeonetAccessor geonet = new GeonetAccessor(new Mocks.HttpWebRequestFactory
     {
         create = _ => request
     });
     geonet.GetQuakesCompletedEvent += (sender, e) => {
         Assert.AreEqual(geonet, sender);
         Assert.AreEqual(GeonetSuccessStatus.NetworkFailure, e.Status);
         Assert.AreEqual(0, e.Quakes.Count);
         EnqueueTestComplete();
     };
     geonet.GetQuakes();
 }