Permalink
Browse files

Add support for GeoPlanet places.q(search) service.

Also added code coverage testsettings back to project.
  • Loading branch information...
Dan Ludwig Dan Ludwig
Dan Ludwig authored and Dan Ludwig committed May 19, 2012
1 parent 50c212b commit d7bb868f4ad670ee091b939b4a14c6ed8cff52bb
View
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<TestSettings name="CodeCoverage" id="27d32a93-e7bf-4fa3-b24b-e327df04c6f0" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
+ <Description>These are default test settings for a local test run.</Description>
+ <Execution>
+ <TestTypeSpecific>
+ <UnitTestRunConfig testTypeId="13cdc9d9-ddb5-4fa4-a97d-d965ccfc6d4b">
+ <AssemblyResolution>
+ <TestDirectory useLoadContext="true" />
+ </AssemblyResolution>
+ </UnitTestRunConfig>
+ <WebTestRunConfiguration testTypeId="4e7599fa-5ecb-43e9-a887-cd63cf72d207">
+ <Browser name="Internet Explorer 7.0">
+ <Headers>
+ <Header name="User-Agent" value="Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)" />
+ <Header name="Accept" value="*/*" />
+ <Header name="Accept-Language" value="{{$IEAcceptLanguage}}" />
+ <Header name="Accept-Encoding" value="GZIP" />
+ </Headers>
+ </Browser>
+ </WebTestRunConfiguration>
+ </TestTypeSpecific>
+ <AgentRule name="LocalMachineDefaultRole">
+ <DataCollectors>
+ <DataCollector uri="datacollector://microsoft/CodeCoverage/1.0" assemblyQualifiedName="Microsoft.VisualStudio.TestTools.CodeCoverage.CoveragePlugIn, Microsoft.VisualStudio.QualityTools.Plugins.CodeCoverage, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" friendlyName="Code Coverage">
+ <Configuration>
+ <CodeCoverage xmlns="">
+ <Regular>
+ <CodeCoverageItem binaryFile="NGeo\bin\Debug\NGeo.dll" pdbFile="NGeo\bin\Debug\NGeo.pdb" instrumentInPlace="true" />
+ </Regular>
+ </CodeCoverage>
+ </Configuration>
+ </DataCollector>
+ </DataCollectors>
+ </AgentRule>
+ </Execution>
+</TestSettings>
@@ -30,5 +30,5 @@
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
-[assembly: AssemblyVersion("1.3.1")]
+[assembly: AssemblyVersion("1.4.0")]
//[assembly: AssemblyFileVersion("1.0.0.0")]
@@ -31,6 +31,53 @@ public void Yahoo_GeoPlanet_GeoPlanetClient_Place_ShouldReturnNull_When404Except
}
}
+ [TestMethod]
+ public void Yahoo_GeoPlanet_GeoPlanetClient_Places_ShouldReturnAtLeast1Result_ForQuery_Sfo()
+ {
+ using (var geoPlanetClient = new GeoPlanetClient())
+ {
+ var places = geoPlanetClient.Places("SFO", AppId);
+
+ places.ShouldNotBeNull();
+ places.Items.Count.ShouldBeInRange(1, int.MaxValue);
+ }
+ }
+
+ [TestMethod]
+ public void Yahoo_GeoPlanet_GeoPlanetClient_Places_ShouldReturnMoreThan1Result_ForQuery_Ca()
+ {
+ using (var geoPlanetClient = new GeoPlanetClient())
+ {
+ var places = geoPlanetClient.Places("CA", AppId);
+
+ places.ShouldNotBeNull();
+ places.Items.Count.ShouldBeInRange(2, int.MaxValue);
+ }
+ }
+
+ [TestMethod]
+ public void Yahoo_GeoPlanet_GeoPlanetClient_Places_ShouldReturnEmpty_WhenNoResultsAreFound()
+ {
+ using (var geoPlanetClient = new GeoPlanetClient())
+ {
+ var places = geoPlanetClient.Places("asdfdfmdlfjkdlajsdlfasdfjdjfdlajlsdflasdjf", AppId);
+
+ places.ShouldNotBeNull();
+ places.Items.Count.ShouldEqual(0);
+ }
+ }
+
+ [TestMethod]
+ public void Yahoo_GeoPlanet_GeoPlanetClient_Places_ShouldReturnNull_WhenArgumentExceptionIsThrown()
+ {
+ using (var geoPlanetClient = new GeoPlanetClient())
+ {
+ var places = geoPlanetClient.Places("", AppId);
+
+ places.ShouldBeNull();
+ }
+ }
+
[TestMethod]
public void Yahoo_GeoPlanet_GeoPlanetClient_Parent_ShouldReturn1Result_ForWoeId2380358()
{
@@ -25,6 +25,16 @@ public void Yahoo_GeoPlanet_Place_ShouldBeInterfaceMethod()
results.ShouldNotBeNull();
}
+ [TestMethod]
+ public void Yahoo_GeoPlanet_Places_ShouldBeInterfaceMethod()
+ {
+ var contract = new Mock<IConsumeGeoPlanet>();
+ contract.Setup(m => m.Places(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<RequestView>()))
+ .Returns(new Places());
+ var results = contract.Object.Places("test", null);
+ results.ShouldNotBeNull();
+ }
+
[TestMethod]
public void Yahoo_GeoPlanet_Parent_ShouldBeInterfaceMethod()
{
@@ -29,6 +29,7 @@ public void Yahoo_GeoPlanet_IInvokeGeoPlanetServices_ShouldHaveOperationContract
var placesResponseOperations = new Dictionary<string, Expression<Func<IInvokeGeoPlanetServices, PlacesResponse>>>
{
+ { "places", p => p.Places(default(string), default(string), default(RequestView)) },
{ "ancestors", p => p.Ancestors(default(string), default(string), default(RequestView)) },
{ "belongtos", p => p.BelongTos(default(string), default(string), default(RequestView)) },
{ "countries", p => p.Countries(default(string), default(RequestView)) },
@@ -68,6 +69,21 @@ public void Yahoo_GeoPlanet_IInvokeGeoPlanetServices_Place_ShouldHaveWebInvokeAt
attributes[0].BodyStyle.ShouldEqual(WebMessageBodyStyle.Bare);
}
+ [TestMethod]
+ public void Yahoo_GeoPlanet_IInvokeGeoPlanetServices_Places_ShouldHaveWebInvokeAttribute()
+ {
+ Expression<Func<IInvokeGeoPlanetServices, PlacesResponse>> method = p => p.Places(default(string),
+ default(string), default(RequestView));
+ var attributes = method.GetAttributes<IInvokeGeoPlanetServices, PlacesResponse, WebGetAttribute>();
+
+ attributes.ShouldNotBeNull();
+ attributes.Length.ShouldEqual(1);
+ attributes[0].UriTemplate.ShouldEqual("places.q({query});count=0?format=json&view={view}&appid={appId}");
+ attributes[0].RequestFormat.ShouldEqual(WebMessageFormat.Json);
+ attributes[0].ResponseFormat.ShouldEqual(WebMessageFormat.Json);
+ attributes[0].BodyStyle.ShouldEqual(WebMessageBodyStyle.Bare);
+ }
+
[TestMethod]
public void Yahoo_GeoPlanet_IInvokeGeoPlanetServices_Parent_ShouldHaveWebInvokeAttribute()
{
@@ -35,6 +35,6 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.3.1")]
+[assembly: AssemblyVersion("1.4.0")]
//[assembly: AssemblyFileVersion("1.0.0.0")]
@@ -1,4 +1,6 @@
-using System.Collections.ObjectModel;
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
using System.Globalization;
using System.Linq;
using System.ServiceModel;
@@ -21,6 +23,26 @@ public Place Place(int woeId, string appId, RequestView view = RequestView.Long)
}
}
+ public Places Places(string query, string appId, RequestView view = RequestView.Long)
+ {
+ try
+ {
+ var response = Channel.Places(query, appId, view);
+ var results = response.Results;
+ if (results != null)
+ results.Items = new ReadOnlyCollection<Place>(
+ results.JsonItems != null
+ ? results.JsonItems.ToPlaces()
+ : new List<Place>()
+ );
+ return results;
+ }
+ catch (ArgumentException)
+ {
+ return null;
+ }
+ }
+
public Place Parent(int woeId, string appId, RequestView view = RequestView.Long)
{
try
@@ -6,6 +6,8 @@ public interface IConsumeGeoPlanet : IDisposable
{
Place Place(int woeId, string appId, RequestView view = RequestView.Long);
+ Places Places(string query, string appId, RequestView view = RequestView.Long);
+
Place Parent(int woeId, string appId, RequestView view = RequestView.Long);
Places Ancestors(int woeId, string appId, RequestView view = RequestView.Short);
@@ -15,6 +15,15 @@ public interface IInvokeGeoPlanetServices
)]
PlaceResponse Place(string woeId, string appId, RequestView view);
+ [OperationContract(Name = "places")]
+ [WebGet(
+ UriTemplate = "places.q({query});count=0?format=json&view={view}&appid={appId}",
+ RequestFormat = WebMessageFormat.Json,
+ ResponseFormat = WebMessageFormat.Json,
+ BodyStyle = WebMessageBodyStyle.Bare
+ )]
+ PlacesResponse Places(string query, string appId, RequestView view);
+
[OperationContract(Name = "parent")]
[WebGet(
UriTemplate = "place/{woeId}/parent?format=json&view={view}&appid={appId}",
View
@@ -1,3 +1,6 @@
+1.4.0
+- Added support for the GeoPlanet places.q(search) service
+
1.3.1
- Fix bug with PlaceFinder throwing exceptions when '' cannot be parsed into int

0 comments on commit d7bb868

Please sign in to comment.