public void BuildUrlForSearch_WithQueryButNotLatLongAndIP_ExpectSuccess() { const string ExpectedUrl = "https://api.twitter.com/1.1/geo/search.json?query=Twitter%20HQ&accuracy=city&granularity=10&max_results=10&contained_within=123&attribute%3Astreet_address=123"; var geoReqProc = new GeoRequestProcessor <Geo>() { BaseUrl = "https://api.twitter.com/1.1/" }; var parameters = new Dictionary <string, string> { { "Type", ((int)GeoType.Search).ToString() }, //{"Latitude", (37.78215).ToString()}, //{"Longitude", (-122.40060).ToString()}, { "Query", "Twitter HQ" }, //{"IP", "168.143.171.180"}, { "Accuracy", "city" }, { "Granularity", "10" }, { "MaxResults", "10" }, { "ContainedWithin", "123" }, { "Attribute", "street_address=123" } }; Request req = geoReqProc.BuildUrl(parameters); Assert.AreEqual(ExpectedUrl, req.FullUrl); }
public void GetParameters_Parses_Parameters() { var geoReqProc = new GeoRequestProcessor <Geo>(); Expression <Func <Geo, bool> > expression = geo => geo.Type == GeoType.Reverse && geo.Accuracy == "10" && geo.Granularity == "city" && geo.Latitude == 37.78215 && geo.Longitude == -122.40060 && geo.MaxResults == 10 && geo.ID == "456" && geo.IP == "168.143.171.180" && geo.Query == "place" && geo.ContainedWithin == "abc" && geo.Attribute == "street_address=123" && geo.PlaceName == "placeName"; var lambdaExpression = expression as LambdaExpression; var queryParams = geoReqProc.GetParameters(lambdaExpression); Assert.IsTrue( queryParams.Contains( new KeyValuePair <string, string>("Type", ((int)GeoType.Reverse).ToString()))); Assert.IsTrue( queryParams.Contains( new KeyValuePair <string, string>("Accuracy", "10"))); Assert.IsTrue( queryParams.Contains( new KeyValuePair <string, string>("Granularity", "city"))); Assert.IsTrue( queryParams.Contains( new KeyValuePair <string, string>("Latitude", (37.78215).ToString()))); Assert.IsTrue( queryParams.Contains( new KeyValuePair <string, string>("Longitude", (-122.4006).ToString()))); Assert.IsTrue( queryParams.Contains( new KeyValuePair <string, string>("MaxResults", "10"))); Assert.IsTrue( queryParams.Contains( new KeyValuePair <string, string>("ID", "456"))); Assert.IsTrue( queryParams.Contains( new KeyValuePair <string, string>("IP", "168.143.171.180"))); Assert.IsTrue( queryParams.Contains( new KeyValuePair <string, string>("Query", "place"))); Assert.IsTrue( queryParams.Contains( new KeyValuePair <string, string>("ContainedWithin", "abc"))); Assert.IsTrue( queryParams.Contains( new KeyValuePair <string, string>("Attribute", "street_address=123"))); Assert.IsTrue( queryParams.Contains( new KeyValuePair <string, string>("PlaceName", "placeName"))); }
public void GetParameters_Parses_Parameters() { var geoReqProc = new GeoRequestProcessor<Geo>(); Expression<Func<Geo, bool>> expression = geo => geo.Type == GeoType.Reverse && geo.Accuracy == "10" && geo.Granularity == "city" && geo.Latitude == 37.78215 && geo.Longitude == -122.40060 && geo.MaxResults == 10 && geo.ID == "456" && geo.IP == "168.143.171.180" && geo.Query == "place" && geo.ContainedWithin == "abc" && geo.Attribute == "street_address=123" && geo.PlaceName == "placeName"; var lambdaExpression = expression as LambdaExpression; var queryParams = geoReqProc.GetParameters(lambdaExpression); Assert.IsTrue( queryParams.Contains( new KeyValuePair<string, string>("Type", ((int)GeoType.Reverse).ToString()))); Assert.IsTrue( queryParams.Contains( new KeyValuePair<string, string>("Accuracy", "10"))); Assert.IsTrue( queryParams.Contains( new KeyValuePair<string, string>("Granularity", "city"))); Assert.IsTrue( queryParams.Contains( new KeyValuePair<string, string>("Latitude", (37.78215).ToString()))); Assert.IsTrue( queryParams.Contains( new KeyValuePair<string, string>("Longitude", (-122.4006).ToString()))); Assert.IsTrue( queryParams.Contains( new KeyValuePair<string, string>("MaxResults", "10"))); Assert.IsTrue( queryParams.Contains( new KeyValuePair<string, string>("ID", "456"))); Assert.IsTrue( queryParams.Contains( new KeyValuePair<string, string>("IP", "168.143.171.180"))); Assert.IsTrue( queryParams.Contains( new KeyValuePair<string, string>("Query", "place"))); Assert.IsTrue( queryParams.Contains( new KeyValuePair<string, string>("ContainedWithin", "abc"))); Assert.IsTrue( queryParams.Contains( new KeyValuePair<string, string>("Attribute", "street_address=123"))); Assert.IsTrue( queryParams.Contains( new KeyValuePair<string, string>("PlaceName", "placeName"))); }
public void ProcessIDResultsTest() { GeoRequestProcessor <Geo> target = new GeoRequestProcessor <Geo>(); XElement twitterResponse = XElement.Parse(m_idResponse); List <Geo> actual = (List <Geo>)target.ProcessResults(twitterResponse); Assert.AreEqual("San Francisco", actual[0].Places[0].Name); }
public void ProcessReverseResultsCultureInsensitiveTest() { GeoRequestProcessor <Geo> target = new GeoRequestProcessor <Geo>(); XElement twitterResponse = XElement.Parse(m_reverseResponse); List <Geo> actual = (List <Geo>)target.ProcessResults(twitterResponse); Assert.AreEqual(5, actual[0].Places.Count); }
public void BuildNearbyURLWithoutArgsTest() { GeoRequestProcessor <Geo> target = new GeoRequestProcessor <Geo>() { BaseUrl = "https://api.twitter.com/1/" }; var parameters = new Dictionary <string, string> { { "Type", ((int)GeoType.Nearby).ToString() }, }; string actual = target.BuildURL(parameters); }
public void ProcessResults_Handles_ReverseGeoCode_Response() { const int ExpectedPlacesCount = 4; var geoReqProc = new GeoRequestProcessor <Geo>(); List <Geo> geo = geoReqProc.ProcessResults(MultiPlaceResponse); Assert.IsNotNull(geo); Assert.IsNotNull(geo.SingleOrDefault()); Assert.IsNotNull(geo.Single().Places); Assert.AreEqual(ExpectedPlacesCount, geo.Single().Places.Count); }
public void ProcessResults_Returns_Empty_Collection_When_Empty_Results() { var geoReqProc = new GeoRequestProcessor <Geo>() { BaseUrl = "https://api.twitter.com/1.1/" }; var geo = geoReqProc.ProcessResults(string.Empty); Assert.IsNotNull(geo); Assert.IsFalse(geo.Any()); }
public static Place CreatePlace(this TwitterContext ctx, string name, string containedWithin, string token, double latitude, double longitude, string attribute, Action<TwitterAsyncResponse<User>> callback) { if (string.IsNullOrEmpty(name)) { throw new ArgumentException("name is a required parameter.", "name"); } if (string.IsNullOrEmpty(containedWithin)) { throw new ArgumentException("containedWithin is a required parameter.", "containedWithin"); } if (string.IsNullOrEmpty(token)) { throw new ArgumentException("token is a required parameter.", "token"); } if (latitude == 0) { throw new ArgumentException("latitude is a required parameter.", "latitude"); } if (longitude == 0) { throw new ArgumentException("longitude is a required parameter.", "longitude"); } string placeUrl = ctx.BaseUrl + "geo/place.json"; var createParams = new Dictionary<string, string> { { "name", name }, { "contained_within", containedWithin }, { "token", token }, { "lat", latitude.ToString(Culture.US) }, { "long", longitude.ToString(Culture.US) }, { "attribute", name } }; var reqProc = new GeoRequestProcessor<Place>(); ITwitterExecute twitExe = ctx.TwitterExecutor; twitExe.AsyncCallback = callback; var resultsJson = twitExe.PostToTwitter( placeUrl, createParams, response => reqProc.ProcessActionResult(response, GeoAction.CreatePlace)); Place results = reqProc.ProcessActionResult(resultsJson, GeoAction.CreatePlace); return results; }
public void ProcessResults_Handles_ID_Response() { const string ExpectedPlaceName = "San Francisco"; var geoReqProc = new GeoRequestProcessor <Geo> { Type = GeoType.ID }; List <Geo> geo = geoReqProc.ProcessResults(IDResponse); Assert.NotNull(geo); Assert.Single(geo); Assert.NotNull(geo.Single().Places); Assert.Equal(ExpectedPlaceName, geo.Single().Places.First().Name); }
public void ProcessResultsForID_WithNullGeometry_ExpectSucces() { const string ExpectedPlaceName = "San Francisco"; var geoReqProc = new GeoRequestProcessor <Geo> { Type = GeoType.ID }; List <Geo> geo = geoReqProc.ProcessResults(IDResponseWithNullGeometry); Assert.IsNotNull(geo); Assert.IsNotNull(geo.SingleOrDefault()); Assert.IsNotNull(geo.Single().Places); Assert.AreEqual(ExpectedPlaceName, geo.Single().Places.First().Name); }
public void BuildReverseURLWithoutLatLongTest() { GeoRequestProcessor <Geo> target = new GeoRequestProcessor <Geo>() { BaseUrl = "https://api.twitter.com/1/" }; var parameters = new Dictionary <string, string> { { "Type", ((int)GeoType.Reverse).ToString() }, { "Accuracy", "city" }, { "Granularity", "10" }, { "MaxResults", "10" } }; string actual = target.BuildURL(parameters); }
public void BuildNearbyURLTest() { GeoRequestProcessor <Geo> target = new GeoRequestProcessor <Geo>() { BaseUrl = "https://api.twitter.com/1/" }; var parameters = new Dictionary <string, string> { { "Type", ((int)GeoType.Nearby).ToString() }, { "IP", "168.143.171.180" }, }; string expected = "https://api.twitter.com/1/geo/nearby_places.json?ip=168.143.171.180"; string actual = target.BuildURL(parameters); Assert.AreEqual(expected, actual); }
public void BuildIDURLTest() { GeoRequestProcessor <Geo> target = new GeoRequestProcessor <Geo>() { BaseUrl = "https://api.twitter.com/1/" }; var parameters = new Dictionary <string, string> { { "Type", ((int)GeoType.ID).ToString() }, { "ID", "7695dd2ec2f86f2b" }, }; string expected = "https://api.twitter.com/1/geo/id/7695dd2ec2f86f2b.json"; string actual = target.BuildURL(parameters); Assert.AreEqual(expected, actual); }
public void BuildUrl_ID_Without_ID_Throws() { const string ExpectedIDParamName = "ID"; var geoReqProc = new GeoRequestProcessor <Geo>() { BaseUrl = "https://api.twitter.com/1.1/" }; var parameters = new Dictionary <string, string> { { "Type", ((int)GeoType.ID).ToString() }, }; var ex = L2TAssert.Throws <ArgumentException>(() => geoReqProc.BuildUrl(parameters)); Assert.AreEqual(ExpectedIDParamName, ex.ParamName); }
public void ProcessResults_Handles_Search_Response() { const int ExpectedPlacesCount = 4; const string ExpectedPlaceFullName = "SoMa, San Francisco"; var geoReqProc = new GeoRequestProcessor <Geo> { Type = GeoType.Search }; List <Geo> geo = geoReqProc.ProcessResults(MultiPlaceResponse); Assert.IsNotNull(geo); Assert.IsNotNull(geo.SingleOrDefault()); Assert.IsNotNull(geo.Single().Places); Assert.AreEqual(ExpectedPlacesCount, geo.Single().Places.Count); Assert.AreEqual(ExpectedPlaceFullName, geo.Single().Places.First().FullName); }
public void BuildUrl_Constructs_ID_Url() { const string ExpectedUrl = "https://api.twitter.com/1.1/geo/id/7695dd2ec2f86f2b.json"; var geoReqProc = new GeoRequestProcessor <Geo>() { BaseUrl = "https://api.twitter.com/1.1/" }; var parameters = new Dictionary <string, string> { { "Type", ((int)GeoType.ID).ToString() }, { "ID", "7695dd2ec2f86f2b" }, }; Request req = geoReqProc.BuildUrl(parameters); Assert.AreEqual(ExpectedUrl, req.FullUrl); }
public void BuildUrl_Search_With_Attribute_Missing_Equals_Symbol_Throws() { const string ExpectedAttributeParam = "Attribute"; var geoReqProc = new GeoRequestProcessor <Geo>() { BaseUrl = "https://api.twitter.com/1.1/" }; var parameters = new Dictionary <string, string> { { "Type", ((int)GeoType.Search).ToString() }, { "IP", "168.143.171.180" }, { "Attribute", "street_address" } }; var ex = L2TAssert.Throws <ArgumentException>(() => geoReqProc.BuildUrl(parameters)); Assert.AreEqual(ExpectedAttributeParam, ex.ParamName); }
public void BuildUrl_Constructs_Reverse_Url() { const string ExpectedUrl = "https://api.twitter.com/1.1/geo/reverse_geocode.json?lat=37.78215&long=-122.4006&accuracy=city&granularity=10&max_results=10"; var geoReqProc = new GeoRequestProcessor<Geo>() { BaseUrl = "https://api.twitter.com/1.1/" }; var parameters = new Dictionary<string, string> { {"Type", ((int) GeoType.Reverse).ToString()}, {"Latitude", "37.78215"}, {"Longitude", "-122.40060"}, {"Accuracy", "city" }, {"Granularity", "10" }, {"MaxResults", "10" } }; Request req = geoReqProc.BuildUrl(parameters); Assert.AreEqual(ExpectedUrl, req.FullUrl); }
public void BuildUrlReverseL_WithoutLatLongIPOrQuery_ExpectException() { const string ExpectedLatLongParamName = "LatLong"; var geoReqProc = new GeoRequestProcessor <Geo>() { BaseUrl = "https://api.twitter.com/1.1/" }; var parameters = new Dictionary <string, string> { { "Type", ((int)GeoType.Reverse).ToString() }, { "Accuracy", "city" }, { "Granularity", "10" }, { "MaxResults", "10" } }; var ex = L2TAssert.Throws <ArgumentException>(() => geoReqProc.BuildUrl(parameters)); Assert.AreEqual(ExpectedLatLongParamName, ex.ParamName); }
public void GetParametersTest() { var geoReqProc = new GeoRequestProcessor <Geo>(); Expression <Func <Geo, bool> > expression = geo => geo.Type == GeoType.Reverse && geo.Accuracy == "10" && geo.Granularity == "city" && geo.Latitude == 37.78215 && geo.Longitude == -122.40060 && geo.MaxResults == 10 && geo.ID == "456" && geo.IP == "168.143.171.180"; LambdaExpression lambdaExpression = expression as LambdaExpression; var queryParams = geoReqProc.GetParameters(lambdaExpression); Assert.IsTrue( queryParams.Contains( new KeyValuePair <string, string>("Type", ((int)GeoType.Reverse).ToString()))); Assert.IsTrue( queryParams.Contains( new KeyValuePair <string, string>("Accuracy", "10"))); Assert.IsTrue( queryParams.Contains( new KeyValuePair <string, string>("Granularity", "city"))); Assert.IsTrue( queryParams.Contains( new KeyValuePair <string, string>("Latitude", "37.78215"))); Assert.IsTrue( queryParams.Contains( new KeyValuePair <string, string>("Longitude", "-122.4006"))); Assert.IsTrue( queryParams.Contains( new KeyValuePair <string, string>("MaxResults", "10"))); Assert.IsTrue( queryParams.Contains( new KeyValuePair <string, string>("ID", "456"))); Assert.IsTrue( queryParams.Contains( new KeyValuePair <string, string>("IP", "168.143.171.180"))); }
public void BuildUrl_Constructs_Similar_Places_Url() { const string ExpectedUrl = "https://api.twitter.com/1.1/geo/similar_places.json?lat=37.78215&long=-122.4006&name=placeName&contained_within=123&attribute%3Astreet_address=123"; var geoReqProc = new GeoRequestProcessor <Geo>() { BaseUrl = "https://api.twitter.com/1.1/" }; var parameters = new Dictionary <string, string> { { "Type", ((int)GeoType.SimilarPlaces).ToString() }, { "Latitude", (37.78215).ToString() }, { "Longitude", (-122.40060).ToString() }, { "PlaceName", "placeName" }, { "ContainedWithin", "123" }, { "Attribute", "street_address=123" } }; Request req = geoReqProc.BuildUrl(parameters); Assert.AreEqual(ExpectedUrl, req.FullUrl); }
public void BuildReverseURLTest() { GeoRequestProcessor <Geo> target = new GeoRequestProcessor <Geo>() { BaseUrl = "https://api.twitter.com/1/" }; var parameters = new Dictionary <string, string> { { "Type", ((int)GeoType.Reverse).ToString() }, { "Latitude", "37.78215" }, { "Longitude", "-122.40060" }, { "Accuracy", "city" }, { "Granularity", "10" }, { "MaxResults", "10" } }; string expected = "https://api.twitter.com/1/geo/reverse_geocode.json?lat=37.78215&long=-122.40060&accuracy=city&granularity=10&max_results=10"; string actual; actual = target.BuildURL(parameters); Assert.AreEqual(expected, actual); }
public void BuildUrl_For_Similar_Places_Requires_PlaceName() { const string ExpectedParamName = "PlaceName"; var geoReqProc = new GeoRequestProcessor <Geo>() { BaseUrl = "https://api.twitter.com/1.1/" }; var parameters = new Dictionary <string, string> { { "Type", ((int)GeoType.SimilarPlaces).ToString() }, { "Latitude", "37.78215" }, { "Longitude", "-122.40060" }, //{"PlaceName", "placeName" }, { "ContainedWithin", "123" }, { "Attribute", "street_address=123" } }; var ex = L2TAssert.Throws <ArgumentException>(() => geoReqProc.BuildUrl(parameters)); Assert.AreEqual(ExpectedParamName, ex.ParamName); }
public void BuildUrl_Constructs_Reverse_Url() { const string ExpectedUrl = "https://api.twitter.com/1.1/geo/reverse_geocode.json?lat=37.78215&long=-122.4006&accuracy=city&granularity=10&max_results=10"; var geoReqProc = new GeoRequestProcessor <Geo>() { BaseUrl = "https://api.twitter.com/1.1/" }; var parameters = new Dictionary <string, string> { { "Type", ((int)GeoType.Reverse).ToString() }, { "Latitude", "37.78215" }, { "Longitude", "-122.40060" }, { "Accuracy", "city" }, { "Granularity", "10" }, { "MaxResults", "10" } }; Request req = geoReqProc.BuildUrl(parameters); Assert.AreEqual(ExpectedUrl, req.FullUrl); }
public void ProcessResults_Handles_Simlar_Places_Response() { const int ExpectedPlacesCount = 4; const string ExpectedPlaceFullName = "SoMa, San Francisco"; const string ExpectedToken = "15f3c6f2b94ba19faee70d9d61aaebee"; var geoReqProc = new GeoRequestProcessor <Geo> { Type = GeoType.SimilarPlaces }; List <Geo> geoResponse = geoReqProc.ProcessResults(MultiPlaceResponse); Assert.IsNotNull(geoResponse); Assert.IsNotNull(geoResponse.SingleOrDefault()); var geo = geoResponse.Single(); Assert.AreEqual(ExpectedToken, geo.Token); var places = geo.Places; Assert.IsNotNull(places); Assert.AreEqual(ExpectedPlacesCount, places.Count); Assert.AreEqual(ExpectedPlaceFullName, places.First().FullName); }
public void BuildUrl_Constructs_ID_Url() { const string ExpectedUrl = "https://api.twitter.com/1.1/geo/id/7695dd2ec2f86f2b.json"; var geoReqProc = new GeoRequestProcessor<Geo>() { BaseUrl = "https://api.twitter.com/1.1/" }; var parameters = new Dictionary<string, string> { {"Type", ((int) GeoType.ID).ToString()}, {"ID", "7695dd2ec2f86f2b"}, }; Request req = geoReqProc.BuildUrl(parameters); Assert.Equal(ExpectedUrl, req.FullUrl); }
public void BuildNearbyURLTest() { GeoRequestProcessor<Geo> target = new GeoRequestProcessor<Geo>() { BaseUrl = "https://api.twitter.com/1/" }; var parameters = new Dictionary<string, string> { {"Type", ((int) GeoType.Nearby).ToString()}, {"IP", "168.143.171.180"}, }; string expected = "https://api.twitter.com/1/geo/nearby_places.json?ip=168.143.171.180"; string actual = target.BuildURL(parameters); Assert.AreEqual(expected, actual); }
public void ProcessResults_Handles_Simlar_Places_Response() { const int ExpectedPlacesCount = 4; const string ExpectedPlaceFullName = "SoMa, San Francisco"; const string ExpectedToken = "15f3c6f2b94ba19faee70d9d61aaebee"; var geoReqProc = new GeoRequestProcessor<Geo> { Type = GeoType.SimilarPlaces }; List<Geo> geoResponse = geoReqProc.ProcessResults(MultiPlaceResponse); Assert.NotNull(geoResponse); Assert.Single(geoResponse); var geo = geoResponse.Single(); Assert.Equal(ExpectedToken, geo.Token); var places = geo.Places; Assert.NotNull(places); Assert.Equal(ExpectedPlacesCount, places.Count); Assert.Equal(ExpectedPlaceFullName, places.First().FullName); }
public void ProcessResults_Handles_ReverseGeoCode_Response() { const int ExpectedPlacesCount = 4; var geoReqProc = new GeoRequestProcessor<Geo>(); List<Geo> geo = geoReqProc.ProcessResults(MultiPlaceResponse); Assert.NotNull(geo); Assert.Single(geo); Assert.NotNull(geo.Single().Places); Assert.Equal(ExpectedPlacesCount, geo.Single().Places.Count); }
public void GeoRequestProcessor_Processes_Json_Format_Responses() { var geoReqProc = new GeoRequestProcessor<Geo>(); Assert.IsAssignableFrom<IRequestProcessorWantsJson>(geoReqProc); }
public void BuildUrl_ReverseL_Without_LatLong_Throws() { const string ExpectedLatLongParamName = "LatLong"; var geoReqProc = new GeoRequestProcessor<Geo>() { BaseUrl = "https://api.twitter.com/1.1/" }; var parameters = new Dictionary<string, string> { {"Type", ((int) GeoType.Reverse).ToString()}, {"Accuracy", "city" }, {"Granularity", "10" }, {"MaxResults", "10" } }; var ex = Assert.Throws<ArgumentException>(() => geoReqProc.BuildUrl(parameters)); Assert.Equal(ExpectedLatLongParamName, ex.ParamName); }
public void BuildUrl_For_Similar_Places_Requires_PlaceName() { const string ExpectedParamName = "PlaceName"; var geoReqProc = new GeoRequestProcessor<Geo>() { BaseUrl = "https://api.twitter.com/1.1/" }; var parameters = new Dictionary<string, string> { {"Type", ((int) GeoType.SimilarPlaces).ToString()}, {"Latitude", "37.78215"}, {"Longitude", "-122.40060"}, //{"PlaceName", "placeName" }, {"ContainedWithin", "123" }, {"Attribute", "street_address=123" } }; var ex = Assert.Throws<ArgumentException>(() => geoReqProc.BuildUrl(parameters)); Assert.Equal(ExpectedParamName, ex.ParamName); }
public void BuildReverseURLWithoutLatLongTest() { GeoRequestProcessor<Geo> target = new GeoRequestProcessor<Geo>() { BaseUrl = "https://api.twitter.com/1/" }; var parameters = new Dictionary<string, string> { {"Type", ((int) GeoType.Reverse).ToString()}, {"Accuracy", "city" }, {"Granularity", "10" }, {"MaxResults", "10" } }; string actual = target.BuildURL(parameters); }
public void GetParametersTest() { var geoReqProc = new GeoRequestProcessor<Geo>(); Expression<Func<Geo, bool>> expression = geo => geo.Type == GeoType.Reverse && geo.Accuracy == "10" && geo.Granularity == "city" && geo.Latitude == 37.78215 && geo.Longitude == -122.40060 && geo.MaxResults == 10 && geo.ID == "456" && geo.IP == "168.143.171.180"; LambdaExpression lambdaExpression = expression as LambdaExpression; var queryParams = geoReqProc.GetParameters(lambdaExpression); Assert.IsTrue( queryParams.Contains( new KeyValuePair<string, string>("Type", ((int)GeoType.Reverse).ToString()))); Assert.IsTrue( queryParams.Contains( new KeyValuePair<string, string>("Accuracy", "10"))); Assert.IsTrue( queryParams.Contains( new KeyValuePair<string, string>("Granularity", "city"))); Assert.IsTrue( queryParams.Contains( new KeyValuePair<string, string>("Latitude", "37.78215"))); Assert.IsTrue( queryParams.Contains( new KeyValuePair<string, string>("Longitude", "-122.4006"))); Assert.IsTrue( queryParams.Contains( new KeyValuePair<string, string>("MaxResults", "10"))); Assert.IsTrue( queryParams.Contains( new KeyValuePair<string, string>("ID", "456"))); Assert.IsTrue( queryParams.Contains( new KeyValuePair<string, string>("IP", "168.143.171.180"))); }
public void ProcessIDResultsTest() { GeoRequestProcessor<Geo> target = new GeoRequestProcessor<Geo>(); XElement twitterResponse = XElement.Parse(m_idResponse); List<Geo> actual = (List<Geo>)target.ProcessResults(twitterResponse); Assert.AreEqual("San Francisco", actual[0].Places[0].Name); }
public void ProcessReverseResultsTest() { GeoRequestProcessor<Geo> target = new GeoRequestProcessor<Geo>(); XElement twitterResponse = XElement.Parse(m_reverseResponse); List<Geo> actual = (List<Geo>)target.ProcessResults(twitterResponse); Assert.AreEqual(5, actual[0].Places.Count); }
public void GeoRequestProcessor_Processes_Json_Format_Responses() { var geoReqProc = new GeoRequestProcessor <Geo>(); Assert.IsInstanceOfType(geoReqProc, typeof(IRequestProcessorWantsJson)); }
public void BuildIDURLTest() { GeoRequestProcessor<Geo> target = new GeoRequestProcessor<Geo>() { BaseUrl = "https://api.twitter.com/1/" }; var parameters = new Dictionary<string, string> { {"Type", ((int) GeoType.ID).ToString()}, {"ID", "7695dd2ec2f86f2b"}, }; string expected = "https://api.twitter.com/1/geo/id/7695dd2ec2f86f2b.json"; string actual = target.BuildURL(parameters); Assert.AreEqual(expected, actual); }
public void BuildUrl_Constructs_Search_Url() { const string ExpectedUrl = "https://api.twitter.com/1.1/geo/search.json?lat=37.78215&long=-122.4006&query=Twitter%20HQ&ip=168.143.171.180&accuracy=city&granularity=10&max_results=10&contained_within=123&attribute%3Astreet_address=123"; var geoReqProc = new GeoRequestProcessor<Geo>() { BaseUrl = "https://api.twitter.com/1.1/" }; var parameters = new Dictionary<string, string> { {"Type", ((int) GeoType.Search).ToString()}, {"Latitude", (37.78215).ToString()}, {"Longitude", (-122.40060).ToString()}, {"Query", "Twitter HQ" }, {"IP", "168.143.171.180"}, {"Accuracy", "city" }, {"Granularity", "10" }, {"MaxResults", "10" }, {"ContainedWithin", "123" }, {"Attribute", "street_address=123" } }; Request req = geoReqProc.BuildUrl(parameters); Assert.Equal(ExpectedUrl, req.FullUrl); }
public void BuildUrl_Constructs_Similar_Places_Url() { const string ExpectedUrl = "https://api.twitter.com/1.1/geo/similar_places.json?lat=37.78215&long=-122.4006&name=placeName&contained_within=123&attribute%3Astreet_address=123"; var geoReqProc = new GeoRequestProcessor<Geo>() { BaseUrl = "https://api.twitter.com/1.1/" }; var parameters = new Dictionary<string, string> { {"Type", ((int) GeoType.SimilarPlaces).ToString()}, {"Latitude", (37.78215).ToString()}, {"Longitude", (-122.40060).ToString()}, {"PlaceName", "placeName" }, {"ContainedWithin", "123" }, {"Attribute", "street_address=123" } }; Request req = geoReqProc.BuildUrl(parameters); Assert.Equal(ExpectedUrl, req.FullUrl); }
public void BuildReverseURLTest() { GeoRequestProcessor<Geo> target = new GeoRequestProcessor<Geo>() { BaseUrl = "https://api.twitter.com/1/" }; var parameters = new Dictionary<string, string> { {"Type", ((int) GeoType.Reverse).ToString()}, {"Latitude", "37.78215"}, {"Longitude", "-122.40060"}, {"Accuracy", "city" }, {"Granularity", "10" }, {"MaxResults", "10" } }; string expected = "https://api.twitter.com/1/geo/reverse_geocode.json?lat=37.78215&long=-122.40060&accuracy=city&granularity=10&max_results=10"; string actual; actual = target.BuildURL(parameters); Assert.AreEqual(expected, actual); }
public void BuildUrl_ID_Without_ID_Throws() { const string ExpectedIDParamName = "ID"; var geoReqProc = new GeoRequestProcessor<Geo>() { BaseUrl = "https://api.twitter.com/1.1/" }; var parameters = new Dictionary<string, string> { {"Type", ((int) GeoType.ID).ToString()}, }; var ex = Assert.Throws<ArgumentException>(() => geoReqProc.BuildUrl(parameters)); Assert.Equal(ExpectedIDParamName, ex.ParamName); }
public void BuildNearbyURLWithoutArgsTest() { GeoRequestProcessor<Geo> target = new GeoRequestProcessor<Geo>() { BaseUrl = "https://api.twitter.com/1/" }; var parameters = new Dictionary<string, string> { {"Type", ((int) GeoType.Nearby).ToString()}, }; string actual = target.BuildURL(parameters); }
public void BuildUrl_Search_With_Attribute_Missing_Equals_Symbol_Throws() { const string ExpectedAttributeParam = "Attribute"; var geoReqProc = new GeoRequestProcessor<Geo>() { BaseUrl = "https://api.twitter.com/1.1/" }; var parameters = new Dictionary<string, string> { {"Type", ((int) GeoType.Search).ToString()}, {"IP", "168.143.171.180"}, {"Attribute", "street_address" } }; var ex = Assert.Throws<ArgumentException>(() => geoReqProc.BuildUrl(parameters)); Assert.Equal(ExpectedAttributeParam, ex.ParamName); }
public void GeoRequestProcessor_Processes_Json_Format_Responses() { var geoReqProc = new GeoRequestProcessor<Geo>(); Assert.IsInstanceOfType(geoReqProc, typeof(IRequestProcessorWantsJson)); }
public void ProcessResults_Handles_ID_Response() { const string ExpectedPlaceName = "San Francisco"; var geoReqProc = new GeoRequestProcessor<Geo> { Type = GeoType.ID }; List<Geo> geo = geoReqProc.ProcessResults(IDResponse); Assert.NotNull(geo); Assert.Single(geo); Assert.NotNull(geo.Single().Places); Assert.Equal(ExpectedPlaceName, geo.Single().Places.First().Name); }
public void ProcessResultsForID_WithNullGeometry_ExpectSucces() { const string ExpectedPlaceName = "San Francisco"; var geoReqProc = new GeoRequestProcessor<Geo> { Type = GeoType.ID }; List<Geo> geo = geoReqProc.ProcessResults(IDResponseWithNullGeometry); Assert.IsNotNull(geo); Assert.IsNotNull(geo.SingleOrDefault()); Assert.IsNotNull(geo.Single().Places); Assert.AreEqual(ExpectedPlaceName, geo.Single().Places.First().Name); }
public void ProcessResults_Handles_Search_Response() { const int ExpectedPlacesCount = 4; const string ExpectedPlaceFullName = "SoMa, San Francisco"; var geoReqProc = new GeoRequestProcessor<Geo> { Type = GeoType.Search }; List<Geo> geo = geoReqProc.ProcessResults(MultiPlaceResponse); Assert.NotNull(geo); Assert.Single(geo); Assert.NotNull(geo.Single().Places); Assert.Equal(ExpectedPlacesCount, geo.Single().Places.Count); Assert.Equal(ExpectedPlaceFullName, geo.Single().Places.First().FullName); }
public void GeoRequestProcessor_Processes_Json_Format_Responses() { var geoReqProc = new GeoRequestProcessor <Geo>(); Assert.IsAssignableFrom <IRequestProcessorWantsJson>(geoReqProc); }
public void ProcessResults_Returns_Empty_Collection_When_Empty_Results() { var geoReqProc = new GeoRequestProcessor<Geo>() { BaseUrl = "https://api.twitter.com/1.1/" }; var geo = geoReqProc.ProcessResults(string.Empty); Assert.NotNull(geo); Assert.Empty(geo); }
public void GeoRequestProcessor_Works_With_Actions() { var geoReqProc = new GeoRequestProcessor<Geo>(); Assert.IsAssignableFrom<IRequestProcessorWithAction<Geo>>(geoReqProc); }