Skip to content

Commit

Permalink
UnitTests fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Pak, Vladislav committed Nov 26, 2024
1 parent bc836d2 commit 342ba6a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/Neo4j.Berries.OGM/Contexts/GraphContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public async Task SaveChangesAsync(CancellationToken cancellationToken = default
{
if (i > 0 && i < validNodeSets.Count())
{
//CypherBuilder.AppendLine("WITH 0 AS nothing");
CypherBuilder.AppendLine("WITH 0 AS nothing");
}
validNodeSets.ElementAt(i).BuildCypher(parameters);
}
Expand Down
38 changes: 19 additions & 19 deletions tests/Neo4j.Berries.OGM.Tests/Models/General/NodeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -972,8 +972,8 @@ public void Should_Archive_All_Root_Relations_If_Marked_As_KeepHistory()
node.ArchiveRelations(cypherBuilder, 0, out var variables);
var cypher = cypherBuilder.ToString().Trim();
cypher.Should().Be("""
OPTIONAL MATCH(a_0:Person WHERE a_0.Id IN $person_id_0)-[r_0:LIVES_IN WHERE r_0.archivedOn IS null]->(:Address) SET r_0.archivedOn=timestamp()
WITH 0 AS nothing
CALL { OPTIONAL MATCH(a_0:Person WHERE a_0.Id IN $person_id_0)-[r_0:LIVES_IN WHERE r_0.archivedOn IS null]->(:Address) SET r_0.archivedOn=timestamp()
}
""");
variables.Should().ContainKey("person_id_0");
var identifiers = variables["person_id_0"] as List<object>;
Expand Down Expand Up @@ -1001,8 +1001,8 @@ public void Should_Archive_All_Multiple_Relations()
node.ArchiveRelations(cypherBuilder, 0, out var variables);
var cypher = cypherBuilder.ToString().Trim();
cypher.Should().Be("""
OPTIONAL MATCH(a_0:Person WHERE a_0.Id IN $person_id_0)-[r_0:FRIENDS_WITH WHERE r_0.archivedOn IS null]->(:Person) SET r_0.archivedOn=timestamp()
WITH 0 AS nothing
CALL { OPTIONAL MATCH(a_0:Person WHERE a_0.Id IN $person_id_0)-[r_0:FRIENDS_WITH WHERE r_0.archivedOn IS null]->(:Person) SET r_0.archivedOn=timestamp()
}
""");
variables.Should().ContainKey("person_id_0");
variables.Should().HaveCount(1);
Expand Down Expand Up @@ -1043,10 +1043,10 @@ public void Should_Archive_Group_Relations()
node.ArchiveRelations(cypherBuilder, 0, out var variables);
var cypher = cypherBuilder.ToString().Trim();
cypher.Should().Be("""
OPTIONAL MATCH(a_0:Person WHERE a_0.Id IN $person_id_0)-[r_0:USES WHERE r_0.archivedOn IS null]->(:Car) SET r_0.archivedOn=timestamp()
WITH 0 AS nothing
OPTIONAL MATCH(a_0:Person WHERE a_0.Id IN $person_id_0)-[r_0:USES WHERE r_0.archivedOn IS null]->(:Room) SET r_0.archivedOn=timestamp()
WITH 0 AS nothing
CALL { OPTIONAL MATCH(a_0:Person WHERE a_0.Id IN $person_id_0)-[r_0:USES WHERE r_0.archivedOn IS null]->(:Car) SET r_0.archivedOn=timestamp()
}
CALL { OPTIONAL MATCH(a_0:Person WHERE a_0.Id IN $person_id_0)-[r_0:USES WHERE r_0.archivedOn IS null]->(:Room) SET r_0.archivedOn=timestamp()
}
""");
variables.Should().ContainKey("person_id_0");
variables.Should().HaveCount(1);
Expand Down Expand Up @@ -1107,14 +1107,14 @@ public void Should_Archive_All_KeepHistory_Relations_In_Root()
node.ArchiveRelations(cypherBuilder, 0, out var variables);
var cypher = cypherBuilder.ToString().Trim();
cypher.Should().Be("""
OPTIONAL MATCH(a_0:Person WHERE a_0.Id IN $person_id_0)-[r_0:LIVES_IN WHERE r_0.archivedOn IS null]->(:Address) SET r_0.archivedOn=timestamp()
WITH 0 AS nothing
OPTIONAL MATCH(a_0:Person WHERE a_0.Id IN $person_id_0)-[r_0:FRIENDS_WITH WHERE r_0.archivedOn IS null]->(:Person) SET r_0.archivedOn=timestamp()
WITH 0 AS nothing
OPTIONAL MATCH(a_0:Person WHERE a_0.Id IN $person_id_0)-[r_0:USES WHERE r_0.archivedOn IS null]->(:Car) SET r_0.archivedOn=timestamp()
WITH 0 AS nothing
OPTIONAL MATCH(a_0:Person WHERE a_0.Id IN $person_id_0)-[r_0:USES WHERE r_0.archivedOn IS null]->(:Room) SET r_0.archivedOn=timestamp()
WITH 0 AS nothing
CALL { OPTIONAL MATCH(a_0:Person WHERE a_0.Id IN $person_id_0)-[r_0:LIVES_IN WHERE r_0.archivedOn IS null]->(:Address) SET r_0.archivedOn=timestamp()
}
CALL { OPTIONAL MATCH(a_0:Person WHERE a_0.Id IN $person_id_0)-[r_0:FRIENDS_WITH WHERE r_0.archivedOn IS null]->(:Person) SET r_0.archivedOn=timestamp()
}
CALL { OPTIONAL MATCH(a_0:Person WHERE a_0.Id IN $person_id_0)-[r_0:USES WHERE r_0.archivedOn IS null]->(:Car) SET r_0.archivedOn=timestamp()
}
CALL { OPTIONAL MATCH(a_0:Person WHERE a_0.Id IN $person_id_0)-[r_0:USES WHERE r_0.archivedOn IS null]->(:Room) SET r_0.archivedOn=timestamp()
}
""");
variables.Should().ContainKey("person_id_0");
variables.Should().HaveCount(1);
Expand Down Expand Up @@ -1167,14 +1167,14 @@ public void Should_Archive_Nested_Single_Relations()
node.ArchiveRelations(cypherBuilder, 0, out var variables);
var cypher = cypherBuilder.ToString().Trim();
cypher.Should().Be("""
OPTIONAL MATCH(a_0_1_0:Person WHERE a_0_1_0.Id IN $person_id_1)-[r_0_1_0:LIVES_IN WHERE r_0_1_0.archivedOn IS null]->(:Address) SET r_0_1_0.archivedOn=timestamp()
WITH 0 AS nothing
CALL { OPTIONAL MATCH(a_0_1_0:Person WHERE a_0_1_0.Id IN $person_id_1)-[r_0_1_0:LIVES_IN WHERE r_0_1_0.archivedOn IS null]->(:Address) SET r_0_1_0.archivedOn=timestamp()
}
""");

variables.Should().ContainKey("person_id_1");
variables.Should().HaveCount(1);
var identifiers = variables["person_id_1"] as List<object>;
identifiers.Should().HaveCount(2);
identifiers.Should().Contain(node.MultipleRelations["Friends"].Identifiers["Id"]);
}

}
12 changes: 6 additions & 6 deletions tests/Neo4j.Berries.OGM.Tests/Models/Match/MatchModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void Should_Create_Match_Without_Eloquent()
{
var sut = new MatchModel<Person>(null, 0);
sut.ToCypher(CypherBuilder);
CypherBuilder.ToString().Should().Be("MATCH (l0:Person)\n");
CypherBuilder.ToString().Trim().Should().Be("MATCH (l0:Person)");
}
[Fact]
public void Should_Create_Match_With_Eloquent()
Expand All @@ -31,7 +31,7 @@ public void Should_Create_Match_With_Eloquent()
eloquent.Where(x => x.Id, Guid.NewGuid());
var sut = new MatchModel<Person>(eloquent, 0);
sut.ToCypher(CypherBuilder);
CypherBuilder.ToString().Should().Be("MATCH (l0:Person WHERE l0.Id = $qp_0_0)\n");
CypherBuilder.ToString().Trim().Should().Be("MATCH (l0:Person WHERE l0.Id = $qp_0_0)");
}
[Fact]
public void Should_Create_Match_OutGoing_Relation_Without_Eloquent()
Expand All @@ -40,7 +40,7 @@ public void Should_Create_Match_OutGoing_Relation_Without_Eloquent()
var relationConfig = new RelationConfiguration<Person, Movie>("ACTED_IN", RelationDirection.Out);
var sut = new MatchRelationModel<Movie>(firstMatch, relationConfig, null, 1);
sut.ToCypher(CypherBuilder);
CypherBuilder.ToString().Should().Be("MATCH (l0)-[r1:ACTED_IN]->(l1:Movie)\n");
CypherBuilder.ToString().Trim().Trim().Should().Be("MATCH (l0)-[r1:ACTED_IN]->(l1:Movie)");
}
[Fact]
public void Should_Create_Match_OutGoing_Relation_With_Eloquent()
Expand All @@ -51,7 +51,7 @@ public void Should_Create_Match_OutGoing_Relation_With_Eloquent()
var relationConfig = new RelationConfiguration<Person, Movie>("ACTED_IN", RelationDirection.Out);
var sut = new MatchRelationModel<Movie>(firstMatch, relationConfig, eloquent, 1);
sut.ToCypher(CypherBuilder);
CypherBuilder.ToString().Should().Be("MATCH (l0)-[r1:ACTED_IN]->(l1:Movie WHERE l1.Id = $qp_1_0)\n");
CypherBuilder.ToString().Trim().Should().Be("MATCH (l0)-[r1:ACTED_IN]->(l1:Movie WHERE l1.Id = $qp_1_0)");
}
[Fact]
public void Should_Create_Match_InComing_Relation_Without_Eloquent()
Expand All @@ -60,7 +60,7 @@ public void Should_Create_Match_InComing_Relation_Without_Eloquent()
var relationConfig = new RelationConfiguration<Movie, Person>("ACTED_IN", RelationDirection.In);
var sut = new MatchRelationModel<Person>(firstMatch, relationConfig, null, 1);
sut.ToCypher(CypherBuilder);
CypherBuilder.ToString().Should().Be("MATCH (l0)<-[r1:ACTED_IN]-(l1:Person)\n");
CypherBuilder.ToString().Trim().Should().Be("MATCH (l0)<-[r1:ACTED_IN]-(l1:Person)");
}
[Fact]
public void Should_Create_Match_InComing_Relation_With_Eloquent()
Expand All @@ -71,6 +71,6 @@ public void Should_Create_Match_InComing_Relation_With_Eloquent()
var relationConfig = new RelationConfiguration<Person, Person>("ACTED_IN", RelationDirection.In);
var sut = new MatchRelationModel<Person>(firstMatch, relationConfig, eloquent, 1);
sut.ToCypher(CypherBuilder);
CypherBuilder.ToString().Should().Be("MATCH (l0)<-[r1:ACTED_IN]-(l1:Person WHERE l1.Id = $qp_1_0)\n");
CypherBuilder.ToString().Trim().Should().Be("MATCH (l0)<-[r1:ACTED_IN]-(l1:Person WHERE l1.Id = $qp_1_0)");
}
}

0 comments on commit 342ba6a

Please sign in to comment.