Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,11 @@ this ICypherFluentQuery query
, relationship.ToCypherString<T, CypherMatchAttribute>(CypherExtensionContext.Create(query), relationship.Key, matchProperties)
, relationship.ToKey);

return matchFunction(query,cql);
dynamic cutdown = relationship.CreateDynamic(options.MatchOverride ?? CypherTypeItemHelper.PropertiesForPurpose<T, CypherMatchAttribute>(relationship));
var matchKey = GetMatchParamName(relationship.Key);

return matchFunction(query, cql)
.WithParam(matchKey, cutdown);
}

public static ICypherFluentQuery MatchRelationship<T>(this ICypherFluentQuery query, T relationship, List<CypherProperty> matchOverride = null) where T : BaseRelationship
Expand Down
44 changes: 44 additions & 0 deletions test/Neo4jClient.Extension.IntegrationTest/Tests/MatchTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using FluentAssertions;
using Neo4jClient.Extension.Cypher;
using Neo4jClient.Extension.Test.Cypher;
using Neo4jClient.Extension.Test.Data.Neo.Relationships;
using Neo4jClient.Extension.Test.TestData.Entities;
using Neo4jClient.Extension.Test.TestEntities.Relationships;
using NUnit.Framework;
Expand Down Expand Up @@ -209,5 +210,48 @@ await CypherQuery
retrieved.BlastRadius.Should().NotBeNull();
retrieved.BlastRadius.Value.SquareKilometers.Should().BeApproximately(12.4, 0.01);
}

public Task ArrangeTestData()
{
var archer = SampleDataFactory.GetWellKnownPerson(1);
var isis = new Organisation {Name="ISIS"};
var kgb = new Organisation { Name = "KGB" };

var archerVariable = "a";
var kgbVariable = "k";
var isisVariable = "i";

var agentRelationship = new WorksForRelationship("special agent", archerVariable, isisVariable);
var doubleAgentRelationship = new WorksForRelationship("double agent", archerVariable, kgbVariable);

var q = RealQueryFactory();

return q
.CreateEntity(archer, archerVariable)
.CreateEntity(isis, isisVariable)
.CreateEntity(kgb, kgbVariable)
.CreateRelationship(agentRelationship)
.CreateRelationship(doubleAgentRelationship)
.ExecuteWithoutResultsAsync();
}

[Test]
public async Task Match()
{
ArrangeTestData();

// Act
var q = RealQueryFactory()
.MatchRelationship(new WorksForRelationship("special agent", "p", "o"))
.Return(o => o.As<Organisation>());

Console.WriteLine(q.GetFormattedDebugText());
var r = (await q.ResultsAsync).ToList();

r.Count.Should().Be(1);

//Not working??
Console.WriteLine($" Org={r[0].Name}");
}
}
}
13 changes: 13 additions & 0 deletions test/Neo4jClient.Extension.Test.Common/Domain/Company.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Neo4jClient.Extension.Test.Cypher
{
public class Organisation
{
public string Name { get; set; }
}
}
14 changes: 14 additions & 0 deletions test/Neo4jClient.Extension.Test.Common/Neo/NeoConfig.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Neo4jClient.Extension.Cypher;
using Neo4jClient.Extension.Test.Cypher;
using Neo4jClient.Extension.Test.Data.Neo.Relationships;
using Neo4jClient.Extension.Test.TestData.Entities;
using Neo4jClient.Extension.Test.TestEntities.Relationships;

Expand Down Expand Up @@ -44,12 +45,25 @@ public static void ConfigureModel()
.MergeOnMatchOrCreate(w => w.BlastRadius)
.Set();


FluentConfig.Config()
.With<Organisation>()
.Merge(x => x.Name)
.MergeOnMatchOrCreate(w => w.Name)
.Set();

FluentConfig.Config()
.With<HomeAddressRelationship>()
.Match(ha => ha.DateEffective)
.MergeOnMatchOrCreate(hr => hr.DateEffective)
.Set();

FluentConfig.Config()
.With<WorksForRelationship>()
.Match(wf => wf.Role)
.MergeOnMatchOrCreate(wf => wf.Role)
.Set();

FluentConfig.Config()
.With<WorkAddressRelationship>()
.Set();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Neo4jClient.Extension.Cypher;
using Neo4jClient.Extension.Cypher.Attributes;

namespace Neo4jClient.Extension.Test.Data.Neo.Relationships
{
[CypherLabel(Name = LabelName)]
public class WorksForRelationship : BaseRelationship
{
public const string LabelName = "WORKS_FOR";

public WorksForRelationship(string role, string from = "person", string to = "organisation")
: base(from, to)
{
Role = role;
}

public WorksForRelationship(string from = "person", string to = "address")
: base(from, to)
{
}

public string Role { get; set; }
}
}
7 changes: 7 additions & 0 deletions test/Neo4jClient.Extension.Test.Common/SampleDataFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,12 @@ public static Weapon GetWellKnownWeapon(int n)
weapon.BlastRadius = Area.FromSquareMeters(20);
return weapon;
}

public static Organisation GetWellKnownOrganisation()
{
var org = new Organisation();
org.Name = "ISIS";
return org;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using System;
using FluentAssertions;
using Neo4jClient.Cypher;
using Neo4jClient.Extension.Cypher;
using Neo4jClient.Extension.Test.Data.Neo.Relationships;
using Neo4jClient.Extension.Test.TestData.Relationships;
using Neo4jClient.Extension.Test.TestEntities.Relationships;
using NUnit.Framework;
Expand Down Expand Up @@ -79,7 +82,34 @@

Console.WriteLine(text);

Assert.That(text, Is.EqualTo(@"MATCH (agent)-[agenthomeAddress:HOME_ADDRESS {dateEffective:$agenthomeAddressMatchKey.dateEffective}]->(homeAddress)"));
Assert.That(text, Is.EqualTo(@"MATCH (agent)-[agenthomeAddress:HOME_ADDRESS {dateEffective:{

Check failure on line 85 in test/Neo4jClient.Extension.UnitTest/Cypher/FluentConfigMatchTests.cs

View workflow job for this annotation

GitHub Actions / Test Results (CI-CD)

Neo4jClient.Extension.Test.Cypher.FluentConfigMatchTests ► MatchRelationshipWithProperty

Failed test found in: test/Neo4jClient.Extension.UnitTest/TestResults/unit-test-results.trx Error: Assert.That(text, Is.EqualTo(@"MATCH (agent)-[agenthomeAddress:HOME_ADDRESS {dateEffective:{ dateEffective: ""2015-08-05T12:00:00+10:00"" }.dateEffective}]->(homeAddress)")) String lengths are both 139. Strings differ at index 100. Expected: "... "2015-08-05T12:00:00+10:00"\n}.dateEffective}]->(homeAddress)" But was: "... "2015-08-05T12:00:00+00:00"\n}.dateEffective}]->(homeAddress)" ------------------------------------^
Raw output
  Assert.That(text, Is.EqualTo(@"MATCH (agent)-[agenthomeAddress:HOME_ADDRESS {dateEffective:{
  dateEffective: ""2015-08-05T12:00:00+10:00""
}.dateEffective}]->(homeAddress)"))
  String lengths are both 139. Strings differ at index 100.
  Expected: "... "2015-08-05T12:00:00+10:00"\n}.dateEffective}]->(homeAddress)"
  But was:  "... "2015-08-05T12:00:00+00:00"\n}.dateEffective}]->(homeAddress)"
  ------------------------------------^

   at Neo4jClient.Extension.Test.Cypher.FluentConfigMatchTests.MatchRelationshipWithProperty() in /home/runner/work/Neo4jClient.Extension/Neo4jClient.Extension/test/Neo4jClient.Extension.UnitTest/Cypher/FluentConfigMatchTests.cs:line 85

1)    at Neo4jClient.Extension.Test.Cypher.FluentConfigMatchTests.MatchRelationshipWithProperty() in /home/runner/work/Neo4jClient.Extension/Neo4jClient.Extension/test/Neo4jClient.Extension.UnitTest/Cypher/FluentConfigMatchTests.cs:line 85

Check failure on line 85 in test/Neo4jClient.Extension.UnitTest/Cypher/FluentConfigMatchTests.cs

View workflow job for this annotation

GitHub Actions / Test Results

Neo4jClient.Extension.Test.Cypher.FluentConfigMatchTests ► MatchRelationshipWithProperty

Failed test found in: test/Neo4jClient.Extension.UnitTest/TestResults/unit-test-results.trx Error: Assert.That(text, Is.EqualTo(@"MATCH (agent)-[agenthomeAddress:HOME_ADDRESS {dateEffective:{ dateEffective: ""2015-08-05T12:00:00+10:00"" }.dateEffective}]->(homeAddress)")) String lengths are both 139. Strings differ at index 100. Expected: "... "2015-08-05T12:00:00+10:00"\n}.dateEffective}]->(homeAddress)" But was: "... "2015-08-05T12:00:00+00:00"\n}.dateEffective}]->(homeAddress)" ------------------------------------^
Raw output
  Assert.That(text, Is.EqualTo(@"MATCH (agent)-[agenthomeAddress:HOME_ADDRESS {dateEffective:{
  dateEffective: ""2015-08-05T12:00:00+10:00""
}.dateEffective}]->(homeAddress)"))
  String lengths are both 139. Strings differ at index 100.
  Expected: "... "2015-08-05T12:00:00+10:00"\n}.dateEffective}]->(homeAddress)"
  But was:  "... "2015-08-05T12:00:00+00:00"\n}.dateEffective}]->(homeAddress)"
  ------------------------------------^

   at Neo4jClient.Extension.Test.Cypher.FluentConfigMatchTests.MatchRelationshipWithProperty() in /home/runner/work/Neo4jClient.Extension/Neo4jClient.Extension/test/Neo4jClient.Extension.UnitTest/Cypher/FluentConfigMatchTests.cs:line 85

1)    at Neo4jClient.Extension.Test.Cypher.FluentConfigMatchTests.MatchRelationshipWithProperty() in /home/runner/work/Neo4jClient.Extension/Neo4jClient.Extension/test/Neo4jClient.Extension.UnitTest/Cypher/FluentConfigMatchTests.cs:line 85

dateEffective: ""2015-08-05T12:00:00+10:00""
}.dateEffective}]->(homeAddress)"));
}

public ICypherFluentQuery MatchRelationshipWithProperty2Act()
{
var archer = SampleDataFactory.GetWellKnownPerson(1);

var personVariable = "p";
var orgVariable = "o";

var roleRelationship = new WorksForRelationship("special agent", personVariable, orgVariable);

var q = GetFluentQuery()
.MatchRelationship(roleRelationship);

return q;
}

[Test]
public void MatchRelationshipWithProperty2()
{
var q = MatchRelationshipWithProperty2Act();
var cypher = q.GetFormattedDebugText();
cypher.Should().Be(@"MATCH (p)-[po:WORKS_FOR {role:{
role: ""special agent""
}.role}]->(o)");
}
}
}
Loading