Skip to content

Commit

Permalink
Fix PlaceFinder after changes in Yahoo API.
Browse files Browse the repository at this point in the history
See this issue for more info: #2
  • Loading branch information
Dan Ludwig authored and Dan Ludwig committed Oct 2, 2012
1 parent e6cb16b commit 8ad391f
Show file tree
Hide file tree
Showing 11 changed files with 650 additions and 158 deletions.
1 change: 1 addition & 0 deletions NGeo.Tests/App.config
Expand Up @@ -3,6 +3,7 @@
<appSettings>
<add key="GeoNamesUserName" value="ngeo" />
<add key="GeoPlanetAppId" value="IQ8qmdzV34Fym0.ZGgLAT2e0t0ZR.IL9seudXbNvocaGxOgk34gtQpa7uWPDStsaWgvco5rW8Lo-" />
<add key="PlaceFinderAppId" value="KJhB504i" />
</appSettings>
<system.serviceModel>
<bindings>
Expand Down
170 changes: 146 additions & 24 deletions NGeo.Tests/Yahoo/PlaceFinder/IInvokePlaceFinderServicesTests.cs

Large diffs are not rendered by default.

160 changes: 80 additions & 80 deletions NGeo.Tests/Yahoo/PlaceFinder/PlaceFinderClientTests.cs

Large diffs are not rendered by default.

65 changes: 54 additions & 11 deletions NGeo.Tests/Yahoo/PlaceFinder/ResultSetTests.cs
Expand Up @@ -23,7 +23,25 @@ public void Yahoo_PlaceFinder_ResultSet_ShouldImplementGenericIEnumerable()
{
var model = new ResultSet
{
ResultsList = new List<Result>
Result = new Result(),
};


model.ShouldImplement(typeof(IEnumerable<Result>));
model.GetEnumerator().ShouldNotBeNull();
((IEnumerable)model).GetEnumerator().ShouldNotBeNull();
foreach (var item in model)
{
item.ShouldNotBeNull();
}
}

[TestMethod]
public void Yahoo_PlaceFinder_ResultSet2_ShouldImplementGenericIEnumerable()
{
var model = new ResultSet2
{
Result = new List<Result>
{
new Result(), new Result(), new Result(),
},
Expand All @@ -46,7 +64,22 @@ public void Yahoo_PlaceFinder_ResultSet_ShouldOverrideToString()
{
Locale = "locale",
ErrorMessage = "error message",
ResultsList = new List<Result>
Result = new Result(),
Found = 1,
};

it.ShouldNotBeNull();
it.ToString().ShouldEqual("locale, error message: 1 of 1");
}

[TestMethod]
public void Yahoo_PlaceFinder_ResultSet2_ShouldOverrideToString()
{
var it = new ResultSet2
{
Locale = "locale",
ErrorMessage = "error message",
Result = new List<Result>
{
new Result(), new Result(), new Result()
},
Expand All @@ -58,11 +91,11 @@ public void Yahoo_PlaceFinder_ResultSet_ShouldOverrideToString()
}

[TestMethod]
public void Yahoo_PlaceFinder_ResultSet_ShouldSetAlternateNamesReadOnlyCollection()
public void Yahoo_PlaceFinder_ResultSet2_ShouldSetAlternateNamesReadOnlyCollection()
{
var it = new ResultSet
var it = new ResultSet2
{
ResultsList = new List<Result>
Result = new List<Result>
{
new Result { Name = "name 1" },
new Result { Name = "name 2" },
Expand All @@ -71,12 +104,12 @@ public void Yahoo_PlaceFinder_ResultSet_ShouldSetAlternateNamesReadOnlyCollectio
};

it.ShouldNotBeNull();
it.ResultsList.ShouldNotBeNull();
it.ResultsList.Count.ShouldEqual(3);
it.Result.ShouldNotBeNull();
it.Result.Count.ShouldEqual(3);
it.Results.ShouldNotBeNull();
it.Results.Count.ShouldEqual(it.ResultsList.Count);
it.Results.Count.ShouldEqual(it.Result.Count);
for (var i = 0; i < it.Results.Count; i++)
it.Results[i].Name.ShouldEqual(it.ResultsList[i].Name);
it.Results[i].Name.ShouldEqual(it.Result[i].Name);
}

[TestMethod]
Expand Down Expand Up @@ -114,13 +147,23 @@ public void Yahoo_PlaceFinder_ResultSet_IntProperties_ShouldHaveDataContractAttr
[TestMethod]
public void Yahoo_PlaceFinder_ResultSet_Items_ShouldHaveDataContractAttribute()
{
var properties = new Dictionary<string, Expression<Func<ResultSet, List<Result>>>>
var properties = new Dictionary<string, Expression<Func<ResultSet, Result>>>
{
{ "Results", p => p.ResultsList },
{ "Result", p => p.Result },
};

properties.ShouldHaveDataMemberAttributes();
}

[TestMethod]
public void Yahoo_PlaceFinder_ResultSet2_Items_ShouldHaveDataContractAttribute()
{
var properties = new Dictionary<string, Expression<Func<ResultSet2, List<Result>>>>
{
{ "Result", p => p.Result },
};

properties.ShouldHaveDataMemberAttributes();
}
}
}
2 changes: 2 additions & 0 deletions NGeo/NGeo.csproj
Expand Up @@ -103,6 +103,8 @@
<Compile Include="Yahoo\GeoPlanet\Point.cs" />
<Compile Include="Yahoo\GeoPlanet\RequestView.cs" />
<Compile Include="Yahoo\GeoPlanet\Locality.cs" />
<Compile Include="Yahoo\PlaceFinder\Response2.cs" />
<Compile Include="Yahoo\PlaceFinder\ResultSet2.cs" />
<Compile Include="Yahoo\PlaceFinder\PlaceBy.cs" />
<Compile Include="Yahoo\PlaceFinder\BoundingBox.cs" />
<Compile Include="Yahoo\PlaceFinder\PlaceByCoordinates.cs" />
Expand Down
76 changes: 70 additions & 6 deletions NGeo/Yahoo/PlaceFinder/IInvokePlaceFinderServices.cs
Expand Up @@ -14,7 +14,19 @@ public interface IInvokePlaceFinderServices
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare
)]
Response FindByCoordinates(string location,
Response FindOneByCoordinates(string location,
string locale, int firstIndex, int maximumResults,
int offset, string flags, string gFlags, string appId);

[OperationContract(Name = "coordinates2")]
[WebGet(
UriTemplate = "geocode?q={location}&locale={locale}&start={firstIndex}&count={maximumResults}" +
"&offset={offset}&flags={flags}&gflags={gFlags}&appid={appId}",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare
)]
Response2 FindManyByCoordinates(string location,
string locale, int firstIndex, int maximumResults,
int offset, string flags, string gFlags, string appId);

Expand All @@ -26,9 +38,18 @@ public interface IInvokePlaceFinderServices
"&offset={offset}&flags={flags}&gflags={gFlags}&appid={appId}",
ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare
)]
Response FindByFreeformText(string location, string locale, int start, int count,
Response FindOneByFreeformText(string location, string locale, int start, int count,
int offset, string flags, string gFlags, string appId);

[OperationContract(Name = "freeform2")]
[WebGet(
UriTemplate = "geocode?q={location}&locale={locale}&start={start}&count={count}" +
"&offset={offset}&flags={flags}&gflags={gFlags}&appid={appId}",
ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare
)]
Response2 FindManyByFreeformText(string location, string locale, int start, int count,
int offset, string flags, string gFlags, string appId);



[OperationContract(Name = "name")]
Expand All @@ -37,7 +58,16 @@ public interface IInvokePlaceFinderServices
"&offset={offset}&flags={flags}&gflags={gFlags}&appid={appId}",
ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare
)]
Response FindByName(string name, string locale, int start, int count,
Response FindOneByName(string name, string locale, int start, int count,
int offset, string flags, string gFlags, string appId);

[OperationContract(Name = "name2")]
[WebGet(
UriTemplate = "geocode?name={name}&locale={locale}&start={start}&count={count}" +
"&offset={offset}&flags={flags}&gflags={gFlags}&appid={appId}",
ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare
)]
Response2 FindManyByName(string name, string locale, int start, int count,
int offset, string flags, string gFlags, string appId);


Expand All @@ -48,7 +78,16 @@ public interface IInvokePlaceFinderServices
"&offset={offset}&flags={flags}&gflags={gFlags}&appid={appId}",
ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare
)]
Response FindByWoeId(int woeId, string locale, int start, int count,
Response FindOneByWoeId(int woeId, string locale, int start, int count,
int offset, string flags, string gFlags, string appId);

[OperationContract(Name = "woeId2")]
[WebGet(
UriTemplate = "geocode?woeid={woeId}&locale={locale}&start={start}&count={count}" +
"&offset={offset}&flags={flags}&gflags={gFlags}&appid={appId}",
ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare
)]
Response2 FindManyByWoeId(int woeId, string locale, int start, int count,
int offset, string flags, string gFlags, string appId);


Expand All @@ -62,7 +101,20 @@ public interface IInvokePlaceFinderServices
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare
)]
Response FindByMultilineAddress(string line1, string line2, string line3,
Response FindOneByMultilineAddress(string line1, string line2, string line3,
string locale, int start, int count, int offset, string flags, string gFlags,
string appId);

[OperationContract(Name = "multiline2")]
[WebGet(
UriTemplate = "geocode?line1={line1}&line2={line2}&line3={line3}" +
"&locale={locale}&start={start}&count={count}" +
"&offset={offset}&flags={flags}&gflags={gFlags}&appid={appId}",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare
)]
Response2 FindManyByMultilineAddress(string line1, string line2, string line3,
string locale, int start, int count, int offset, string flags, string gFlags,
string appId);

Expand All @@ -76,7 +128,19 @@ public interface IInvokePlaceFinderServices
"&offset={offset}&flags={flags}&gflags={gFlags}&appid={appId}",
ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare
)]
Response FindByFullyParsedAddress(string house, string street, string unitType, string unit, string crossStreet,
Response FindOneByFullyParsedAddress(string house, string street, string unitType, string unit, string crossStreet,
string postal, string neighborhood, string city, string county, string state, string country, string locale,
int start, int count, int offset, string flags, string gFlags, string appId);

[OperationContract(Name = "fullyParsed2")]
[WebGet(
UriTemplate = "geocode?house={house}&street={street}&unittype={unitType}&unit={unit}" +
"&xstreet={crossStreet}&postal={postal}&neighborhood={neighborhood}&city={city}&county={county}" +
"&state={state}&country={country}&locale={locale}&start={start}&count={count}" +
"&offset={offset}&flags={flags}&gflags={gFlags}&appid={appId}",
ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare
)]
Response2 FindManyByFullyParsedAddress(string house, string street, string unitType, string unit, string crossStreet,
string postal, string neighborhood, string city, string county, string state, string country, string locale,
int start, int count, int offset, string flags, string gFlags, string appId);

Expand Down

0 comments on commit 8ad391f

Please sign in to comment.