diff --git a/.gitignore b/.gitignore index 491a91c..b7201c8 100644 --- a/.gitignore +++ b/.gitignore @@ -109,4 +109,5 @@ UpgradeLog*.XML MSTest.* -*.nupkg \ No newline at end of file +*.nupkg +/packages/* \ No newline at end of file diff --git a/PiplApisProd.sln b/PiplApisProd.sln index c4eb999..ca6c1de 100644 --- a/PiplApisProd.sln +++ b/PiplApisProd.sln @@ -3,9 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 16 VisualStudioVersion = 16.0.29215.179 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Piplapis", "Piplapis\Piplapis.csproj", "{E9921187-C395-422D-844A-6136C55CD6BC}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Piplapis", "Piplapis\Piplapis.csproj", "{E9921187-C395-422D-844A-6136C55CD6BC}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTests", "UnitTests\UnitTests.csproj", "{D7E2E676-B827-47EE-B82A-89686DB6D00F}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTests", "UnitTests\UnitTests.csproj", "{D7E2E676-B827-47EE-B82A-89686DB6D00F}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/Piplapis/Data/Fields/Phone.cs b/Piplapis/Data/Fields/Phone.cs index cf3c8db..53b1322 100644 --- a/Piplapis/Data/Fields/Phone.cs +++ b/Piplapis/Data/Fields/Phone.cs @@ -73,8 +73,12 @@ public override bool IsSearchable { get { - return (!string.IsNullOrEmpty(Raw)) || - (Number != null && (CountryCode == null || CountryCode >= 0 && CountryCode < 999)); + + if (!string.IsNullOrEmpty(Raw)) return true; + if (CountryCode == null && Number >= 99999999) return true; + if (CountryCode != null && CountryCode>0 && CountryCode <=999 && Number >= 999999) return true; + return false; + } } diff --git a/Piplapis/Piplapis.csproj b/Piplapis/Piplapis.csproj index a6a5429..d9d6148 100644 --- a/Piplapis/Piplapis.csproj +++ b/Piplapis/Piplapis.csproj @@ -16,7 +16,7 @@ - + \ No newline at end of file diff --git a/UnitTests/UnitTest1.cs b/UnitTests/UnitTest1.cs index d36e69d..a496243 100644 --- a/UnitTests/UnitTest1.cs +++ b/UnitTests/UnitTest1.cs @@ -1,22 +1,67 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using System.Configuration; +using System.Diagnostics; +using System.Collections.Specialized; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using System.IO; +using Pipl.APIs; using Pipl.APIs.Search; +using Pipl.APIs.Data; +using Pipl.APIs.Data.Fields; +using Pipl.APIs.Data.Containers; +using Pipl.APIs.Data.Enums; +using Pipl.APIs.Utils; -namespace UnitTests + +namespace UnitTestProjectAPIc { - [TestClass] public class UnitTest1 { - public static string API_KEY = "YOUR API KEY HERE"; + + + public UnitTest1() + { + //Init(); + } + private SearchConfiguration setDefaultSearchConfiguration() + { + //edit your API key in appsettings app.config file such as: < add key = "PIPL_APIKey" value = "YOURKEY" /> + //this is not working perhaps bec of project differences or because of test project; see irregularTTextParser project + //string api_key = ConfigurationManager.AppSettings.Get("Pipl_APIKey"); //?? throw new ArgumentNullException("No PIPL API key set in App.config"); + string api_key = "BUSINESS-PREMIUM-YOURKEY"; + + return new SearchConfiguration() + { + ApiKey = api_key, + ShowSources = ShowSources.Matching, + //For improved latency, rate and consistent results + LiveFeeds = false, + + //Work only with single matching profiles (Person responses), and must have social_profiles including LinkedIn sources + // see https://pipl.com/api/reference/#match-criteria and https://pipl.com/api/reference/#source + MinimumMatch = 1, + MatchRequirements = "social_profiles", + SourceCategoryRequirements = "professional_and_business", + UseHttps = true + + }; + + } [TestMethod] public void TestTopMatch() { - SearchConfiguration config = new SearchConfiguration(topMatch: true, apiKey: API_KEY); - SearchAPIRequest s = new SearchAPIRequest(firstName: "Moshe", lastName: "Elkayam", requestConfiguration: config); - + SearchConfiguration sConfig = setDefaultSearchConfiguration(); + sConfig.TopMatch = true; + SearchAPIRequest s = new SearchAPIRequest(firstName: "Moshe", lastName: "Elkayam", requestConfiguration: sConfig); SearchAPIResponse res = s.Send(); Assert.IsTrue(res.TopMatch); @@ -25,12 +70,141 @@ public void TestTopMatch() [TestMethod] public void TestNotTopMatch() { - SearchConfiguration config = new SearchConfiguration(apiKey: API_KEY); - SearchAPIRequest s = new SearchAPIRequest(firstName: "Moshe", lastName: "Elkayam", requestConfiguration: config); - + SearchConfiguration sConfig = setDefaultSearchConfiguration(); + SearchAPIRequest s = new SearchAPIRequest(firstName: "Moshe", lastName: "Elkayam", requestConfiguration: sConfig); SearchAPIResponse res = s.Send(); Assert.IsFalse(res.TopMatch); } + + [TestMethod] + public void aaa_testControlCheck() + { + + Debug.WriteLine("hi. Control check. "); + Assert.IsTrue(true); + } + [TestMethod] + public void TestPersonPhoneQParam() + { + SearchConfiguration sConfig = setDefaultSearchConfiguration(); + List fields = new List(); + var person = new Person(fields); + + SearchAPIRequest request = new SearchAPIRequest(phone: "+14152549431", requestConfiguration: sConfig); + SearchAPIResponse response = request.Send(); + Assert.IsTrue(response.Person != null); + + request = new SearchAPIRequest(phone: "14152549431", requestConfiguration: sConfig); + response = request.Send(); + Assert.IsTrue(response.Person != null); + + request = new SearchAPIRequest(phone: "+14152549431", requestConfiguration: sConfig); + response = request.Send(); + Assert.IsTrue(response.Person != null); + + request = new SearchAPIRequest(phone: "+972508915495", requestConfiguration: sConfig); + response = request.Send(); + Assert.IsTrue(response.PersonsCount == 0); + + request = new SearchAPIRequest(phone: "4152549431", requestConfiguration: sConfig); + response = request.Send(); + Assert.IsTrue(response.Person != null); + + //fields.Add(new Phone(raw: "4152549431")); //Clark Kent # + //SearchAPIRequest request = new SearchAPIRequest(person: person, requestConfiguration: sConfig); + //fields.Add(new Phone(countryCode: System.Convert.ToInt32(recIn.CountryCode), number: System.Convert.ToInt64(recIn.PhoneNum))); + + } + + + [TestMethod] + public void TestPersonPhonePersonSearch() + { + SearchConfiguration sConfig = setDefaultSearchConfiguration(); + List fields = new List(); + + fields.Add(new Phone(countryCode: 1, number: 4152549431)); + var person = new Person(fields); + SearchAPIRequest request = new SearchAPIRequest(person: person, requestConfiguration: sConfig); + SearchAPIResponse response = request.Send(); + Assert.IsTrue(response.Person != null); + + fields = new List(); + fields.Add(new Phone(number: 4152549431)); + person = new Person(fields); + request = new SearchAPIRequest(person: person, requestConfiguration: sConfig); + response = request.Send(); + Assert.IsTrue(response.Person != null); + + fields = new List(); + fields.Add(new Phone(countryCode: 34, number: 636117049)); + person = new Person(fields); + request = new SearchAPIRequest(person: person, requestConfiguration: sConfig); + response = request.Send(); + Assert.IsTrue(response.PersonsCount >= 0); + } + [TestMethod] + public void TestPersonPhonePersonSearchNull() + { + SearchConfiguration sConfig = setDefaultSearchConfiguration(); + List fields = new List(); + + fields = new List(); + fields.Add(new Phone(countryCode: null, number: 636117049)); + var person = new Person(fields); + SearchAPIRequest request = new SearchAPIRequest(person: person, requestConfiguration: sConfig); + request = new SearchAPIRequest(person: person, requestConfiguration: sConfig); + SearchAPIResponse response; + + try + { + response = request.Send(); + Assert.IsTrue(false); //if it gets this far, it's false; + } + catch (SearchAPIError apiError) + { + Assert.IsTrue(apiError.Error == "The query does not contain any valid name/username/user_id/phone/email/address to search by"); + } + catch (System.Net.WebException e) + { } + catch (Exception e) + { } + + } + + + + [TestMethod] + public void TestIsPhoneSearchable() + { + SearchConfiguration sConfig = setDefaultSearchConfiguration(); + List fields = new List(); + + fields.Add(new Phone(countryCode: 1, number: 4152549431)); + Assert.IsTrue(fields[0].IsSearchable); + fields.Add(new Phone(countryCode: 9, number: 4152549431)); + Assert.IsTrue(fields[1].IsSearchable); + fields.Add(new Phone(countryCode: 999, number: 4152549431)); + Assert.IsTrue(fields[2].IsSearchable); + fields.Add(new Phone(countryCode: +1, number: +4152549431)); + Assert.IsTrue(fields[3].IsSearchable); + fields.Add(new Phone(countryCode: 34, number: 636117049)); + Assert.IsTrue(fields[4].IsSearchable); + fields.Add(new Phone(countryCode: +34, number: +636117049)); + Assert.IsTrue(fields[5].IsSearchable); + fields.Add(new Phone(countryCode: -1, number: -4152549431)); + Assert.IsFalse(fields[6].IsSearchable); + fields.Add(new Phone(countryCode: 9999, number: 636117049)); + Assert.IsFalse(fields[7].IsSearchable); + fields.Add(new Phone(countryCode: 1, number: 99999)); + Assert.IsFalse(fields[8].IsSearchable); + fields.Add(new Phone(countryCode: null, number: +4152549431)); + Assert.IsTrue(fields[9].IsSearchable); + fields.Add(new Phone(countryCode: null, number: +4152549431)); + Assert.IsTrue(fields[10].IsSearchable); + + } + } } diff --git a/UnitTests/UnitTests.csproj b/UnitTests/UnitTests.csproj index 52a1d9c..1c12232 100644 --- a/UnitTests/UnitTests.csproj +++ b/UnitTests/UnitTests.csproj @@ -16,11 +16,11 @@ - + - +