Skip to content

Commit

Permalink
Add GoogleMaps Tests from CluedIn Repo
Browse files Browse the repository at this point in the history
  • Loading branch information
VladMB committed Nov 5, 2019
1 parent 9239850 commit dd33ac0
Show file tree
Hide file tree
Showing 3 changed files with 242 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ExternalSearch.Providers.GoogleMaps.sln
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Git", "Git", "{17EE3C8D-BAE
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ExternalSearch.Providers.GoogleMaps", "src\ExternalSearch.Providers.GoogleMaps.csproj", "{E5832F12-6BB8-4ACA-AB23-F82888FF3971}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ExternalSearch.GoogleMaps.Integration.Tests", "test\integration\Integration.Tests\ExternalSearch.GoogleMaps.Integration.Tests.csproj", "{8CBDF6EB-A861-466E-932B-04CA5917923C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -60,6 +62,10 @@ Global
{E5832F12-6BB8-4ACA-AB23-F82888FF3971}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E5832F12-6BB8-4ACA-AB23-F82888FF3971}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E5832F12-6BB8-4ACA-AB23-F82888FF3971}.Release|Any CPU.Build.0 = Release|Any CPU
{8CBDF6EB-A861-466E-932B-04CA5917923C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8CBDF6EB-A861-466E-932B-04CA5917923C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8CBDF6EB-A861-466E-932B-04CA5917923C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8CBDF6EB-A861-466E-932B-04CA5917923C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -72,6 +78,7 @@ Global
{02641789-0D38-4DBB-9288-23592CF55D25} = {9BD54E81-D9C8-4419-82B8-8EE6CC7E2647}
{2C3AECCF-DCB5-4ED7-8B7B-8F373EDE3A5E} = {9BD54E81-D9C8-4419-82B8-8EE6CC7E2647}
{17EE3C8D-BAE4-481A-B9CC-1BE878E86124} = {9BD54E81-D9C8-4419-82B8-8EE6CC7E2647}
{8CBDF6EB-A861-466E-932B-04CA5917923C} = {DBD1964B-DBD9-4C70-96CA-391C34B3D75F}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6A61CB42-80C5-4A83-AC3E-DA41FC875525}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<ProjectGuid>{8CBDF6EB-A861-466E-932B-04CA5917923C}</ProjectGuid>
<TargetFramework>net452</TargetFramework>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
<IsCodedUITest>False</IsCodedUITest>
<TestProjectType>UnitTest</TestProjectType>
<AssemblyTitle>Integration.Tests</AssemblyTitle>
<Product>Integration.Tests</Product>
<Copyright>Copyright © 2019</Copyright>
<OutputPath>bin\$(Configuration)\</OutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugType>full</DebugType>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
</PropertyGroup>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" />
<PackageReference Include="MSTest.TestAdapter" Version="1.4.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="CluedIn.Core" Version="2.4.0-alpha0103" />
<PackageReference Include="CluedIn.Testing.Base" Version="2.4.0" />
<PackageReference Include="Moq" Version="4.13.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.3.2" />
<PackageReference Include="MSTest.TestFramework" Version="1.3.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\ExternalSearch.Providers.GoogleMaps.csproj" />
</ItemGroup>
</Project>
198 changes: 198 additions & 0 deletions test/integration/Integration.Tests/GoogleMapsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
using System;
using System.Collections.Generic;
using System.Linq;
using CluedIn.Core.Data;
using CluedIn.Core.Data.Parts;
using CluedIn.Core.Messages.Processing;
using CluedIn.ExternalSearch;
using CluedIn.ExternalSearch.Providers.GoogleMaps;
using CluedIn.ExternalSearch.Providers.GoogleMaps.Models;
using CluedIn.Testing.Base.Context;
using CluedIn.Testing.Base.ExternalSearch;
using CluedIn.Testing.Base.Processing.Actors;
using Moq;
using Xunit;
//using TestContext = CluedIn.Tests.Unit.TestContext;

namespace CluedIn.Tests.Integration.ExternalSearch
{
public class GoogleMapsTests : BaseExternalSearchTest<GoogleMapsExternalSearchProvider>
{
[Theory]
[InlineData("CluedIn APS", "Titangade 11", "Titangade 11, 2200 København, Denmark")]
[InlineData("CluedIn APS", "11 Titangade", "Titangade 11, 2200 København, Denmark")]
[InlineData("CluedIn APS", "Denmark, Titangade 11", "Titangade 11, 2200 København, Denmark")]
// Fails since api call does not yield enough information,
// and no persons are returned.
public void TestClueProduction(string name, string address, string formattedAdress)
{
var list = new List<string>(new string[] { "AIzaSyA8oZKYh7NT4bX_yZl8vKIMdecoQCHJC4I" });
object[] parameters = { list };
var properties = new EntityMetadataPart();
properties.Properties.Add(CluedIn.Core.Data.Vocabularies.Vocabularies.CluedInOrganization.OrganizationName, name);
properties.Properties.Add(CluedIn.Core.Data.Vocabularies.Vocabularies.CluedInOrganization.Address, address);


IEntityMetadata entityMetadata = new EntityMetadataPart() {
EntityType = EntityType.Organization,
Properties = properties.Properties
};

//var tokenProvider = new DummyTokenProvider("AIzaSyA8oZKYh7NT4bX_yZl8vKIMdecoQCHJC4I");

this.Setup(parameters, entityMetadata);

// Assert
this.testContext.ProcessingHub.Verify(h => h.SendCommand(It.IsAny<ProcessClueCommand>()), Times.AtLeastOnce);
Assert.True(clues.Count > 0);
foreach(var clue in this.clues)
{
clue.Decompress().Data.EntityData.Properties
.TryGetValue("googleMaps.Organization.FormattedAddress", out var value);

Assert.Equal(formattedAdress, value);
}
}

[Theory]

[InlineData(null)]
public void TestNoClueProduction(string name)
{
IEntityMetadata entityMetadata = new EntityMetadataPart() {
Name = name,
EntityType = EntityType.Organization
};

this.Setup(null, entityMetadata);

// Assert
this.testContext.ProcessingHub.Verify(h => h.SendCommand(It.IsAny<ProcessClueCommand>()), Times.Never);
Assert.True(clues.Count == 0);
}

// TODO Issue 170 - Test Failures
//[Theory]
//[InlineData("null")]
//[InlineData("empty")]
//[InlineData("nonWorking")]
//public void TestInvalidApiToken(string provider)
//{
// var tokenProvider = GetProviderByName(provider);
// object[] parameters = { tokenProvider };

// IEntityMetadata entityMetadata = new EntityMetadataPart()
// {
// Name = "Sitecore",
// EntityType = EntityType.Organization
// };

// Setup(parameters, entityMetadata);
// // Assert
// this.testContext.ProcessingHub.Verify(h => h.SendCommand(It.IsAny<ProcessClueCommand>()), Times.Never);
// Assert.True(clues.Count == 0);
//}

//[Fact]
//public void NullTest()
//{
// var dummyTokenProvider = new DummyTokenProvider("1234");
// var permIdExternalSearchProvider = new PermIdExternalSearchProvider(dummyTokenProvider);

// var query = new ExternalSearchQuery(permIdExternalSearchProvider, EntityType.FAQ, "asd", "gfh");
// var result = new ExternalSearchQueryResult<object>(query, null);

// var actual = permIdExternalSearchProvider.GetPrimaryEntityMetadata(null, result, null);

// Assert.Null(actual);
//}

//[Fact]
//public void TestNoAdditionalInfo()
//{
// var dummyTokenProvider = new DummyTokenProvider("1234");
// var permIdExternalSearchProvider = new PermIdExternalSearchProvider(dummyTokenProvider);

// var permIdSocialResponse = new PermIdSocialResponse {
// AdditionalInfo = null,
// DomiciledIn = new List<string>() { "Copenhagen" },
// PermId = new List<string>() { "123" },
// OrganizationName = new List<string>() { "Organization name" }
// };

// var query = new ExternalSearchQuery {
// ProviderId = new Guid("8bc514e4-3dcd-44ca-9e36-479c0940f646"),
// QueryKey = "abc",
// EntityType = EntityType.Organization
// };

// var result = new ExternalSearchQueryResult<PermIdSocialResponse>(query, permIdSocialResponse);
// var dummyContext = new TestContext().Context;
// var dummyRequest = new DummyRequest();

// foreach (var clue in permIdExternalSearchProvider.BuildClues(dummyContext, query, result, dummyRequest))
// {
// if (clue.Data.EntityData.EntityType != EntityType.Organization)
// throw new Exception("EntityType should be Organization, since only data about organization is provided");
// }
//}

//[Fact]
//public void TestAdditionalInfo()
//{
// var dummyTokenProvider = new DummyTokenProvider("1234");
// var permIdExternalSearchProvider = new PermIdExternalSearchProvider(dummyTokenProvider);

// var person = new AssociatedPerson() {
// FamilyName = new List<string>() { "FamilyName" },
// PersonUrl = new List<string>() { "abc" }
// };

// var permIdSocialResponse = new PermIdSocialResponse {
// AdditionalInfo = new List<AssociatedPerson>() { person },
// DomiciledIn = new List<string>() { "Copenhagen" },
// PermId = new List<string>() { "123" },
// OrganizationName = new List<string>() { "Organization name" }
// };

// var query = new ExternalSearchQuery {
// ProviderId = new Guid("8bc514e4-3dcd-44ca-9e36-479c0940f646"),
// QueryKey = "abc",
// EntityType = EntityType.Organization
// };

// var result = new ExternalSearchQueryResult<PermIdSocialResponse>(query, permIdSocialResponse);
// var dummyContext = new TestContext().Context;
// var dummyRequest = new DummyRequest();

// var hasYieldedPerson = false;
// foreach (var clue in permIdExternalSearchProvider.BuildClues(dummyContext, query, result, dummyRequest))
// {
// if (clue.Data.EntityData.EntityType == EntityType.Infrastructure.User)
// hasYieldedPerson = true;
// }

// if (!hasYieldedPerson)
// throw new Exception("Should yield at least one person, since data about one has been provided");
//}

//public class DummyRequest : IExternalSearchRequest
//{
// public IEntityMetadata EntityMetaData
// { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
// public object CustomQueryInput
// { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
// public bool? NoRecursion
// { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
// public List<Guid> ProviderIds
// { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
// public IExternalSearchQueryParameters QueryParameters
// { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
// public List<IExternalSearchQuery> Queries
// { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
// public bool IsFinished
// { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
// public bool AllQueriesHasExecuted => throw new NotImplementedException();
//}
}
}

0 comments on commit dd33ac0

Please sign in to comment.