From d5aa0543439b089020888065644dd522bc05bf01 Mon Sep 17 00:00:00 2001 From: Eric Devenport Date: Fri, 27 Sep 2024 13:15:02 -0600 Subject: [PATCH] Added Address Search Feature for the US Address Enrichment API Modified Enrichment Tests to include all datasets and the Address Search Feature --- .../USEnrichmentGeoReferenceExample.cs | 24 +- src/examples/USEnrichmentPropertyExample.cs | 45 +++- src/examples/USEnrichmentSecondaryExample.cs | 34 +++ src/examples/USEnrichmentUniversalExample.cs | 27 ++- src/sdk/USEnrichmentApi/Client.cs | 35 ++- .../USEnrichmentApi/GeoReference/Lookup.cs | 6 +- src/sdk/USEnrichmentApi/Lookup.cs | 84 ++++++- .../Property/Financial/Lookup.cs | 6 +- .../Property/Principal/Lookup.cs | 7 +- .../USEnrichmentApi/Secondary/Count/Lookup.cs | 6 +- src/sdk/USEnrichmentApi/Secondary/Lookup.cs | 6 +- src/sdk/USEnrichmentApi/Universal/Lookup.cs | 2 +- src/tests/USEnrichmentApi/ClientTests.cs | 205 +++++++++++++++++- 13 files changed, 452 insertions(+), 35 deletions(-) diff --git a/src/examples/USEnrichmentGeoReferenceExample.cs b/src/examples/USEnrichmentGeoReferenceExample.cs index 8ff2261..b0594b2 100644 --- a/src/examples/USEnrichmentGeoReferenceExample.cs +++ b/src/examples/USEnrichmentGeoReferenceExample.cs @@ -27,11 +27,29 @@ public static void Run() var client = new ClientBuilder(authId, authToken).BuildUsEnrichmentApiClient(); SmartyStreets.USEnrichmentApi.GeoReference.Result[] results = null; - var lookup = new SmartyStreets.USEnrichmentApi.GeoReference.Lookup("1682393594"); + + + // Create a lookup with a smarty key using the line below + var lookup = new SmartyStreets.USEnrichmentApi.GeoReference.Lookup("325023201"); + + // Create a lookup with address components using the lines below + var componentsLookup = new SmartyStreets.USEnrichmentApi.GeoReference.Lookup(); + componentsLookup.SetStreet("56 Union Ave"); + componentsLookup.SetCity("Somerville"); + componentsLookup.SetState("NJ"); + componentsLookup.SetZipcode("08876"); + + // Create a lookup with a single line address using the line below + var freeformLookup = new SmartyStreets.USEnrichmentApi.GeoReference.Lookup(); + freeformLookup.SetFreeform("56 Union Ave Somerville NJ 08876"); + // Options available for the GeoReference Lookup - // lookup.SetEtag("GEZTSMZYHE3DMNA"); + // lookup.SetEtag("GEZDSNBUHE3DEMQ"); + try { - // results = client.SendGeoReferenceLookup("1682393594"); // simple call with just a SmartyKey + // results = client.SendGeoReferenceLookup("325023201"); // simple call with just a SmartyKey + + // Send a lookup using the line below results = client.SendGeoReferenceLookup(lookup); // more flexible call to set other lookup options } catch (NotModifiedException ex) { diff --git a/src/examples/USEnrichmentPropertyExample.cs b/src/examples/USEnrichmentPropertyExample.cs index eab0407..3b999ec 100644 --- a/src/examples/USEnrichmentPropertyExample.cs +++ b/src/examples/USEnrichmentPropertyExample.cs @@ -28,14 +28,31 @@ public static void Run() SmartyStreets.USEnrichmentApi.Property.Principal.Result[] results = null; - var lookup = new SmartyStreets.USEnrichmentApi.Property.Principal.Lookup("1682393594"); + + // Create a lookup with a smarty key using the line below + var lookup = new SmartyStreets.USEnrichmentApi.Property.Principal.Lookup("325023201"); + + // Create a lookup with address components using the lines below + var componentsLookup = new SmartyStreets.USEnrichmentApi.Property.Principal.Lookup(); + componentsLookup.SetStreet("56 Union Ave"); + componentsLookup.SetCity("Somerville"); + componentsLookup.SetState("NJ"); + componentsLookup.SetZipcode("08876"); + + // Create a lookup with a single line address using the line below + var freeformLookup = new SmartyStreets.USEnrichmentApi.Property.Principal.Lookup(); + freeformLookup.SetFreeform("56 Union Ave Somerville NJ 08876"); + // See the US Enrichment API documenation for available lookup properties https://www.smarty.com/docs/cloud/us-address-enrichment-api#http-request-input-fields // Options available for the Property Lookup - // lookup.SetEtag("GU4TINZRHA4TQMY"); + // lookup.SetEtag("AIDAIAQCAIEQKAIC"); // lookup.SetIncludeFields("assessed_value,assessor_last_update"); // lookup.SetExcludeFields("tax_fiscal_year,tax_jurisdiction"); + try { - // results = client.SendPropertyPrincipalLookup("1682393594"); // simple call with just a SmartyKey + // results = client.SendPropertyPrincipalLookup("325023201"); // simple call with just a SmartyKey + + // Send a lookup using the line below results = client.SendPropertyPrincipalLookup(lookup); // more flexible call to set other lookup options } catch (NotModifiedException ex) { @@ -55,13 +72,29 @@ public static void Run() } SmartyStreets.USEnrichmentApi.Property.Financial.Result[] financialResults = null; - var financialLookup = new SmartyStreets.USEnrichmentApi.Property.Financial.Lookup("1682393594"); + + // Create a lookup with a smarty key using the line below + var financialLookup = new SmartyStreets.USEnrichmentApi.Property.Financial.Lookup("325023201"); + + // Create a lookup with address components using the lines below + var financialComponentsLookup = new SmartyStreets.USEnrichmentApi.Property.Financial.Lookup(); + financialComponentsLookup.SetStreet("56 Union Ave"); + financialComponentsLookup.SetCity("Somerville"); + financialComponentsLookup.SetState("NJ"); + financialComponentsLookup.SetZipcode("08876"); + + // Create a lookup with a single line address using the line below + var financialFreeformLookup = new SmartyStreets.USEnrichmentApi.Property.Financial.Lookup(); + financialFreeformLookup.SetFreeform("56 Union Ave Somerville NJ 08876"); + // Options available for the Property Lookup - // financialLookup.SetEtag("GU4TINZRHA4TQMY"); + // financialLookup.SetEtag("AIDAIAQCAIEQKAIC"); // financialLookup.SetIncludeFields("assessed_value,assessor_last_update"); // financialLookup.SetExcludeFields("tax_fiscal_year,tax_jurisdiction"); try { - // financialResults = client.SendPropertyFinancialLookup("1682393594"); // simple call with just a SmartyKey + // financialResults = client.SendPropertyFinancialLookup("325023201"); // simple call with just a SmartyKey + + // Send a lookup using the line below financialResults = client.SendPropertyFinancialLookup(financialLookup); // more flexible call to set other lookup options } catch (NotModifiedException ex) { diff --git a/src/examples/USEnrichmentSecondaryExample.cs b/src/examples/USEnrichmentSecondaryExample.cs index e2ff451..62a967c 100644 --- a/src/examples/USEnrichmentSecondaryExample.cs +++ b/src/examples/USEnrichmentSecondaryExample.cs @@ -29,11 +29,28 @@ public static void Run() // See the US Enrichment API documenation for all available datasets and data subsets https://www.smarty.com/docs/cloud/us-address-enrichment-api#data-sets SmartyStreets.USEnrichmentApi.Secondary.Result[] results = null; + + // Create a lookup with a smarty key using the line below var lookup = new SmartyStreets.USEnrichmentApi.Secondary.Lookup("325023201"); + + // Create a lookup with address components using the lines below + var componentsLookup = new SmartyStreets.USEnrichmentApi.Secondary.Lookup(); + componentsLookup.SetStreet("56 Union Ave"); + componentsLookup.SetCity("Somerville"); + componentsLookup.SetState("NJ"); + componentsLookup.SetZipcode("08876"); + + // Create a lookup with a single line address using the line below + var freeformLookup = new SmartyStreets.USEnrichmentApi.Secondary.Lookup(); + freeformLookup.SetFreeform("56 Union Ave Somerville NJ 08876"); + // Options available for Lookup // lookup.SetEtag("HAYDKMJXHA4DKNA"); try { + // results = client.SendSecondaryLookup("325023201"); // simple call with just a SmartyKey + + // Send a lookup using the line below results = client.SendSecondaryLookup(lookup); } catch (NotModifiedException ex) { @@ -67,11 +84,28 @@ public static void Run() } SmartyStreets.USEnrichmentApi.Secondary.Count.Result[] countResults = null; + + // Create a lookup with a smarty key using the line below var countLookup = new SmartyStreets.USEnrichmentApi.Secondary.Count.Lookup("325023201"); + + // Create a lookup with address components using the lines below + var countComponentsLookup = new SmartyStreets.USEnrichmentApi.Secondary.Lookup(); + countComponentsLookup.SetStreet("56 Union Ave"); + countComponentsLookup.SetCity("Somerville"); + countComponentsLookup.SetState("NJ"); + countComponentsLookup.SetZipcode("08876"); + + // Create a lookup with a single line address using the line below + var countFreeformLookup = new SmartyStreets.USEnrichmentApi.Secondary.Count.Lookup(); + countFreeformLookup.SetFreeform("56 Union Ave Somerville NJ 08876"); + // Options available for Lookup // lookup.SetEtag("HAYDKMJXHA4DKNA"); try { + // results = client.SendSecondaryCountLookup("325023201"); // simple call with just a SmartyKey + + // Send a lookup using the line below countResults = client.SendSecondaryCountLookup(countLookup); } catch (NotModifiedException ex) { diff --git a/src/examples/USEnrichmentUniversalExample.cs b/src/examples/USEnrichmentUniversalExample.cs index ff1cb15..21babe6 100644 --- a/src/examples/USEnrichmentUniversalExample.cs +++ b/src/examples/USEnrichmentUniversalExample.cs @@ -26,16 +26,37 @@ public static void Run() ServicePointManager.SecurityProtocol = tlsProtocol1_2; var client = new ClientBuilder(authId, authToken).BuildUsEnrichmentApiClient(); - + byte[] results = null; // See the US Enrichment API documenation for all available datasets and data subsets https://www.smarty.com/docs/cloud/us-address-enrichment-api#data-sets - var lookup = new SmartyStreets.USEnrichmentApi.Universal.Lookup("1682393594","property","principal"); + + // Create a lookup with a smarty key using the line below + var lookup = new SmartyStreets.USEnrichmentApi.Universal.Lookup("325023201","property","principal"); + + // Create a lookup with address components using the lines below + var componentsLookup = new SmartyStreets.USEnrichmentApi.Universal.Lookup(); + componentsLookup.SetDatasetName("property"); + componentsLookup.SetDataSubsetName("principal"); + componentsLookup.SetStreet("56 Union Ave"); + componentsLookup.SetCity("Somerville"); + componentsLookup.SetState("NJ"); + componentsLookup.SetZipcode("08876"); + + // Create a lookup with a single line address using the lines below + var freeformLookup = new SmartyStreets.USEnrichmentApi.Universal.Lookup(); + freeformLookup.SetDatasetName("property"); + freeformLookup.SetDataSubsetName("principal"); + freeformLookup.SetFreeform("56 Union Ave Somerville NJ 08876"); + // Options available for Lookup - // lookup.SetEtag("GU4TINZRHA4TQMY"); + // lookup.SetEtag("AIDAIAQCAIEQKAIC"); // lookup.SetIncludeFields("assessed_value,assessor_last_update"); // applicable to Property lookups only // lookup.SetExcludeFields("tax_fiscal_year,tax_jurisdiction"); // applicable to Property lookups only try { + // results = client.SendUniversalLookup("325023201", "property", "principal"); // simple call with just a SmartyKey and Dataset info + + // Send a lookup using the line below results = client.SendUniversalLookup(lookup); } catch (NotModifiedException ex) { diff --git a/src/sdk/USEnrichmentApi/Client.cs b/src/sdk/USEnrichmentApi/Client.cs index f676fe7..6b33158 100644 --- a/src/sdk/USEnrichmentApi/Client.cs +++ b/src/sdk/USEnrichmentApi/Client.cs @@ -87,8 +87,8 @@ public byte[] SendUniversalLookup(Universal.Lookup lookup) private void Send(Lookup lookup) { - if (lookup == null || string.IsNullOrEmpty(lookup.GetSmartyKey())) - throw new SmartyStreets.SmartyException("Client.Send() requires a Lookup with the 'smartyKey' field set"); + if (lookup == null || (string.IsNullOrEmpty(lookup.GetSmartyKey()) && string.IsNullOrEmpty(lookup.GetStreet()) && string.IsNullOrEmpty(lookup.GetFreeform()))) + throw new SmartyStreets.SmartyException("Client.Send() requires a Lookup with the 'smartyKey', 'street', or 'freeform' field set"); Request request = BuildRequest(lookup); Response response = this.sender.Send(request); foreach(var entry in response.HeaderInfo) { @@ -98,6 +98,9 @@ private void Send(Lookup lookup) } if (response.Payload != null){ using (var payloadStream = new MemoryStream(response.Payload)){ + if (serializer == null) { + Console.WriteLine("true"); + } lookup.DeserializeAndSetResults(serializer, payloadStream); } } @@ -108,10 +111,18 @@ private SmartyStreets.Request BuildRequest(Lookup lookup) SmartyStreets.Request request = new SmartyStreets.Request(); // some datasets have no data subset - if (lookup.GetDataSubsetName() == "") { - request.SetUrlComponents("/" + lookup.GetSmartyKey() + "/" + lookup.GetDatasetName()); + if (string.IsNullOrEmpty(lookup.GetSmartyKey())) { + if (lookup.GetDataSubsetName() == "") { + request.SetUrlComponents("/search/" + lookup.GetDatasetName()); + } else { + request.SetUrlComponents("/search/" + lookup.GetDatasetName() + "/" + lookup.GetDataSubsetName()); + } } else { + if (lookup.GetDataSubsetName() == "") { + request.SetUrlComponents("/" + lookup.GetSmartyKey() + "/" + lookup.GetDatasetName()); + } else { request.SetUrlComponents("/" + lookup.GetSmartyKey() + "/" + lookup.GetDatasetName() + "/" + lookup.GetDataSubsetName()); + } } if (lookup.GetIncludeFields() != null) { @@ -120,7 +131,21 @@ private SmartyStreets.Request BuildRequest(Lookup lookup) if (lookup.GetExcludeFields() != null) { request.SetParameter("exclude", lookup.GetExcludeFields()); } - + if (lookup.GetFreeform() != null) { + request.SetParameter("freeform", lookup.GetFreeform()); + } + if (lookup.GetStreet() != null) { + request.SetParameter("street", lookup.GetStreet()); + } + if (lookup.GetCity() != null) { + request.SetParameter("city", lookup.GetCity()); + } + if (lookup.GetState() != null) { + request.SetParameter("state", lookup.GetState()); + } + if (lookup.GetZipcode() != null) { + request.SetParameter("zipcode", lookup.GetZipcode()); + } if (lookup.GetEtag() != null) { request.SetHeader("Etag", lookup.GetEtag()); } diff --git a/src/sdk/USEnrichmentApi/GeoReference/Lookup.cs b/src/sdk/USEnrichmentApi/GeoReference/Lookup.cs index 5728830..cdf7758 100644 --- a/src/sdk/USEnrichmentApi/GeoReference/Lookup.cs +++ b/src/sdk/USEnrichmentApi/GeoReference/Lookup.cs @@ -8,7 +8,7 @@ public class Lookup : SmartyStreets.USEnrichmentApi.Lookup { private Result[] results; - public Lookup(string smartyKey) : base(smartyKey, "geo-reference", "") + public Lookup(string smartyKey = null) : base(smartyKey, "geo-reference", "") { } @@ -25,7 +25,9 @@ public void SetResults(Result[] results) public override void DeserializeAndSetResults(SmartyStreets.ISerializer serializer, Stream payload) { this.results = serializer.Deserialize(payload); - this.results[0].Etag = this.GetEtag(); + if (this.results != null) { + this.results[0].Etag = this.GetEtag(); + } } } } \ No newline at end of file diff --git a/src/sdk/USEnrichmentApi/Lookup.cs b/src/sdk/USEnrichmentApi/Lookup.cs index fa6cfca..88fda9b 100644 --- a/src/sdk/USEnrichmentApi/Lookup.cs +++ b/src/sdk/USEnrichmentApi/Lookup.cs @@ -5,18 +5,29 @@ namespace SmartyStreets.USEnrichmentApi public abstract class Lookup { - private readonly string smartyKey; - private readonly string datasetName; - private readonly string dataSubsetName; + private string smartyKey; + private string datasetName; + private string dataSubsetName; + private string freeform; + private string street; + private string city; + private string state; + private string zipcode; private string includeFields; private string excludeFields; private string eTag; - public Lookup(string smartyKey, string datasetName, string dataSubsetName) + public Lookup(string smartyKey = null, string datasetName = null, string dataSubsetName = null, string freeform = null, string street = null, + string city = null, string state = null, string zipcode = null) { this.smartyKey = smartyKey; this.datasetName = datasetName; this.dataSubsetName = dataSubsetName; + this.freeform = freeform; + this.street = street; + this.city = city; + this.state = state; + this.zipcode = zipcode; } public string GetSmartyKey() @@ -34,6 +45,31 @@ public string GetDataSubsetName() return dataSubsetName; } + public string GetFreeform() + { + return freeform; + } + + public string GetStreet() + { + return street; + } + + public string GetCity() + { + return city; + } + + public string GetState() + { + return state; + } + + public string GetZipcode() + { + return zipcode; + } + public string GetIncludeFields() { return includeFields; @@ -64,6 +100,46 @@ public void SetEtag(string eTag) this.eTag = eTag; } + public void SetSmartyKey(string smartyKey) + { + this.smartyKey = smartyKey; + } + + public void SetDatasetName(string datasetName) + { + this.datasetName = datasetName; + } + + public void SetDataSubsetName(string dataSubsetName) + { + this.dataSubsetName = dataSubsetName; + } + + public void SetFreeform(string freeform) + { + this.freeform = freeform; + } + + public void SetStreet(string street) + { + this.street = street; + } + + public void SetCity(string city) + { + this.city = city; + } + + public void SetState(string state) + { + this.state = state; + } + + public void SetZipcode(string zipcode) + { + this.zipcode = zipcode; + } + public abstract void DeserializeAndSetResults(SmartyStreets.ISerializer serializer, Stream payload); } diff --git a/src/sdk/USEnrichmentApi/Property/Financial/Lookup.cs b/src/sdk/USEnrichmentApi/Property/Financial/Lookup.cs index 6bb0445..25ba0b6 100644 --- a/src/sdk/USEnrichmentApi/Property/Financial/Lookup.cs +++ b/src/sdk/USEnrichmentApi/Property/Financial/Lookup.cs @@ -7,7 +7,7 @@ public class Lookup : SmartyStreets.USEnrichmentApi.Lookup { private Result[] results; - public Lookup(string smartyKey) : base(smartyKey, "property", "financial") + public Lookup(string smartyKey = null) : base(smartyKey, "property", "financial") { } @@ -24,7 +24,9 @@ public void SetResults(Result[] results) public override void DeserializeAndSetResults(SmartyStreets.ISerializer serializer, Stream payload) { this.results = serializer.Deserialize(payload); - this.results[0].Etag = this.GetEtag(); + if (this.results != null) { + this.results[0].Etag = this.GetEtag(); + } } } diff --git a/src/sdk/USEnrichmentApi/Property/Principal/Lookup.cs b/src/sdk/USEnrichmentApi/Property/Principal/Lookup.cs index 70f5e66..c50e17d 100644 --- a/src/sdk/USEnrichmentApi/Property/Principal/Lookup.cs +++ b/src/sdk/USEnrichmentApi/Property/Principal/Lookup.cs @@ -7,8 +7,7 @@ namespace SmartyStreets.USEnrichmentApi.Property.Principal public class Lookup : SmartyStreets.USEnrichmentApi.Lookup { private Result[] results; - - public Lookup(string smartyKey) : base(smartyKey, "property", "principal") + public Lookup(string smartyKey = null) : base(smartyKey, "property", "principal") { } @@ -25,7 +24,9 @@ public void SetResults(Result[] results) public override void DeserializeAndSetResults(SmartyStreets.ISerializer serializer, Stream payload) { this.results = serializer.Deserialize(payload); - this.results[0].Etag = this.GetEtag(); + if (this.results != null) { + this.results[0].Etag = this.GetEtag(); + } } } } \ No newline at end of file diff --git a/src/sdk/USEnrichmentApi/Secondary/Count/Lookup.cs b/src/sdk/USEnrichmentApi/Secondary/Count/Lookup.cs index a0972c7..b019fe2 100644 --- a/src/sdk/USEnrichmentApi/Secondary/Count/Lookup.cs +++ b/src/sdk/USEnrichmentApi/Secondary/Count/Lookup.cs @@ -8,7 +8,7 @@ public class Lookup : SmartyStreets.USEnrichmentApi.Lookup { private Result[] results; - public Lookup(string smartyKey) : base(smartyKey, "secondary", "count") + public Lookup(string smartyKey = null) : base(smartyKey, "secondary", "count") { } @@ -25,7 +25,9 @@ public void SetResults(Result[] results) public override void DeserializeAndSetResults(SmartyStreets.ISerializer serializer, Stream payload) { this.results = serializer.Deserialize(payload); - this.results[0].Etag = this.GetEtag(); + if (this.results != null) { + this.results[0].Etag = this.GetEtag(); + } } } } \ No newline at end of file diff --git a/src/sdk/USEnrichmentApi/Secondary/Lookup.cs b/src/sdk/USEnrichmentApi/Secondary/Lookup.cs index 5747834..df75b16 100644 --- a/src/sdk/USEnrichmentApi/Secondary/Lookup.cs +++ b/src/sdk/USEnrichmentApi/Secondary/Lookup.cs @@ -8,7 +8,7 @@ public class Lookup : SmartyStreets.USEnrichmentApi.Lookup { private Result[] results; - public Lookup(string smartyKey) : base(smartyKey, "secondary", "") + public Lookup(string smartyKey = null) : base(smartyKey, "secondary", "") { } @@ -25,7 +25,9 @@ public void SetResults(Result[] results) public override void DeserializeAndSetResults(SmartyStreets.ISerializer serializer, Stream payload) { this.results = serializer.Deserialize(payload); - this.results[0].Etag = this.GetEtag(); + if (this.results != null) { + this.results[0].Etag = this.GetEtag(); + } } } } \ No newline at end of file diff --git a/src/sdk/USEnrichmentApi/Universal/Lookup.cs b/src/sdk/USEnrichmentApi/Universal/Lookup.cs index 63e3e05..521f48b 100644 --- a/src/sdk/USEnrichmentApi/Universal/Lookup.cs +++ b/src/sdk/USEnrichmentApi/Universal/Lookup.cs @@ -9,7 +9,7 @@ public class Lookup : SmartyStreets.USEnrichmentApi.Lookup { private byte[] results; - public Lookup(string smartyKey, string dataSet, string dataSubset) : base(smartyKey, dataSet, dataSubset) + public Lookup(string smartyKey = null, string dataSet = null, string dataSubset = null) : base(smartyKey, dataSet, dataSubset) { } diff --git a/src/tests/USEnrichmentApi/ClientTests.cs b/src/tests/USEnrichmentApi/ClientTests.cs index 128cd3b..67959f2 100644 --- a/src/tests/USEnrichmentApi/ClientTests.cs +++ b/src/tests/USEnrichmentApi/ClientTests.cs @@ -17,6 +17,7 @@ public void Setup() this.urlSender = new URLPrefixSender("http://localhost", this.capturingSender); } + //Property Principal Lookup Tests: [Test] public void TestSendingFullyPopulatedPrincipalLookup() @@ -30,7 +31,40 @@ public void TestSendingFullyPopulatedPrincipalLookup() Assert.AreEqual(expectedUrl, this.capturingSender.Request.GetUrl()); } - [Test] + public void TestSendingFullyPopulatedPrincipalComponenetsLookup() + { + var serializer = new FakeSerializer(null); + var client = new Client(this.urlSender, serializer); + const string expectedUrl= "http://localhost/search/property/principal?street=street&city=city&state=state&zipcode=zipcode"; + + var lookup = new Property.Principal.Lookup(); + lookup.SetStreet("street"); + lookup.SetCity("city"); + lookup.SetState("state"); + lookup.SetZipcode("zipcode"); + + client.SendPropertyPrincipalLookup(lookup); + + Assert.AreEqual(expectedUrl, this.capturingSender.Request.GetUrl()); + } + + public void TestSendingFullyPopulatedPrincipalFreeformLookup() + { + var serializer = new FakeSerializer(null); + var client = new Client(this.urlSender, serializer); + const string expectedUrl= "http://localhost/search/property/principal?freeform=freeform"; + + var lookup = new Property.Principal.Lookup(); + lookup.SetFreeform("freeform"); + + client.SendPropertyPrincipalLookup(lookup); + + Assert.AreEqual(expectedUrl, this.capturingSender.Request.GetUrl()); + } + + //Property Financial Lookup Tests: + + [Test] public void TestSendingFullyPopulatedFinancialLookup() { var serializer = new FakeSerializer(null); @@ -42,13 +76,180 @@ public void TestSendingFullyPopulatedFinancialLookup() Assert.AreEqual(expectedUrl, this.capturingSender.Request.GetUrl()); } + public void TestSendingFullyPopulatedFinancialComponenetsLookup() + { + var serializer = new FakeSerializer(null); + var client = new Client(this.urlSender, serializer); + const string expectedUrl= "http://localhost/search/property/financial?street=street&city=city&state=state&zipcode=zipcode"; + + var lookup = new Property.Financial.Lookup(); + lookup.SetStreet("street"); + lookup.SetCity("city"); + lookup.SetState("state"); + lookup.SetZipcode("zipcode"); + + client.SendPropertyFinancialLookup(lookup); + + Assert.AreEqual(expectedUrl, this.capturingSender.Request.GetUrl()); + } + + public void TestSendingFullyPopulatedFinancialFreeformLookup() + { + var serializer = new FakeSerializer(null); + var client = new Client(this.urlSender, serializer); + const string expectedUrl= "http://localhost/search/property/financial?freeform=freeform"; + + var lookup = new Property.Financial.Lookup(); + lookup.SetFreeform("freeform"); + + client.SendPropertyFinancialLookup(lookup); + + Assert.AreEqual(expectedUrl, this.capturingSender.Request.GetUrl()); + } + + //GeoReference Lookup Tests: + + [Test] + public void TestSendingFullyPopulatedGeoReferenceLookup() + { + var serializer = new FakeSerializer(null); + var client = new Client(this.urlSender, serializer); + const string expectedUrl= "http://localhost/1/geo-reference?"; + + client.SendGeoReferenceLookup("1"); + + Assert.AreEqual(expectedUrl, this.capturingSender.Request.GetUrl()); + } + + public void TestSendingFullyPopulatedGeoReferenceComponenetsLookup() + { + var serializer = new FakeSerializer(null); + var client = new Client(this.urlSender, serializer); + const string expectedUrl= "http://localhost/search/geo-reference?street=street&city=city&state=state&zipcode=zipcode"; + + var lookup = new GeoReference.Lookup(); + lookup.SetStreet("street"); + lookup.SetCity("city"); + lookup.SetState("state"); + lookup.SetZipcode("zipcode"); + + client.SendGeoReferenceLookup(lookup); + + Assert.AreEqual(expectedUrl, this.capturingSender.Request.GetUrl()); + } + + public void TestSendingFullyPopulatedGeoReferenceFreeformLookup() + { + var serializer = new FakeSerializer(null); + var client = new Client(this.urlSender, serializer); + const string expectedUrl= "http://localhost/search/geo-reference?freeform=freeform"; + + var lookup = new GeoReference.Lookup(); + lookup.SetFreeform("freeform"); + + client.SendGeoReferenceLookup(lookup); + + Assert.AreEqual(expectedUrl, this.capturingSender.Request.GetUrl()); + } + + //Secondary Lookup Tests: + + [Test] + public void TestSendingFullyPopulatedSecondaryLookup() + { + var serializer = new FakeSerializer(null); + var client = new Client(this.urlSender, serializer); + const string expectedUrl= "http://localhost/1/secondary?"; + + client.SendSecondaryLookup("1"); + + Assert.AreEqual(expectedUrl, this.capturingSender.Request.GetUrl()); + } + + public void TestSendingFullyPopulatedSecondaryComponenetsLookup() + { + var serializer = new FakeSerializer(null); + var client = new Client(this.urlSender, serializer); + const string expectedUrl= "http://localhost/search/secondary?street=street&city=city&state=state&zipcode=zipcode"; + + var lookup = new Secondary.Lookup(); + lookup.SetStreet("street"); + lookup.SetCity("city"); + lookup.SetState("state"); + lookup.SetZipcode("zipcode"); + + client.SendSecondaryLookup(lookup); + + Assert.AreEqual(expectedUrl, this.capturingSender.Request.GetUrl()); + } + + public void TestSendingFullyPopulatedSecondaryFreeformLookup() + { + var serializer = new FakeSerializer(null); + var client = new Client(this.urlSender, serializer); + const string expectedUrl= "http://localhost/search/secondary?freeform=freeform"; + + var lookup = new Secondary.Lookup(); + lookup.SetFreeform("freeform"); + + client.SendSecondaryLookup(lookup); + + Assert.AreEqual(expectedUrl, this.capturingSender.Request.GetUrl()); + } + + //Secondary Count Lookup Tests: + + [Test] + public void TestSendingFullyPopulatedSecondaryCountLookup() + { + var serializer = new FakeSerializer(null); + var client = new Client(this.urlSender, serializer); + const string expectedUrl= "http://localhost/1/secondary/count?"; + + client.SendSecondaryCountLookup("1"); + + Assert.AreEqual(expectedUrl, this.capturingSender.Request.GetUrl()); + } + + public void TestSendingFullyPopulatedSecondaryCountComponenetsLookup() + { + var serializer = new FakeSerializer(null); + var client = new Client(this.urlSender, serializer); + const string expectedUrl= "http://localhost/search/secondary/count?street=street&city=city&state=state&zipcode=zipcode"; + + var lookup = new Secondary.Count.Lookup(); + lookup.SetStreet("street"); + lookup.SetCity("city"); + lookup.SetState("state"); + lookup.SetZipcode("zipcode"); + + client.SendSecondaryCountLookup(lookup); + + Assert.AreEqual(expectedUrl, this.capturingSender.Request.GetUrl()); + } + + public void TestSendingFullyPopulatedSecondaryCountFreeformLookup() + { + var serializer = new FakeSerializer(null); + var client = new Client(this.urlSender, serializer); + const string expectedUrl= "http://localhost/search/secondary/count?freeform=freeform"; + + var lookup = new Secondary.Count.Lookup(); + lookup.SetFreeform("freeform"); + + client.SendSecondaryCountLookup(lookup); + + Assert.AreEqual(expectedUrl, this.capturingSender.Request.GetUrl()); + } + [Test] public void TestRejectNullLookup() { var serializer = new FakeSerializer(null); var client = new Client(this.urlSender, serializer); + string smartyKey = null; - Assert.Throws(() => client.SendPropertyFinancialLookup(null)); + Assert.Throws(() => client.SendPropertyFinancialLookup(smartyKey)); } } } \ No newline at end of file