Skip to content

Commit

Permalink
Add test from latest version of code (lovro's branch in CluedIn repo)
Browse files Browse the repository at this point in the history
  • Loading branch information
VladMB committed Nov 5, 2019
1 parent dd33ac0 commit 1428c84
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 135 deletions.
3 changes: 2 additions & 1 deletion src/GoogleMapsExternalSearchProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ public override IEnumerable<IExternalSearchQueryResult> ExecuteSearch(ExecutionC

if (query.QueryParameters.ContainsKey("companyName") && query.QueryParameters.ContainsKey("companyAddress"))
{
var input = new {
var input = new
{
name = query.QueryParameters["companyName"].FirstOrDefault(),
address = query.QueryParameters["companyAddress"].FirstOrDefault()
};
Expand Down
196 changes: 62 additions & 134 deletions test/integration/Integration.Tests/GoogleMapsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,83 @@
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 Xunit.Abstractions;
//using TestContext = CluedIn.Tests.Unit.TestContext;

namespace CluedIn.Tests.Integration.ExternalSearch
{
public class GoogleMapsTests : BaseExternalSearchTest<GoogleMapsExternalSearchProvider>
{
private readonly ITestOutputHelper outputHelper;

public GoogleMapsTests(ITestOutputHelper outputHelper)
{
this.outputHelper = outputHelper;
}

[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")]
[InlineData("Gowan Rd", "-27.595919728", "153.064914419", "Gowan Rd, Brisbane QLD, Australia")]
// Fails since api call does not yield enough information,
// and no persons are returned.
public void TestClueProductionLocation(/*string name, */string address, string lattitude, string longitude, string formattedAdress)
{
var code = new EntityCode(EntityType.Location, CodeOrigin.CluedIn, $"{lattitude}, {longitude}");

var list = new List<string>(new string[] { "AIzaSyA8oZKYh7NT4bX_yZl8vKIMdecoQCHJC4I" });
object[] parameters = { list };
var properties = new EntityMetadataPart();
properties.Properties.Add(CluedIn.Core.Data.Vocabularies.Vocabularies.CluedInLocation.AddressNameStreet, address);
properties.Properties.Add(CluedIn.Core.Data.Vocabularies.Vocabularies.CluedInLocation.AddressLattitude, lattitude);
properties.Properties.Add(CluedIn.Core.Data.Vocabularies.Vocabularies.CluedInLocation.AddressLongitude, longitude);

IEntityMetadata entityMetadata = new EntityMetadataPart()
{
EntityType = EntityType.Location,
Properties = properties.Properties,
OriginEntityCode = code,
};

entityMetadata.Codes.Add(code);

//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(this.clues.Count > 0);
foreach (var clue in this.clues)
{
var c = clue.Decompress();

this.outputHelper.WriteLine(c.Serialize());

c.Data.EntityData.Properties.TryGetValue("googleMaps.Location.formattedAddress", out var value);

Assert.Equal(formattedAdress, value);
}
}

[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)
public void TestClueProductionOrganization(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() {
IEntityMetadata entityMetadata = new EntityMetadataPart()
{
EntityType = EntityType.Organization,
Properties = properties.Properties
};
Expand All @@ -45,7 +95,7 @@ public void TestClueProduction(string name, string address, string formattedAdre
// Assert
this.testContext.ProcessingHub.Verify(h => h.SendCommand(It.IsAny<ProcessClueCommand>()), Times.AtLeastOnce);
Assert.True(clues.Count > 0);
foreach(var clue in this.clues)
foreach (var clue in this.clues)
{
clue.Decompress().Data.EntityData.Properties
.TryGetValue("googleMaps.Organization.FormattedAddress", out var value);
Expand All @@ -59,7 +109,8 @@ public void TestClueProduction(string name, string address, string formattedAdre
[InlineData(null)]
public void TestNoClueProduction(string name)
{
IEntityMetadata entityMetadata = new EntityMetadataPart() {
IEntityMetadata entityMetadata = new EntityMetadataPart()
{
Name = name,
EntityType = EntityType.Organization
};
Expand All @@ -69,130 +120,7 @@ public void TestNoClueProduction(string name)
// 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 1428c84

Please sign in to comment.