Beispiel #1
0
        public void Yahoo_PlaceFinder_PlaceByName_ShouldConstructWithName()
        {
            var it = new PlaceByName("name");

            it.ShouldNotBeNull();
            it.Name.ShouldEqual("name");
        }
Beispiel #2
0
        public void Yahoo_PlaceFinder_PlaceByName_ShouldAllowNameToBeChanged_AfterConstruction()
        {
            var it = new PlaceByName("name") { Name = "other name" };

            it.ShouldNotBeNull();
            it.Name.ShouldEqual("other name");
        }
Beispiel #3
0
 private Response ChannelFindByName(PlaceByName request, int retry = 0)
 {
     try
     {
         return(Channel.FindByName(request.Name, request.Locale,
                                   request.Start, request.Count, request.Offset,
                                   request.GetFlagsAsString(), request.GetGFlagsAsString(),
                                   request.AppId));
     }
     catch (ProtocolException ex)
     {
         if (retry < RetryLimit && ex.InnerException is WebException)
         {
             return(ChannelFindByName(request, ++retry));
         }
         throw;
     }
     catch (CommunicationException ex)
     {
         if (retry < RetryLimit && ex.Message == "Server Error")
         {
             return(ChannelFindByName(request, ++retry));
         }
         throw;
     }
 }
Beispiel #4
0
        public void Yahoo_PlaceFinder_PlaceByName_ShouldConstructWithName()
        {
            var it = new PlaceByName("name");

            it.ShouldNotBeNull();
            it.Name.ShouldEqual("name");
        }
Beispiel #5
0
 private static BossResponse OAuthFind(PlaceByName request, string consumerKey, string consumerSecret, int retry = 0)
 {
     try
     {
         using (var oAuth = new OAuthClient())
         {
             var json          = oAuth.Get(request.GetUri(), consumerKey, consumerSecret);
             var bossContainer = JsonConvert.DeserializeObject <BossContainer>(json);
             if (bossContainer != null)
             {
                 return(bossContainer.BossResponse);
             }
             throw new InvalidOperationException("Unable to parse BOSS GEO Response. Raw JSON:\r\n" + json);
         }
     }
     catch (ProtocolException ex)
     {
         if (retry < RetryLimit && ex.InnerException is WebException)
         {
             return(OAuthFind(request, consumerKey, consumerSecret, ++retry));
         }
         throw;
     }
     catch (CommunicationException ex)
     {
         if (retry < RetryLimit && ex.Message == "Server Error")
         {
             return(OAuthFind(request, consumerKey, consumerSecret, ++retry));
         }
         throw;
     }
 }
        public ResultSet Find(PlaceByName request, string consumerKey, string consumerSecret)
        {
            if (request == null) throw new ArgumentNullException("request");
            EnsureContractsAreSatisfied(request);

            var response = OAuthFind(request, consumerKey, consumerSecret);
            return response.PlaceFinder;
        }
Beispiel #7
0
 public void Yahoo_PlaceFinder_PlaceBy_ShouldPreserveOffset()
 {
     var request = new PlaceByName("name")
     {
         Offset = 50,
     };
     request.Offset.ShouldEqual(50);
 }
Beispiel #8
0
        public void Yahoo_PlaceFinder_PlaceBy_ShouldPreserveOffset()
        {
            var request = new PlaceByName("name")
            {
                Offset = 50,
            };

            request.Offset.ShouldEqual(50);
        }
Beispiel #9
0
        internal static Uri GetUri(this PlaceByName request)
        {
            const string template = "name={name}";

            var urlBuilder = new StringBuilder(GetBaseUrl(request, template));

            urlBuilder.Replace("{name}", request.Name);

            return(new Uri(urlBuilder.ToString()));
        }
Beispiel #10
0
        public void Yahoo_PlaceFinder_PlaceByName_ShouldAllowNameToBeChanged_AfterConstruction()
        {
            var it = new PlaceByName("name")
            {
                Name = "other name"
            };

            it.ShouldNotBeNull();
            it.Name.ShouldEqual("other name");
        }
Beispiel #11
0
        public ResultSet Find(PlaceByName request, string consumerKey, string consumerSecret)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }
            EnsureContractsAreSatisfied(request);

            var response = OAuthFind(request, consumerKey, consumerSecret);

            return(response.PlaceFinder);
        }
        public void Yahoo_PlaceFinder_PlaceFinderClient_FindByName_ShouldReturn1Result_ForYahooExample()
        {
            using (var client = new PlaceFinderClient())
            {
                var request = new PlaceByName("Yosemite National Park");

                var results = client.Find(request, ConsumerKey, ConsumerSecret);
                results.ShouldNotBeNull();
                results.Results.ShouldNotBeNull();
                results.Count.ShouldEqual(1);
            }
        }
Beispiel #13
0
        public ResultSet Find(PlaceByName request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }
            EnsureContractsAreSatisfied(request);

            var response = ChannelFindByName(request);

            return(response.ResultSet);
        }
        public void Yahoo_PlaceFinder_PlaceFinderClient_ShouldEnsureStreetDetailFlagIsRemoved()
        {
            using (var client = new PlaceFinderClient())
            {
                var request = new PlaceByName("Eiffel Tower")
                {
                    Flags = new HashSet <Flag>
                    {
                        Flag.StreetDetail,
                    }
                };

                var results = client.Find(request, ConsumerKey, ConsumerSecret);
                results.ShouldNotBeNull();
                request.Flags.ShouldNotContain(Flag.StreetDetail);
            }
        }
        public void Yahoo_PlaceFinder_PlaceFinderClient_ShouldEnsurePhpFlagIsRemoved()
        {
            using (var client = new PlaceFinderClient())
            {
                var request = new PlaceByName("Great Pyramids")
                {
                    Flags = new HashSet <Flag>
                    {
                        Flag.Php,
                    }
                };

                var results = client.Find(request, ConsumerKey, ConsumerSecret);
                results.ShouldNotBeNull();
                request.Flags.ShouldNotContain(Flag.Php);
            }
        }
        public void Yahoo_PlaceFinder_PlaceFinderClient_ShouldEnsureStreetDetailFlagIsRemoved()
        {
            using (var client = new PlaceFinderClient())
            {
                var request = new PlaceByName("Eiffel Tower")
                {
                    Flags = new HashSet<Flag>
                    {
                        Flag.StreetDetail,
                    }
                };

                var results = client.Find(request);
                results.ShouldNotBeNull();
                request.Flags.ShouldNotContain(Flag.StreetDetail);
            }
        }
        public void Yahoo_PlaceFinder_PlaceFinderClient_ShouldEnsurePhpFlagIsRemoved()
        {
            using (var client = new PlaceFinderClient())
            {
                var request = new PlaceByName("Great Pyramids")
                {
                    Flags = new HashSet<Flag>
                    {
                        Flag.Php,
                    }
                };

                var results = client.Find(request);
                results.ShouldNotBeNull();
                request.Flags.ShouldNotContain(Flag.Php);
            }
        }
        public void Yahoo_PlaceFinder_PlaceFinderClient_FindByName_ShouldReturn1Result_ForYahooExample()
        {
            using (var client = new PlaceFinderClient())
            {
                var request = new PlaceByName("Yosemite National Park");

                var results = client.Find(request);
                results.ShouldNotBeNull();
                results.Results.ShouldNotBeNull();
                results.Results.Count.ShouldEqual(1);
            }
        }
 private static BossResponse OAuthFind(PlaceByName request, string consumerKey, string consumerSecret, int retry = 0)
 {
     try
     {
         using (var oAuth = new OAuthClient())
         {
             var json = oAuth.Get(request.GetUri(), consumerKey, consumerSecret);
             var bossContainer = JsonConvert.DeserializeObject<BossContainer>(json);
             if (bossContainer != null) return bossContainer.BossResponse;
             throw new InvalidOperationException("Unable to parse BOSS GEO Response. Raw JSON:\r\n" + json);
         }
     }
     catch (ProtocolException ex)
     {
         if (retry < RetryLimit && ex.InnerException is WebException)
             return OAuthFind(request, consumerKey, consumerSecret, ++retry);
         throw;
     }
     catch (CommunicationException ex)
     {
         if (retry < RetryLimit && ex.Message == "Server Error")
             return OAuthFind(request, consumerKey, consumerSecret, ++retry);
         throw;
     }
 }