From 8be66dd764914b03c9ea5f1e5aacb21d9cb3a732 Mon Sep 17 00:00:00 2001 From: Simon Pinn Date: Mon, 20 Mar 2017 16:30:20 +1100 Subject: [PATCH 1/3] ISSUE-25 potential fix --- .../Cypher/Extension/CypherExtension.Main.cs | 6 +++++- .../Cypher/FluentConfigMatchTests.cs | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Neo4jClient.Extension/Cypher/Extension/CypherExtension.Main.cs b/src/Neo4jClient.Extension/Cypher/Extension/CypherExtension.Main.cs index dd056d5..d414348 100644 --- a/src/Neo4jClient.Extension/Cypher/Extension/CypherExtension.Main.cs +++ b/src/Neo4jClient.Extension/Cypher/Extension/CypherExtension.Main.cs @@ -196,7 +196,11 @@ this ICypherFluentQuery query , relationship.ToCypherString(CypherExtensionContext.Create(query), relationship.Key, matchProperties) , relationship.ToKey); - return matchFunction(query,cql); + dynamic cutdown = relationship.CreateDynamic(options.MatchOverride ?? CypherTypeItemHelper.PropertiesForPurpose(relationship)); + var matchKey = GetMatchParamName(relationship.Key); + + return matchFunction(query, cql) + .WithParam(matchKey, cutdown); } public static ICypherFluentQuery MatchRelationship(this ICypherFluentQuery query, T relationship, List matchOverride = null) where T : BaseRelationship diff --git a/test/Neo4jClient.Extension.UnitTest/Cypher/FluentConfigMatchTests.cs b/test/Neo4jClient.Extension.UnitTest/Cypher/FluentConfigMatchTests.cs index db5bd12..e8076b3 100644 --- a/test/Neo4jClient.Extension.UnitTest/Cypher/FluentConfigMatchTests.cs +++ b/test/Neo4jClient.Extension.UnitTest/Cypher/FluentConfigMatchTests.cs @@ -79,14 +79,14 @@ public void MatchRelationshipSimple() [Test] public void MatchRelationshipWithProperty() { - var addressRelationship = new HomeAddressRelationship(DateTimeOffset.Parse("2015-08-05 12:00"), "agent", "homeAddress"); + var addressRelationship = new HomeAddressRelationship(DateTimeOffset.Parse("2015-08-05T12:00:00+10:00"), "agent", "homeAddress"); var q = GetFluentQuery() .MatchRelationship(addressRelationship); var text = q.GetFormattedDebugText(); Console.WriteLine(text); - Assert.AreEqual(@"MATCH (agent)-[agenthomeAddress:HOME_ADDRESS {dateEffective:{agenthomeAddressMatchKey}.dateEffective}]->(homeAddress)", text); + Assert.AreEqual("MATCH (agent)-[agenthomeAddress:HOME_ADDRESS {dateEffective:{\r\n dateEffective: \"2015-08-05T12:00:00+10:00\"\r\n}.dateEffective}]->(homeAddress)", text); } } } From eff966435aa235ead601a9aef7bc1e3b39653f2c Mon Sep 17 00:00:00 2001 From: neutmute Date: Sat, 1 Jul 2017 22:49:21 +1000 Subject: [PATCH 2/3] #25 tests --- .../IntegrationTest.cs | 2 +- ...o4jClient.Extension.IntegrationTest.csproj | 1 + .../Tests/MatchTests.cs | 58 +++++++++++++++++++ .../Domain/Company.cs | 13 +++++ .../Neo/NeoConfig.cs | 14 +++++ .../Neo/Relationships/WorksForRelationship.cs | 29 ++++++++++ .../Neo4jClient.Extension.Test.Common.csproj | 2 + .../SampleDataFactory.cs | 7 +++ .../Cypher/FluentConfigMatchTests.cs | 51 ++++++++++++++-- 9 files changed, 170 insertions(+), 7 deletions(-) create mode 100644 test/Neo4jClient.Extension.IntegrationTest/Tests/MatchTests.cs create mode 100644 test/Neo4jClient.Extension.Test.Common/Domain/Company.cs create mode 100644 test/Neo4jClient.Extension.Test.Common/Neo/Relationships/WorksForRelationship.cs diff --git a/test/Neo4jClient.Extension.IntegrationTest/IntegrationTest.cs b/test/Neo4jClient.Extension.IntegrationTest/IntegrationTest.cs index 2a792cc..ac74cd2 100644 --- a/test/Neo4jClient.Extension.IntegrationTest/IntegrationTest.cs +++ b/test/Neo4jClient.Extension.IntegrationTest/IntegrationTest.cs @@ -17,7 +17,7 @@ public class IntegrationTest { protected static ITransactionalGraphClient GraphClient { get; private set; } - protected ICypherFluentQuery CypherQuery { get { return GraphClient.Cypher; } } + protected ICypherFluentQuery CypherQuery => GraphClient.Cypher; [SetUp] public void Setup() diff --git a/test/Neo4jClient.Extension.IntegrationTest/Neo4jClient.Extension.IntegrationTest.csproj b/test/Neo4jClient.Extension.IntegrationTest/Neo4jClient.Extension.IntegrationTest.csproj index 4cee7c7..c418cba 100644 --- a/test/Neo4jClient.Extension.IntegrationTest/Neo4jClient.Extension.IntegrationTest.csproj +++ b/test/Neo4jClient.Extension.IntegrationTest/Neo4jClient.Extension.IntegrationTest.csproj @@ -63,6 +63,7 @@ + diff --git a/test/Neo4jClient.Extension.IntegrationTest/Tests/MatchTests.cs b/test/Neo4jClient.Extension.IntegrationTest/Tests/MatchTests.cs new file mode 100644 index 0000000..36c1f18 --- /dev/null +++ b/test/Neo4jClient.Extension.IntegrationTest/Tests/MatchTests.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Neo4jClient.Extension.Cypher; +using Neo4jClient.Extension.Test.Cypher; +using Neo4jClient.Extension.Test.Data.Neo.Relationships; +using NUnit.Framework; + +namespace Neo4jClient.Extension.Test.Integration.Tests +{ + class MatchTests : IntegrationTest + { + public void 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(); + + q + .CreateEntity(archer, archerVariable) + .CreateEntity(isis, isisVariable) + .CreateEntity(kgb, kgbVariable) + .CreateRelationship(agentRelationship) + .CreateRelationship(doubleAgentRelationship) + .ExecuteWithoutResults(); + } + + [Test] + public void Match() + { + ArrangeTestData(); + + // Act + var q = RealQueryFactory() + .MatchRelationship(new WorksForRelationship("special agent", "p", "o")) + .Return(o => o.As()); + + Console.WriteLine(q.GetFormattedDebugText()); + var r = q.Results.ToList(); + + Assert.AreEqual(1, r.Count); + + //Not working?? + Console.WriteLine($" Org={r[0].Name}"); + } + } +} diff --git a/test/Neo4jClient.Extension.Test.Common/Domain/Company.cs b/test/Neo4jClient.Extension.Test.Common/Domain/Company.cs new file mode 100644 index 0000000..9778cc3 --- /dev/null +++ b/test/Neo4jClient.Extension.Test.Common/Domain/Company.cs @@ -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; } + } +} diff --git a/test/Neo4jClient.Extension.Test.Common/Neo/NeoConfig.cs b/test/Neo4jClient.Extension.Test.Common/Neo/NeoConfig.cs index 7aae177..9943ada 100644 --- a/test/Neo4jClient.Extension.Test.Common/Neo/NeoConfig.cs +++ b/test/Neo4jClient.Extension.Test.Common/Neo/NeoConfig.cs @@ -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; @@ -37,12 +38,25 @@ public static void ConfigureModel() .MergeOnMatchOrCreate(w => w.BlastRadius) .Set(); + + FluentConfig.Config() + .With() + .Merge(x => x.Name) + .MergeOnMatchOrCreate(w => w.Name) + .Set(); + FluentConfig.Config() .With() .Match(ha => ha.DateEffective) .MergeOnMatchOrCreate(hr => hr.DateEffective) .Set(); + FluentConfig.Config() + .With() + .Match(wf => wf.Role) + .MergeOnMatchOrCreate(wf => wf.Role) + .Set(); + FluentConfig.Config() .With() .Set(); diff --git a/test/Neo4jClient.Extension.Test.Common/Neo/Relationships/WorksForRelationship.cs b/test/Neo4jClient.Extension.Test.Common/Neo/Relationships/WorksForRelationship.cs new file mode 100644 index 0000000..1631072 --- /dev/null +++ b/test/Neo4jClient.Extension.Test.Common/Neo/Relationships/WorksForRelationship.cs @@ -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; } + } +} diff --git a/test/Neo4jClient.Extension.Test.Common/Neo4jClient.Extension.Test.Common.csproj b/test/Neo4jClient.Extension.Test.Common/Neo4jClient.Extension.Test.Common.csproj index c997a86..e85d437 100644 --- a/test/Neo4jClient.Extension.Test.Common/Neo4jClient.Extension.Test.Common.csproj +++ b/test/Neo4jClient.Extension.Test.Common/Neo4jClient.Extension.Test.Common.csproj @@ -50,10 +50,12 @@ + + diff --git a/test/Neo4jClient.Extension.Test.Common/SampleDataFactory.cs b/test/Neo4jClient.Extension.Test.Common/SampleDataFactory.cs index 54acc59..e20760e 100644 --- a/test/Neo4jClient.Extension.Test.Common/SampleDataFactory.cs +++ b/test/Neo4jClient.Extension.Test.Common/SampleDataFactory.cs @@ -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; + } } } \ No newline at end of file diff --git a/test/Neo4jClient.Extension.UnitTest/Cypher/FluentConfigMatchTests.cs b/test/Neo4jClient.Extension.UnitTest/Cypher/FluentConfigMatchTests.cs index e8076b3..d0f62d5 100644 --- a/test/Neo4jClient.Extension.UnitTest/Cypher/FluentConfigMatchTests.cs +++ b/test/Neo4jClient.Extension.UnitTest/Cypher/FluentConfigMatchTests.cs @@ -7,6 +7,7 @@ using Neo4jClient.Cypher; using Neo4jClient.Extension.Cypher; using Neo4jClient.Extension.Cypher.Attributes; +using Neo4jClient.Extension.Test.Data.Neo.Relationships; using Neo4jClient.Extension.Test.TestData.Relationships; using Neo4jClient.Extension.Test.TestEntities.Relationships; using NUnit.Framework; @@ -15,13 +16,25 @@ namespace Neo4jClient.Extension.Test.Cypher { public class FluentConfigMatchTests : FluentConfigBaseTest { + public FluentConfigMatchTests() + { + + } + + /// + /// Ctor for Integration tests to use + /// + public FluentConfigMatchTests(Func seedQueryFactory) + { + UseQueryFactory(seedQueryFactory); + } [Test] public void MatchEntity() { var person = SampleDataFactory.GetWellKnownPerson(7); var q = GetFluentQuery() - .MatchEntity(person); + .MatchEntity(person); var text = q.GetFormattedDebugText(); Console.WriteLine(text); @@ -63,12 +76,12 @@ public void OptionalMatchRelationship() OPTIONAL MATCH (person)-[personaddress:HOME_ADDRESS]->(address)", text); } - [Test] + [Test] public void MatchRelationshipSimple() { var addressRelationship = new CheckedOutRelationship(); var q = GetFluentQuery() - .MatchRelationship(addressRelationship); + .MatchRelationship(addressRelationship); var text = q.GetFormattedDebugText(); Console.WriteLine(text); @@ -79,14 +92,40 @@ public void MatchRelationshipSimple() [Test] public void MatchRelationshipWithProperty() { - var addressRelationship = new HomeAddressRelationship(DateTimeOffset.Parse("2015-08-05T12:00:00+10:00"), "agent", "homeAddress"); + var addressRelationship = new HomeAddressRelationship(DateTimeOffset.Parse("2015-08-05T12:00:00+10:00"), + "agent", "homeAddress"); var q = GetFluentQuery() - .MatchRelationship(addressRelationship); + .MatchRelationship(addressRelationship); var text = q.GetFormattedDebugText(); Console.WriteLine(text); - Assert.AreEqual("MATCH (agent)-[agenthomeAddress:HOME_ADDRESS {dateEffective:{\r\n dateEffective: \"2015-08-05T12:00:00+10:00\"\r\n}.dateEffective}]->(homeAddress)", text); + Assert.AreEqual( + "MATCH (agent)-[agenthomeAddress:HOME_ADDRESS {dateEffective:{\r\n dateEffective: \"2015-08-05T12:00:00+10:00\"\r\n}.dateEffective}]->(homeAddress)", + text); + } + + 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(); + Assert.AreEqual("MATCH (p)-[po:WORKS_FOR {role:{\r\n role: \"special agent\"\r\n}.role}]->(o)", cypher); } } } From c918b47b63707b50982f68deb891830019c64d7a Mon Sep 17 00:00:00 2001 From: Simon Pinn Date: Mon, 20 Oct 2025 16:11:12 +1100 Subject: [PATCH 3/3] #25 merge master for fix --- .../Tests/MatchTests.cs | 13 +++++++------ .../Cypher/FluentConfigMatchTests.cs | 12 +++++++++--- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/test/Neo4jClient.Extension.IntegrationTest/Tests/MatchTests.cs b/test/Neo4jClient.Extension.IntegrationTest/Tests/MatchTests.cs index f7f408e..b55926a 100644 --- a/test/Neo4jClient.Extension.IntegrationTest/Tests/MatchTests.cs +++ b/test/Neo4jClient.Extension.IntegrationTest/Tests/MatchTests.cs @@ -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; @@ -210,7 +211,7 @@ await CypherQuery retrieved.BlastRadius.Value.SquareKilometers.Should().BeApproximately(12.4, 0.01); } - public void ArrangeTestData() + public Task ArrangeTestData() { var archer = SampleDataFactory.GetWellKnownPerson(1); var isis = new Organisation {Name="ISIS"}; @@ -225,17 +226,17 @@ public void ArrangeTestData() var q = RealQueryFactory(); - q + return q .CreateEntity(archer, archerVariable) .CreateEntity(isis, isisVariable) .CreateEntity(kgb, kgbVariable) .CreateRelationship(agentRelationship) .CreateRelationship(doubleAgentRelationship) - .ExecuteWithoutResults(); + .ExecuteWithoutResultsAsync(); } [Test] - public void Match() + public async Task Match() { ArrangeTestData(); @@ -245,9 +246,9 @@ public void Match() .Return(o => o.As()); Console.WriteLine(q.GetFormattedDebugText()); - var r = q.Results.ToList(); + var r = (await q.ResultsAsync).ToList(); - Assert.AreEqual(1, r.Count); + r.Count.Should().Be(1); //Not working?? Console.WriteLine($" Org={r[0].Name}"); diff --git a/test/Neo4jClient.Extension.UnitTest/Cypher/FluentConfigMatchTests.cs b/test/Neo4jClient.Extension.UnitTest/Cypher/FluentConfigMatchTests.cs index 7d4a847..0f43a2b 100644 --- a/test/Neo4jClient.Extension.UnitTest/Cypher/FluentConfigMatchTests.cs +++ b/test/Neo4jClient.Extension.UnitTest/Cypher/FluentConfigMatchTests.cs @@ -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; @@ -79,10 +82,11 @@ public void MatchRelationshipWithProperty() 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:{ + dateEffective: ""2015-08-05T12:00:00+10:00"" +}.dateEffective}]->(homeAddress)")); } - [Test] public ICypherFluentQuery MatchRelationshipWithProperty2Act() { var archer = SampleDataFactory.GetWellKnownPerson(1); @@ -103,7 +107,9 @@ public void MatchRelationshipWithProperty2() { var q = MatchRelationshipWithProperty2Act(); var cypher = q.GetFormattedDebugText(); - Assert.AreEqual("MATCH (p)-[po:WORKS_FOR {role:{\r\n role: \"special agent\"\r\n}.role}]->(o)", cypher); + cypher.Should().Be(@"MATCH (p)-[po:WORKS_FOR {role:{ + role: ""special agent"" +}.role}]->(o)"); } } }