コード例 #1
0
 /// <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());
 }
コード例 #2
0
 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();
 }
コード例 #3
0
 public EarthquakeContainer(IHttpWebRequestFactory factory)
 {
     appSettings = new AppSettings();
     geonet = new GeonetAccessor(factory);
     geonet.GetQuakesCompletedEvent += QuakeListener;
 }
コード例 #4
0
        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();
        }
コード例 #5
0
 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();
 }