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 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();
 }