From bd3b8911d70c81e1054565bf0778518f40b42fea Mon Sep 17 00:00:00 2001 From: Grant Lodge <6323995+thelonelyvulpes@users.noreply.github.com> Date: Sun, 19 Jan 2025 23:29:03 +0000 Subject: [PATCH 1/6] update to fluent assertions and lock tests to use 7.0 --- .../Neo4j.Driver.Tests.Integration.csproj | 2 +- .../Neo4j.Driver.Tests/ConfigTests.cs | 7 +- .../BeginMessageSerializerTests.cs | 6 +- .../CommitMessageSerializerTests.cs | 2 +- .../DiscardMessageSerializerTests.cs | 2 +- .../GoodbyeMessageSerializerTests.cs | 2 +- .../HelloMessageSerializerTests.cs | 2 +- .../PullMessageSerializerTests.cs | 4 +- .../RecordMessageSerializerTests.cs | 4 +- .../ResetMessageSerializerTests.cs | 4 +- .../RollbackMessageSerializerTests.cs | 2 +- .../RouteMessageSerializerTests.cs | 4 +- .../RouteMessageSerializerV43Tests.cs | 4 +- .../RunWithMetadataMessageSerializerTests.cs | 8 +-- .../SuccessMessageSerializerTests.cs | 6 +- .../Internal/IO/PackStreamTests.cs | 5 +- .../ValueSerializers/NodeSerializerTests.cs | 4 +- .../ValueSerializers/PathSerializerTests.cs | 6 +- .../RelationshipSerializerTests.cs | 6 +- .../UtcZonedDateTimeSerializerTests.cs | 4 +- .../UnboundRelationshipSerializerTests.cs | 6 +- .../Messages/BeginMessageTests.cs | 72 ++++++++++--------- .../Messages/BoltAgentBuilderTests.cs | 5 +- .../Messages/HelloMessageTests.cs | 24 +++---- .../Messages/PullMessageTests.cs | 6 +- .../Messages/RunWithMetaDataMessageTests.cs | 32 ++++----- .../Protocol/BoltProtocolVersionTests.cs | 2 +- .../DelegateAsyncEnumerableExtensionsTests.cs | 36 +++++----- ...teExecutableQueryMappingExtensionsTests.cs | 43 +++++------ .../Mapping/RecordMappingTests.cs | 28 ++++---- .../Neo4j.Driver.Tests.csproj | 2 +- .../Result/ResultCursorBuilderTests.cs | 6 +- .../Routing/ClusterDiscoveryTests.cs | 11 +-- .../Routing/LoadBalancerTests.cs | 4 +- .../Routing/RoutingTableManagerTests.cs | 50 ++++++------- .../Routing/RoutingTableTests.cs | 34 ++++----- .../SessionConfigBuilderTests.cs | 5 +- .../Neo4j.Driver.Tests/TestUtil/Assertions.cs | 2 +- .../Neo4j.Driver.Tests/TransactionTests.cs | 10 +-- 39 files changed, 234 insertions(+), 228 deletions(-) diff --git a/Neo4j.Driver/Neo4j.Driver.Tests.Integration/Neo4j.Driver.Tests.Integration.csproj b/Neo4j.Driver/Neo4j.Driver.Tests.Integration/Neo4j.Driver.Tests.Integration.csproj index 82a41340e..15c66164b 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests.Integration/Neo4j.Driver.Tests.Integration.csproj +++ b/Neo4j.Driver/Neo4j.Driver.Tests.Integration/Neo4j.Driver.Tests.Integration.csproj @@ -20,7 +20,7 @@ - + diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/ConfigTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/ConfigTests.cs index 2d9933c2d..a7305bbf2 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/ConfigTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/ConfigTests.cs @@ -14,6 +14,7 @@ // limitations under the License. using System; +using System.Collections.Generic; using System.IO; using System.Net.Security; using System.Security.Authentication; @@ -362,8 +363,7 @@ public void WithNotifications_ShouldSetSeverity() config .Which - .DisabledCategories.Should() - .BeEquivalentTo([]); + .DisabledCategories.Should().BeEmpty(); config .Which @@ -384,8 +384,7 @@ public void WithNotifications_ShouldSetSeverityWhenUsingClassification() config .Which - .DisabledCategories.Should() - .BeEquivalentTo([]); + .DisabledCategories.Should().BeEmpty(); config .Which diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/BeginMessageSerializerTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/BeginMessageSerializerTests.cs index ee72817f5..63391c08f 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/BeginMessageSerializerTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/BeginMessageSerializerTests.cs @@ -31,7 +31,7 @@ public class BeginMessageSerializerTests [Fact] public void ShouldHaveWriteableTypesAsCommitMessage() { - BeginMessageSerializer.Instance.WritableTypes.Should().BeEquivalentTo(typeof(BeginMessage)); + BeginMessageSerializer.Instance.WritableTypes.Should().BeEquivalentTo([typeof(BeginMessage)]); } [Fact] @@ -81,7 +81,7 @@ public void ShouldSerialize(int major, int minor) headerBytes[1].Should().Be(0x11); var meta = reader.ReadMap(); - meta.Should().ContainKey("db").WhichValue.Should().Be("neo4j"); - meta.Should().ContainKey("bookmarks").WhichValue.Should().BeEquivalentTo(new[] { "a" }); + meta.Should().ContainKey("db").WhoseValue.Should().Be("neo4j"); + meta.Should().ContainKey("bookmarks").WhoseValue.Should().BeEquivalentTo(new[] { "a" }); } } diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/CommitMessageSerializerTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/CommitMessageSerializerTests.cs index 5a80811f5..522a10d44 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/CommitMessageSerializerTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/CommitMessageSerializerTests.cs @@ -30,7 +30,7 @@ public class CommitMessageSerializerTests [Fact] public void ShouldHaveWriteableTypesAsCommitMessage() { - CommitMessageSerializer.Instance.WritableTypes.Should().BeEquivalentTo(typeof(CommitMessage)); + CommitMessageSerializer.Instance.WritableTypes.Should().BeEquivalentTo([typeof(CommitMessage)]); } [Fact] diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/DiscardMessageSerializerTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/DiscardMessageSerializerTests.cs index b4a644202..61d38db3d 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/DiscardMessageSerializerTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/DiscardMessageSerializerTests.cs @@ -31,7 +31,7 @@ public class DiscardMessageSerializerTests [Fact] public void ShouldHaveWriteableTypesAsDiscardMessage() { - DiscardMessageSerializer.Instance.WritableTypes.Should().BeEquivalentTo(typeof(DiscardMessage)); + DiscardMessageSerializer.Instance.WritableTypes.Should().BeEquivalentTo([typeof(DiscardMessage)]); } [Fact] diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/GoodbyeMessageSerializerTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/GoodbyeMessageSerializerTests.cs index 6b736b356..2ed8db583 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/GoodbyeMessageSerializerTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/GoodbyeMessageSerializerTests.cs @@ -30,7 +30,7 @@ public class GoodbyeMessageSerializerTests [Fact] public void ShouldHaveWriteableTypesAsGoodbyeMessage() { - GoodbyeMessageSerializer.Instance.WritableTypes.Should().BeEquivalentTo(typeof(GoodbyeMessage)); + GoodbyeMessageSerializer.Instance.WritableTypes.Should().BeEquivalentTo([typeof(GoodbyeMessage)]); } [Fact] diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/HelloMessageSerializerTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/HelloMessageSerializerTests.cs index 705b4fa9c..9398cb261 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/HelloMessageSerializerTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/HelloMessageSerializerTests.cs @@ -72,6 +72,6 @@ public void ShouldSerialize(int major, int minor) bytes[1].Should().Be(0x01); var meta = reader.ReadMap(); - meta.Should().ContainKey("user_agent").WhichValue.Should().Be("user"); + meta.Should().ContainKey("user_agent").WhoseValue.Should().Be("user"); } } diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/PullMessageSerializerTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/PullMessageSerializerTests.cs index 8860a6447..9176210a4 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/PullMessageSerializerTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/PullMessageSerializerTests.cs @@ -70,7 +70,7 @@ public void ShouldSerialize(int major, int minor) var metadata = reader.ReadMap(); - metadata.Should().ContainKey("qid").WhichValue.Should().Be(42); - metadata.Should().ContainKey("n").WhichValue.Should().Be(10); + metadata.Should().ContainKey("qid").WhoseValue.Should().Be(42); + metadata.Should().ContainKey("n").WhoseValue.Should().Be(10); } } diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/RecordMessageSerializerTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/RecordMessageSerializerTests.cs index f5ee5ae1f..da16775d0 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/RecordMessageSerializerTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/RecordMessageSerializerTests.cs @@ -57,6 +57,6 @@ public void ShouldDeserialize(int major, int minor) var message = RecordMessageSerializer.Instance.Deserialize(reader); - message.Should().BeOfType().Which.Fields.Should().BeEquivalentTo(0L, "a"); + message.Should().BeOfType().Which.Fields.Should().BeEquivalentTo(new object[]{0L, "a"}); } -} \ No newline at end of file +} diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/ResetMessageSerializerTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/ResetMessageSerializerTests.cs index b5e1c4d7b..d231ed666 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/ResetMessageSerializerTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/ResetMessageSerializerTests.cs @@ -32,7 +32,7 @@ public void ShouldBeAbleToWriteRunWithMetadataMessage() { ResetMessageSerializer.Instance.WritableTypes .Should() - .BeEquivalentTo(typeof(ResetMessage)); + .BeEquivalentTo([typeof(ResetMessage)]); } [Fact] @@ -71,4 +71,4 @@ public void ShouldSerialize(int major, int minor) // message tag headerBytes[1].Should().Be(0x0F); } -} \ No newline at end of file +} diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/RollbackMessageSerializerTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/RollbackMessageSerializerTests.cs index ebb586d87..37f07c899 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/RollbackMessageSerializerTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/RollbackMessageSerializerTests.cs @@ -32,7 +32,7 @@ public void ShouldBeAbleToWriteRunWithMetadataMessage() { RollbackMessageSerializer.Instance.WritableTypes .Should() - .BeEquivalentTo(typeof(RollbackMessage)); + .BeEquivalentTo([typeof(RollbackMessage)]); } [Fact] diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/RouteMessageSerializerTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/RouteMessageSerializerTests.cs index cc1dccde8..1038b126b 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/RouteMessageSerializerTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/RouteMessageSerializerTests.cs @@ -32,7 +32,7 @@ public class RouteMessageSerializerTests [Fact] public void ShouldHaveWriteableTypesAsRouteMessageV43Message() { - RouteMessageSerializer.Instance.WritableTypes.Should().BeEquivalentTo(typeof(RouteMessage)); + RouteMessageSerializer.Instance.WritableTypes.Should().BeEquivalentTo([typeof(RouteMessage)]); } [Fact] @@ -78,7 +78,7 @@ public void ShouldSerialize(int major, int minor) headerBytes[1].Should().Be(0x66); var meta = reader.ReadMap(); - meta.Should().ContainKey("a").WhichValue.Should().Be("b"); + meta.Should().ContainKey("a").WhoseValue.Should().Be("b"); var bookmarks = reader.ReadList(); bookmarks.Should().BeEquivalentTo(new[] { "bm:a" }); diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/RouteMessageSerializerV43Tests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/RouteMessageSerializerV43Tests.cs index 3efaf23ce..b9e763224 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/RouteMessageSerializerV43Tests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/RouteMessageSerializerV43Tests.cs @@ -32,7 +32,7 @@ public class RouteMessageSerializerV43Tests [Fact] public void ShouldHaveWriteableTypesAsRouteMessageV43Message() { - RouteMessageSerializerV43.Instance.WritableTypes.Should().BeEquivalentTo(typeof(RouteMessageV43)); + RouteMessageSerializerV43.Instance.WritableTypes.Should().BeEquivalentTo([typeof(RouteMessageV43)]); } [Fact] @@ -77,7 +77,7 @@ public void ShouldSerialize(int major, int minor) headerBytes[1].Should().Be(0x66); var meta = reader.ReadMap(); - meta.Should().ContainKey("a").WhichValue.Should().Be("b"); + meta.Should().ContainKey("a").WhoseValue.Should().Be("b"); var bookmarks = reader.ReadList(); bookmarks.Should().BeEquivalentTo(new[] { "bm:a" }); diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/RunWithMetadataMessageSerializerTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/RunWithMetadataMessageSerializerTests.cs index 76684f369..4a1aeba59 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/RunWithMetadataMessageSerializerTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/RunWithMetadataMessageSerializerTests.cs @@ -32,7 +32,7 @@ public void ShouldBeAbleToWriteRunWithMetadataMessage() { RunWithMetadataMessageSerializer.Instance.WritableTypes .Should() - .BeEquivalentTo(typeof(RunWithMetadataMessage)); + .BeEquivalentTo([typeof(RunWithMetadataMessage)]); } [Fact] @@ -80,8 +80,8 @@ public void ShouldSerialize(int major, int minor) var query = reader.ReadString(); query.Should().Be("..."); var parameters = reader.ReadMap(); - parameters.Should().ContainKey("x").WhichValue.Should().Be(10L); + parameters.Should().ContainKey("x").WhoseValue.Should().Be(10L); var metadata = reader.ReadMap(); - metadata.Should().ContainKey("db").WhichValue.Should().Be("neo4j"); + metadata.Should().ContainKey("db").WhoseValue.Should().Be("neo4j"); } -} \ No newline at end of file +} diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/SuccessMessageSerializerTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/SuccessMessageSerializerTests.cs index 2bde578ad..8935ee618 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/SuccessMessageSerializerTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/SuccessMessageSerializerTests.cs @@ -63,8 +63,8 @@ public void ShouldDeserialize(int major, int minor) message.Should() .BeOfType() .Which.Meta.Should() - .ContainKey("unknown") - .WhichValue.Should() + .ContainKey("unknown").WhoseValue + .Should() .Be(1L); } -} \ No newline at end of file +} diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/PackStreamTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/PackStreamTests.cs index 036748eaa..aa66a2a02 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/PackStreamTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/PackStreamTests.cs @@ -89,8 +89,7 @@ public void ShouldReadViaStructHandlerIfThereIsAHandlerRegisteredForSignature() var structValue = (StructType)value; structValue.Values.Should().NotBeNull(); - structValue.Values.Should().HaveCount(5); - structValue.Values.Should().Equal(1L, 2L, true, 3.0, "something"); + structValue.Values.Should().BeEquivalentTo(new object[] {1L, 2L, true, 3.0, "something"}); } [Fact] @@ -159,4 +158,4 @@ public void Serialize(BoltProtocolVersion _, PackStreamWriter writer, object val throw new NotImplementedException(); } } -} \ No newline at end of file +} diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/NodeSerializerTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/NodeSerializerTests.cs index ab3c2741d..92a1d04a8 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/NodeSerializerTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/NodeSerializerTests.cs @@ -56,7 +56,7 @@ public void ShouldDeserializeWhenInList() var value = readerMachine.Reader().Read(); value.Should().NotBeNull(); - value.Should().BeAssignableTo().Which.Should().HaveCount(1); + value.Should().BeAssignableTo>().Which.Should().HaveCount(1); VerifySerializedNode(value.Should().BeAssignableTo().Which[0]); } @@ -144,7 +144,7 @@ public void ShouldDeserializeSpanWhenInList() var value = readerMachine.Read(); value.Should().NotBeNull(); - value.Should().BeAssignableTo().Which.Should().HaveCount(1); + value.Should().BeAssignableTo().Which.Count.Should().Be(1); VerifySerializedNode(value.Should().BeAssignableTo().Which[0]); } diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/PathSerializerTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/PathSerializerTests.cs index 947775e7e..35a8955ad 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/PathSerializerTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/PathSerializerTests.cs @@ -101,7 +101,7 @@ public void ShouldDeserializeWhenInList() var value = readerMachine.Reader().Read(); value.Should().NotBeNull(); - value.Should().BeAssignableTo().Which.Should().HaveCount(1); + value.Should().BeAssignableTo().Which.Count.Should().Be(1); VerifySerializedPath(value.Should().BeAssignableTo().Which[0]); } @@ -119,7 +119,7 @@ public void ShouldDeserializeSpanWhenInList() var value = reader.Read(); value.Should().NotBeNull(); - value.Should().BeAssignableTo().Which.Should().HaveCount(1); + value.Should().BeAssignableTo().Which.Count.Should().Be(1); VerifySerializedPath(value.Should().BeAssignableTo().Which[0]); } @@ -282,4 +282,4 @@ private static void VerifySerializedUnboundedRelationship( .And .Contain(new KeyValuePair("rProp1", $"something{expectedId}")); } -} \ No newline at end of file +} diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/RelationshipSerializerTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/RelationshipSerializerTests.cs index ad372b821..0299fe824 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/RelationshipSerializerTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/RelationshipSerializerTests.cs @@ -56,7 +56,7 @@ public void ShouldDeserializeWhenInList() var value = readerMachine.Reader().Read(); value.Should().NotBeNull(); - value.Should().BeAssignableTo().Which.Should().HaveCount(1); + value.Should().BeAssignableTo>().Subject.Should().HaveCount(1); VerifySerializedRelationship(value.Should().BeAssignableTo().Which[0]); } @@ -112,7 +112,7 @@ public void ShouldDeserializeSpanWhenInList() var value = reader.Read(); value.Should().NotBeNull(); - value.Should().BeAssignableTo().Which.Should().HaveCount(1); + value.Should().BeAssignableTo().Which.Count.Should().Be(1); VerifySerializedRelationship(value.Should().BeAssignableTo().Which[0]); } @@ -176,4 +176,4 @@ private static void VerifySerializedRelationship(object value) new KeyValuePair("prop3", false) }); } -} \ No newline at end of file +} diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/Temporal/UtcZonedDateTimeSerializerTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/Temporal/UtcZonedDateTimeSerializerTests.cs index 899780eb9..26b93bc7e 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/Temporal/UtcZonedDateTimeSerializerTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/Temporal/UtcZonedDateTimeSerializerTests.cs @@ -375,6 +375,6 @@ public void ShouldSerializeUtcAndNonUtcSecondsToSameValue() reader.Read(); reader.Read().Should().Be(0); - bstSecs.Should().Equals(utcSecs); + bstSecs.Should().Be(utcSecs); } -} \ No newline at end of file +} diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/UnboundRelationshipSerializerTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/UnboundRelationshipSerializerTests.cs index 422ce94f0..3790c4b0d 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/UnboundRelationshipSerializerTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/UnboundRelationshipSerializerTests.cs @@ -63,7 +63,7 @@ public void ShouldDeserializeWhenInList() var value = readerMachine.Reader().Read(); value.Should().NotBeNull(); - value.Should().BeAssignableTo().Which.Should().HaveCount(1); + value.Should().BeAssignableTo().Which.Count.Should().Be(1); VerifySerializedUnboundRelationship(value.Should().BeAssignableTo().Which[0]); } @@ -119,7 +119,7 @@ public void ShouldDeserializeSpanWhenInList() var value = reader.Read(); value.Should().NotBeNull(); - value.Should().BeAssignableTo().Which.Should().HaveCount(1); + value.Should().BeAssignableTo().Which.Count.Should().Be(1);; VerifySerializedUnboundRelationship(value.Should().BeAssignableTo().Which[0]); } @@ -181,4 +181,4 @@ private static void VerifySerializedUnboundRelationship(object value) new KeyValuePair("prop3", false) }); } -} \ No newline at end of file +} diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/MessageHandling/Messages/BeginMessageTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/MessageHandling/Messages/BeginMessageTests.cs index 67e059879..4151adac4 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/MessageHandling/Messages/BeginMessageTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/MessageHandling/Messages/BeginMessageTests.cs @@ -63,12 +63,12 @@ public void ShouldHandleSetValues(int major, int minor) new SessionConfig("Douglas Fir"), null); - message.Metadata.Should().ContainKey("bookmarks").WhichValue.Should().BeEquivalentTo(new[] { "bm:a" }); - message.Metadata.Should().ContainKey("imp_user").WhichValue.Should().BeEquivalentTo("Douglas Fir"); - message.Metadata.Should().ContainKey("tx_timeout").WhichValue.Should().BeEquivalentTo(1000L); - message.Metadata.Should().ContainKey("tx_metadata").WhichValue.Should().BeEquivalentTo(txMeta); - message.Metadata.Should().ContainKey("mode").WhichValue.Should().BeEquivalentTo("r"); - message.Metadata.Should().ContainKey("db").WhichValue.Should().BeEquivalentTo("neo4j"); + message.Metadata.Should().ContainKey("bookmarks").WhoseValue.Should().BeEquivalentTo(new[] { "bm:a" }); + message.Metadata.Should().ContainKey("imp_user").WhoseValue.Should().BeEquivalentTo("Douglas Fir"); + message.Metadata.Should().ContainKey("tx_timeout").WhoseValue.Should().BeEquivalentTo(1000L); + message.Metadata.Should().ContainKey("tx_metadata").WhoseValue.Should().BeEquivalentTo(txMeta); + message.Metadata.Should().ContainKey("mode").WhoseValue.Should().BeEquivalentTo("r"); + message.Metadata.Should().ContainKey("db").WhoseValue.Should().BeEquivalentTo("neo4j"); message.ToString() .Should() @@ -97,12 +97,12 @@ public void ShouldIgnoreNotificationConfig(int major, int minor) new SessionConfig("Douglas Fir"), new NotificationsDisabledConfig()); - message.Metadata.Should().ContainKey("bookmarks").WhichValue.Should().BeEquivalentTo(new[] { "bm:a" }); - message.Metadata.Should().ContainKey("imp_user").WhichValue.Should().BeEquivalentTo("Douglas Fir"); - message.Metadata.Should().ContainKey("tx_timeout").WhichValue.Should().BeEquivalentTo(1000L); - message.Metadata.Should().ContainKey("tx_metadata").WhichValue.Should().BeEquivalentTo(txMeta); - message.Metadata.Should().ContainKey("mode").WhichValue.Should().BeEquivalentTo("r"); - message.Metadata.Should().ContainKey("db").WhichValue.Should().BeEquivalentTo("neo4j"); + message.Metadata.Should().ContainKey("bookmarks").WhoseValue.Should().BeEquivalentTo(new[] { "bm:a" }); + message.Metadata.Should().ContainKey("imp_user").WhoseValue.Should().BeEquivalentTo("Douglas Fir"); + message.Metadata.Should().ContainKey("tx_timeout").WhoseValue.Should().BeEquivalentTo(1000L); + message.Metadata.Should().ContainKey("tx_metadata").WhoseValue.Should().BeEquivalentTo(txMeta); + message.Metadata.Should().ContainKey("mode").WhoseValue.Should().BeEquivalentTo("r"); + message.Metadata.Should().ContainKey("db").WhoseValue.Should().BeEquivalentTo("neo4j"); message.ToString() .Should() @@ -130,16 +130,16 @@ public void ShouldHandleSetValuesWithNotifications(int major, int minor) new SessionConfig("Douglas Fir"), new NotificationsConfig(Severity.Warning, new[] { Category.Generic })); - message.Metadata.Should().ContainKey("bookmarks").WhichValue.Should().BeEquivalentTo(new[] { "bm:a" }); - message.Metadata.Should().ContainKey("imp_user").WhichValue.Should().BeEquivalentTo("Douglas Fir"); - message.Metadata.Should().ContainKey("tx_timeout").WhichValue.Should().BeEquivalentTo(1000L); - message.Metadata.Should().ContainKey("tx_metadata").WhichValue.Should().BeEquivalentTo(txMeta); - message.Metadata.Should().ContainKey("mode").WhichValue.Should().BeEquivalentTo("r"); - message.Metadata.Should().ContainKey("db").WhichValue.Should().BeEquivalentTo("neo4j"); - message.Metadata.Should().ContainKey("notifications_minimum_severity").WhichValue.Should().BeEquivalentTo("WARNING"); + message.Metadata.Should().ContainKey("bookmarks").WhoseValue.Should().BeEquivalentTo(new[] { "bm:a" }); + message.Metadata.Should().ContainKey("imp_user").WhoseValue.Should().BeEquivalentTo("Douglas Fir"); + message.Metadata.Should().ContainKey("tx_timeout").WhoseValue.Should().BeEquivalentTo(1000L); + message.Metadata.Should().ContainKey("tx_metadata").WhoseValue.Should().BeEquivalentTo(txMeta); + message.Metadata.Should().ContainKey("mode").WhoseValue.Should().BeEquivalentTo("r"); + message.Metadata.Should().ContainKey("db").WhoseValue.Should().BeEquivalentTo("neo4j"); + message.Metadata.Should().ContainKey("notifications_minimum_severity").WhoseValue.Should().BeEquivalentTo("WARNING"); message.Metadata.Should() - .ContainKey("notifications_disabled_categories") - .WhichValue.Should() + .ContainKey("notifications_disabled_categories").WhoseValue + .Should() .BeEquivalentTo(new[] { "GENERIC" }); message.ToString() @@ -168,20 +168,20 @@ public void ShouldHandleSetValuesWithNotificationsClassifications(int major, int new SessionConfig("Douglas Fir"), new NotificationsConfig(Severity.Warning, [Category.Generic])); - message.Metadata.Should().ContainKey("bookmarks").WhichValue.Should().BeEquivalentTo(new[] { "bm:a" }); - message.Metadata.Should().ContainKey("imp_user").WhichValue.Should().BeEquivalentTo("Douglas Fir"); - message.Metadata.Should().ContainKey("tx_timeout").WhichValue.Should().BeEquivalentTo(1000L); - message.Metadata.Should().ContainKey("tx_metadata").WhichValue.Should().BeEquivalentTo(txMeta); - message.Metadata.Should().ContainKey("mode").WhichValue.Should().BeEquivalentTo("r"); - message.Metadata.Should().ContainKey("db").WhichValue.Should().BeEquivalentTo("neo4j"); + message.Metadata.Should().ContainKey("bookmarks").WhoseValue.Should().BeEquivalentTo(new[] { "bm:a" }); + message.Metadata.Should().ContainKey("imp_user").WhoseValue.Should().BeEquivalentTo("Douglas Fir"); + message.Metadata.Should().ContainKey("tx_timeout").WhoseValue.Should().BeEquivalentTo(1000L); + message.Metadata.Should().ContainKey("tx_metadata").WhoseValue.Should().BeEquivalentTo(txMeta); + message.Metadata.Should().ContainKey("mode").WhoseValue.Should().BeEquivalentTo("r"); + message.Metadata.Should().ContainKey("db").WhoseValue.Should().BeEquivalentTo("neo4j"); message.Metadata.Should() - .ContainKey("notifications_minimum_severity") - .WhichValue.Should() + .ContainKey("notifications_minimum_severity").WhoseValue + .Should() .BeEquivalentTo("WARNING"); message.Metadata.Should() - .ContainKey("notifications_disabled_classifications") - .WhichValue.Should() + .ContainKey("notifications_disabled_classifications").WhoseValue + .Should() .BeEquivalentTo(new[] { "GENERIC" }); message.ToString() @@ -232,12 +232,12 @@ public void ShouldAddNotificationsCategories(int major, int minor) beginMessage.Metadata.Should() .ContainKey("notifications_disabled_categories") - .WhichValue.Should() + .WhoseValue.Should() .BeEquivalentTo(new[] { "HINT" }); beginMessage.Metadata.Should() .ContainKey("notifications_minimum_severity") - .WhichValue.Should() + .WhoseValue.Should() .Be("INFORMATION"); } @@ -259,12 +259,14 @@ public void ShouldAddNotificationsClassifications(int major, int minor) beginMessage.Metadata.Should() .ContainKey("notifications_disabled_classifications") - .WhichValue.Should() + .WhoseValue + .Should() .BeEquivalentTo(new[] { "HINT" }); beginMessage.Metadata.Should() .ContainKey("notifications_minimum_severity") - .WhichValue.Should() + .WhoseValue + .Should() .Be("INFORMATION"); } } diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/MessageHandling/Messages/BoltAgentBuilderTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/MessageHandling/Messages/BoltAgentBuilderTests.cs index e8c6efacf..e52d36741 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/MessageHandling/Messages/BoltAgentBuilderTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/MessageHandling/Messages/BoltAgentBuilderTests.cs @@ -30,7 +30,8 @@ public void ShouldReturnBoltAgent() .And.ContainKey("platform") .And.ContainKey("language_details") .And.ContainKey("product") - .WhichValue.Should() + .WhoseValue + .Should() .MatchRegex(@"^neo4j-dotnet/\d\.\d+\.\d+$"); } -} \ No newline at end of file +} diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/MessageHandling/Messages/HelloMessageTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/MessageHandling/Messages/HelloMessageTests.cs index 0c8a359d1..6002501fb 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/MessageHandling/Messages/HelloMessageTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/MessageHandling/Messages/HelloMessageTests.cs @@ -64,7 +64,7 @@ public void ShouldHandleValues(int major, int minor) null, (IDictionary)null); - helloMessage.Metadata.Should().ContainKey("user_agent").WhichValue.Should().Be("jeff"); + helloMessage.Metadata.Should().ContainKey("user_agent").WhoseValue.Should().Be("jeff"); helloMessage.ToString().Should().Be("HELLO [{user_agent, jeff}]"); } @@ -123,9 +123,9 @@ public void ShouldIncludeAuth(int major, int minor) null); helloMessage.Serializer.Should().BeOfType(); - helloMessage.Metadata.Should().ContainKey("scheme").WhichValue.Should().Be("basic"); - helloMessage.Metadata.Should().ContainKey("principal").WhichValue.Should().Be("jeff"); - helloMessage.Metadata.Should().ContainKey("credentials").WhichValue.Should().Be("hidden"); + helloMessage.Metadata.Should().ContainKey("scheme").WhoseValue.Should().Be("basic"); + helloMessage.Metadata.Should().ContainKey("principal").WhoseValue.Should().Be("jeff"); + helloMessage.Metadata.Should().ContainKey("credentials").WhoseValue.Should().Be("hidden"); helloMessage.ToString() .Should() .Be( @@ -178,13 +178,13 @@ public void ShouldAddNotificationsCategories(int major, int minor) cfg); helloMessage.Metadata.Should() - .ContainKey("notifications_disabled_categories") - .WhichValue.Should() + .ContainKey("notifications_disabled_categories").WhoseValue + .Should() .BeEquivalentTo(new[] { "HINT" }); helloMessage.Metadata.Should() - .ContainKey("notifications_minimum_severity") - .WhichValue.Should() + .ContainKey("notifications_minimum_severity").WhoseValue + .Should() .Be("INFORMATION"); } @@ -202,13 +202,13 @@ public void ShouldAddNotificationsClassifications(int major, int minor) cfg); helloMessage.Metadata.Should() - .ContainKey("notifications_disabled_classifications") - .WhichValue.Should() + .ContainKey("notifications_disabled_classifications").WhoseValue + .Should() .BeEquivalentTo(new[] { "HINT" }); helloMessage.Metadata.Should() - .ContainKey("notifications_minimum_severity") - .WhichValue.Should() + .ContainKey("notifications_minimum_severity").WhoseValue + .Should() .Be("INFORMATION"); } } diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/MessageHandling/Messages/PullMessageTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/MessageHandling/Messages/PullMessageTests.cs index 7016ed7a8..0bcf54581 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/MessageHandling/Messages/PullMessageTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/MessageHandling/Messages/PullMessageTests.cs @@ -34,7 +34,7 @@ public void ShouldHandleNullValue() { var message = new PullMessage(10); - message.Metadata.Should().ContainKey("n").WhichValue.Should().Be(10); + message.Metadata.Should().ContainKey("n").WhoseValue.Should().Be(10); message.Metadata.Should().NotContainKey("qid"); message.ToString().Should().Be("PULL [{n, 10}]"); } @@ -43,8 +43,8 @@ public void ShouldHandleNullValue() public void ShouldHandleQueryId() { var message = new PullMessage(42, 10); - message.Metadata.Should().ContainKey("n").WhichValue.Should().Be(10); - message.Metadata.Should().ContainKey("qid").WhichValue.Should().Be(42); + message.Metadata.Should().ContainKey("n").WhoseValue.Should().Be(10); + message.Metadata.Should().ContainKey("qid").WhoseValue.Should().Be(42); message.ToString().Should().Be("PULL [{n, 10}, {qid, 42}]"); } } diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/MessageHandling/Messages/RunWithMetaDataMessageTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/MessageHandling/Messages/RunWithMetaDataMessageTests.cs index a2463ba78..c0834e6a5 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/MessageHandling/Messages/RunWithMetaDataMessageTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/MessageHandling/Messages/RunWithMetaDataMessageTests.cs @@ -54,7 +54,7 @@ public void ShouldIncludeImpersonatedUserKeyWithBoltVersionGreaterThan44(int maj null, sessionConfig: new SessionConfig("jeff")); rm.Query.Should().BeNull(); - rm.Metadata.Should().ContainKey("imp_user").WhichValue.Should().Be("jeff"); + rm.Metadata.Should().ContainKey("imp_user").WhoseValue.Should().Be("jeff"); rm.ToString().Should().Be("RUN [{imp_user, jeff}]"); } @@ -78,16 +78,16 @@ public void ShouldIncludeValues() "neo4j", new SessionConfig("jeff")); - rm.Metadata.Should().ContainKey("bookmarks").WhichValue.Should().BeEquivalentTo(new[] { "bm:a" }); - rm.Metadata.Should().ContainKey("tx_timeout").WhichValue.Should().Be(1000L); + rm.Metadata.Should().ContainKey("bookmarks").WhoseValue.Should().BeEquivalentTo(new[] { "bm:a" }); + rm.Metadata.Should().ContainKey("tx_timeout").WhoseValue.Should().Be(1000L); rm.Metadata.Should() - .ContainKey("tx_metadata") - .WhichValue.Should() + .ContainKey("tx_metadata").WhoseValue + .Should() .BeEquivalentTo(new Dictionary { ["a"] = "b" }); - rm.Metadata.Should().ContainKey("mode").WhichValue.Should().BeEquivalentTo("r"); - rm.Metadata.Should().ContainKey("db").WhichValue.Should().BeEquivalentTo("neo4j"); - rm.Metadata.Should().ContainKey("imp_user").WhichValue.Should().BeEquivalentTo("jeff"); + rm.Metadata.Should().ContainKey("mode").WhoseValue.Should().BeEquivalentTo("r"); + rm.Metadata.Should().ContainKey("db").WhoseValue.Should().BeEquivalentTo("neo4j"); + rm.Metadata.Should().ContainKey("imp_user").WhoseValue.Should().BeEquivalentTo("jeff"); rm.ToString() .Should() @@ -109,13 +109,13 @@ public void ShouldAddNotificationsCategories(int major, int minor) notificationsConfig: cfg); runMessage.Metadata.Should() - .ContainKey("notifications_disabled_categories") - .WhichValue.Should() + .ContainKey("notifications_disabled_categories").WhoseValue + .Should() .BeEquivalentTo(new[] { "HINT" }); runMessage.Metadata.Should() - .ContainKey("notifications_minimum_severity") - .WhichValue.Should() + .ContainKey("notifications_minimum_severity").WhoseValue + .Should() .Be("INFORMATION"); } @@ -132,13 +132,13 @@ public void ShouldAddNotificationsClassifications(int major, int minor) notificationsConfig: cfg); runMessage.Metadata.Should() - .ContainKey("notifications_disabled_classifications") - .WhichValue.Should() + .ContainKey("notifications_disabled_classifications").WhoseValue + .Should() .BeEquivalentTo(new[] { "HINT" }); runMessage.Metadata.Should() - .ContainKey("notifications_minimum_severity") - .WhichValue.Should() + .ContainKey("notifications_minimum_severity").WhoseValue + .Should() .Be("INFORMATION"); } } diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/Protocol/BoltProtocolVersionTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/Protocol/BoltProtocolVersionTests.cs index 8b99e862b..d987742fe 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/Protocol/BoltProtocolVersionTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/Protocol/BoltProtocolVersionTests.cs @@ -269,6 +269,6 @@ public void PackToRangeSuccess(int major, int minor, int lowerMajor, int lowerMi var lowerVersion = new BoltProtocolVersion(lowerMajor, lowerMinor); var packedValue = version.PackToIntRange(lowerVersion); - packedValue.Should().Equals(expectedValue); + packedValue.Should().Be(expectedValue); } } diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/DelegateAsyncEnumerableExtensionsTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/DelegateAsyncEnumerableExtensionsTests.cs index 8c6f2cb5b..6417eb0fa 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/DelegateAsyncEnumerableExtensionsTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/DelegateAsyncEnumerableExtensionsTests.cs @@ -70,8 +70,8 @@ async IAsyncEnumerable GetRecordsAsync() var result = await GetRecordsAsync().ToListAsync((string name, int age) => new { name, age }); result.Should() .BeEquivalentTo( - new { name = "Alice", age = 25 }, - new { name = "Bob", age = 30 }); + [new { name = "Alice", age = 25 }, + new { name = "Bob", age = 30 }]); } [Fact] @@ -95,9 +95,9 @@ async IAsyncEnumerable GetRecordsAsync() .ToListAsync((string name, int age, string city) => new { name, age, city }); result.Should() - .BeEquivalentTo( + .BeEquivalentTo([ new { name = "Alice", age = 25, city = "New York" }, - new { name = "Bob", age = 30, city = "Los Angeles" }); + new { name = "Bob", age = 30, city = "Los Angeles" }]); } [Fact] @@ -121,9 +121,9 @@ async IAsyncEnumerable GetRecordsAsync() .ToListAsync((string name, int age, string city, string country) => new { name, age, city, country }); result.Should() - .BeEquivalentTo( + .BeEquivalentTo([ new { name = "Alice", age = 25, city = "New York", country = "USA" }, - new { name = "Bob", age = 30, city = "Los Angeles", country = "USA" }); + new { name = "Bob", age = 30, city = "Los Angeles", country = "USA" }]); } [Fact] @@ -160,9 +160,9 @@ async IAsyncEnumerable GetRecordsAsync() new { name, age, city, country, job }); result.Should() - .BeEquivalentTo( + .BeEquivalentTo([ new { name = "Alice", age = 25, city = "New York", country = "USA", job = "Engineer" }, - new { name = "Bob", age = 30, city = "Los Angeles", country = "USA", job = "Doctor" }); + new { name = "Bob", age = 30, city = "Los Angeles", country = "USA", job = "Doctor" }]); } [Fact] @@ -201,7 +201,7 @@ async IAsyncEnumerable GetRecordsAsync() new { name, age, city, country, job, hobby }); result.Should() - .BeEquivalentTo( + .BeEquivalentTo([ new { name = "Alice", age = 25, city = "New York", country = "USA", job = "Engineer", hobby = "Reading" @@ -209,7 +209,7 @@ async IAsyncEnumerable GetRecordsAsync() new { name = "Bob", age = 30, city = "Los Angeles", country = "USA", job = "Doctor", hobby = "Swimming" - }); + }]); } [Fact] @@ -250,7 +250,7 @@ async IAsyncEnumerable GetRecordsAsync() new { name, age, city, country, job, hobby, pet }); result.Should() - .BeEquivalentTo( + .BeEquivalentTo([ new { name = "Alice", age = 25, city = "New York", country = "USA", job = "Engineer", hobby = "Reading", @@ -260,7 +260,7 @@ async IAsyncEnumerable GetRecordsAsync() { name = "Bob", age = 30, city = "Los Angeles", country = "USA", job = "Doctor", hobby = "Swimming", pet = "Cat" - }); + }]); } [Fact] @@ -303,7 +303,7 @@ async IAsyncEnumerable GetRecordsAsync() new { name, age, city, country, job, hobby, pet, car }); result.Should() - .BeEquivalentTo( + .BeEquivalentTo([ new { name = "Alice", age = 25, city = "New York", country = "USA", job = "Engineer", hobby = "Reading", @@ -313,7 +313,7 @@ async IAsyncEnumerable GetRecordsAsync() { name = "Bob", age = 30, city = "Los Angeles", country = "USA", job = "Doctor", hobby = "Swimming", pet = "Cat", car = "BMW" - }); + }]); } [Fact] @@ -366,7 +366,7 @@ async IAsyncEnumerable GetRecordsAsync() string food) => new { name, age, city, country, job, hobby, pet, car, food }); result.Should() - .BeEquivalentTo( + .BeEquivalentTo([ new { name = "Alice", age = 25, city = "New York", country = "USA", job = "Engineer", hobby = "Reading", @@ -376,7 +376,7 @@ async IAsyncEnumerable GetRecordsAsync() { name = "Bob", age = 30, city = "Los Angeles", country = "USA", job = "Doctor", hobby = "Swimming", pet = "Cat", car = "BMW", food = "Burger" - }); + }]); } [Fact] @@ -432,7 +432,7 @@ async IAsyncEnumerable GetRecordsAsync() string sport) => new { name, age, city, country, job, hobby, pet, car, food, sport }); result.Should() - .BeEquivalentTo( + .BeEquivalentTo([ new { name = "Alice", age = 25, city = "New York", country = "USA", job = "Engineer", hobby = "Reading", @@ -442,6 +442,6 @@ async IAsyncEnumerable GetRecordsAsync() { name = "Bob", age = 30, city = "Los Angeles", country = "USA", job = "Doctor", hobby = "Swimming", pet = "Cat", car = "BMW", food = "Burger", sport = "Football" - }); + }]); } } diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/DelegateExecutableQueryMappingExtensionsTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/DelegateExecutableQueryMappingExtensionsTests.cs index 80e31d4db..1cf28243f 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/DelegateExecutableQueryMappingExtensionsTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/DelegateExecutableQueryMappingExtensionsTests.cs @@ -44,10 +44,10 @@ Task>> GetRecordsAsync() GetRecordsAsync() .AsObjectsAsync((string name) => new { name }) .Result.Should() - .BeEquivalentTo( + .BeEquivalentTo([ new { name = "Bob" }, new { name = "Alice" }, - new { name = "Eve" }); + new { name = "Eve" }]); } [Fact] @@ -70,10 +70,10 @@ Task>> GetRecordsAsync() GetRecordsAsync() .AsObjectsAsync((string name, int age) => new { name, age }) .Result.Should() - .BeEquivalentTo( + .BeEquivalentTo([ new { name = "Bob", age = 30 }, new { name = "Alice", age = 25 }, - new { name = "Eve", age = 35 }); + new { name = "Eve", age = 35 }]); } [Fact] @@ -97,10 +97,10 @@ Task>> GetRecordsAsync() GetRecordsAsync() .AsObjectsAsync((string name, int age, string city) => new { name, age, city }) .Result.Should() - .BeEquivalentTo( + .BeEquivalentTo([ new { name = "Bob", age = 30, city = "New York" }, new { name = "Alice", age = 25, city = "Los Angeles" }, - new { name = "Eve", age = 35, city = "Chicago" }); + new { name = "Eve", age = 35, city = "Chicago" }]); } [Fact] @@ -140,10 +140,10 @@ Task>> GetRecordsAsync() GetRecordsAsync() .AsObjectsAsync((string name, int age, string city, string country) => new { name, age, city, country }) .Result.Should() - .BeEquivalentTo( + .BeEquivalentTo([ new { name = "Bob", age = 30, city = "New York", country = "USA" }, new { name = "Alice", age = 25, city = "Los Angeles", country = "USA" }, - new { name = "Eve", age = 35, city = "Chicago", country = "USA" }); + new { name = "Eve", age = 35, city = "Chicago", country = "USA" }]); } [Fact] @@ -182,10 +182,10 @@ Task>> GetRecordsAsync() (string name, int age, string city, string country, string job) => new { name, age, city, country, job }) .Result.Should() - .BeEquivalentTo( + .BeEquivalentTo([ new { name = "Bob", age = 30, city = "New York", country = "USA", job = "Engineer" }, new { name = "Alice", age = 25, city = "Los Angeles", country = "USA", job = "Doctor" }, - new { name = "Eve", age = 35, city = "Chicago", country = "USA", job = "Teacher" }); + new { name = "Eve", age = 35, city = "Chicago", country = "USA", job = "Teacher" }]); } [Fact] @@ -224,13 +224,13 @@ Task>> GetRecordsAsync() (string name, int age, string city, string country, string job, string gender) => new { name, age, city, country, job, gender }) .Result.Should() - .BeEquivalentTo( + .BeEquivalentTo([ new { name = "Bob", age = 30, city = "New York", country = "USA", job = "Engineer", gender = "Male" }, new { name = "Alice", age = 25, city = "Los Angeles", country = "USA", job = "Doctor", gender = "Female" }, - new { name = "Eve", age = 35, city = "Chicago", country = "USA", job = "Teacher", gender = "Female" }); + new { name = "Eve", age = 35, city = "Chicago", country = "USA", job = "Teacher", gender = "Female" }]); } [Fact] @@ -272,7 +272,7 @@ Task>> GetRecordsAsync() (string name, int age, string city, string country, string job, string gender, string maritalStatus) => new { name, age, city, country, job, gender, maritalStatus }) .Result.Should() - .BeEquivalentTo( + .BeEquivalentTo([ new { name = "Bob", age = 30, city = "New York", country = "USA", job = "Engineer", gender = "Male", @@ -287,7 +287,8 @@ Task>> GetRecordsAsync() { name = "Eve", age = 35, city = "Chicago", country = "USA", job = "Teacher", gender = "Female", maritalStatus = "Divorced" - }); + } + ]); } [Fact] @@ -336,7 +337,7 @@ Task>> GetRecordsAsync() string maritalStatus, int children) => new { name, age, city, country, job, gender, maritalStatus, children }) .Result.Should() - .BeEquivalentTo( + .BeEquivalentTo([ new { name = "Bob", age = 30, city = "New York", country = "USA", job = "Engineer", gender = "Male", @@ -351,7 +352,9 @@ Task>> GetRecordsAsync() { name = "Eve", age = 35, city = "Chicago", country = "USA", job = "Teacher", gender = "Female", maritalStatus = "Divorced", children = 1 - }); + } + ] + ); } [Fact] @@ -402,7 +405,7 @@ Task>> GetRecordsAsync() string education) => new { name, age, city, country, job, gender, maritalStatus, children, education }) .Result.Should() - .BeEquivalentTo( + .BeEquivalentTo([ new { name = "Bob", age = 30, city = "New York", country = "USA", job = "Engineer", gender = "Male", @@ -417,7 +420,7 @@ Task>> GetRecordsAsync() { name = "Eve", age = 35, city = "Chicago", country = "USA", job = "Teacher", gender = "Female", maritalStatus = "Divorced", children = 1, education = "PhD" - }); + }]); } [Fact] @@ -472,7 +475,7 @@ Task>> GetRecordsAsync() int income) => new { name, age, city, country, job, gender, maritalStatus, children, education, income }) .Result.Should() - .BeEquivalentTo( + .BeEquivalentTo([ new { name = "Bob", age = 30, city = "New York", country = "USA", job = "Engineer", gender = "Male", @@ -487,6 +490,6 @@ Task>> GetRecordsAsync() { name = "Eve", age = 35, city = "Chicago", country = "USA", job = "Teacher", gender = "Female", maritalStatus = "Divorced", children = 1, education = "PhD", income = 60000 - }); + }]); } } diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/RecordMappingTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/RecordMappingTests.cs index 77e2d4f64..0aec97327 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/RecordMappingTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/RecordMappingTests.cs @@ -209,7 +209,7 @@ public void ShouldMapComplexObjects() mappedObject.MovieTitleIdeas.Should().BeEquivalentTo("A Band Apart", "Amazing Squad", "Ten Men Named Ben"); mappedObject.HistoricalMovies.Should() - .BeEquivalentTo( + .BeEquivalentTo([ new Movie { Title = "Forrest Gump", Released = 1994, Tagline = "Life is like a box of chocolates..." @@ -218,16 +218,16 @@ public void ShouldMapComplexObjects() { Title = "Cast Away", Released = 2000, Tagline = "At the edge of the world, his journey begins." }, - new Movie { Title = "The Green Mile", Released = 1999, Tagline = null }); + new Movie { Title = "The Green Mile", Released = 1999, Tagline = null }]); mappedObject.OtherMovies.Should() - .BeEquivalentTo( + .BeEquivalentTo([ new Movie { Title = "The Blind Venetian", Released = 2023, Tagline = "Read between the lines" }, new Movie { Title = "When The Night Ends", Released = 2022, Tagline = "Just when you thought it was safe to go to sleep" - }); + }]); } [Fact] @@ -250,10 +250,10 @@ Task>> GetRecordsAsync() GetRecordsAsync() .AsObjectsAsync() .Result.Should() - .BeEquivalentTo( + .BeEquivalentTo([ new TestPerson { Name = "Bob" }, new TestPerson { Name = "Alice", Born = 1988 }, - new TestPerson { Name = "Eve", Born = 1999 }); + new TestPerson { Name = "Eve", Born = 1999 }]); } [Fact] @@ -276,10 +276,10 @@ Task>> GetRecordsAsync() GetRecordsAsync() .AsObjectsFromBlueprintAsync(new { name = "", born = 0 }) .Result.Should() - .BeEquivalentTo( + .BeEquivalentTo([ new { name = "Bob", born = 1977 }, new { name = "Alice", born = 1988 }, - new { name = "Eve", born = 1999 }); + new { name = "Eve", born = 1999 }]); } [Fact] @@ -302,10 +302,10 @@ async IAsyncEnumerable GetRecordsAsync() var result = await GetRecordsAsync().ToListAsync(); result.Should() - .BeEquivalentTo( + .BeEquivalentTo([ new TestPerson { Name = "Bob" }, new TestPerson { Name = "Alice", Born = 1988 }, - new TestPerson { Name = "Eve", Born = 1999 }); + new TestPerson { Name = "Eve", Born = 1999 }]); } [Fact] @@ -329,10 +329,10 @@ async IAsyncEnumerable GetRecordsAsync() var blueprint = new { name = "", born = 0 }; var result = await GetRecordsAsync().ToListFromBlueprintAsync(blueprint); result.Should() - .BeEquivalentTo( + .BeEquivalentTo([ new { name = "Bob", born = 1977 }, new { name = "Alice", born = 1988 }, - new { name = "Eve", born = 1999 }); + new { name = "Eve", born = 1999 }]); } [Fact] @@ -360,10 +360,10 @@ async IAsyncEnumerable GetRecordsAsync() } people.Should() - .BeEquivalentTo( + .BeEquivalentTo([ new SimpleTestPerson { Name = "Bob" }, new SimpleTestPerson { Name = "Alice", Born = 1988 }, - new SimpleTestPerson { Name = "Eve", Born = 1999 }); + new SimpleTestPerson { Name = "Eve", Born = 1999 }]); } private class CarAndPainting diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Neo4j.Driver.Tests.csproj b/Neo4j.Driver/Neo4j.Driver.Tests/Neo4j.Driver.Tests.csproj index 1a6cea0dd..1339429d6 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Neo4j.Driver.Tests.csproj +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Neo4j.Driver.Tests.csproj @@ -17,7 +17,7 @@ - + diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Result/ResultCursorBuilderTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Result/ResultCursorBuilderTests.cs index 3a38fa96a..b35379c64 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Result/ResultCursorBuilderTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Result/ResultCursorBuilderTests.cs @@ -310,7 +310,7 @@ public async Task ShouldCallMoreOnceAndReturnRecords() var list = await builder.CreateCursor().ToListAsync(r => r[0].As()); - list.Should().BeEquivalentTo(1, 2, 3); + list.Should().BeEquivalentTo([1, 2, 3]); moreCallCount.Should().Be(1); cancelCallCount.Should().Be(0); } @@ -339,7 +339,7 @@ public async Task ShouldCallMoreTwiceAndReturnRecords() var list = await builder.CreateCursor().ToListAsync(r => r[0].As()); - list.Should().BeEquivalentTo(1, 2, 3); + list.Should().BeEquivalentTo([1, 2, 3]); moreCallCount.Should().Be(2); cancelCallCount.Should().Be(0); } @@ -369,7 +369,7 @@ public async Task ShouldCallMoreThreeTimesAndReturnRecords() var list = await builder.CreateCursor().ToListAsync(r => r[0].As()); - list.Should().BeEquivalentTo(1, 2, 3); + list.Should().BeEquivalentTo([1, 2, 3]); moreCallCount.Should().Be(3); cancelCallCount.Should().Be(0); } diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Routing/ClusterDiscoveryTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Routing/ClusterDiscoveryTests.cs index 10de75810..231e233a1 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Routing/ClusterDiscoveryTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Routing/ClusterDiscoveryTests.cs @@ -72,12 +72,13 @@ public async Task ShouldParseRoutingTableResult() // Then table.Database.Should().Be("test"); - table.Readers.Should().BeEquivalentTo(new Uri("neo4j://localhost:7689")); - table.Writers.Should().BeEquivalentTo(new Uri("neo4j://anotherServer:7687")); + table.Readers.Should().BeEquivalentTo([new Uri("neo4j://localhost:7689")]); + table.Writers.Should().BeEquivalentTo([new Uri("neo4j://anotherServer:7687")]); table.Routers.Should() - .BeEquivalentTo( + .BeEquivalentTo([ new Uri("neo4j://localhost:7689"), - new Uri("neo4j://anotherServer:7687")); + new Uri("neo4j://anotherServer:7687") + ]); table.ExpireAfterSeconds.Should().Be(15000L); } @@ -180,4 +181,4 @@ public MockedConnection( public Mock MockConn { get; } = new(); } -} \ No newline at end of file +} diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Routing/LoadBalancerTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Routing/LoadBalancerTests.cs index a946be6e4..93291d912 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Routing/LoadBalancerTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Routing/LoadBalancerTests.cs @@ -201,7 +201,7 @@ public void ShouldForgetServerWhenFailedToEstablishConn(AccessMode mode) // When & Then balancer.Awaiting(b => b.AcquireAsync(mode, It.IsAny(), It.IsAny(), Bookmarks.Empty)) .Should() - .Throw() + .ThrowAsync() .WithMessage("Failed to connect to any*"); // should be removed @@ -271,7 +271,7 @@ public void ShouldThrowErrorDirectlyIfProtocolError(AccessMode mode) // When balancer.Awaiting(b => b.AcquireAsync(mode, null, null, Bookmarks.Empty)) .Should() - .Throw() + .ThrowAsync() .WithMessage("*do not understand struct 0x01*"); // while the server is not removed diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Routing/RoutingTableManagerTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Routing/RoutingTableManagerTests.cs index 23eb83126..e3b418446 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Routing/RoutingTableManagerTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Routing/RoutingTableManagerTests.cs @@ -150,7 +150,7 @@ public void ShouldPrependInitialRouterIfWriterIsAbsent() m => m.UpdateRoutingTableAsync(AccessMode.Read, "", null, Bookmarks.Empty)) .Should() - .Throw(); + .ThrowAsync(); // Then poolManagerMock.Verify(x => x.AddConnectionPoolAsync(It.IsAny>()), Times.Once); @@ -649,17 +649,17 @@ public void ShouldRemoveFromCorrectRoutingTable() manager.ForgetServer(server05, "foo"); - manager.RoutingTableFor("foo").Routers.Should().BeEquivalentTo(server04); + manager.RoutingTableFor("foo").Routers.Should().BeEquivalentTo([server04]); manager.RoutingTableFor("foo").Readers.Should().BeEmpty(); - manager.RoutingTableFor("foo").Writers.Should().BeEquivalentTo(server06); + manager.RoutingTableFor("foo").Writers.Should().BeEquivalentTo([server06]); - manager.RoutingTableFor("").Routers.Should().BeEquivalentTo(server01); - manager.RoutingTableFor("").Readers.Should().BeEquivalentTo(server02, server05); - manager.RoutingTableFor("").Writers.Should().BeEquivalentTo(server03); + manager.RoutingTableFor("").Routers.Should().BeEquivalentTo([server01]); + manager.RoutingTableFor("").Readers.Should().BeEquivalentTo([server02, server05]); + manager.RoutingTableFor("").Writers.Should().BeEquivalentTo([server03]); - manager.RoutingTableFor("bar").Routers.Should().BeEquivalentTo(server07); - manager.RoutingTableFor("bar").Readers.Should().BeEquivalentTo(server08); - manager.RoutingTableFor("bar").Writers.Should().BeEquivalentTo(server09, server05); + manager.RoutingTableFor("bar").Routers.Should().BeEquivalentTo([server07]); + manager.RoutingTableFor("bar").Readers.Should().BeEquivalentTo([server08]); + manager.RoutingTableFor("bar").Writers.Should().BeEquivalentTo([server09, server05]); } [Fact] @@ -691,17 +691,17 @@ public void ShouldRemoveWriterFromCorrectRoutingTable() manager.ForgetWriter(server06, "foo"); - manager.RoutingTableFor("foo").Routers.Should().BeEquivalentTo(server04, server06); - manager.RoutingTableFor("foo").Readers.Should().BeEquivalentTo(server05); - manager.RoutingTableFor("foo").Writers.Should().BeEquivalentTo(server04); + manager.RoutingTableFor("foo").Routers.Should().BeEquivalentTo([server04, server06]); + manager.RoutingTableFor("foo").Readers.Should().BeEquivalentTo([server05]); + manager.RoutingTableFor("foo").Writers.Should().BeEquivalentTo([server04]); - manager.RoutingTableFor("").Routers.Should().BeEquivalentTo(server01); - manager.RoutingTableFor("").Readers.Should().BeEquivalentTo(server02, server05); - manager.RoutingTableFor("").Writers.Should().BeEquivalentTo(server03); + manager.RoutingTableFor("").Routers.Should().BeEquivalentTo([server01]); + manager.RoutingTableFor("").Readers.Should().BeEquivalentTo([server02, server05]); + manager.RoutingTableFor("").Writers.Should().BeEquivalentTo([server03]); - manager.RoutingTableFor("bar").Routers.Should().BeEquivalentTo(server07); - manager.RoutingTableFor("bar").Readers.Should().BeEquivalentTo(server08); - manager.RoutingTableFor("bar").Writers.Should().BeEquivalentTo(server09, server05); + manager.RoutingTableFor("bar").Routers.Should().BeEquivalentTo([server07]); + manager.RoutingTableFor("bar").Readers.Should().BeEquivalentTo([server08]); + manager.RoutingTableFor("bar").Writers.Should().BeEquivalentTo([server09, server05]); } } @@ -854,16 +854,16 @@ public async Task ShouldIsolateEntriesFromFailures() routingTable1.Should().Be(defaultRoutingTable); routingTable2.Should().Be(fooRoutingTable); - manager.Awaiting(m => m.EnsureRoutingTableForModeAsync(AccessMode.Write, "bar", null, Bookmarks.Empty)) + await manager.Awaiting(m => m.EnsureRoutingTableForModeAsync(AccessMode.Write, "bar", null, Bookmarks.Empty)) .Should() - .Throw(); + .ThrowAsync(); manager.RoutingTableFor("").Should().Be(defaultRoutingTable); manager.RoutingTableFor("foo").Should().Be(fooRoutingTable); } [Fact] - public void ShouldThrowOnFatalDiscovery() + public async Task ShouldThrowOnFatalDiscovery() { var error = new FatalDiscoveryException("message"); @@ -885,11 +885,11 @@ public void ShouldThrowOnFatalDiscovery() Mock.Of(), TimeSpan.MaxValue); + manager.Awaiting(m => m.EnsureRoutingTableForModeAsync(AccessMode.Write, "bar", null, Bookmarks.Empty)) .Should() - .Throw() - .Which.Should() - .Be(error); + .ThrowAsync() + .WithMessage(error.Message); } [Fact] @@ -923,4 +923,4 @@ public async Task ShouldPassBookmarkDownToDiscovery() discovery.Verify(x => x.DiscoverAsync(It.IsAny(), "foo", null, bookmark), Times.Once); } } -} \ No newline at end of file +} diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Routing/RoutingTableTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Routing/RoutingTableTests.cs index 155ed39dc..52de13371 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Routing/RoutingTableTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Routing/RoutingTableTests.cs @@ -284,13 +284,13 @@ public void ShouldRemoveFromAll() routingTable.Database.Should().Be("foo"); routingTable.Routers.Should() - .BeEquivalentTo(new Uri("bolt://my-server-1"), new Uri("http://my-server-3")); + .BeEquivalentTo([new Uri("bolt://my-server-1"), new Uri("http://my-server-3")]); routingTable.Writers.Should() - .BeEquivalentTo(new Uri("bolt://my-server-1"), new Uri("http://my-server-3")); + .BeEquivalentTo([new Uri("bolt://my-server-1"), new Uri("http://my-server-3")]); routingTable.Readers.Should() - .BeEquivalentTo(new Uri("bolt://my-server-1"), new Uri("http://my-server-3")); + .BeEquivalentTo([new Uri("bolt://my-server-1"), new Uri("http://my-server-3")]); routingTable.ExpireAfterSeconds.Should().Be(10); } @@ -309,13 +309,13 @@ public void ShouldNotRemoveIfNotPresent() routingTable.Database.Should().Be("foo"); routingTable.Routers.Should() - .BeEquivalentTo(new Uri("bolt://my-server-1"), new Uri("neo4j://my-server-2")); + .BeEquivalentTo([new Uri("bolt://my-server-1"), new Uri("neo4j://my-server-2")]); routingTable.Writers.Should() - .BeEquivalentTo(new Uri("bolt://my-server-1"), new Uri("neo4j://my-server-2")); + .BeEquivalentTo([new Uri("bolt://my-server-1"), new Uri("neo4j://my-server-2")]); routingTable.Readers.Should() - .BeEquivalentTo(new Uri("bolt://my-server-1"), new Uri("neo4j://my-server-2")); + .BeEquivalentTo([new Uri("bolt://my-server-1"), new Uri("neo4j://my-server-2")]); routingTable.ExpireAfterSeconds.Should().Be(10); } @@ -346,19 +346,19 @@ public void ShouldRemoveFromWritersOnly() routingTable.Database.Should().Be("foo"); routingTable.Routers.Should() - .BeEquivalentTo( + .BeEquivalentTo([ new Uri("bolt://my-server-1"), new Uri("neo4j://my-server-2"), - new Uri("http://my-server-3")); + new Uri("http://my-server-3")]); routingTable.Writers.Should() - .BeEquivalentTo(new Uri("bolt://my-server-1"), new Uri("http://my-server-3")); + .BeEquivalentTo([new Uri("bolt://my-server-1"), new Uri("http://my-server-3")]); routingTable.Readers.Should() - .BeEquivalentTo( + .BeEquivalentTo([ new Uri("bolt://my-server-1"), new Uri("neo4j://my-server-2"), - new Uri("http://my-server-3")); + new Uri("http://my-server-3")]); routingTable.ExpireAfterSeconds.Should().Be(10); } @@ -377,13 +377,13 @@ public void ShouldNotRemoveIfNotPresent() routingTable.Database.Should().Be("foo"); routingTable.Routers.Should() - .BeEquivalentTo(new Uri("bolt://my-server-1"), new Uri("neo4j://my-server-2")); + .BeEquivalentTo([new Uri("bolt://my-server-1"), new Uri("neo4j://my-server-2")]); routingTable.Writers.Should() - .BeEquivalentTo(new Uri("bolt://my-server-1"), new Uri("neo4j://my-server-2")); + .BeEquivalentTo([new Uri("bolt://my-server-1"), new Uri("neo4j://my-server-2")]); routingTable.Readers.Should() - .BeEquivalentTo(new Uri("bolt://my-server-1"), new Uri("neo4j://my-server-2")); + .BeEquivalentTo([new Uri("bolt://my-server-1"), new Uri("neo4j://my-server-2")]); routingTable.ExpireAfterSeconds.Should().Be(10); } @@ -406,10 +406,10 @@ public void ShouldUnionAll() routingTable.All() .Should() - .BeEquivalentTo( + .BeEquivalentTo([ new Uri("bolt://my-server-1"), new Uri("neo4j://my-server-2"), - new Uri("http://my-server-3")); + new Uri("http://my-server-3")]); } [Fact] @@ -446,4 +446,4 @@ public async Task ShouldReturnExpectedValue(int expiresAfterSecs, int expiredFor } */ } -} \ No newline at end of file +} diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/SessionConfigBuilderTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/SessionConfigBuilderTests.cs index 27572b798..fa109fd50 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/SessionConfigBuilderTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/SessionConfigBuilderTests.cs @@ -14,6 +14,7 @@ // limitations under the License. using System; +using System.Collections.Generic; using FluentAssertions; using Neo4j.Driver.Internal.Types; using Xunit; @@ -146,7 +147,7 @@ public void WithNotifications_ShouldSetSeverity() config .Which .DisabledCategories.Should() - .BeEquivalentTo([]); + .BeEquivalentTo(new HashSet()); config .Which @@ -168,7 +169,7 @@ public void WithNotifications_ShouldSetSeverityWhenUsingClassification() config .Which .DisabledCategories.Should() - .BeEquivalentTo([]); + .BeEquivalentTo(new HashSet()); config .Which diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/TestUtil/Assertions.cs b/Neo4j.Driver/Neo4j.Driver.Tests/TestUtil/Assertions.cs index 3368347e9..8db383965 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/TestUtil/Assertions.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/TestUtil/Assertions.cs @@ -28,7 +28,7 @@ public static AndConstraint> BeGreaterOrEqualTo( T accuracy, string because = "", params object[] becauseArgs) - where T : struct, IConvertible + where T : struct, IConvertible, IComparable { var expectedAsDouble = Convert.ToDouble(expected); var accuracyAsDouble = Convert.ToDouble(accuracy); diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/TransactionTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/TransactionTests.cs index 3c128017e..6d9bd0165 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/TransactionTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/TransactionTests.cs @@ -210,7 +210,7 @@ public async Task ShouldThrowExceptionToRunAfterMarkToClosed() tx.Awaiting(t => t.RunAsync("should not run")) .Should() - .Throw(); + .ThrowAsync(); mockConn.Verify(x => x.RollbackTransactionAsync(), Times.Never); mockConn.Verify(x => x.SyncAsync(), Times.Never); @@ -225,9 +225,9 @@ public async Task ShouldNotEnqueueMoreMessagesAfterMarkToClosedInCommitAsync() mockConn.Invocations.Clear(); tx.TransactionError = new Exception(); await tx.MarkToCloseAsync(); - tx.Awaiting(t => t.CommitAsync()) + await tx.Awaiting(t => t.CommitAsync()) .Should() - .Throw(); + .ThrowAsync(); mockConn.Verify(x => x.CommitTransactionAsync(tx), Times.Never); mockConn.Verify(x => x.SyncAsync(), Times.Never); @@ -242,7 +242,7 @@ public async Task ShouldNotEnqueueMoreMessagesAfterMarkToClosedInRollbackAsync() mockConn.Invocations.Clear(); await tx.MarkToCloseAsync(); - tx.Awaiting(t => t.RollbackAsync()).Should().NotThrow(); + await tx.Awaiting(t => t.RollbackAsync()).Should().NotThrowAsync(); mockConn.Verify(x => x.RollbackTransactionAsync(), Times.Never); mockConn.Verify(x => x.SyncAsync(), Times.Never); } @@ -327,4 +327,4 @@ await tx.BeginTransactionAsync( tx.IsOpen.Should().BeFalse(); } } -} \ No newline at end of file +} From 9c12e81faecbf6c783f5b6cb60b6b0d468b5f02f Mon Sep 17 00:00:00 2001 From: Grant Lodge <6323995+thelonelyvulpes@users.noreply.github.com> Date: Sun, 19 Jan 2025 23:36:41 +0000 Subject: [PATCH 2/6] reformat --- .../Neo4j.Driver.Tests/AsyncSessionTests.cs | 7 +- .../Auth/Neo4jAuthTokenManagerTests.cs | 13 +- .../Neo4j.Driver.Tests/BookmarkTests.cs | 2 +- .../Neo4j.Driver.Tests/ConfigTests.cs | 11 +- .../Neo4j.Driver.Tests/ConnectionPoolTests.cs | 3 +- .../ConnectionValidatorTests.cs | 34 +- .../Connector/MockedMessagingClient.cs | 2 +- .../Connector/SocketClientTests.cs | 7 +- .../Connector/SocketConnectionTests.cs | 10 +- .../Neo4j.Driver.Tests/DriverTests.cs | 19 +- .../Exceptions/Neo4jExceptionFactoryTests.cs | 18 +- .../ExecutableQuery/ExecutableQueryTests.cs | 14 +- .../Extensions/StreamExtensionTests.cs | 3 +- .../Neo4j.Driver.Tests/Filters/OSFilters.cs | 2 +- .../Filters/RuntimeFilters.cs | 2 +- .../GqlCompliance/GqlErrorTests.cs | 4 +- .../Internal/IO/ChunkReaderTests.cs | 8 +- .../Internal/IO/ChunkWriterTests.cs | 3 +- .../IgnoredMessageSerializerTests.cs | 2 +- .../PullAllMessageSerializerTests.cs | 2 +- .../RecordMessageSerializerTests.cs | 2 +- .../SuccessMessageSerializerTests.cs | 3 +- .../Internal/IO/PackStreamTests.cs | 14 +- .../Internal/IO/Utils/Machines.cs | 2 +- .../ElementNodeSerializerTests.cs | 12 +- .../ElementPathSerializerTests.cs | 1 - .../ElementRelationshipSerializerTests.cs | 8 +- ...ementUnboundRelationshipSerializerTests.cs | 8 +- .../ValueSerializers/NodeSerializerTests.cs | 11 +- .../ValueSerializers/PathSerializerTests.cs | 8 +- .../ValueSerializers/PointSerializerTests.cs | 5 +- .../RelationshipSerializerTests.cs | 11 +- .../Temporal/DurationSerializerTests.cs | 2 +- .../Temporal/LocalDateTimeSerializerTests.cs | 2 +- .../Temporal/OffsetTimeSerializerTests.cs | 1 - .../Temporal/SystemDateTimeSerializerTests.cs | 2 +- .../UnboundRelationshipSerializerTests.cs | 14 +- .../InMemoryPipelinedMessageReaderTests.cs | 52 +- .../Messages/BeginMessageTests.cs | 18 +- .../Messages/DiscardMessageTests.cs | 2 +- .../Messages/HelloMessageTests.cs | 12 +- .../Messages/RunWithMetaDataMessageTests.cs | 17 +- ...usObjectsAndNotificationsCollectorTests.cs | 55 +- .../GqlStatusObjectsAndNotificationsTests.cs | 8 +- .../NetworkedPipelinedMessageReaderTests.cs | 542 +++++++++--------- .../Internal/Protocol/BoltProtocolTests.cs | 3 +- .../Util/PipeReaderMemoryPoolTests.cs | 16 +- .../Internal/Util/TransactionTimeoutTests.cs | 10 +- .../Mapping/AsyncEnumerableExtensionsTests.cs | 54 +- .../Mapping/BlueprintMappingTests.cs | 8 +- .../Mapping/BuiltMapperTests.cs | 32 +- .../Mapping/DefaultMapperTests.cs | 272 ++++----- ...teExecutableQueryMappingExtensionsTests.cs | 323 ++++++----- .../Mapping/DelegateMapperTests.cs | 89 +-- .../Mapping/DictAsRecordTests.cs | 10 +- .../Mapping/LabelCaptureTests.cs | 86 +-- .../LambdaMappingRecordExtensionsTests.cs | 18 +- .../Mapping/MappableValueProviderTests.cs | 12 +- .../Mapping/MappedListCreatorTests.cs | 36 +- .../Mapping/MappingBuilderTests.cs | 16 +- .../Mapping/MappingProviderTests.cs | 236 ++++---- .../Mapping/OptionalMappingTests.cs | 63 +- .../Mapping/RecordMappingTests.cs | 378 ++++++------ .../Neo4j.Driver.Tests.csproj | 46 +- Neo4j.Driver/Neo4j.Driver.Tests/NodeTests.cs | 2 +- .../Internal/InternalRxSessionTests.cs | 3 +- .../Reactive/Utils/Utils.cs | 11 +- .../Neo4j.Driver.Tests/RelationshipTests.cs | 2 +- .../Neo4j.Driver.Tests/Result/RecordTests.cs | 6 +- .../Result/ResultCursorBuilderTests.cs | 69 ++- .../Neo4j.Driver.Tests/Result/ResultTests.cs | 6 +- .../Routing/ClusterConnectionPoolTests.cs | 2 +- .../Routing/ClusterDiscoveryTests.cs | 5 +- .../Routing/LoadBalancerTests.cs | 33 +- .../Routing/RoundRobinArrayIndexTests.cs | 2 +- .../Routing/RoutingTableManagerTests.cs | 19 +- .../Routing/RoutingTableTests.cs | 18 +- .../SessionConfigBuilderTests.cs | 5 +- .../Neo4j.Driver.Tests/TestDriverContext.cs | 4 +- .../TestUtil/CollectionExtensionsTests.cs | 5 +- .../TestUtil/MockExtensionsTests.cs | 10 +- .../Neo4j.Driver.Tests/TestUtil/TestRecord.cs | 6 +- .../Neo4j.Driver.Tests/TransactionTests.cs | 50 +- .../Neo4j.Driver.Tests/Types/DurationTests.cs | 2 +- .../Types/LocalTimeTests.cs | 2 +- .../Types/NotificationTests.cs | 40 +- .../Types/ZonedDateTimeWithOffsetTests.cs | 2 +- .../Types/ZonedDateTimeWithZoneIdTests.cs | 6 +- .../ValueExtensionsTests.cs | 2 +- 89 files changed, 1623 insertions(+), 1375 deletions(-) diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/AsyncSessionTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/AsyncSessionTests.cs index 2e7f00ac1..46358a4d3 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/AsyncSessionTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/AsyncSessionTests.cs @@ -72,8 +72,7 @@ internal static Mock MockedConnectionWithSuccessResponse(IBoltProto It.IsAny(), It.IsAny())) .Returns(Task.CompletedTask) - .Callback( - (IRequestMessage _, IResponseHandler h1) => { h1.OnSuccess(new Dictionary()); }); + .Callback((IRequestMessage _, IResponseHandler h1) => { h1.OnSuccess(new Dictionary()); }); if (protocol == null) { @@ -299,7 +298,9 @@ public async void PipelinedShouldBeginWithoutBlocking() false, false); - await session.PipelinedExecuteReadAsync(_ => Task.FromResult(null as EagerResult), new TransactionConfig()); + await session.PipelinedExecuteReadAsync( + _ => Task.FromResult(null as EagerResult), + new TransactionConfig()); mockProtocol.Verify( x => diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Auth/Neo4jAuthTokenManagerTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Auth/Neo4jAuthTokenManagerTests.cs index eea931c15..dc4ad0db7 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Auth/Neo4jAuthTokenManagerTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Auth/Neo4jAuthTokenManagerTests.cs @@ -1,14 +1,12 @@ // Copyright (c) "Neo4j" -// Neo4j Sweden AB [http://neo4j.com] -// -// This file is part of Neo4j. -// +// Neo4j Sweden AB [https://neo4j.com] +// // Licensed under the Apache License, Version 2.0 (the "License"). // You may not use this file except in compliance with the License. // You may obtain a copy of the License at -// +// // http://www.apache.org/licenses/LICENSE-2.0 -// +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -44,7 +42,8 @@ public async Task ShouldCacheToken() { var (authData, _) = GetTwoAuthTokens(); - int callCount = 0; + var callCount = 0; + ValueTask TokenProvider() { callCount++; diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/BookmarkTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/BookmarkTests.cs index 95c3d0b8a..cf672adb2 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/BookmarkTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/BookmarkTests.cs @@ -98,4 +98,4 @@ public void ShouldUnionValues(string[] values1, string[] values2, string[] value } } } -} \ No newline at end of file +} diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/ConfigTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/ConfigTests.cs index 90cd7d4b3..4163ee270 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/ConfigTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/ConfigTests.cs @@ -14,7 +14,6 @@ // limitations under the License. using System; -using System.Collections.Generic; using System.IO; using System.Net.Security; using System.Security.Authentication; @@ -366,7 +365,8 @@ public void WithNotifications_ShouldSetSeverity() config .Which - .DisabledCategories.Should().BeEmpty(); + .DisabledCategories.Should() + .BeEmpty(); config .Which @@ -402,7 +402,7 @@ public void WithNotifications_ShouldWorkWithSecondParameterNull() var configBuilder = new ConfigBuilder(new Config()); // this line would fail to compile before the fix - configBuilder.WithNotifications(Severity.Warning, null); + configBuilder.WithNotifications(Severity.Warning); var config = configBuilder.Build() .NotificationsConfig.Should() @@ -451,7 +451,7 @@ public void WithNotifications_ShouldHaveNullExclusions() var configBuilder = new ConfigBuilder(new Config()); // this line would fail to compile before the fix - configBuilder.WithNotifications(Severity.Warning, null); + configBuilder.WithNotifications(Severity.Warning); var config = configBuilder.Build() .NotificationsConfig.Should() @@ -459,7 +459,8 @@ public void WithNotifications_ShouldHaveNullExclusions() config .Which - .DisabledCategories.Should().BeEmpty(); + .DisabledCategories.Should() + .BeNull(); config .Which diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/ConnectionPoolTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/ConnectionPoolTests.cs index 4543ed91a..2a3e7f68a 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/ConnectionPoolTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/ConnectionPoolTests.cs @@ -24,8 +24,8 @@ using Moq; using Neo4j.Driver.Internal; using Neo4j.Driver.Internal.Connector; -using Neo4j.Driver.Internal.Util; using Neo4j.Driver.Internal.Protocol; +using Neo4j.Driver.Internal.Util; using Neo4j.Driver.Tests.TestUtil; using Xunit; using Xunit.Abstractions; @@ -291,6 +291,7 @@ private Mock MockValidator(Action x.GetConnectionLifetimeStatus(It.IsAny())) .Returns(AcquireStatus.Healthy); } + return validator; } diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/ConnectionValidatorTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/ConnectionValidatorTests.cs index b15dc0323..2f2ff44d7 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/ConnectionValidatorTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/ConnectionValidatorTests.cs @@ -30,8 +30,23 @@ private static ConnectionValidator NewConnectionValidator( TimeSpan? maxConnLifetime = null, TimeSpan? livelinessCheckTimeout = null) { - return new ConnectionValidator(connIdleTimeout ?? Config.InfiniteInterval, - maxConnLifetime ?? Config.InfiniteInterval, livelinessCheckTimeout); + return new ConnectionValidator( + connIdleTimeout ?? Config.InfiniteInterval, + maxConnLifetime ?? Config.InfiniteInterval, + livelinessCheckTimeout); + } + + private static (Mock conn, Mock idle, Mock life) Mock() + { + var conn = new Mock(); + conn.Setup(x => x.Version).Returns(BoltProtocolVersion.V5_1); + + var idleTimer = new Mock(); + var lifeTimer = new Mock(); + + conn.Setup(x => x.IdleTimer).Returns(idleTimer.Object); + conn.Setup(x => x.LifetimeTimer).Returns(lifeTimer.Object); + return (conn, idleTimer, lifeTimer); } public class IsConnectionReusableTests @@ -131,17 +146,4 @@ public void ShouldRequireLiveness() idleTimer.Verify(x => x.Reset(), Times.Once); } } - - private static (Mock conn, Mock idle, Mock life) Mock() - { - var conn = new Mock(); - conn.Setup(x => x.Version).Returns(BoltProtocolVersion.V5_1); - - var idleTimer = new Mock(); - var lifeTimer = new Mock(); - - conn.Setup(x => x.IdleTimer).Returns(idleTimer.Object); - conn.Setup(x => x.LifetimeTimer).Returns(lifeTimer.Object); - return (conn, idleTimer, lifeTimer); - } -} \ No newline at end of file +} diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Connector/MockedMessagingClient.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Connector/MockedMessagingClient.cs index d76eeebb4..d9d3874ec 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Connector/MockedMessagingClient.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Connector/MockedMessagingClient.cs @@ -171,4 +171,4 @@ internal static SuccessMessage SuccessMessage(IDictionary fields ? new SuccessMessage(new Dictionary()) : new SuccessMessage(fields); } -} \ No newline at end of file +} diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Connector/SocketClientTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Connector/SocketClientTests.cs index a0a35a84e..65d47ae90 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Connector/SocketClientTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Connector/SocketClientTests.cs @@ -75,7 +75,7 @@ private static (Mock, Mock) CreateMockIo mockIoFactory .Setup(x => x.TcpSocketClient(It.IsAny(), It.IsAny())) .Returns(connMock.Object); - + configureFactory?.Invoke(mockIoFactory); return (connMock, mockIoFactory); @@ -127,8 +127,7 @@ public async void ShouldNotCatchHandshakeFailuresOrConstructIoTypes() var client = NewClient(io, null, mockHandshaker); - var ex = await Record.ExceptionAsync( - () => client.ConnectAsync(CancellationToken.None)); + var ex = await Record.ExceptionAsync(() => client.ConnectAsync(CancellationToken.None)); mockHandshaker.Verify( x => x.DoHandshakeAsync( @@ -337,4 +336,4 @@ public async Task ShouldCallDisconnectAsyncOnTheTcpSocketClientWhenStoppedAsync( client.IsOpen.Should().BeFalse(); } } -} \ No newline at end of file +} diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Connector/SocketConnectionTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Connector/SocketConnectionTests.cs index 4766c3cf8..fb7f11999 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Connector/SocketConnectionTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Connector/SocketConnectionTests.cs @@ -74,11 +74,13 @@ public async Task ShouldConnectClient() var bpFactory = new Mock(); bpFactory.Setup(x => x.ForVersion(BoltProtocolVersion.V3_0)).Returns(protocolMock.Object); - var conn = NewSocketConnection(mockClient.Object, boltProtocolFactory: bpFactory.Object, + var conn = NewSocketConnection( + mockClient.Object, + boltProtocolFactory: bpFactory.Object, context: new DriverContext(new Uri("bolt://localhost:7687"), AuthTokenManagers.None, new Config())); // When - await conn.InitAsync(null); + await conn.InitAsync(); // Then mockClient.Verify(c => c.ConnectAsync(CancellationToken.None), Times.Once); @@ -102,7 +104,7 @@ public async Task ShouldThrowClientErrorIfFailedToConnectToServerWithinTimeout() // ReSharper disable once ObjectCreationAsStatement var conn = new SocketConnection(mockClient.Object, AuthToken, Logger, Server); // When - var error = await Record.ExceptionAsync(() => conn.InitAsync(null)); + var error = await Record.ExceptionAsync(() => conn.InitAsync()); // Then error.Should().BeOfType(); error.Message.Should().Be("I will stop socket conn from initialization"); @@ -227,7 +229,7 @@ public async Task ShouldEnqueueBoth() var h1 = new Mock(); var m2 = new Mock(); var h2 = new Mock(); - + await con.EnqueueAsync(m1.Object, h1.Object, m2.Object, h2.Object); con.Messages[0].Should().Be(m1.Object); diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/DriverTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/DriverTests.cs index b1fc3a30f..adc4c9b91 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/DriverTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/DriverTests.cs @@ -19,7 +19,6 @@ using Moq; using Neo4j.Driver.Internal; using Xunit; - using InternalDriver = Neo4j.Driver.Internal.Driver; #pragma warning disable CS0618 @@ -71,8 +70,7 @@ public void ShouldErrorIfUriWrongFormat() [Fact] public void ShouldErrorIfBoltSchemeWithRoutingContext() { - var exception = Record.Exception( - () => GraphDatabase.Driver("bolt://localhost/?name=molly&age=1&color=white")); + var exception = Record.Exception(() => GraphDatabase.Driver("bolt://localhost/?name=molly&age=1&color=white")); exception.Should().BeOfType(); exception.Message.Should().Contain("Routing context are not supported with scheme 'bolt'"); @@ -156,10 +154,12 @@ public async void ShouldTryVerifyConnection() mock.Setup(x => x.VerifyConnectivityAndGetInfoAsync()) .Returns(Task.FromResult(new Mock().Object)); - var driver = (IDriver)new InternalDriver(new Uri("bolt://localhost"), + var driver = (IDriver)new InternalDriver( + new Uri("bolt://localhost"), mock.Object, null, TestDriverContext.MockContext); + var connects = await driver.TryVerifyConnectivityAsync(); connects.Should().BeTrue(); @@ -172,10 +172,12 @@ public async void ShouldCatchInTryVerifyConnection() mock.Setup(x => x.VerifyConnectivityAndGetInfoAsync()) .ThrowsAsync(new Exception("broken")); - var driver = (IDriver)new InternalDriver(new Uri("bolt://localhost"), + var driver = (IDriver)new InternalDriver( + new Uri("bolt://localhost"), mock.Object, null, TestDriverContext.MockContext); + var connects = await driver.TryVerifyConnectivityAsync(); connects.Should().BeFalse(); @@ -189,7 +191,8 @@ public async void ShouldGetInfoConnection() mock.Setup(x => x.VerifyConnectivityAndGetInfoAsync()) .Returns(Task.FromResult(mockServerInfo)); - var driver = new InternalDriver(new Uri("bolt://localhost"), + var driver = new InternalDriver( + new Uri("bolt://localhost"), mock.Object, null, TestDriverContext.MockContext); @@ -205,10 +208,12 @@ public async void ShouldTestSupportMultiDb() { var mock = new Mock(); mock.Setup(x => x.SupportsMultiDbAsync()).Returns(Task.FromResult(true)); - var driver = new InternalDriver(new Uri("bolt://localhost"), + var driver = new InternalDriver( + new Uri("bolt://localhost"), mock.Object, null, TestDriverContext.MockContext); + await driver.SupportsMultiDbAsync(); mock.Verify(x => x.SupportsMultiDbAsync(), Times.Once); diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Exceptions/Neo4jExceptionFactoryTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Exceptions/Neo4jExceptionFactoryTests.cs index ddbd8c08c..cc13cda3d 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Exceptions/Neo4jExceptionFactoryTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Exceptions/Neo4jExceptionFactoryTests.cs @@ -1,14 +1,12 @@ // Copyright (c) "Neo4j" -// Neo4j Sweden AB [http://neo4j.com] -// -// This file is part of Neo4j. -// -// Licensed under the Apache License, Version 2.0 (the "License"): -// you may not use this file except in compliance with the License. +// Neo4j Sweden AB [https://neo4j.com] +// +// Licensed under the Apache License, Version 2.0 (the "License"). +// You may not use this file except in compliance with the License. // You may obtain a copy of the License at -// +// // http://www.apache.org/licenses/LICENSE-2.0 -// +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -16,7 +14,6 @@ // limitations under the License. using System; -using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using FluentAssertions; using Neo4j.Driver.Internal.ExceptionHandling; @@ -46,7 +43,8 @@ public class Neo4jExceptionFactoryTests ["Neo.TransientError.TemporaryDisabled", typeof(TransientException)] ]; - [Theory, MemberData(nameof(CodeToTypeMapping))] + [Theory] + [MemberData(nameof(CodeToTypeMapping))] public void ShouldCreateCorrectExceptionType(string code, Type exceptionType) { var subject = new Neo4jExceptionFactory(); diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/ExecutableQuery/ExecutableQueryTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/ExecutableQuery/ExecutableQueryTests.cs index 4ab4fc271..c7977789e 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/ExecutableQuery/ExecutableQueryTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/ExecutableQuery/ExecutableQueryTests.cs @@ -1,14 +1,12 @@ // Copyright (c) "Neo4j" -// Neo4j Sweden AB [http://neo4j.com] -// -// This file is part of Neo4j. -// +// Neo4j Sweden AB [https://neo4j.com] +// // Licensed under the Apache License, Version 2.0 (the "License"). // You may not use this file except in compliance with the License. // You may obtain a copy of the License at -// +// // http://www.apache.org/licenses/LICENSE-2.0 -// +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -275,7 +273,7 @@ public async Task ShouldReturnMappedTransformedReducedValue() var result = await subject .WithMap(i => i * 10) - .WithReduce(() => 0, (x, y) => x + y, i => $"<{(i * 2)}>") + .WithReduce(() => 0, (x, y) => x + y, i => $"<{i * 2}>") .ExecuteAsync(); result.Result.Should().Be("<900>"); @@ -352,7 +350,7 @@ public async Task ShouldUseStreamProcessor() async IAsyncEnumerable GetInts(int start, int count) { - foreach(var i in Enumerable.Range(start, count)) + foreach (var i in Enumerable.Range(start, count)) { await Task.Yield(); yield return i; diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Extensions/StreamExtensionTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Extensions/StreamExtensionTests.cs index 864f50538..500f190c3 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Extensions/StreamExtensionTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Extensions/StreamExtensionTests.cs @@ -44,8 +44,7 @@ void Callback(Memory _, CancellationToken token) const int timeout = 100; - var ex = await Record.ExceptionAsync( - () => streamMock.Object.ReadWithTimeoutAsync(new byte[1], 0, 1, timeout)); + var ex = await Record.ExceptionAsync(() => streamMock.Object.ReadWithTimeoutAsync(new byte[1], 0, 1, timeout)); ex.Should() .BeOfType() diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Filters/OSFilters.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Filters/OSFilters.cs index 0b929829a..d36612f4a 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Filters/OSFilters.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Filters/OSFilters.cs @@ -100,4 +100,4 @@ public class UnixTheoryAttribute : OSTheoryAttribute public UnixTheoryAttribute() : base(OSPlatform.Linux, OSPlatform.OSX) { } -} \ No newline at end of file +} diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Filters/RuntimeFilters.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Filters/RuntimeFilters.cs index 825fe90da..c16372b6e 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Filters/RuntimeFilters.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Filters/RuntimeFilters.cs @@ -73,4 +73,4 @@ public DotnetCoreTheoryAttribute() Skip = "Test is supposed to be run only on .net core runtimes"; } } -} \ No newline at end of file +} diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/GqlCompliance/GqlErrorTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/GqlCompliance/GqlErrorTests.cs index b61835885..fbe15a7dd 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/GqlCompliance/GqlErrorTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/GqlCompliance/GqlErrorTests.cs @@ -45,7 +45,7 @@ public void BuildFailureMessage_ShouldDeserializeCorrectly() } }; - int majorVersion = 4; + var majorVersion = 4; // Act var result = FailureMessageSerializer.BuildFailureMessage(values, majorVersion); @@ -73,7 +73,7 @@ public void BuildFailureMessage_ShouldDeserializeCorrectly() result.GqlClassification.Should().Be("UNKNOWN"); } - [Fact] + [Fact] public void GetException_ShouldHandleNestedFailureMessages() { // Arrange diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ChunkReaderTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ChunkReaderTests.cs index 381874a26..0e96d8889 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ChunkReaderTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ChunkReaderTests.cs @@ -280,7 +280,11 @@ private static byte[] GenerateMessageChunk(int messageSize) { var buffer = Enumerable.Range(0, messageSize).Select(i => i % byte.MaxValue).Select(i => (byte)i).ToArray(); var stream = new MemoryStream(); - var cs = new DriverContext(new Uri("bolt://localhost:7687"), new StaticAuthTokenManager(AuthTokens.None), new Config()); + var cs = new DriverContext( + new Uri("bolt://localhost:7687"), + new StaticAuthTokenManager(AuthTokens.None), + new Config()); + var writer = new ChunkWriter(stream, cs, new Mock().Object); writer.OpenChunk(); @@ -314,4 +318,4 @@ private static byte[] GenerateMessages(int messageSizePerChunk, int maxBytes) return stream.ToArray(); } -} \ No newline at end of file +} diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ChunkWriterTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ChunkWriterTests.cs index eda98c059..07f3db5a9 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ChunkWriterTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ChunkWriterTests.cs @@ -29,6 +29,7 @@ namespace Neo4j.Driver.Tests.Internal.IO; public class ChunkWriterTests { private readonly Mock _logger = new(); + private static DriverContext TestContext(int defaultRead, int defaultWrite, int maxRead, int maxWrite) { return TestDriverContext.With( @@ -354,4 +355,4 @@ private static async Task ConstructMessage(byte[] buffer) return stream.ToArray(); } -} \ No newline at end of file +} diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/IgnoredMessageSerializerTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/IgnoredMessageSerializerTests.cs index 8c9ec7967..1da56ed38 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/IgnoredMessageSerializerTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/IgnoredMessageSerializerTests.cs @@ -35,4 +35,4 @@ public void ShouldReturnIgnoredMessage() var message = IgnoredMessageSerializer.Instance.Deserialize(null); message.Should().Be(IgnoredMessage.Instance); } -} \ No newline at end of file +} diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/PullAllMessageSerializerTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/PullAllMessageSerializerTests.cs index 5d74786bc..9f16ad4d6 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/PullAllMessageSerializerTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/PullAllMessageSerializerTests.cs @@ -68,4 +68,4 @@ public void ShouldSerialize(int major, int minor) bytes[0].Should().Be(0xB0); bytes[1].Should().Be(0x3F); } -} \ No newline at end of file +} diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/RecordMessageSerializerTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/RecordMessageSerializerTests.cs index da16775d0..39168f62e 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/RecordMessageSerializerTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/RecordMessageSerializerTests.cs @@ -57,6 +57,6 @@ public void ShouldDeserialize(int major, int minor) var message = RecordMessageSerializer.Instance.Deserialize(reader); - message.Should().BeOfType().Which.Fields.Should().BeEquivalentTo(new object[]{0L, "a"}); + message.Should().BeOfType().Which.Fields.Should().BeEquivalentTo(new object[] { 0L, "a" }); } } diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/SuccessMessageSerializerTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/SuccessMessageSerializerTests.cs index 8935ee618..a6aeb146f 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/SuccessMessageSerializerTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/MessageSerializers/SuccessMessageSerializerTests.cs @@ -63,7 +63,8 @@ public void ShouldDeserialize(int major, int minor) message.Should() .BeOfType() .Which.Meta.Should() - .ContainKey("unknown").WhoseValue + .ContainKey("unknown") + .WhoseValue .Should() .Be(1L); } diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/PackStreamTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/PackStreamTests.cs index aa66a2a02..692c533c2 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/PackStreamTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/PackStreamTests.cs @@ -45,8 +45,10 @@ internal virtual PackStreamReaderMachine CreateReaderMachine( internal override PackStreamWriterMachine CreateWriterMachine(BoltProtocolVersion version = null) { - return CreateWriterMachine(new MessageFormat(version ?? BoltProtocolVersion.V3_0, - TestDriverContext.MockContext).WriteStructHandlers); + return CreateWriterMachine( + new MessageFormat( + version ?? BoltProtocolVersion.V3_0, + TestDriverContext.MockContext).WriteStructHandlers); } internal override PackStreamReaderMachine CreateReaderMachine(byte[] data, BoltProtocolVersion version = null) @@ -89,7 +91,7 @@ public void ShouldReadViaStructHandlerIfThereIsAHandlerRegisteredForSignature() var structValue = (StructType)value; structValue.Values.Should().NotBeNull(); - structValue.Values.Should().BeEquivalentTo(new object[] {1L, 2L, true, 3.0, "something"}); + structValue.Values.Should().BeEquivalentTo(new object[] { 1L, 2L, true, 3.0, "something" }); } [Fact] @@ -153,7 +155,11 @@ public void Serialize(BoltProtocolVersion _, PackStreamWriter writer, object val } } - public (object, int) DeserializeSpan(BoltProtocolVersion version, SpanPackStreamReader reader, byte signature, int size) + public (object, int) DeserializeSpan( + BoltProtocolVersion version, + SpanPackStreamReader reader, + byte signature, + int size) { throw new NotImplementedException(); } diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/Utils/Machines.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/Utils/Machines.cs index 500844e59..5266f410f 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/Utils/Machines.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/Utils/Machines.cs @@ -57,4 +57,4 @@ internal PackStreamReader Reader() { return _reader; } -} \ No newline at end of file +} diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/ElementNodeSerializerTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/ElementNodeSerializerTests.cs index 474443884..aa1054b89 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/ElementNodeSerializerTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/ElementNodeSerializerTests.cs @@ -63,12 +63,9 @@ private static void Validate(object value) .Which.Properties.Should() .HaveCount(3) .And.Contain( - new[] - { - new KeyValuePair("prop1", "something"), - new KeyValuePair("prop2", 15L), - new KeyValuePair("prop3", true) - }); + new KeyValuePair("prop1", "something"), + new KeyValuePair("prop2", 15L), + new KeyValuePair("prop3", true)); value.Should().BeOfType().Which.ElementId.Should().Be("1"); } @@ -89,6 +86,7 @@ public void ShouldDeserializeSpan() { "prop2", 15 }, { "prop3", true } }); + writer.Write("1"); var readerMachine = CreateSpanReader(writerMachine.GetOutput()); @@ -96,4 +94,4 @@ public void ShouldDeserializeSpan() Validate(value); } -} \ No newline at end of file +} diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/ElementPathSerializerTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/ElementPathSerializerTests.cs index 89241af1e..8d7a08f7d 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/ElementPathSerializerTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/ElementPathSerializerTests.cs @@ -171,7 +171,6 @@ private static void ValidateAdding(object value) relationships[0].EndNodeElementId.Should().Be("2"); } - private static void ValidatePath(AndWhichConstraint path) { path.Which.Nodes.Should().AllBeOfType(); diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/ElementRelationshipSerializerTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/ElementRelationshipSerializerTests.cs index 71dd92598..dd5bf606b 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/ElementRelationshipSerializerTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/ElementRelationshipSerializerTests.cs @@ -93,14 +93,10 @@ private static void Validate(object value) .BeOfType() .Which.Properties.Should() .HaveCount(1) - .And.Contain( - new[] - { - new KeyValuePair("prop3", true) - }); + .And.Contain(new KeyValuePair("prop3", true)); value.Should().BeOfType().Which.ElementId.Should().Be("r1"); value.Should().BeOfType().Which.StartNodeElementId.Should().Be("n1"); value.Should().BeOfType().Which.EndNodeElementId.Should().Be("n2"); } -} \ No newline at end of file +} diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/ElementUnboundRelationshipSerializerTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/ElementUnboundRelationshipSerializerTests.cs index 527d3dd79..3b18fca1c 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/ElementUnboundRelationshipSerializerTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/ElementUnboundRelationshipSerializerTests.cs @@ -42,6 +42,7 @@ public void ShouldDeserialize() { { "prop3", true } }); + writer.Write("r1"); var readerMachine = CreateReaderMachine(writerMachine.GetOutput()); @@ -64,6 +65,7 @@ public void ShouldDeserializeSpan() { { "prop3", true } }); + writer.Write("r1"); var readerMachine = CreateSpanReader(writerMachine.GetOutput()); @@ -83,11 +85,7 @@ private static void Validate(object value) .BeOfType() .Which.Properties.Should() .HaveCount(1) - .And.Contain( - new[] - { - new KeyValuePair("prop3", true) - }); + .And.Contain(new KeyValuePair("prop3", true)); value.Should().BeOfType().Which.ElementId.Should().Be("r1"); value.Should().BeOfType().Which.StartNodeElementId.Should().Be("-1"); diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/NodeSerializerTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/NodeSerializerTests.cs index 92a1d04a8..0957da3d1 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/NodeSerializerTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/NodeSerializerTests.cs @@ -109,14 +109,11 @@ private static void VerifySerializedNode(object value) .Which.Properties.Should() .HaveCount(3) .And.Contain( - new[] - { - new KeyValuePair("prop1", "something"), - new KeyValuePair("prop2", 15L), - new KeyValuePair("prop3", true) - }); + new KeyValuePair("prop1", "something"), + new KeyValuePair("prop2", 15L), + new KeyValuePair("prop3", true)); } - + [Fact] public void ShouldDeserializeSpan() { diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/PathSerializerTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/PathSerializerTests.cs index 35a8955ad..12e896ff6 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/PathSerializerTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/PathSerializerTests.cs @@ -59,7 +59,7 @@ public void ShouldDeserializeSpan() VerifySerializedPath(value); } - + [Fact] public void ShouldDeserializeReverse() { @@ -84,7 +84,7 @@ public void ShouldDeserializeSpanReverse() var reader = CreateSpanReader(writerMachine.GetOutput()); var value = reader.Read(); - + VerifySerializedPathReverse(value); } @@ -123,7 +123,7 @@ public void ShouldDeserializeSpanWhenInList() VerifySerializedPath(value.Should().BeAssignableTo().Which[0]); } - + [Fact] public void ShouldDeserializeWhenInMap() { @@ -171,7 +171,7 @@ public void ShouldDeserializeSpanWhenInMap() VerifySerializedPath(value.Should().BeAssignableTo().Which["x"]); } - + private static void SerializePath(PackStreamWriter writer, bool reverse = false) { writer.WriteStructHeader(3, PathSerializer.Path); diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/PointSerializerTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/PointSerializerTests.cs index 683ab1b18..0f5afb53e 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/PointSerializerTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/PointSerializerTests.cs @@ -117,7 +117,6 @@ public void ShouldDeserializeSpanPoint2D() ValidatePoint2D(value); } - [Fact] public void ShouldDeserializeSpanPoint3D() { @@ -144,7 +143,7 @@ private static void ValidatePoint2D(object value) value.Should().BeOfType().Which.Y.Should().Be(-0.105658); value.Should().BeOfType().Which.Z.Should().Be(double.NaN); } - + private static void ValidatePoint3D(object value) { value.Should().NotBeNull(); @@ -153,4 +152,4 @@ private static void ValidatePoint3D(object value) value.Should().BeOfType().Which.Y.Should().Be(-0.105658); value.Should().BeOfType().Which.Z.Should().Be(35.25); } -} \ No newline at end of file +} diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/RelationshipSerializerTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/RelationshipSerializerTests.cs index 0299fe824..19b74e376 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/RelationshipSerializerTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/RelationshipSerializerTests.cs @@ -140,7 +140,7 @@ public void ShouldDeserializeSpanWhenInMap() VerifySerializedRelationship(value.Should().BeAssignableTo().Which["x"]); } - + private static void SerializeRelationship(PackStreamWriter writer) { writer.WriteStructHeader(5, RelationshipSerializer.Relationship); @@ -169,11 +169,8 @@ private static void VerifySerializedRelationship(object value) .Which.Properties.Should() .HaveCount(3) .And.Contain( - new[] - { - new KeyValuePair("prop1", "something"), - new KeyValuePair("prop2", 2.0), - new KeyValuePair("prop3", false) - }); + new KeyValuePair("prop1", "something"), + new KeyValuePair("prop2", 2.0), + new KeyValuePair("prop3", false)); } } diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/Temporal/DurationSerializerTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/Temporal/DurationSerializerTests.cs index 41e0f3f0a..0227c9d95 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/Temporal/DurationSerializerTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/Temporal/DurationSerializerTests.cs @@ -89,4 +89,4 @@ private static void Validate(object value) value.Should().BeOfType().Which.Seconds.Should().Be(564L); value.Should().BeOfType().Which.Nanos.Should().Be(865); } -} \ No newline at end of file +} diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/Temporal/LocalDateTimeSerializerTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/Temporal/LocalDateTimeSerializerTests.cs index 5c8d72e2f..c99060fd5 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/Temporal/LocalDateTimeSerializerTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/Temporal/LocalDateTimeSerializerTests.cs @@ -89,4 +89,4 @@ public void ShouldDeserializeSpanDateTime() value.Should().BeOfType().Which.Second.Should().Be(59); value.Should().BeOfType().Which.Nanosecond.Should().Be(128000987); } -} \ No newline at end of file +} diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/Temporal/OffsetTimeSerializerTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/Temporal/OffsetTimeSerializerTests.cs index ae01e4017..0f0fa8f4c 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/Temporal/OffsetTimeSerializerTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/Temporal/OffsetTimeSerializerTests.cs @@ -89,5 +89,4 @@ private static void Validate(object value) .Which.OffsetSeconds.Should() .Be((int)TimeSpan.FromMinutes(150).TotalSeconds); } - } diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/Temporal/SystemDateTimeSerializerTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/Temporal/SystemDateTimeSerializerTests.cs index 1888bed53..2eb3948d4 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/Temporal/SystemDateTimeSerializerTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/Temporal/SystemDateTimeSerializerTests.cs @@ -88,4 +88,4 @@ public void ShouldSerializeDateTimeUtc() reader.Read().Should().Be(999000000L); reader.Read().Should().Be(0L); } -} \ No newline at end of file +} diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/UnboundRelationshipSerializerTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/UnboundRelationshipSerializerTests.cs index 3790c4b0d..f90e703c7 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/UnboundRelationshipSerializerTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/IO/ValueSerializers/UnboundRelationshipSerializerTests.cs @@ -119,7 +119,8 @@ public void ShouldDeserializeSpanWhenInList() var value = reader.Read(); value.Should().NotBeNull(); - value.Should().BeAssignableTo().Which.Count.Should().Be(1);; + value.Should().BeAssignableTo().Which.Count.Should().Be(1); + ; VerifySerializedUnboundRelationship(value.Should().BeAssignableTo().Which[0]); } @@ -147,7 +148,7 @@ public void ShouldDeserializeSpanWhenInMap() VerifySerializedUnboundRelationship(value.Should().BeAssignableTo().Which["x"]); } - + private static void SerializeUnboundRelationship(PackStreamWriter writer) { writer.WriteStructHeader(3, UnboundRelationshipSerializer.UnboundRelationship); @@ -174,11 +175,8 @@ private static void VerifySerializedUnboundRelationship(object value) .Which.Properties.Should() .HaveCount(3) .And.Contain( - new[] - { - new KeyValuePair("prop1", "something"), - new KeyValuePair("prop2", 2.0), - new KeyValuePair("prop3", false) - }); + new KeyValuePair("prop1", "something"), + new KeyValuePair("prop2", 2.0), + new KeyValuePair("prop3", false)); } } diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/MessageHandling/InMemoryPipelinedMessageReaderTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/MessageHandling/InMemoryPipelinedMessageReaderTests.cs index e1e9025f5..9a916b298 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/MessageHandling/InMemoryPipelinedMessageReaderTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/MessageHandling/InMemoryPipelinedMessageReaderTests.cs @@ -1,7 +1,5 @@ // Copyright (c) "Neo4j" -// Neo4j Sweden AB [http://neo4j.com] -// -// This file is part of Neo4j. +// Neo4j Sweden AB [https://neo4j.com] // // Licensed under the Apache License, Version 2.0 (the "License"). // You may not use this file except in compliance with the License. @@ -62,8 +60,11 @@ public async Task ShouldReadMessage() var pipereader = new PipelinedMessageReader(memoryStream, TestDriverContext.MockContext, -1); var pipeline = MockPipeline(); - await pipereader.ReadAsync(pipeline.Object, new MessageFormat(BoltProtocolVersion.V5_0, - TestDriverContext.MockContext)); + await pipereader.ReadAsync( + pipeline.Object, + new MessageFormat( + BoltProtocolVersion.V5_0, + TestDriverContext.MockContext)); pipeline.Verify(x => x.OnSuccess(It.IsAny>()), Times.Once); } @@ -86,8 +87,11 @@ public async Task ShouldReadMultiChunkMessage() memoryStream.Position = 0L; var pipereader = new PipelinedMessageReader(memoryStream, TestDriverContext.MockContext, -1); var pipeline = MockPipeline(); - await pipereader.ReadAsync(pipeline.Object, new MessageFormat(BoltProtocolVersion.V5_0, - TestDriverContext.MockContext)); + await pipereader.ReadAsync( + pipeline.Object, + new MessageFormat( + BoltProtocolVersion.V5_0, + TestDriverContext.MockContext)); pipeline.Verify(x => x.OnSuccess(It.IsAny>()), Times.Once); } @@ -111,8 +115,11 @@ public async Task ShouldIgnoreNoOpChunk() memoryStream.Position = 0L; var pipereader = new PipelinedMessageReader(memoryStream, TestDriverContext.MockContext, -1); var pipeline = MockPipeline(); - await pipereader.ReadAsync(pipeline.Object, new MessageFormat(BoltProtocolVersion.V5_0, - TestDriverContext.MockContext)); + await pipereader.ReadAsync( + pipeline.Object, + new MessageFormat( + BoltProtocolVersion.V5_0, + TestDriverContext.MockContext)); pipeline.Verify(x => x.OnSuccess(It.IsAny>()), Times.Once); } @@ -144,8 +151,11 @@ public async Task ShouldIgnoreAllNoOpChunks() memoryStream.Position = 0L; var pipereader = new PipelinedMessageReader(memoryStream, TestDriverContext.MockContext, -1); var pipeline = MockPipeline(); - await pipereader.ReadAsync(pipeline.Object, new MessageFormat(BoltProtocolVersion.V5_0, - TestDriverContext.MockContext)); + await pipereader.ReadAsync( + pipeline.Object, + new MessageFormat( + BoltProtocolVersion.V5_0, + TestDriverContext.MockContext)); pipeline.Verify(x => x.OnSuccess(It.IsAny>()), Times.Once); } @@ -163,7 +173,7 @@ public async Task ShouldStopReadAllMessagesAfterAFailure() // 5 bytes 0x00, 0x00, 0x00, 0x00, // 9 bytes - PackStream.String8, 1, Encoding.UTF8.GetBytes("a")[0], PackStream.String8, 7, + PackStream.String8, 1, Encoding.UTF8.GetBytes("a")[0], PackStream.String8, 7, // 14 bytes 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 21 bytes @@ -175,14 +185,19 @@ public async Task ShouldStopReadAllMessagesAfterAFailure() PackStream.TinyStruct, MessageFormat.MsgIgnored, 0x00, 0x00 }; + Encoding.UTF8.GetBytes("code").CopyTo(message.AsSpan().Slice(2 + 5)); Encoding.UTF8.GetBytes("message").CopyTo(message.AsSpan().Slice(2 + 14)); - + var memoryStream = new MemoryStream(message); var pipereader = new PipelinedMessageReader(memoryStream, TestDriverContext.MockContext, -1); var pipeline = MockPipeline(); - await pipereader.ReadAsync(pipeline.Object, new MessageFormat(BoltProtocolVersion.V5_0, - TestDriverContext.MockContext)); + await pipereader.ReadAsync( + pipeline.Object, + new MessageFormat( + BoltProtocolVersion.V5_0, + TestDriverContext.MockContext)); + pipeline.Verify(x => x.OnFailure(It.IsAny()), Times.Once); pipeline.Verify(x => x.OnIgnored(), Times.Never); } @@ -195,8 +210,11 @@ public async Task ShouldReadLargeMessages() var pipereader = new PipelinedMessageReader(memoryStream, TestDriverContext.MockContext, -1); var pipeline = MockPipeline(); - await pipereader.ReadAsync(pipeline.Object, new MessageFormat(BoltProtocolVersion.V5_0, - TestDriverContext.MockContext)); + await pipereader.ReadAsync( + pipeline.Object, + new MessageFormat( + BoltProtocolVersion.V5_0, + TestDriverContext.MockContext)); pipeline.Verify( x => x.OnSuccess(It.Is>(y => y["a"].As().Length == 500_000)), diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/MessageHandling/Messages/BeginMessageTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/MessageHandling/Messages/BeginMessageTests.cs index 4151adac4..f691477cb 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/MessageHandling/Messages/BeginMessageTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/MessageHandling/Messages/BeginMessageTests.cs @@ -136,9 +136,14 @@ public void ShouldHandleSetValuesWithNotifications(int major, int minor) message.Metadata.Should().ContainKey("tx_metadata").WhoseValue.Should().BeEquivalentTo(txMeta); message.Metadata.Should().ContainKey("mode").WhoseValue.Should().BeEquivalentTo("r"); message.Metadata.Should().ContainKey("db").WhoseValue.Should().BeEquivalentTo("neo4j"); - message.Metadata.Should().ContainKey("notifications_minimum_severity").WhoseValue.Should().BeEquivalentTo("WARNING"); message.Metadata.Should() - .ContainKey("notifications_disabled_categories").WhoseValue + .ContainKey("notifications_minimum_severity") + .WhoseValue.Should() + .BeEquivalentTo("WARNING"); + + message.Metadata.Should() + .ContainKey("notifications_disabled_categories") + .WhoseValue .Should() .BeEquivalentTo(new[] { "GENERIC" }); @@ -175,12 +180,14 @@ public void ShouldHandleSetValuesWithNotificationsClassifications(int major, int message.Metadata.Should().ContainKey("mode").WhoseValue.Should().BeEquivalentTo("r"); message.Metadata.Should().ContainKey("db").WhoseValue.Should().BeEquivalentTo("neo4j"); message.Metadata.Should() - .ContainKey("notifications_minimum_severity").WhoseValue + .ContainKey("notifications_minimum_severity") + .WhoseValue .Should() .BeEquivalentTo("WARNING"); message.Metadata.Should() - .ContainKey("notifications_disabled_classifications").WhoseValue + .ContainKey("notifications_disabled_classifications") + .WhoseValue .Should() .BeEquivalentTo(new[] { "GENERIC" }); @@ -189,7 +196,7 @@ public void ShouldHandleSetValuesWithNotificationsClassifications(int major, int .Be( "BEGIN [{bookmarks, [bm:a]}, {tx_timeout, 1000}, {tx_metadata, [{a, b}]}, {mode, r}, {db, neo4j}, {imp_user, Douglas Fir}, {notifications_minimum_severity, WARNING}, {notifications_disabled_classifications, [GENERIC]}]"); } - + [Fact] public void ShouldThrowIfBoltVersionLessThan44() { @@ -213,7 +220,6 @@ public void ShouldThrowIfBoltVersionLessThan44() .BeOfType(); } - [Theory] [InlineData(5, 2)] [InlineData(5, 3)] diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/MessageHandling/Messages/DiscardMessageTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/MessageHandling/Messages/DiscardMessageTests.cs index c3f4dcae3..4126f113d 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/MessageHandling/Messages/DiscardMessageTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/MessageHandling/Messages/DiscardMessageTests.cs @@ -42,4 +42,4 @@ public void ShouldHandleValues() var message = new DiscardMessage(42, 10); message.ToString().Should().Be("DISCARD [{n, 10}, {qid, 42}]"); } -} \ No newline at end of file +} diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/MessageHandling/Messages/HelloMessageTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/MessageHandling/Messages/HelloMessageTests.cs index 6002501fb..b56546c14 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/MessageHandling/Messages/HelloMessageTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/MessageHandling/Messages/HelloMessageTests.cs @@ -178,12 +178,14 @@ public void ShouldAddNotificationsCategories(int major, int minor) cfg); helloMessage.Metadata.Should() - .ContainKey("notifications_disabled_categories").WhoseValue + .ContainKey("notifications_disabled_categories") + .WhoseValue .Should() .BeEquivalentTo(new[] { "HINT" }); helloMessage.Metadata.Should() - .ContainKey("notifications_minimum_severity").WhoseValue + .ContainKey("notifications_minimum_severity") + .WhoseValue .Should() .Be("INFORMATION"); } @@ -202,12 +204,14 @@ public void ShouldAddNotificationsClassifications(int major, int minor) cfg); helloMessage.Metadata.Should() - .ContainKey("notifications_disabled_classifications").WhoseValue + .ContainKey("notifications_disabled_classifications") + .WhoseValue .Should() .BeEquivalentTo(new[] { "HINT" }); helloMessage.Metadata.Should() - .ContainKey("notifications_minimum_severity").WhoseValue + .ContainKey("notifications_minimum_severity") + .WhoseValue .Should() .Be("INFORMATION"); } diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/MessageHandling/Messages/RunWithMetaDataMessageTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/MessageHandling/Messages/RunWithMetaDataMessageTests.cs index c0834e6a5..83e186af2 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/MessageHandling/Messages/RunWithMetaDataMessageTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/MessageHandling/Messages/RunWithMetaDataMessageTests.cs @@ -53,6 +53,7 @@ public void ShouldIncludeImpersonatedUserKeyWithBoltVersionGreaterThan44(int maj new BoltProtocolVersion(major, minor), null, sessionConfig: new SessionConfig("jeff")); + rm.Query.Should().BeNull(); rm.Metadata.Should().ContainKey("imp_user").WhoseValue.Should().Be("jeff"); @@ -81,7 +82,8 @@ public void ShouldIncludeValues() rm.Metadata.Should().ContainKey("bookmarks").WhoseValue.Should().BeEquivalentTo(new[] { "bm:a" }); rm.Metadata.Should().ContainKey("tx_timeout").WhoseValue.Should().Be(1000L); rm.Metadata.Should() - .ContainKey("tx_metadata").WhoseValue + .ContainKey("tx_metadata") + .WhoseValue .Should() .BeEquivalentTo(new Dictionary { ["a"] = "b" }); @@ -95,7 +97,6 @@ public void ShouldIncludeValues() "RUN `...`, [] [{bookmarks, [bm:a]}, {tx_timeout, 1000}, {tx_metadata, [{a, b}]}, {mode, r}, {db, neo4j}, {imp_user, jeff}]"); } - [Theory] [InlineData(5, 2)] [InlineData(5, 3)] @@ -109,12 +110,14 @@ public void ShouldAddNotificationsCategories(int major, int minor) notificationsConfig: cfg); runMessage.Metadata.Should() - .ContainKey("notifications_disabled_categories").WhoseValue + .ContainKey("notifications_disabled_categories") + .WhoseValue .Should() .BeEquivalentTo(new[] { "HINT" }); runMessage.Metadata.Should() - .ContainKey("notifications_minimum_severity").WhoseValue + .ContainKey("notifications_minimum_severity") + .WhoseValue .Should() .Be("INFORMATION"); } @@ -132,12 +135,14 @@ public void ShouldAddNotificationsClassifications(int major, int minor) notificationsConfig: cfg); runMessage.Metadata.Should() - .ContainKey("notifications_disabled_classifications").WhoseValue + .ContainKey("notifications_disabled_classifications") + .WhoseValue .Should() .BeEquivalentTo(new[] { "HINT" }); runMessage.Metadata.Should() - .ContainKey("notifications_minimum_severity").WhoseValue + .ContainKey("notifications_minimum_severity") + .WhoseValue .Should() .Be("INFORMATION"); } diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/MessageHandling/Metadata/GqlStatusObjectsAndNotificationsCollectorTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/MessageHandling/Metadata/GqlStatusObjectsAndNotificationsCollectorTests.cs index faeb3c7c6..00b1bc4d4 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/MessageHandling/Metadata/GqlStatusObjectsAndNotificationsCollectorTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/MessageHandling/Metadata/GqlStatusObjectsAndNotificationsCollectorTests.cs @@ -1,4 +1,19 @@ -#pragma warning disable CS0618 // Type or member is obsolete +// Copyright (c) "Neo4j" +// Neo4j Sweden AB [https://neo4j.com] +// +// Licensed under the Apache License, Version 2.0 (the "License"). +// You may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma warning disable CS0618 // Type or member is obsolete // Copyright (c) "Neo4j" // Neo4j Sweden AB [https://neo4j.com] // @@ -123,6 +138,7 @@ public void ShouldCollectGqlStatuses() ["column"] = 3L } }; + first.GqlStatus.Should().Be("000000"); first.StatusDescription.Should().Be("it is a status"); first.Position.Should().Be(new InputPosition(1, 2, 3)); @@ -136,7 +152,7 @@ public void ShouldCollectGqlStatuses() first.Title.Should().Be("blah"); }); } - + [Fact] public void ShouldCollectMinimalGqlStatuses() { @@ -165,8 +181,9 @@ public void ShouldCollectMinimalGqlStatuses() { ["CURRENT_SCHEMA"] = "/", ["OPERATION"] = "", - ["OPERATION_CODE"] = "0", + ["OPERATION_CODE"] = "0" }; + first.GqlStatus.Should().Be("030000"); first.StatusDescription.Should().Be("it is a status"); first.Position.Should().BeNull(); @@ -196,8 +213,8 @@ public void ShouldMergeDiagnosticRecord() ["diagnostic_record"] = new Dictionary { ["Example"] = "blah-de-blah", - ["OPERATION"] = "OP!", - }, + ["OPERATION"] = "OP!" + } } } }); @@ -214,13 +231,13 @@ public void ShouldMergeDiagnosticRecord() ["Example"] = "blah-de-blah", ["CURRENT_SCHEMA"] = "/", ["OPERATION"] = "OP!", - ["OPERATION_CODE"] = "0", + ["OPERATION_CODE"] = "0" }; first.DiagnosticRecord.Should().BeEquivalentTo(dict); }); } - + [Fact] public void ShouldPolyfilGqlStatusesIntoNotifications() { @@ -366,9 +383,7 @@ public void ShouldCollectMinimalNotification() { ["notifications"] = new List { - new Dictionary - { - } + new Dictionary() } }); @@ -413,8 +428,9 @@ public void ShouldUpgradeMinimalNotificationToGqlStatus() { ["CURRENT_SCHEMA"] = "/", ["OPERATION"] = "", - ["OPERATION_CODE"] = "0", + ["OPERATION_CODE"] = "0" }; + var first = x.Should().BeOfType().Which; first.GqlStatus.Should().Be("03N42"); first.Title.Should().BeNull(); @@ -462,16 +478,17 @@ public void ShouldUpgradeNotificationToGqlStatus() var dict = new Dictionary { ["_severity"] = "WARNING", - ["_position"] = new Dictionary - { - ["offset"] = 1L, - ["line"] = 2L, - ["column"] = 3L - }, + ["_position"] = new Dictionary + { + ["offset"] = 1L, + ["line"] = 2L, + ["column"] = 3L + }, ["CURRENT_SCHEMA"] = "/", ["OPERATION"] = "", - ["OPERATION_CODE"] = "0", + ["OPERATION_CODE"] = "0" }; + var first = x.Should().BeOfType().Which; first.GqlStatus.Should().Be("01N42"); first.Title.Should().Be("blah"); @@ -484,7 +501,7 @@ public void ShouldUpgradeNotificationToGqlStatus() first.DiagnosticRecord.Should().BeEquivalentTo(dict); }); } - + [Fact] public void ShouldNotPolyfilWhenProvidedGqlStatus() { diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/MessageHandling/Metadata/GqlStatusObjectsAndNotificationsTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/MessageHandling/Metadata/GqlStatusObjectsAndNotificationsTests.cs index 6ed69f0e5..536386325 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/MessageHandling/Metadata/GqlStatusObjectsAndNotificationsTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/MessageHandling/Metadata/GqlStatusObjectsAndNotificationsTests.cs @@ -57,7 +57,7 @@ public void FinalizeStatusObjectsShouldPolyfil(bool hadRecords, bool hadKeys, IG { ["CURRENT_SCHEMA"] = "/", ["OPERATION"] = "", - ["OPERATION_CODE"] = "0", + ["OPERATION_CODE"] = "0" }; first.GqlStatus.Should().Be(exp.GqlStatus); @@ -87,16 +87,16 @@ public void ShouldOrderByCodeWhenPolyfilling() { ["CURRENT_SCHEMA"] = "/", ["OPERATION"] = "", - ["OPERATION_CODE"] = "0", + ["OPERATION_CODE"] = "0" }; - var statuses = new List() + var statuses = new List { new GqlStatusObject("04-", "", null, null, null, dict, null, false), new GqlStatusObject("01-", "", null, null, null, dict, null, false), new GqlStatusObject("03-", "", null, null, null, dict, null, false), new GqlStatusObject("02-", "", null, null, null, dict, null, false), - new GqlStatusObject("1", "", null, null, null, dict, null, false), + new GqlStatusObject("1", "", null, null, null, dict, null, false) }; var objs = new GqlStatusObjectsAndNotifications(null, statuses, false); diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/MessageHandling/NetworkedPipelinedMessageReaderTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/MessageHandling/NetworkedPipelinedMessageReaderTests.cs index 8657f1c8c..59a38ee12 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/MessageHandling/NetworkedPipelinedMessageReaderTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/MessageHandling/NetworkedPipelinedMessageReaderTests.cs @@ -1,7 +1,5 @@ // Copyright (c) "Neo4j" -// Neo4j Sweden AB [http://neo4j.com] -// -// This file is part of Neo4j. +// Neo4j Sweden AB [https://neo4j.com] // // Licensed under the Apache License, Version 2.0 (the "License"). // You may not use this file except in compliance with the License. @@ -32,70 +30,71 @@ namespace Neo4j.Driver.Tests.Internal.MessageHandling; /// /// These are close to integration tests as they used tcp, but they are not integration tests as they do not -/// integrate against another process. +/// integrate against another process. /// public class NetworkedPipelinedMessageReaderTests { - const int Port = 9111; - + private const int Port = 9111; + [Fact] public async Task ShouldReadSimpleMessage() { var pipeline = MockPipeline(); using var cts = new CancellationTokenSource(5000); - + await Task.WhenAll( - Task.Run(async () => - { - var tcp = new TcpListener(IPAddress.Loopback, Port); - TcpClient stream = null; - try + Task.Run( + async () => { - tcp.Start(); - stream = await tcp.AcceptTcpClientAsync(cts.Token); - stream.GetStream() - .Write( - new byte[] - { - 0x00, 0x03, - PackStream.TinyStruct, MessageFormat.MsgSuccess, PackStream.TinyMap, - 0x00, 0x00 - }.AsSpan()); - + var tcp = new TcpListener(IPAddress.Loopback, Port); + TcpClient stream = null; try { - await Task.Delay(1000, cts.Token); + tcp.Start(); + stream = await tcp.AcceptTcpClientAsync(cts.Token); + stream.GetStream() + .Write( + new byte[] + { + 0x00, 0x03, + PackStream.TinyStruct, MessageFormat.MsgSuccess, PackStream.TinyMap, + 0x00, 0x00 + }.AsSpan()); + + try + { + await Task.Delay(1000, cts.Token); + } + catch (OperationCanceledException) + { + } } - catch (OperationCanceledException) + finally { + stream?.Close(); + tcp.Stop(); } - } - finally - { - stream?.Close(); - tcp.Stop(); - } - }), - Task.Run(async () => - { - await Task.Delay(100); - var client = new TcpClient(); - try + }), + Task.Run( + async () => { - await client.ConnectAsync(IPAddress.Loopback, Port, cts.Token); - var pipereader = new PipelinedMessageReader(client.GetStream(), TestDriverContext.MockContext); - await pipereader.ReadAsync( - pipeline.Object, - new MessageFormat(BoltProtocolVersion.V5_0, TestDriverContext.MockContext)); - } - finally - { - client.Close(); - cts.Cancel(); + await Task.Delay(100); + var client = new TcpClient(); + try + { + await client.ConnectAsync(IPAddress.Loopback, Port, cts.Token); + var pipereader = new PipelinedMessageReader(client.GetStream(), TestDriverContext.MockContext); + await pipereader.ReadAsync( + pipeline.Object, + new MessageFormat(BoltProtocolVersion.V5_0, TestDriverContext.MockContext)); + } + finally + { + client.Close(); + cts.Cancel(); + } + })); - } - })); - pipeline.Verify(x => x.OnSuccess(It.IsAny>()), Times.Once); } @@ -104,286 +103,289 @@ public async Task ShouldTimeoutWaitingForSize() { var pipeline = MockPipeline(); using var cts = new CancellationTokenSource(5000); - + await Task.WhenAll( - Task.Run(async () => - { - var tcp = new TcpListener(IPAddress.Loopback, Port); - TcpClient stream = null; - try + Task.Run( + async () => { - tcp.Start(); - stream = await tcp.AcceptTcpClientAsync(cts.Token); - stream.GetStream() - .Write( - new byte[] - { - 0x00 - }.AsSpan()); + var tcp = new TcpListener(IPAddress.Loopback, Port); + TcpClient stream = null; try { - await Task.Delay(-1, cts.Token); + tcp.Start(); + stream = await tcp.AcceptTcpClientAsync(cts.Token); + stream.GetStream() + .Write( + new byte[] + { + 0x00 + }.AsSpan()); + + try + { + await Task.Delay(-1, cts.Token); + } + catch (OperationCanceledException) + { + } } - catch (OperationCanceledException) + finally { + stream?.Close(); + tcp.Stop(); } - } - finally + }), + Task.Run( + async () => { - stream?.Close(); - tcp.Stop(); - } - }), - Task.Run(async () => - { - - await Task.Delay(100); - var client = new TcpClient(); - try - { - await client.ConnectAsync(IPAddress.Loopback, Port, cts.Token); - var pipereader = new PipelinedMessageReader(client.GetStream(), TestDriverContext.MockContext); - pipereader.SetReadTimeoutInMs(250); - var exc = await Record.ExceptionAsync( - async () => - { - await pipereader.ReadAsync( - pipeline.Object, - new MessageFormat(BoltProtocolVersion.V5_0, TestDriverContext.MockContext)); - }); - - exc.Should().BeOfType(); - } - finally - { - client.Close(); - cts.Cancel(); + await Task.Delay(100); + var client = new TcpClient(); + try + { + await client.ConnectAsync(IPAddress.Loopback, Port, cts.Token); + var pipereader = new PipelinedMessageReader(client.GetStream(), TestDriverContext.MockContext); + pipereader.SetReadTimeoutInMs(250); + var exc = await Record.ExceptionAsync( + async () => + { + await pipereader.ReadAsync( + pipeline.Object, + new MessageFormat(BoltProtocolVersion.V5_0, TestDriverContext.MockContext)); + }); + + exc.Should().BeOfType(); + } + finally + { + client.Close(); + cts.Cancel(); + } + })); - } - })); - pipeline.Verify(x => x.OnSuccess(It.IsAny>()), Times.Never); } - + [Fact] public async Task ShouldReadSimpleMessageWithDelays() { var pipeline = MockPipeline(); using var cts = new CancellationTokenSource(5000); - + await Task.WhenAll( - Task.Run(async () => - { - var tcp = new TcpListener(IPAddress.Loopback, Port); - TcpClient stream = null; - try + Task.Run( + async () => { - tcp.Start(); - stream = await tcp.AcceptTcpClientAsync(cts.Token); - stream.GetStream() - .Write( - new byte[] - { - 0x00 - }.AsSpan()); + var tcp = new TcpListener(IPAddress.Loopback, Port); + TcpClient stream = null; + try + { + tcp.Start(); + stream = await tcp.AcceptTcpClientAsync(cts.Token); + stream.GetStream() + .Write( + new byte[] + { + 0x00 + }.AsSpan()); - await Task.Delay(500); - - stream.GetStream() - .Write( - new byte[] - { - 0x03, - PackStream.TinyStruct, MessageFormat.MsgSuccess, PackStream.TinyMap, - }.AsSpan()); + await Task.Delay(500); - await Task.Delay(500); - stream.GetStream() - .Write( - new byte[] - { - 0x00, 0x00 - }.AsSpan()); + stream.GetStream() + .Write( + new byte[] + { + 0x03, + PackStream.TinyStruct, MessageFormat.MsgSuccess, PackStream.TinyMap + }.AsSpan()); + + await Task.Delay(500); + stream.GetStream() + .Write( + new byte[] + { + 0x00, 0x00 + }.AsSpan()); + + try + { + await Task.Delay(1000, cts.Token); + } + catch (OperationCanceledException) + { + } + } + finally + { + stream?.Close(); + tcp.Stop(); + } + }), + Task.Run( + async () => + { + await Task.Delay(100); + var client = new TcpClient(); try { - await Task.Delay(1000, cts.Token); + await client.ConnectAsync(IPAddress.Loopback, Port, cts.Token); + var pipereader = new PipelinedMessageReader(client.GetStream(), TestDriverContext.MockContext); + pipereader.SetReadTimeoutInMs(1000); + await pipereader.ReadAsync( + pipeline.Object, + new MessageFormat(BoltProtocolVersion.V5_0, TestDriverContext.MockContext)); } - catch (OperationCanceledException) + finally { + client.Close(); + cts.Cancel(); } - } - finally - { - stream?.Close(); - tcp.Stop(); - } - }), - Task.Run(async () => - { - await Task.Delay(100); - var client = new TcpClient(); - try - { - await client.ConnectAsync(IPAddress.Loopback, Port, cts.Token); - var pipereader = new PipelinedMessageReader(client.GetStream(), TestDriverContext.MockContext); - pipereader.SetReadTimeoutInMs(1000); - await pipereader.ReadAsync( - pipeline.Object, - new MessageFormat(BoltProtocolVersion.V5_0, TestDriverContext.MockContext)); - } - finally - { - client.Close(); - cts.Cancel(); + })); - } - })); - pipeline.Verify(x => x.OnSuccess(It.IsAny>()), Times.Once); } - + [Fact] public async Task ShouldTimeoutWaitingAfterSize() { var pipeline = MockPipeline(); using var cts = new CancellationTokenSource(5000); - + await Task.WhenAll( - Task.Run(async () => - { - var tcp = new TcpListener(IPAddress.Loopback, Port); - TcpClient stream = null; - try + Task.Run( + async () => { - tcp.Start(); - stream = await tcp.AcceptTcpClientAsync(cts.Token); - stream.GetStream() - .Write( - new byte[] - { - 0x00,0x03 - }.AsSpan()); - + var tcp = new TcpListener(IPAddress.Loopback, Port); + TcpClient stream = null; try { - await Task.Delay(-1, cts.Token); + tcp.Start(); + stream = await tcp.AcceptTcpClientAsync(cts.Token); + stream.GetStream() + .Write( + new byte[] + { + 0x00, 0x03 + }.AsSpan()); + + try + { + await Task.Delay(-1, cts.Token); + } + catch (OperationCanceledException) + { + } } - catch (OperationCanceledException) + finally { + stream?.Close(); + tcp.Stop(); } - } - finally - { - stream?.Close(); - tcp.Stop(); - } - }), - Task.Run(async () => - { - - await Task.Delay(100); - var client = new TcpClient(); - try + }), + Task.Run( + async () => { - await client.ConnectAsync(IPAddress.Loopback, Port, cts.Token); - var pipereader = new PipelinedMessageReader(client.GetStream(), TestDriverContext.MockContext); - pipereader.SetReadTimeoutInMs(2000); - var exc = await Record.ExceptionAsync( - async () => - { - await pipereader.ReadAsync( - pipeline.Object, - new MessageFormat(BoltProtocolVersion.V5_0, TestDriverContext.MockContext)); - }); - - exc.Should().BeOfType(); - } - finally - { - client.Close(); - cts.Cancel(); + await Task.Delay(100); + var client = new TcpClient(); + try + { + await client.ConnectAsync(IPAddress.Loopback, Port, cts.Token); + var pipereader = new PipelinedMessageReader(client.GetStream(), TestDriverContext.MockContext); + pipereader.SetReadTimeoutInMs(2000); + var exc = await Record.ExceptionAsync( + async () => + { + await pipereader.ReadAsync( + pipeline.Object, + new MessageFormat(BoltProtocolVersion.V5_0, TestDriverContext.MockContext)); + }); + + exc.Should().BeOfType(); + } + finally + { + client.Close(); + cts.Cancel(); + } + })); - } - })); - pipeline.Verify(x => x.OnSuccess(It.IsAny>()), Times.Never); } - + [Fact] public async Task ShouldTimeoutWaitingForData() { var pipeline = MockPipeline(); using var cts = new CancellationTokenSource(5000); - + await Task.WhenAll( - Task.Run(async () => - { - var tcp = new TcpListener(IPAddress.Loopback, Port); - TcpClient stream = null; - try + Task.Run( + async () => { - tcp.Start(); - stream = await tcp.AcceptTcpClientAsync(cts.Token); - stream.GetStream() - .Write( - new byte[] - { - 0x00,0x03 - }.AsSpan()); - - await Task.Delay(1000); - stream.GetStream() - .Write( - new byte[] - { - 0x00 - }.AsSpan()); - + var tcp = new TcpListener(IPAddress.Loopback, Port); + TcpClient stream = null; try { - await Task.Delay(-1, cts.Token); + tcp.Start(); + stream = await tcp.AcceptTcpClientAsync(cts.Token); + stream.GetStream() + .Write( + new byte[] + { + 0x00, 0x03 + }.AsSpan()); + + await Task.Delay(1000); + stream.GetStream() + .Write( + new byte[] + { + 0x00 + }.AsSpan()); + + try + { + await Task.Delay(-1, cts.Token); + } + catch (OperationCanceledException) + { + } } - catch (OperationCanceledException) + finally { + stream?.Close(); + tcp.Stop(); } - } - finally - { - stream?.Close(); - tcp.Stop(); - } - }), - Task.Run(async () => - { - - await Task.Delay(100); - var client = new TcpClient(); - try + }), + Task.Run( + async () => { - await client.ConnectAsync(IPAddress.Loopback, Port, cts.Token); - var pipereader = new PipelinedMessageReader(client.GetStream(), TestDriverContext.MockContext); - pipereader.SetReadTimeoutInMs(2000); - var exc = await Record.ExceptionAsync( - async () => - { - await pipereader.ReadAsync( - pipeline.Object, - new MessageFormat(BoltProtocolVersion.V5_0, TestDriverContext.MockContext)); - }); - - exc.Should().BeOfType(); - } - finally - { - client.Close(); - cts.Cancel(); + await Task.Delay(100); + var client = new TcpClient(); + try + { + await client.ConnectAsync(IPAddress.Loopback, Port, cts.Token); + var pipereader = new PipelinedMessageReader(client.GetStream(), TestDriverContext.MockContext); + pipereader.SetReadTimeoutInMs(2000); + var exc = await Record.ExceptionAsync( + async () => + { + await pipereader.ReadAsync( + pipeline.Object, + new MessageFormat(BoltProtocolVersion.V5_0, TestDriverContext.MockContext)); + }); + + exc.Should().BeOfType(); + } + finally + { + client.Close(); + cts.Cancel(); + } + })); - } - })); - pipeline.Verify(x => x.OnSuccess(It.IsAny>()), Times.Never); } - + private static Mock MockPipeline() { var done = (object)false; diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/Protocol/BoltProtocolTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/Protocol/BoltProtocolTests.cs index bf50c245d..a652cc31b 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/Protocol/BoltProtocolTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/Protocol/BoltProtocolTests.cs @@ -718,7 +718,8 @@ public async Task ShouldSendPullMessageWhenNotReactive() new PullResponseHandler( resultCursorBuilderMock.Object, new SummaryBuilder(new Query("..."), new ServerInfo(new Uri("http://0.0.0.0"))), - mockBt.Object, true)); + mockBt.Object, + true)); handlerFactory.Setup( x => x.NewResultCursorBuilder( diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/Util/PipeReaderMemoryPoolTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/Util/PipeReaderMemoryPoolTests.cs index 3069466b3..58cc2a2da 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/Util/PipeReaderMemoryPoolTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/Util/PipeReaderMemoryPoolTests.cs @@ -38,7 +38,7 @@ public void ShouldRentMemoryInPower(int size, int expectedSize, int maxReadBuffe using var memoryOwner = pool.Rent(size); memoryOwner.Memory.Length.Should().Be(expectedSize); } - + [Fact] public void ShouldRentMemoryInPowerWithDefaultSize() { @@ -46,7 +46,7 @@ public void ShouldRentMemoryInPowerWithDefaultSize() using var memoryOwner = pool.Rent(); memoryOwner.Memory.Length.Should().Be(1024); } - + [Fact] public void ShouldReusePooledObjects() { @@ -58,17 +58,17 @@ public void ShouldReusePooledObjects() length = memoryOwner.Memory.Length; memoryOwner.Memory.Span[0] = 1; } - + using (var memoryOwner = pool.Rent(4321)) { memoryOwner.Memory.Length.Should().Be(length); memoryOwner.Memory.Span[0].Should().Be(1); } } - + /// - /// This test is to verify the behaviour of the shared pool. - /// It is an unnecessary test but it proves the behaviour to validate + /// This test is to verify the behaviour of the shared pool. It is an unnecessary test but it proves the behaviour + /// to validate /// [Fact] public void SharedPoolShouldReturnSameValue() @@ -97,7 +97,7 @@ public void ShouldNotReturnSharedPoolObjects() memoryOwner.Memory.Length.Should().Be(1024); memoryOwner.Memory.Span[0] = 1; } - + pool = new PipeReaderMemoryPool(1024, 2048); using (var memoryOwner = pool.Rent(1024)) { @@ -110,7 +110,7 @@ public void ShouldNotReturnSharedPoolObjects() public void CanBorrowMaxLengthArray() { var pool = new PipeReaderMemoryPool(1024, Constants.MaxReadBufferSize); - + // 2146435071 is the max length of an array in .NET using (var memoryOwner = pool.Rent(2146435071)) { diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/Util/TransactionTimeoutTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/Util/TransactionTimeoutTests.cs index e6d6f26bc..c06dc7dad 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Internal/Util/TransactionTimeoutTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Internal/Util/TransactionTimeoutTests.cs @@ -1,14 +1,12 @@ // Copyright (c) "Neo4j" -// Neo4j Sweden AB [http://neo4j.com] -// -// This file is part of Neo4j. -// +// Neo4j Sweden AB [https://neo4j.com] +// // Licensed under the Apache License, Version 2.0 (the "License"). // You may not use this file except in compliance with the License. // You may obtain a copy of the License at -// +// // http://www.apache.org/licenses/LICENSE-2.0 -// +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/AsyncEnumerableExtensionsTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/AsyncEnumerableExtensionsTests.cs index 536c69cb8..de11c57dd 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/AsyncEnumerableExtensionsTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/AsyncEnumerableExtensionsTests.cs @@ -71,8 +71,10 @@ async IAsyncEnumerable GetRecordsAsync() var result = await GetRecordsAsync().ToListAsync((string name, int age) => new { name, age }); result.Should() .BeEquivalentTo( - [new { name = "Alice", age = 25 }, - new { name = "Bob", age = 30 }]); + [ + new { name = "Alice", age = 25 }, + new { name = "Bob", age = 30 } + ]); } [Fact] @@ -96,9 +98,11 @@ async IAsyncEnumerable GetRecordsAsync() .ToListAsync((string name, int age, string city) => new { name, age, city }); result.Should() - .BeEquivalentTo([ + .BeEquivalentTo( + [ new { name = "Alice", age = 25, city = "New York" }, - new { name = "Bob", age = 30, city = "Los Angeles" }]); + new { name = "Bob", age = 30, city = "Los Angeles" } + ]); } [Fact] @@ -122,9 +126,11 @@ async IAsyncEnumerable GetRecordsAsync() .ToListAsync((string name, int age, string city, string country) => new { name, age, city, country }); result.Should() - .BeEquivalentTo([ + .BeEquivalentTo( + [ new { name = "Alice", age = 25, city = "New York", country = "USA" }, - new { name = "Bob", age = 30, city = "Los Angeles", country = "USA" }]); + new { name = "Bob", age = 30, city = "Los Angeles", country = "USA" } + ]); } [Fact] @@ -161,9 +167,11 @@ async IAsyncEnumerable GetRecordsAsync() new { name, age, city, country, job }); result.Should() - .BeEquivalentTo([ + .BeEquivalentTo( + [ new { name = "Alice", age = 25, city = "New York", country = "USA", job = "Engineer" }, - new { name = "Bob", age = 30, city = "Los Angeles", country = "USA", job = "Doctor" }]); + new { name = "Bob", age = 30, city = "Los Angeles", country = "USA", job = "Doctor" } + ]); } [Fact] @@ -202,7 +210,8 @@ async IAsyncEnumerable GetRecordsAsync() new { name, age, city, country, job, hobby }); result.Should() - .BeEquivalentTo([ + .BeEquivalentTo( + [ new { name = "Alice", age = 25, city = "New York", country = "USA", job = "Engineer", hobby = "Reading" @@ -210,7 +219,8 @@ async IAsyncEnumerable GetRecordsAsync() new { name = "Bob", age = 30, city = "Los Angeles", country = "USA", job = "Doctor", hobby = "Swimming" - }]); + } + ]); } [Fact] @@ -251,7 +261,8 @@ async IAsyncEnumerable GetRecordsAsync() new { name, age, city, country, job, hobby, pet }); result.Should() - .BeEquivalentTo([ + .BeEquivalentTo( + [ new { name = "Alice", age = 25, city = "New York", country = "USA", job = "Engineer", hobby = "Reading", @@ -261,7 +272,8 @@ async IAsyncEnumerable GetRecordsAsync() { name = "Bob", age = 30, city = "Los Angeles", country = "USA", job = "Doctor", hobby = "Swimming", pet = "Cat" - }]); + } + ]); } [Fact] @@ -304,7 +316,8 @@ async IAsyncEnumerable GetRecordsAsync() new { name, age, city, country, job, hobby, pet, car }); result.Should() - .BeEquivalentTo([ + .BeEquivalentTo( + [ new { name = "Alice", age = 25, city = "New York", country = "USA", job = "Engineer", hobby = "Reading", @@ -314,7 +327,8 @@ async IAsyncEnumerable GetRecordsAsync() { name = "Bob", age = 30, city = "Los Angeles", country = "USA", job = "Doctor", hobby = "Swimming", pet = "Cat", car = "BMW" - }]); + } + ]); } [Fact] @@ -367,7 +381,8 @@ async IAsyncEnumerable GetRecordsAsync() string food) => new { name, age, city, country, job, hobby, pet, car, food }); result.Should() - .BeEquivalentTo([ + .BeEquivalentTo( + [ new { name = "Alice", age = 25, city = "New York", country = "USA", job = "Engineer", hobby = "Reading", @@ -377,7 +392,8 @@ async IAsyncEnumerable GetRecordsAsync() { name = "Bob", age = 30, city = "Los Angeles", country = "USA", job = "Doctor", hobby = "Swimming", pet = "Cat", car = "BMW", food = "Burger" - }]); + } + ]); } [Fact] @@ -433,7 +449,8 @@ async IAsyncEnumerable GetRecordsAsync() string sport) => new { name, age, city, country, job, hobby, pet, car, food, sport }); result.Should() - .BeEquivalentTo([ + .BeEquivalentTo( + [ new { name = "Alice", age = 25, city = "New York", country = "USA", job = "Engineer", hobby = "Reading", @@ -443,7 +460,8 @@ async IAsyncEnumerable GetRecordsAsync() { name = "Bob", age = 30, city = "Los Angeles", country = "USA", job = "Doctor", hobby = "Swimming", pet = "Cat", car = "BMW", food = "Burger", sport = "Football" - }]); + } + ]); } [Fact] diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/BlueprintMappingTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/BlueprintMappingTests.cs index 7a0e560d8..42fb4ba6a 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/BlueprintMappingTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/BlueprintMappingTests.cs @@ -114,10 +114,6 @@ public void ShouldThrowMappingFailedExceptionForMismatchedTypes() act.Should().Throw(); } - private record Point( - [MappingSource("x")] int X, - [MappingSource("y")] int Y); - [Fact] public void ShouldMapPropertiesOfMappableTypes() { @@ -154,4 +150,8 @@ public void ShouldMapPropertiesOfAnonymousTypes() result.point.y.Should().Be(2); result.color.Should().Be("red"); } + + private record Point( + [MappingSource("x")] int X, + [MappingSource("y")] int Y); } diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/BuiltMapperTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/BuiltMapperTests.cs index 4cc0cc04b..7c0c4a2ee 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/BuiltMapperTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/BuiltMapperTests.cs @@ -22,16 +22,6 @@ namespace Neo4j.Driver.Tests.Mapping; public class BuiltMapperTests { - private class NoParameterlessConstructor - { - public int Value { get; } - - public NoParameterlessConstructor(int value) - { - Value = value; - } - } - [Fact] public void ShouldThrowIfNoParameterlessConstructor() { @@ -51,12 +41,6 @@ public void ShouldUseConstructorWhenInstructed() result.Value.Should().Be(48); } - private class TwoPropertyClass - { - public int Value1 { get; set; } - public int Value2 { get; set; } - } - [Fact] public void ShouldMapProperties() { @@ -83,4 +67,20 @@ public void ShouldThrowWhenPropertyNotFoundInRecord() var act = () => mapper.Map(record); act.Should().Throw(); } + + private class NoParameterlessConstructor + { + public NoParameterlessConstructor(int value) + { + Value = value; + } + + public int Value { get; } + } + + private class TwoPropertyClass + { + public int Value1 { get; set; } + public int Value2 { get; set; } + } } diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/DefaultMapperTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/DefaultMapperTests.cs index 441fcaf43..8c54e0228 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/DefaultMapperTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/DefaultMapperTests.cs @@ -25,12 +25,6 @@ namespace Neo4j.Driver.Tests.Mapping; public class DefaultMapperTests { - private class SimpleClass - { - public int Id { get; set; } - public string Name { get; set; } = null!; - } - [Fact] public void ShouldMapSimpleClass() { @@ -43,18 +37,6 @@ public void ShouldMapSimpleClass() result.Name.Should().Be("Foo"); } - private class ConstructorClass - { - public int Id { get; } - public string Name { get; } - - public ConstructorClass(int id, string name) - { - Id = id; - Name = name; - } - } - [Fact] public void ShouldMapConstructorClass() { @@ -67,25 +49,6 @@ public void ShouldMapConstructorClass() result.Name.Should().Be("Foo"); } - private class NonDefaultConstructorClass - { - public int Id { get; } - public string Name { get; } - - public NonDefaultConstructorClass() - { - Id = -99; - Name = "error"; - } - - [MappingConstructor] - public NonDefaultConstructorClass(int id, string name) - { - Id = id; - Name = name; - } - } - [Fact] public void ShouldMapNonDefaultConstructorClass() { @@ -98,20 +61,6 @@ public void ShouldMapNonDefaultConstructorClass() result.Name.Should().Be("Foo"); } - private class Person - { - public Person( - [MappingSource("person.name")] string name, - [MappingSource("person.born")] int born) - { - Name = name; - Born = born; - } - - public string Name { get; } - public int Born { get; } - } - [Fact] public void ShouldMapFromInsideDictionaries() { @@ -151,18 +100,6 @@ public void ShouldMapFromNodesInRecords() person.Born.Should().Be(1977); } - public class NaturalPhenomenon - { - public string Name { get; } - public List Components { get; } - - public NaturalPhenomenon(string name, List components) - { - Name = name; - Components = components; - } - } - [Fact] public void ShouldMapListsThroughConstructor() { @@ -176,18 +113,6 @@ public void ShouldMapListsThroughConstructor() result.Components.Should().BeEquivalentTo("wind", "rain"); } - public class NaturalPhenomenonCommaSeparated - { - public string Name { get; } - public string Components { get; } - - public NaturalPhenomenonCommaSeparated(string name, string components) - { - Name = name; - Components = components; - } - } - [Fact] public void ShouldMapCommaSeparatedListsThroughConstructor() { @@ -201,18 +126,6 @@ public void ShouldMapCommaSeparatedListsThroughConstructor() result.Components.Should().Be("wind,rain"); } - public class HistoricalPhenomenon - { - public NaturalPhenomenon Phenomenon { get; } - public int Year { get; } - - public HistoricalPhenomenon(NaturalPhenomenon phenomenon, int year) - { - Phenomenon = phenomenon; - Year = year; - } - } - [Fact] public void ShouldMapNestedObjectsThroughConstructor() { @@ -232,18 +145,6 @@ public void ShouldMapNestedObjectsThroughConstructor() result.Year.Should().Be(2021); } - public class YearOfPhenomena - { - public int Year { get; } - public List Phenomena { get; } - - public YearOfPhenomena(int year, List phenomena) - { - Year = year; - Phenomena = phenomena; - } - } - [Fact] public void ShouldMapListsOfNodesThroughConstructor() { @@ -283,21 +184,6 @@ public void ShouldMapListsOfNodesThroughConstructor() result.Phenomena[2].Components.Should().BeEquivalentTo("earth", "quaking"); } - private class ClassWithProperties - { - public ClassWithProperties(int year, string occurrence) - { - Year = year * 10; - Occurrence = occurrence.ToLowerInvariant(); - } - - public int Year { get; } - public string Occurrence { get; } - - [MappingSource("description")] - public string Description { get; set; } - } - [Fact] public void ShouldSetPropertiesNotSetInConstructor() { @@ -313,11 +199,130 @@ public void ShouldSetPropertiesNotSetInConstructor() result.Description.Should().Be("Covid-19"); } - private class ClassWithPropertiesWithMappingHints + [Fact] + public void ShouldSetPropertiesNotSetInConstructorWithMappingHints() { - public ClassWithPropertiesWithMappingHints( - [MappingSource("year")] int year, - string occurrence) + var record = TestRecord.Create( + new[] { "year", "occurrence", "description", "something" }, + new object[] { 2021, "PANDEMIC", "Covid-19", "something" }); + + var mapper = DefaultMapper.Get(); + var result = mapper.Map(record); + + result.Year.Should().Be(20210); + result.Occurrence.Should().Be("pandemic"); + result.OtherText.Should().Be("Covid-19"); + } + + [Fact] + public void ShouldThrowIfClassHasNoConstructors() + { + var act = () => DefaultMapper.Get(); + act.Should().Throw(); + } + + private class SimpleClass + { + public int Id { get; set; } + public string Name { get; } = null!; + } + + private class ConstructorClass + { + public ConstructorClass(int id, string name) + { + Id = id; + Name = name; + } + + public int Id { get; } + public string Name { get; } + } + + private class NonDefaultConstructorClass + { + public NonDefaultConstructorClass() + { + Id = -99; + Name = "error"; + } + + [MappingConstructor] + public NonDefaultConstructorClass(int id, string name) + { + Id = id; + Name = name; + } + + public int Id { get; } + public string Name { get; } + } + + private class Person + { + public Person( + [MappingSource("person.name")] string name, + [MappingSource("person.born")] int born) + { + Name = name; + Born = born; + } + + public string Name { get; } + public int Born { get; } + } + + public class NaturalPhenomenon + { + public NaturalPhenomenon(string name, List components) + { + Name = name; + Components = components; + } + + public string Name { get; } + public List Components { get; } + } + + public class NaturalPhenomenonCommaSeparated + { + public NaturalPhenomenonCommaSeparated(string name, string components) + { + Name = name; + Components = components; + } + + public string Name { get; } + public string Components { get; } + } + + public class HistoricalPhenomenon + { + public HistoricalPhenomenon(NaturalPhenomenon phenomenon, int year) + { + Phenomenon = phenomenon; + Year = year; + } + + public NaturalPhenomenon Phenomenon { get; } + public int Year { get; } + } + + public class YearOfPhenomena + { + public YearOfPhenomena(int year, List phenomena) + { + Year = year; + Phenomena = phenomena; + } + + public int Year { get; } + public List Phenomena { get; } + } + + private class ClassWithProperties + { + public ClassWithProperties(int year, string occurrence) { Year = year * 10; Occurrence = occurrence.ToLowerInvariant(); @@ -327,22 +332,24 @@ public ClassWithPropertiesWithMappingHints( public string Occurrence { get; } [MappingSource("description")] - public string OtherText { get; set; } + public string Description { get; set; } } - [Fact] - public void ShouldSetPropertiesNotSetInConstructorWithMappingHints() + private class ClassWithPropertiesWithMappingHints { - var record = TestRecord.Create( - new[] { "year", "occurrence", "description", "something" }, - new object[] { 2021, "PANDEMIC", "Covid-19", "something" }); + public ClassWithPropertiesWithMappingHints( + [MappingSource("year")] int year, + string occurrence) + { + Year = year * 10; + Occurrence = occurrence.ToLowerInvariant(); + } - var mapper = DefaultMapper.Get(); - var result = mapper.Map(record); + public int Year { get; } + public string Occurrence { get; } - result.Year.Should().Be(20210); - result.Occurrence.Should().Be("pandemic"); - result.OtherText.Should().Be("Covid-19"); + [MappingSource("description")] + public string OtherText { get; set; } } private class NoConstructors @@ -351,11 +358,4 @@ private NoConstructors() { } } - - [Fact] - public void ShouldThrowIfClassHasNoConstructors() - { - var act = () => DefaultMapper.Get(null); - act.Should().Throw(); - } } diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/DelegateExecutableQueryMappingExtensionsTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/DelegateExecutableQueryMappingExtensionsTests.cs index 3b3a2e493..d52c74e8d 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/DelegateExecutableQueryMappingExtensionsTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/DelegateExecutableQueryMappingExtensionsTests.cs @@ -29,9 +29,9 @@ public void ShouldMapAllRecordsWith_01_Field() { Task>> GetRecordsAsync() { - var record1 = TestRecord.Create([("name", "Bob")]); - var record2 = TestRecord.Create([("name", "Alice")]); - var record3 = TestRecord.Create([("name", "Eve")]); + var record1 = TestRecord.Create(("name", "Bob")); + var record2 = TestRecord.Create(("name", "Alice")); + var record3 = TestRecord.Create(("name", "Eve")); var result = new EagerResult>( new List { record1, record2, record3 }, @@ -44,10 +44,12 @@ Task>> GetRecordsAsync() GetRecordsAsync() .AsObjectsAsync((string name) => new { name }) .Result.Should() - .BeEquivalentTo([ + .BeEquivalentTo( + [ new { name = "Bob" }, new { name = "Alice" }, - new { name = "Eve" }]); + new { name = "Eve" } + ]); } [Fact] @@ -55,9 +57,9 @@ public void ShouldMapAllRecordsWith_02_Fields() { Task>> GetRecordsAsync() { - var record1 = TestRecord.Create([("name", "Bob"), ("age", 30)]); - var record2 = TestRecord.Create([("name", "Alice"), ("age", 25)]); - var record3 = TestRecord.Create([("name", "Eve"), ("age", 35)]); + var record1 = TestRecord.Create(("name", "Bob"), ("age", 30)); + var record2 = TestRecord.Create(("name", "Alice"), ("age", 25)); + var record3 = TestRecord.Create(("name", "Eve"), ("age", 35)); var result = new EagerResult>( new List { record1, record2, record3 }, @@ -70,10 +72,12 @@ Task>> GetRecordsAsync() GetRecordsAsync() .AsObjectsAsync((string name, int age) => new { name, age }) .Result.Should() - .BeEquivalentTo([ + .BeEquivalentTo( + [ new { name = "Bob", age = 30 }, new { name = "Alice", age = 25 }, - new { name = "Eve", age = 35 }]); + new { name = "Eve", age = 35 } + ]); } [Fact] @@ -81,10 +85,10 @@ public void ShouldMapAllRecordsWith_03_Fields() { Task>> GetRecordsAsync() { - var record1 = TestRecord.Create([("name", "Bob"), ("age", 30), ("city", "New York")]); - var record2 = TestRecord.Create([("name", "Alice"), ("age", 25), ("city", "Los Angeles")]); + var record1 = TestRecord.Create(("name", "Bob"), ("age", 30), ("city", "New York")); + var record2 = TestRecord.Create(("name", "Alice"), ("age", 25), ("city", "Los Angeles")); - var record3 = TestRecord.Create([("name", "Eve"), ("age", 35), ("city", "Chicago")]); + var record3 = TestRecord.Create(("name", "Eve"), ("age", 35), ("city", "Chicago")); var result = new EagerResult>( new List { record1, record2, record3 }, @@ -97,10 +101,12 @@ Task>> GetRecordsAsync() GetRecordsAsync() .AsObjectsAsync((string name, int age, string city) => new { name, age, city }) .Result.Should() - .BeEquivalentTo([ + .BeEquivalentTo( + [ new { name = "Bob", age = 30, city = "New York" }, new { name = "Alice", age = 25, city = "Los Angeles" }, - new { name = "Eve", age = 35, city = "Chicago" }]); + new { name = "Eve", age = 35, city = "Chicago" } + ]); } [Fact] @@ -109,25 +115,22 @@ public void ShouldMapAllRecordsWith_04_Fields() Task>> GetRecordsAsync() { var record1 = TestRecord.Create( - new[] - { - ("name", (object)"Bob"), ("age", (object)30), ("city", (object)"New York"), - ("country", (object)"USA") - }); + ("name", "Bob"), + ("age", 30), + ("city", "New York"), + ("country", "USA")); var record2 = TestRecord.Create( - new[] - { - ("name", (object)"Alice"), ("age", (object)25), ("city", (object)"Los Angeles"), - ("country", (object)"USA") - }); + ("name", "Alice"), + ("age", 25), + ("city", "Los Angeles"), + ("country", "USA")); var record3 = TestRecord.Create( - new[] - { - ("name", (object)"Eve"), ("age", (object)35), ("city", (object)"Chicago"), - ("country", (object)"USA") - }); + ("name", "Eve"), + ("age", 35), + ("city", "Chicago"), + ("country", "USA")); var result = new EagerResult>( new List { record1, record2, record3 }, @@ -140,10 +143,12 @@ Task>> GetRecordsAsync() GetRecordsAsync() .AsObjectsAsync((string name, int age, string city, string country) => new { name, age, city, country }) .Result.Should() - .BeEquivalentTo([ + .BeEquivalentTo( + [ new { name = "Bob", age = 30, city = "New York", country = "USA" }, new { name = "Alice", age = 25, city = "Los Angeles", country = "USA" }, - new { name = "Eve", age = 35, city = "Chicago", country = "USA" }]); + new { name = "Eve", age = 35, city = "Chicago", country = "USA" } + ]); } [Fact] @@ -152,22 +157,25 @@ public void ShouldMapAllRecordsWith_05_Fields() Task>> GetRecordsAsync() { var record1 = TestRecord.Create( - [ - ("name", "Bob"), ("age", 30), ("city", "New York"), - ("country", "USA"), ("job", "Engineer") - ]); + ("name", "Bob"), + ("age", 30), + ("city", "New York"), + ("country", "USA"), + ("job", "Engineer")); var record2 = TestRecord.Create( - [ - ("name", "Alice"), ("age", 25), ("city", "Los Angeles"), - ("country", "USA"), ("job", "Doctor") - ]); + ("name", "Alice"), + ("age", 25), + ("city", "Los Angeles"), + ("country", "USA"), + ("job", "Doctor")); var record3 = TestRecord.Create( - [ - ("name", "Eve"), ("age", 35), ("city", "Chicago"), - ("country", "USA"), ("job", "Teacher") - ]); + ("name", "Eve"), + ("age", 35), + ("city", "Chicago"), + ("country", "USA"), + ("job", "Teacher")); var result = new EagerResult>( new List { record1, record2, record3 }, @@ -182,10 +190,12 @@ Task>> GetRecordsAsync() (string name, int age, string city, string country, string job) => new { name, age, city, country, job }) .Result.Should() - .BeEquivalentTo([ + .BeEquivalentTo( + [ new { name = "Bob", age = 30, city = "New York", country = "USA", job = "Engineer" }, new { name = "Alice", age = 25, city = "Los Angeles", country = "USA", job = "Doctor" }, - new { name = "Eve", age = 35, city = "Chicago", country = "USA", job = "Teacher" }]); + new { name = "Eve", age = 35, city = "Chicago", country = "USA", job = "Teacher" } + ]); } [Fact] @@ -194,22 +204,28 @@ public void ShouldMapAllRecordsWith_06_Fields() Task>> GetRecordsAsync() { var record1 = TestRecord.Create( - [ - ("name", "Bob"), ("age", 30), ("city", "New York"), - ("country", "USA"), ("job", "Engineer"), ("gender", "Male") - ]); + ("name", "Bob"), + ("age", 30), + ("city", "New York"), + ("country", "USA"), + ("job", "Engineer"), + ("gender", "Male")); var record2 = TestRecord.Create( - [ - ("name", "Alice"), ("age", 25), ("city", "Los Angeles"), - ("country", "USA"), ("job", "Doctor"), ("gender", "Female") - ]); + ("name", "Alice"), + ("age", 25), + ("city", "Los Angeles"), + ("country", "USA"), + ("job", "Doctor"), + ("gender", "Female")); var record3 = TestRecord.Create( - [ - ("name", "Eve"), ("age", 35), ("city", "Chicago"), - ("country", "USA"), ("job", "Teacher"), ("gender", "Female") - ]); + ("name", "Eve"), + ("age", 35), + ("city", "Chicago"), + ("country", "USA"), + ("job", "Teacher"), + ("gender", "Female")); var result = new EagerResult>( new List { record1, record2, record3 }, @@ -224,13 +240,15 @@ Task>> GetRecordsAsync() (string name, int age, string city, string country, string job, string gender) => new { name, age, city, country, job, gender }) .Result.Should() - .BeEquivalentTo([ + .BeEquivalentTo( + [ new { name = "Bob", age = 30, city = "New York", country = "USA", job = "Engineer", gender = "Male" }, new { name = "Alice", age = 25, city = "Los Angeles", country = "USA", job = "Doctor", gender = "Female" }, - new { name = "Eve", age = 35, city = "Chicago", country = "USA", job = "Teacher", gender = "Female" }]); + new { name = "Eve", age = 35, city = "Chicago", country = "USA", job = "Teacher", gender = "Female" } + ]); } [Fact] @@ -239,25 +257,31 @@ public void ShouldMapAllRecordsWith_07_Fields() Task>> GetRecordsAsync() { var record1 = TestRecord.Create( - [ - ("name", "Bob"), ("age", 30), ("city", "New York"), - ("country", "USA"), ("job", "Engineer"), ("gender", "Male"), - ("maritalStatus", "Single") - ]); + ("name", "Bob"), + ("age", 30), + ("city", "New York"), + ("country", "USA"), + ("job", "Engineer"), + ("gender", "Male"), + ("maritalStatus", "Single")); var record2 = TestRecord.Create( - [ - ("name", "Alice"), ("age", 25), ("city", "Los Angeles"), - ("country", "USA"), ("job", "Doctor"), ("gender", "Female"), - ("maritalStatus", "Married") - ]); + ("name", "Alice"), + ("age", 25), + ("city", "Los Angeles"), + ("country", "USA"), + ("job", "Doctor"), + ("gender", "Female"), + ("maritalStatus", "Married")); var record3 = TestRecord.Create( - [ - ("name", "Eve"), ("age", 35), ("city", "Chicago"), - ("country", "USA"), ("job", "Teacher"), ("gender", "Female"), - ("maritalStatus", "Divorced") - ]); + ("name", "Eve"), + ("age", 35), + ("city", "Chicago"), + ("country", "USA"), + ("job", "Teacher"), + ("gender", "Female"), + ("maritalStatus", "Divorced")); var result = new EagerResult>( new List { record1, record2, record3 }, @@ -272,7 +296,8 @@ Task>> GetRecordsAsync() (string name, int age, string city, string country, string job, string gender, string maritalStatus) => new { name, age, city, country, job, gender, maritalStatus }) .Result.Should() - .BeEquivalentTo([ + .BeEquivalentTo( + [ new { name = "Bob", age = 30, city = "New York", country = "USA", job = "Engineer", gender = "Male", @@ -288,7 +313,7 @@ Task>> GetRecordsAsync() name = "Eve", age = 35, city = "Chicago", country = "USA", job = "Teacher", gender = "Female", maritalStatus = "Divorced" } - ]); + ]); } [Fact] @@ -297,25 +322,34 @@ public void ShouldMapAllRecordsWith_08_Fields() Task>> GetRecordsAsync() { var record1 = TestRecord.Create( - [ - ("name", "Bob"), ("age", 30), ("city", "New York"), - ("country", "USA"), ("job", "Engineer"), ("gender", "Male"), - ("maritalStatus", "Single"), ("children", 2) - ]); + ("name", "Bob"), + ("age", 30), + ("city", "New York"), + ("country", "USA"), + ("job", "Engineer"), + ("gender", "Male"), + ("maritalStatus", "Single"), + ("children", 2)); var record2 = TestRecord.Create( - [ - ("name", "Alice"), ("age", 25), ("city", "Los Angeles"), - ("country", "USA"), ("job", "Doctor"), ("gender", "Female"), - ("maritalStatus", "Married"), ("children", 0) - ]); + ("name", "Alice"), + ("age", 25), + ("city", "Los Angeles"), + ("country", "USA"), + ("job", "Doctor"), + ("gender", "Female"), + ("maritalStatus", "Married"), + ("children", 0)); var record3 = TestRecord.Create( - [ - ("name", "Eve"), ("age", 35), ("city", "Chicago"), - ("country", "USA"), ("job", "Teacher"), ("gender", "Female"), - ("maritalStatus", "Divorced"), ("children", 1) - ]); + ("name", "Eve"), + ("age", 35), + ("city", "Chicago"), + ("country", "USA"), + ("job", "Teacher"), + ("gender", "Female"), + ("maritalStatus", "Divorced"), + ("children", 1)); var result = new EagerResult>( new List { record1, record2, record3 }, @@ -337,7 +371,8 @@ Task>> GetRecordsAsync() string maritalStatus, int children) => new { name, age, city, country, job, gender, maritalStatus, children }) .Result.Should() - .BeEquivalentTo([ + .BeEquivalentTo( + [ new { name = "Bob", age = 30, city = "New York", country = "USA", job = "Engineer", gender = "Male", @@ -353,8 +388,7 @@ Task>> GetRecordsAsync() name = "Eve", age = 35, city = "Chicago", country = "USA", job = "Teacher", gender = "Female", maritalStatus = "Divorced", children = 1 } - ] - ); + ]); } [Fact] @@ -363,25 +397,37 @@ public void ShouldMapAllRecordsWith_09_Fields() Task>> GetRecordsAsync() { var record1 = TestRecord.Create( - [ - ("name", "Bob"), ("age", 30), ("city", "New York"), - ("country", "USA"), ("job", "Engineer"), ("gender", "Male"), - ("maritalStatus", "Single"), ("children", 2), ("education", "Bachelor's") - ]); + ("name", "Bob"), + ("age", 30), + ("city", "New York"), + ("country", "USA"), + ("job", "Engineer"), + ("gender", "Male"), + ("maritalStatus", "Single"), + ("children", 2), + ("education", "Bachelor's")); var record2 = TestRecord.Create( - [ - ("name", "Alice"), ("age", 25), ("city", "Los Angeles"), - ("country", "USA"), ("job", "Doctor"), ("gender", "Female"), - ("maritalStatus", "Married"), ("children", 0), ("education", "Master's") - ]); + ("name", "Alice"), + ("age", 25), + ("city", "Los Angeles"), + ("country", "USA"), + ("job", "Doctor"), + ("gender", "Female"), + ("maritalStatus", "Married"), + ("children", 0), + ("education", "Master's")); var record3 = TestRecord.Create( - [ - ("name", "Eve"), ("age", 35), ("city", "Chicago"), - ("country", "USA"), ("job", "Teacher"), ("gender", "Female"), - ("maritalStatus", "Divorced"), ("children", 1), ("education", "PhD") - ]); + ("name", "Eve"), + ("age", 35), + ("city", "Chicago"), + ("country", "USA"), + ("job", "Teacher"), + ("gender", "Female"), + ("maritalStatus", "Divorced"), + ("children", 1), + ("education", "PhD")); var result = new EagerResult>( new List { record1, record2, record3 }, @@ -405,7 +451,8 @@ Task>> GetRecordsAsync() string education) => new { name, age, city, country, job, gender, maritalStatus, children, education }) .Result.Should() - .BeEquivalentTo([ + .BeEquivalentTo( + [ new { name = "Bob", age = 30, city = "New York", country = "USA", job = "Engineer", gender = "Male", @@ -420,7 +467,8 @@ Task>> GetRecordsAsync() { name = "Eve", age = 35, city = "Chicago", country = "USA", job = "Teacher", gender = "Female", maritalStatus = "Divorced", children = 1, education = "PhD" - }]); + } + ]); } [Fact] @@ -429,25 +477,40 @@ public void ShouldMapAllRecordsWith_10_Fields() Task>> GetRecordsAsync() { var record1 = TestRecord.Create( - [ - ("name", "Bob"), ("age", 30), ("city", "New York"), - ("country", "USA"), ("job", "Engineer"), ("gender", "Male"), - ("maritalStatus", "Single"), ("children", 2), ("education", "Bachelor's"), ("income", 70000) - ]); + ("name", "Bob"), + ("age", 30), + ("city", "New York"), + ("country", "USA"), + ("job", "Engineer"), + ("gender", "Male"), + ("maritalStatus", "Single"), + ("children", 2), + ("education", "Bachelor's"), + ("income", 70000)); var record2 = TestRecord.Create( - [ - ("name", "Alice"), ("age", 25), ("city", "Los Angeles"), - ("country", "USA"), ("job", "Doctor"), ("gender", "Female"), - ("maritalStatus", "Married"), ("children", 0), ("education", "Master's"), ("income", 80000) - ]); + ("name", "Alice"), + ("age", 25), + ("city", "Los Angeles"), + ("country", "USA"), + ("job", "Doctor"), + ("gender", "Female"), + ("maritalStatus", "Married"), + ("children", 0), + ("education", "Master's"), + ("income", 80000)); var record3 = TestRecord.Create( - [ - ("name", "Eve"), ("age", 35), ("city", "Chicago"), - ("country", "USA"), ("job", "Teacher"), ("gender", "Female"), - ("maritalStatus", "Divorced"), ("children", 1), ("education", "PhD"), ("income", 60000) - ]); + ("name", "Eve"), + ("age", 35), + ("city", "Chicago"), + ("country", "USA"), + ("job", "Teacher"), + ("gender", "Female"), + ("maritalStatus", "Divorced"), + ("children", 1), + ("education", "PhD"), + ("income", 60000)); var result = new EagerResult>( new List { record1, record2, record3 }, @@ -475,7 +538,8 @@ Task>> GetRecordsAsync() int income) => new { name, age, city, country, job, gender, maritalStatus, children, education, income }) .Result.Should() - .BeEquivalentTo([ + .BeEquivalentTo( + [ new { name = "Bob", age = 30, city = "New York", country = "USA", job = "Engineer", gender = "Male", @@ -490,6 +554,7 @@ Task>> GetRecordsAsync() { name = "Eve", age = 35, city = "Chicago", country = "USA", job = "Teacher", gender = "Female", maritalStatus = "Divorced", children = 1, education = "PhD", income = 60000 - }]); + } + ]); } } diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/DelegateMapperTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/DelegateMapperTests.cs index 8404c5713..6317a89da 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/DelegateMapperTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/DelegateMapperTests.cs @@ -1,12 +1,12 @@ // Copyright (c) "Neo4j" // Neo4j Sweden AB [https://neo4j.com] -// +// // Licensed under the Apache License, Version 2.0 (the "License"). // You may not use this file except in compliance with the License. // You may obtain a copy of the License at -// +// // http://www.apache.org/licenses/LICENSE-2.0 -// +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -297,35 +297,6 @@ public void ShouldMapWithUserSuppliedLambdaExpression() result.Should().Be("AAA"); } - private abstract class SpokenStatement - { - public abstract bool IsTrue { get; } - public string Description { get; } - - protected SpokenStatement(string description) - { - Description = description; - } - } - - private class Truth : SpokenStatement - { - public override bool IsTrue => true; - - public Truth(string description) : base(description) - { - } - } - - private class Myth : SpokenStatement - { - public override bool IsTrue => false; - - public Myth(string description) : base(description) - { - } - } - [Fact] public void ShouldSucceedForExampleGivenInDocumentation() { @@ -339,8 +310,6 @@ public void ShouldSucceedForExampleGivenInDocumentation() spokenStatement.Description.Should().Be("This is true"); } - private record Person([MappingSource("name")] string Name, [MappingSource("age")] int Age); - [Fact] public void ShouldPassMappedObjectsToLambdaWhenRequired() { @@ -370,7 +339,11 @@ public void ShouldMapToObjectParameterIfPossible() public void ShouldSucceedWithMethodInsteadOfLambda() { var record = TestRecord.Create(("country", "Sweden"), ("population", 1234)); - string MakeStatement(string c,int p) => $"{c} has a population of {p}"; + + string MakeStatement(string c, int p) + { + return $"{c} has a population of {p}"; + } var result = record.AsObject((string country, int population) => MakeStatement(country, population)); @@ -382,16 +355,48 @@ public void ShouldFailIfDelegateThrowsException() { var record = TestRecord.Create(("x", 69)); - Action act = () => record.AsObject((int x) => - { - if(x == 69) + Action act = () => record.AsObject( + (int x) => { - throw new Exception("Test exception"); - } + if (x == 69) + { + throw new Exception("Test exception"); + } - return new string('A', x); - }); + return new string('A', x); + }); act.Should().Throw().WithInnerException().WithMessage("Test exception"); } + + private abstract class SpokenStatement + { + protected SpokenStatement(string description) + { + Description = description; + } + + public abstract bool IsTrue { get; } + public string Description { get; } + } + + private class Truth : SpokenStatement + { + public Truth(string description) : base(description) + { + } + + public override bool IsTrue => true; + } + + private class Myth : SpokenStatement + { + public Myth(string description) : base(description) + { + } + + public override bool IsTrue => false; + } + + private record Person([MappingSource("name")] string Name, [MappingSource("age")] int Age); } diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/DictAsRecordTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/DictAsRecordTests.cs index 08e35d4ce..cf3c0b01c 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/DictAsRecordTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/DictAsRecordTests.cs @@ -1,19 +1,18 @@ // Copyright (c) "Neo4j" // Neo4j Sweden AB [https://neo4j.com] -// +// // Licensed under the Apache License, Version 2.0 (the "License"). // You may not use this file except in compliance with the License. // You may obtain a copy of the License at -// +// // http://www.apache.org/licenses/LICENSE-2.0 -// +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -using System; using System.Collections; using System.Collections.Generic; using FluentAssertions; @@ -21,6 +20,7 @@ using Neo4j.Driver.Mapping; using Neo4j.Driver.Tests.TestUtil; using Xunit; +using InvalidOperationException = System.InvalidOperationException; namespace Neo4j.Driver.Tests.Mapping; @@ -263,7 +263,7 @@ public void IReadOnlyDict_CountShouldReturnCorrectCount() var subject = new DictAsRecord(dict, originalRecord); - ((IReadOnlyDictionary)subject).Count.Should().Be(2); + subject.Count.Should().Be(2); } [Fact] diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/LabelCaptureTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/LabelCaptureTests.cs index 00c43dfe7..88f39a6d4 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/LabelCaptureTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/LabelCaptureTests.cs @@ -25,21 +25,6 @@ namespace Neo4j.Driver.Tests.Mapping; public class LabelCaptureTests { - public class TestMappedClass - { - [MappingSource("Person", EntityMappingSource.NodeLabel)] - [MappingOptional] - public string Label { get; set; } - - [MappingSource("Person", EntityMappingSource.NodeLabel)] - [MappingOptional] - public List Labels { get; set; } - - [MappingSource("Relationship", EntityMappingSource.RelationshipType)] - [MappingOptional] - public string RelationshipType { get; set; } - } - public LabelCaptureTests() { RecordObjectMapping.Reset(); @@ -78,34 +63,6 @@ public void ShouldCaptureRelationshipType() mapped.RelationshipType.Should().Be("ACTED_IN"); } - class CustomMapper : IMappingProvider - { - /// - public void CreateMappers(IMappingRegistry registry) - { - registry.RegisterMapping( - b => b - .Map( - x => x.Label, - "Person", - EntityMappingSource.NodeLabel, - x => string.Join("|", ((string[])x).Select(y => y.ToUpper())), - optional: true) - .Map( - x => x.Labels, - "Person", - EntityMappingSource.NodeLabel, - x => ((string[])x).Select(y => y.Replace("a", "x")).ToList(), - optional: true) - .Map( - x => x.RelationshipType, - "Relationship", - EntityMappingSource.RelationshipType, - x => x?.ToString()?.ToLower(), - optional: true)); - } - } - [Fact] public void ShouldCaptureAndConvertLabels() { @@ -130,4 +87,47 @@ public void ShouldCaptureAndConvertRelationshipType() mapped.RelationshipType.Should().Be("acted_in"); } + + public class TestMappedClass + { + [MappingSource("Person", EntityMappingSource.NodeLabel)] + [MappingOptional] + public string Label { get; set; } + + [MappingSource("Person", EntityMappingSource.NodeLabel)] + [MappingOptional] + public List Labels { get; set; } + + [MappingSource("Relationship", EntityMappingSource.RelationshipType)] + [MappingOptional] + public string RelationshipType { get; set; } + } + + private class CustomMapper : IMappingProvider + { + /// + public void CreateMappers(IMappingRegistry registry) + { + registry.RegisterMapping( + b => b + .Map( + x => x.Label, + "Person", + EntityMappingSource.NodeLabel, + x => string.Join("|", ((string[])x).Select(y => y.ToUpper())), + true) + .Map( + x => x.Labels, + "Person", + EntityMappingSource.NodeLabel, + x => ((string[])x).Select(y => y.Replace("a", "x")).ToList(), + true) + .Map( + x => x.RelationshipType, + "Relationship", + EntityMappingSource.RelationshipType, + x => x?.ToString()?.ToLower(), + true)); + } + } } diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/LambdaMappingRecordExtensionsTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/LambdaMappingRecordExtensionsTests.cs index 062d4e5b8..11bafaef8 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/LambdaMappingRecordExtensionsTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/LambdaMappingRecordExtensionsTests.cs @@ -1,12 +1,12 @@ // Copyright (c) "Neo4j" // Neo4j Sweden AB [https://neo4j.com] -// +// // Licensed under the Apache License, Version 2.0 (the "License"). // You may not use this file except in compliance with the License. // You may obtain a copy of the License at -// +// // http://www.apache.org/licenses/LICENSE-2.0 -// +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -284,7 +284,7 @@ public void ShouldMapToAnonymousTypeWithEightProperties() result.e.Should().Be(123L); result.f.Should().Be('x'); result.g.Should().Be(123.45m); - result.h.Should().Be((byte)123); + result.h.Should().Be(123); } [Fact] @@ -349,8 +349,8 @@ public void ShouldMapToAnonymousTypeWithNineProperties() result.e.Should().Be(123L); result.f.Should().Be('x'); result.g.Should().Be(123.45m); - result.h.Should().Be((byte)123); - result.i.Should().Be((short)12345); + result.h.Should().Be(123); + result.i.Should().Be(12345); } [Fact] @@ -420,9 +420,9 @@ public void ShouldMapToAnonymousTypeWithTenProperties() result.e.Should().Be(123L); result.f.Should().Be('x'); result.g.Should().Be(123.45m); - result.h.Should().Be((byte)123); - result.i.Should().Be((short)12345); - result.j.Should().Be((ushort)12345); + result.h.Should().Be(123); + result.i.Should().Be(12345); + result.j.Should().Be(12345); } [Fact] diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/MappableValueProviderTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/MappableValueProviderTests.cs index 8b8471ee4..8fdab357f 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/MappableValueProviderTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/MappableValueProviderTests.cs @@ -56,12 +56,6 @@ public void ShouldReturnSimpleValue() value.Should().Be("test-value"); } - private class Person - { - public string Name { get; set; } = null!; - public int Age { get; set; } - } - [Fact] public void ShouldApplyMappingToEntities() { @@ -276,4 +270,10 @@ public void ShouldConvertValueToRequestedType() result.Should().Be("123"); } + + private class Person + { + public string Name { get; set; } = null!; + public int Age { get; set; } + } } diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/MappedListCreatorTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/MappedListCreatorTests.cs index 982074119..4dc92ea1d 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/MappedListCreatorTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/MappedListCreatorTests.cs @@ -1,14 +1,12 @@ // Copyright (c) "Neo4j" -// Neo4j Sweden AB [http://neo4j.com] -// -// This file is part of Neo4j. -// +// Neo4j Sweden AB [https://neo4j.com] +// // Licensed under the Apache License, Version 2.0 (the "License"). // You may not use this file except in compliance with the License. // You may obtain a copy of the License at -// +// // http://www.apache.org/licenses/LICENSE-2.0 -// +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -38,18 +36,6 @@ public void ShouldCreateList() list.Should().BeEquivalentTo(Enumerable.Range(0, 10).Select(x => x.ToString())); } - private class Person - { - public Person(string name, int age) - { - Name = name; - Age = age; - } - - public string Name { get; set; } - public int Age { get; set; } - } - [Fact] public void ShouldCreateListOfMappedObjectsFromDictionaries() { @@ -57,7 +43,7 @@ public void ShouldCreateListOfMappedObjectsFromDictionaries() { new Dictionary(), new Dictionary(), new Dictionary() }; var record = Mock.Of(); - var people = new List{ new("Alan", 99), new("Basil", 999), new("David", 9999) }; + var people = new List { new("Alan", 99), new("Basil", 999), new("David", 9999) }; _mocker.GetMock() .SetupSequence(x => x.Map(It.IsAny(), typeof(Person))) @@ -87,4 +73,16 @@ public void ShouldCreateListOfMappedObjectsFromNodes() mappedList.Should().BeEquivalentTo(people); } + + private class Person + { + public Person(string name, int age) + { + Name = name; + Age = age; + } + + public string Name { get; set; } + public int Age { get; set; } + } } diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/MappingBuilderTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/MappingBuilderTests.cs index d7d143032..bf538f0ba 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/MappingBuilderTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/MappingBuilderTests.cs @@ -22,13 +22,6 @@ namespace Neo4j.Driver.Tests.Mapping; public class MappingBuilderTests { - private class TestClass - { - public int Settable { get; set; } - public int NotSettable { get; } = -1; - public int NotAProperty = 0x6060B017; - } - [Fact] public void ShouldThrowIfNotAMemberExpression() { @@ -52,4 +45,11 @@ public void ShouldThrowIfPropertyDoesNotHaveASetter() var act = () => subject.Map(x => x.NotSettable, "foo"); act.Should().Throw(); } -} \ No newline at end of file + + private class TestClass + { + public readonly int NotAProperty = 0x6060B017; + public int Settable { get; set; } + public int NotSettable { get; } = -1; + } +} diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/MappingProviderTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/MappingProviderTests.cs index 6506128c2..c0485905f 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/MappingProviderTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/MappingProviderTests.cs @@ -23,61 +23,6 @@ namespace Neo4j.Driver.Tests.Mapping; public class MappingProviderTests { - private class TestObject - { - [MappingSource("intValue")] - public int IntValue { get; set; } - - [MappingSource("stringValue")] - public string Text { get; set; } = null!; - } - - private class SecondTestObject - { - public int Number { get; set; } - public string Text { get; set; } = null!; - } - - private class ThirdTestObject - { - public int IntValue { get; set; } = -1; - public string StringValue { get; set; } = "unset"; - } - - private class PersonWithAge - { - [MappingSource("name")] - public string Name { get; set; } = null!; - - [MappingOptional] - public int Age { get; set; } - } - - private class TestMappingProvider : IMappingProvider - { - public void CreateMappers(IMappingRegistry registry) - { - registry - .RegisterMapping( - b => b - .UseDefaultMapping() - .Map(x => x.Text, "stringValue", converter: x => x.As().ToUpper() + "!")) - .RegisterMapping( - b => b - .MapWholeObject( - r => new SecondTestObject - { - Number = r.Get("intValue") + 1, - Text = r.Get("stringValue").ToLower() - })) - .RegisterMapping(_ => {}) - .RegisterMapping( - b => b - .UseDefaultMapping() - .Map(x => x.Age, r => r.Get("active") - r.Get("born"))); - } - } - public MappingProviderTests() { RecordObjectMapping.Reset(); @@ -131,6 +76,103 @@ public void ShouldMapPropertiesFromRecordIfRequired() obj.Age.Should().Be(23); } + [Fact] + public void ShouldUseCustomMapper() + { + var record1 = TestRecord.Create(("favourite_color", "blue"), ("lucky_number", 7)); + var record2 = TestRecord.Create(("job_title", "developer"), ("years_of_service", 5)); + + RecordObjectMapping.Register(new NamingConventionTranslator()); + RecordObjectMapping.Register(new NamingConventionTranslator()); + + var obj1 = record1.AsObject(); + var obj2 = record2.AsObject(); + + obj1.FavouriteColor.Should().Be("blue"); + obj1.LuckyNumber.Should().Be(7); + obj2.JobTitle.Should().Be("developer"); + obj2.YearsOfService.Should().Be(5); + } + + [Fact] + public void ShouldNotFailWhenUsingDefaultMapperButMappingSomePropertiesExplicitly() + { + var guid = Guid.NewGuid(); + var testRecord = TestRecord.Create(("Name", "Alice"), ("Guid", guid.ToString())); + RecordObjectMapping.RegisterProvider(new MappingProviderThatUsesDefaultMappingAndOverridesAGuidProperty(true)); + + var obj = testRecord.AsObject(); + + obj.Name.Should().Be("Alice"); + obj.Guid.Should().Be(guid); + } + + [Fact] + public void ShouldFailWhenUsingDefaultMapperWithoutOverriding() + { + var guid = Guid.NewGuid(); + var testRecord = TestRecord.Create(("Name", "Alice"), ("Guid", guid.ToString())); + RecordObjectMapping.RegisterProvider(new MappingProviderThatUsesDefaultMappingAndOverridesAGuidProperty(false)); + + var act = () => testRecord.AsObject(); + act.Should().Throw(); + } + + private class TestObject + { + [MappingSource("intValue")] + public int IntValue { get; set; } + + [MappingSource("stringValue")] + public string Text { get; } = null!; + } + + private class SecondTestObject + { + public int Number { get; set; } + public string Text { get; set; } = null!; + } + + private class ThirdTestObject + { + public int IntValue { get; } = -1; + public string StringValue { get; } = "unset"; + } + + private class PersonWithAge + { + [MappingSource("name")] + public string Name { get; } = null!; + + [MappingOptional] + public int Age { get; set; } + } + + private class TestMappingProvider : IMappingProvider + { + public void CreateMappers(IMappingRegistry registry) + { + registry + .RegisterMapping( + b => b + .UseDefaultMapping() + .Map(x => x.Text, "stringValue", converter: x => x.As().ToUpper() + "!")) + .RegisterMapping( + b => b + .MapWholeObject( + r => new SecondTestObject + { + Number = r.Get("intValue") + 1, + Text = r.Get("stringValue").ToLower() + })) + .RegisterMapping(_ => {}) + .RegisterMapping( + b => b + .UseDefaultMapping() + .Map(x => x.Age, r => r.Get("active") - r.Get("born"))); + } + } + private class FirstNameMappingTestObject { public string FavouriteColor { get; set; } @@ -145,6 +187,23 @@ private class SecondNameMappingTestObject private class NamingConventionTranslator : IRecordMapper { + /// + public T Map(IRecord record) + { + var type = typeof(T); + var obj = Activator.CreateInstance(type); + foreach (var field in record.Keys) + { + var property = type.GetProperty(GetTranslatedPropertyName(field)); + if (property != null) + { + property.SetValue(obj, record[field]); + } + } + + return (T)obj; + } + private string GetTranslatedPropertyName(string fieldName) { // convert from snake_case to PascalCase @@ -165,50 +224,15 @@ private string GetTranslatedPropertyName(string fieldName) return result; } - - /// - public T Map(IRecord record) - { - var type = typeof(T); - var obj = Activator.CreateInstance(type); - foreach (var field in record.Keys) - { - var property = type.GetProperty(GetTranslatedPropertyName(field)); - if (property != null) - { - property.SetValue(obj, record[field]); - } - } - - return (T)obj; - } - } - - [Fact] - public void ShouldUseCustomMapper() - { - var record1 = TestRecord.Create(("favourite_color", "blue"), ("lucky_number", 7)); - var record2 = TestRecord.Create(("job_title", "developer"), ("years_of_service", 5)); - - RecordObjectMapping.Register(new NamingConventionTranslator()); - RecordObjectMapping.Register(new NamingConventionTranslator()); - - var obj1 = record1.AsObject(); - var obj2 = record2.AsObject(); - - obj1.FavouriteColor.Should().Be("blue"); - obj1.LuckyNumber.Should().Be(7); - obj2.JobTitle.Should().Be("developer"); - obj2.YearsOfService.Should().Be(5); } private class NameAndGuid { - public string Name { get; set; } = null!; + public string Name { get; } = null!; public Guid Guid { get; set; } } - private class MappingProviderThatUsesDefaultMappingAndOverridesAGuidProperty(bool overrideGuid): IMappingProvider + private class MappingProviderThatUsesDefaultMappingAndOverridesAGuidProperty(bool overrideGuid) : IMappingProvider { public void CreateMappers(IMappingRegistry registry) { @@ -216,37 +240,11 @@ public void CreateMappers(IMappingRegistry registry) b => { b.UseDefaultMapping(); - if(overrideGuid) + if (overrideGuid) { b.Map(x => x.Guid, "Guid", converter: x => Guid.Parse(x.As())); } }); } } - - [Fact] - public void ShouldNotFailWhenUsingDefaultMapperButMappingSomePropertiesExplicitly() - { - var guid = Guid.NewGuid(); - var testRecord = TestRecord.Create(("Name", "Alice"), ("Guid", guid.ToString())); - RecordObjectMapping.RegisterProvider( - new MappingProviderThatUsesDefaultMappingAndOverridesAGuidProperty(true)); - - var obj = testRecord.AsObject(); - - obj.Name.Should().Be("Alice"); - obj.Guid.Should().Be(guid); - } - - [Fact] - public void ShouldFailWhenUsingDefaultMapperWithoutOverriding() - { - var guid = Guid.NewGuid(); - var testRecord = TestRecord.Create(("Name", "Alice"), ("Guid", guid.ToString())); - RecordObjectMapping.RegisterProvider( - new MappingProviderThatUsesDefaultMappingAndOverridesAGuidProperty(false)); - - var act = () => testRecord.AsObject(); - act.Should().Throw(); - } } diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/OptionalMappingTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/OptionalMappingTests.cs index bd3423571..f41798521 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/OptionalMappingTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/OptionalMappingTests.cs @@ -23,12 +23,6 @@ namespace Neo4j.Driver.Tests.Mapping; public class OptionalMappingTests { - private class ClassWithOptionalProperty - { - [MappingOptional] - public int Value { get; set; } = 1234; - } - [Fact] public void ShouldNotThrowIfOptionalPropertyIsNotPresent() { @@ -38,12 +32,6 @@ public void ShouldNotThrowIfOptionalPropertyIsNotPresent() mapped.Value.Should().Be(1234); } - private class ClassWithPropertyWithDefaultValue - { - [MappingDefaultValue(42)] - public int Value { get; set; } - } - [Fact] public void ShouldUseDefaultValueIfOptionalPropertyIsNotPresent() { @@ -53,16 +41,6 @@ public void ShouldUseDefaultValueIfOptionalPropertyIsNotPresent() mapped.Value.Should().Be(42); } - private class ClassWithConstructorParameterWithDefaultValue - { - public int Value { get; } - - public ClassWithConstructorParameterWithDefaultValue([MappingDefaultValue(42)] int value) - { - Value = value; - } - } - [Fact] public void ShouldMapConstructorParameterWithDefaultValue() { @@ -89,20 +67,12 @@ public void ShouldNotUseDefaultValueIfConstructorParameterIsPresent() mapped.Value.Should().Be(69); } - - private class ClassWithPropertyWithoutDefaultValue - { - public int Value { get; set; } - } [Fact] public void ShouldFailToCreateObject() { var record = TestRecord.Create(["NotTheValue"], [69]); - var act = () => - { - _ = record.AsObject(); - }; + var act = () => { _ = record.AsObject(); }; act.Should().Throw(); } @@ -117,12 +87,35 @@ public void ShouldFailToCreateList() TestRecord.Create(["Value"], [3]) }; - var act = () => - { - _ = records.Select(r => r.AsObject()).ToList(); - }; + var act = () => { _ = records.Select(r => r.AsObject()).ToList(); }; act.Should().Throw(); } + private class ClassWithOptionalProperty + { + [MappingOptional] + public int Value { get; } = 1234; + } + + private class ClassWithPropertyWithDefaultValue + { + [MappingDefaultValue(42)] + public int Value { get; set; } + } + + private class ClassWithConstructorParameterWithDefaultValue + { + public ClassWithConstructorParameterWithDefaultValue([MappingDefaultValue(42)] int value) + { + Value = value; + } + + public int Value { get; } + } + + private class ClassWithPropertyWithoutDefaultValue + { + public int Value { get; set; } + } } diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/RecordMappingTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/RecordMappingTests.cs index ab450f2cc..d4cbfd7cb 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/RecordMappingTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/RecordMappingTests.cs @@ -25,35 +25,6 @@ namespace Neo4j.Driver.Tests.Mapping; public class RecordMappingTests { - private class TestPerson - { - [MappingDefaultValue("A. Test Name")] - [MappingSource("person.name")] - public string Name { get; set; } - - [MappingOptional] - [MappingSource("person.born")] - public int? Born { get; set; } - - [MappingOptional] - [MappingSource("hobbies")] - public List Hobbies { get; set; } = null!; - } - - private class SimpleTestPerson - { - [MappingOptional] - [MappingSource("name")] - public string Name { get; set; } = "A. Test Name"; - - [MappingOptional] - [MappingSource("born")] - public int? Born { get; set; } - - [MappingOptional] - public List Hobbies { get; set; } = null!; - } - [Fact] public void ShouldMapPrimitives() { @@ -71,15 +42,6 @@ public void ShouldMapList() person.Hobbies.Should().BeEquivalentTo("Coding", "Swimming"); } - private class PersonInDict - { - [MappingSource("person.name")] - public string Name { get; set; } = ""; - - [MappingSource("person.born")] - public int Born { get; set; } - } - [Fact] public void ShouldMapFromInsideDictionaries() { @@ -101,43 +63,6 @@ public void ShouldLeaveDefaultsIfFieldAbsent() person!.Born.Should().Be(1977); } - private class Movie - { - [MappingSource("title")] - public string Title { get; set; } = ""; - - [MappingSource("released")] - public int Released { get; set; } - - [MappingOptional] - [MappingSource("tagline")] - public string Tagline { get; set; } - } - - private class Person - { - [MappingSource("name")] - public string Name { get; set; } = ""; - - [MappingSource("born")] - public int? Born { get; set; } - } - - private class ProducingCareer - { - [MappingSource("person")] - public Person Producer { get; set; } = null!; - - [MappingSource("titles")] - public List MovieTitleIdeas { get; set; } = null!; - - [MappingSource("movies")] - public List HistoricalMovies { get; set; } = null!; - - [MappingSource("moviesDict")] - public List OtherMovies { get; set; } = null!; - } - [Fact] public void ShouldMapComplexObjects() { @@ -208,7 +133,8 @@ public void ShouldMapComplexObjects() mappedObject.MovieTitleIdeas.Should().BeEquivalentTo("A Band Apart", "Amazing Squad", "Ten Men Named Ben"); mappedObject.HistoricalMovies.Should() - .BeEquivalentTo([ + .BeEquivalentTo( + [ new Movie { Title = "Forrest Gump", Released = 1994, Tagline = "Life is like a box of chocolates..." @@ -217,16 +143,19 @@ public void ShouldMapComplexObjects() { Title = "Cast Away", Released = 2000, Tagline = "At the edge of the world, his journey begins." }, - new Movie { Title = "The Green Mile", Released = 1999, Tagline = null }]); + new Movie { Title = "The Green Mile", Released = 1999, Tagline = null } + ]); mappedObject.OtherMovies.Should() - .BeEquivalentTo([ + .BeEquivalentTo( + [ new Movie { Title = "The Blind Venetian", Released = 2023, Tagline = "Read between the lines" }, new Movie { Title = "When The Night Ends", Released = 2022, Tagline = "Just when you thought it was safe to go to sleep" - }]); + } + ]); } [Fact] @@ -249,10 +178,12 @@ Task>> GetRecordsAsync() GetRecordsAsync() .AsObjectsAsync() .Result.Should() - .BeEquivalentTo([ + .BeEquivalentTo( + [ new TestPerson { Name = "Bob" }, new TestPerson { Name = "Alice", Born = 1988 }, - new TestPerson { Name = "Eve", Born = 1999 }]); + new TestPerson { Name = "Eve", Born = 1999 } + ]); } [Fact] @@ -275,10 +206,12 @@ Task>> GetRecordsAsync() GetRecordsAsync() .AsObjectsFromBlueprintAsync(new { name = "", born = 0 }) .Result.Should() - .BeEquivalentTo([ + .BeEquivalentTo( + [ new { name = "Bob", born = 1977 }, new { name = "Alice", born = 1988 }, - new { name = "Eve", born = 1999 }]); + new { name = "Eve", born = 1999 } + ]); } [Fact] @@ -301,10 +234,12 @@ async IAsyncEnumerable GetRecordsAsync() var result = await GetRecordsAsync().ToListAsync(); result.Should() - .BeEquivalentTo([ + .BeEquivalentTo( + [ new TestPerson { Name = "Bob" }, new TestPerson { Name = "Alice", Born = 1988 }, - new TestPerson { Name = "Eve", Born = 1999 }]); + new TestPerson { Name = "Eve", Born = 1999 } + ]); } [Fact] @@ -328,10 +263,12 @@ async IAsyncEnumerable GetRecordsAsync() var blueprint = new { name = "", born = 0 }; var result = await GetRecordsAsync().ToListFromBlueprintAsync(blueprint); result.Should() - .BeEquivalentTo([ + .BeEquivalentTo( + [ new { name = "Bob", born = 1977 }, new { name = "Alice", born = 1988 }, - new { name = "Eve", born = 1999 }]); + new { name = "Eve", born = 1999 } + ]); } [Fact] @@ -359,41 +296,12 @@ async IAsyncEnumerable GetRecordsAsync() } people.Should() - .BeEquivalentTo([ + .BeEquivalentTo( + [ new SimpleTestPerson { Name = "Bob" }, new SimpleTestPerson { Name = "Alice", Born = 1988 }, - new SimpleTestPerson { Name = "Eve", Born = 1999 }]); - } - - private class CarAndPainting - { - [MappingSource("car")] - public Car Car { get; set; } = null!; - - [MappingSource("painting")] - public Painting Painting { get; set; } = null!; - } - - private class Painting - { - [MappingSource("painting.artist")] - public string Artist { get; set; } = ""; - - [MappingSource("painting.title")] - public string Title { get; set; } = ""; - } - - private class Car - { - [MappingSource("car.make")] - public string Make { get; set; } = ""; - - [MappingSource("car.model")] - public string Model { get; set; } = ""; - - [MappingDefaultValue("unset")] - [MappingSource("car.madeup")] - public string MadeUp { get; set; } + new SimpleTestPerson { Name = "Eve", Born = 1999 } + ]); } [Fact] @@ -428,14 +336,6 @@ public void ShouldMapSubNodesWithAbsolutePaths() mappedObject.Car.MadeUp.Should().Be("unset"); } - private class PersonWithoutBornSetter - { - [MappingSource("name")] - public string Name { get; set; } = ""; - - public int? Born { get; } = 1999; // no setter - } - [Fact] public void DefaultMapperShouldIgnorePropertiesWithoutSetter() { @@ -445,15 +345,6 @@ public void DefaultMapperShouldIgnorePropertiesWithoutSetter() person.Born.Should().Be(1999); } - private class TestPersonWithoutBornMapped - { - [MappingSource("name")] - public string Name { get; set; } = "A. Test Name"; - - [MappingIgnored] - public int? Born { get; set; } = 9999; - } - [Fact] public void ShouldIgnorePropertiesWithDoNotMapAttribute() { @@ -463,21 +354,6 @@ public void ShouldIgnorePropertiesWithDoNotMapAttribute() person.Born.Should().Be(9999); } - private class Book - { - [MappingSource("title")] - public string Title { get; set; } - } - - private class Author - { - [MappingSource("author.name")] - public string Name { get; set; } - - [MappingSource("author.books")] - public List Books { get; set; } - } - [Fact] public void ShouldMapEntitiesWithListsOfNodes() { @@ -502,11 +378,6 @@ public void ShouldMapEntitiesWithListsOfNodes() mappedObject.Books[1].Title.Should().Be("The Thin End"); } - private record Song( - [MappingSource("recordingArtist")] string Artist, - [MappingSource("title")] string Title, - [MappingSource("year")] int Year); - [Fact] public void ShouldMapToRecords() { @@ -544,15 +415,6 @@ public void ShouldFailMappingToRecordsWithMissingFields() act.Should().Throw(); } - private class ClassWithInitProperties - { - [MappingSource("name")] - public string Name { get; init; } = ""; - - [MappingSource("age")] - public int Age { get; init; } - } - [Fact] public void ShouldMapToInitProperties() { @@ -562,12 +424,6 @@ public void ShouldMapToInitProperties() person.Age.Should().Be(1977); } - private class ClassWithDefaultConstructor(string forename, int age) - { - public string Name => forename; - public int Age => age; - } - [Fact] public void ShouldMapToDefaultConstructorParameters() { @@ -577,12 +433,6 @@ public void ShouldMapToDefaultConstructorParameters() person.Age.Should().Be(1977); } - private class ClassWithDefaultConstructorWithAttributes([MappingSource("forename")] string name, int age) - { - public string Name => name; - public int Age => age; - } - [Fact] public void ShouldMapToDefaultConstructorParametersWithAttributes() { @@ -653,10 +503,6 @@ public void ShouldMapToAnonymousTypeWithLambda() result.y.Should().Be("test"); } - private record TestXY(int X, string Y) - { - } - [Fact] public void ShouldMapToAnonymousTypeWithTypedLambda() { @@ -679,4 +525,172 @@ public void AsObject_ShouldMapRecordToObjectType() result.Should().BeOfType(expectedPerson.GetType()); result.Should().BeEquivalentTo(expectedPerson); } + + private class TestPerson + { + [MappingDefaultValue("A. Test Name")] + [MappingSource("person.name")] + public string Name { get; set; } + + [MappingOptional] + [MappingSource("person.born")] + public int? Born { get; set; } + + [MappingOptional] + [MappingSource("hobbies")] + public List Hobbies { get; } = null!; + } + + private class SimpleTestPerson + { + [MappingOptional] + [MappingSource("name")] + public string Name { get; set; } = "A. Test Name"; + + [MappingOptional] + [MappingSource("born")] + public int? Born { get; set; } + + [MappingOptional] + public List Hobbies { get; set; } = null!; + } + + private class PersonInDict + { + [MappingSource("person.name")] + public string Name { get; } = ""; + + [MappingSource("person.born")] + public int Born { get; set; } + } + + private class Movie + { + [MappingSource("title")] + public string Title { get; set; } = ""; + + [MappingSource("released")] + public int Released { get; set; } + + [MappingOptional] + [MappingSource("tagline")] + public string Tagline { get; set; } + } + + private class Person + { + [MappingSource("name")] + public string Name { get; } = ""; + + [MappingSource("born")] + public int? Born { get; set; } + } + + private class ProducingCareer + { + [MappingSource("person")] + public Person Producer { get; } = null!; + + [MappingSource("titles")] + public List MovieTitleIdeas { get; } = null!; + + [MappingSource("movies")] + public List HistoricalMovies { get; } = null!; + + [MappingSource("moviesDict")] + public List OtherMovies { get; } = null!; + } + + private class CarAndPainting + { + [MappingSource("car")] + public Car Car { get; } = null!; + + [MappingSource("painting")] + public Painting Painting { get; } = null!; + } + + private class Painting + { + [MappingSource("painting.artist")] + public string Artist { get; } = ""; + + [MappingSource("painting.title")] + public string Title { get; } = ""; + } + + private class Car + { + [MappingSource("car.make")] + public string Make { get; } = ""; + + [MappingSource("car.model")] + public string Model { get; } = ""; + + [MappingDefaultValue("unset")] + [MappingSource("car.madeup")] + public string MadeUp { get; set; } + } + + private class PersonWithoutBornSetter + { + [MappingSource("name")] + public string Name { get; } = ""; + + public int? Born { get; } = 1999; // no setter + } + + private class TestPersonWithoutBornMapped + { + [MappingSource("name")] + public string Name { get; } = "A. Test Name"; + + [MappingIgnored] + public int? Born { get; } = 9999; + } + + private class Book + { + [MappingSource("title")] + public string Title { get; set; } + } + + private class Author + { + [MappingSource("author.name")] + public string Name { get; set; } + + [MappingSource("author.books")] + public List Books { get; set; } + } + + private record Song( + [MappingSource("recordingArtist")] string Artist, + [MappingSource("title")] string Title, + [MappingSource("year")] int Year); + + private class ClassWithInitProperties + { + [MappingSource("name")] + public string Name { get; } = ""; + + [MappingSource("age")] + public int Age { get; init; } + } + + private class ClassWithDefaultConstructor(string forename, int age) + { + public string Name => forename; + public int Age => age; + } + + private class ClassWithDefaultConstructorWithAttributes([MappingSource("forename")] string name, int age) + { + public string Name => name; + public int Age => age; + } + + private record TestXY(int X, string Y) + { + } } diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Neo4j.Driver.Tests.csproj b/Neo4j.Driver/Neo4j.Driver.Tests/Neo4j.Driver.Tests.csproj index e14dd683f..a727e7cd4 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Neo4j.Driver.Tests.csproj +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Neo4j.Driver.Tests.csproj @@ -1,5 +1,5 @@  - + false Debug;Release;ReleaseSigned;DebugDelaySigned @@ -16,38 +16,38 @@ preview - - - - - - - - - - - + + + + + + + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + + - - - - - - - + + + + + + + - + diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/NodeTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/NodeTests.cs index f83e04906..c7753e3c4 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/NodeTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/NodeTests.cs @@ -55,4 +55,4 @@ public void ShouldEqualIfIdEquals() node1.Equals(node3).Should().BeTrue(); Equals(node1, node3).Should().BeTrue(); } -} \ No newline at end of file +} diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Reactive/Internal/InternalRxSessionTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Reactive/Internal/InternalRxSessionTests.cs index 37fe5a92b..330992822 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Reactive/Internal/InternalRxSessionTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Reactive/Internal/InternalRxSessionTests.cs @@ -114,8 +114,7 @@ public class BeginTransaction : AbstractRxTest public void ShouldReturnObservable() { var session = new Mock(); - session.Setup( - x => x.BeginTransactionAsync(It.IsAny>(), It.IsAny())) + session.Setup(x => x.BeginTransactionAsync(It.IsAny>(), It.IsAny())) .ReturnsAsync(Mock.Of()); var rxSession = new InternalRxSession(session.Object, Mock.Of()); diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Reactive/Utils/Utils.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Reactive/Utils/Utils.cs index bd6d460c2..e5e46d114 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Reactive/Utils/Utils.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Reactive/Utils/Utils.cs @@ -48,11 +48,12 @@ public static Func MatchesKeys(params string[] keys) public static Func MatchesRecord(string[] keys, params object[] fields) { - return Matches(rec => - { - rec.Keys.Should().BeEquivalentTo(keys); - rec.Values.Values.Should().BeEquivalentTo(fields); - }); + return Matches( + rec => + { + rec.Keys.Should().BeEquivalentTo(keys); + rec.Values.Values.Should().BeEquivalentTo(fields); + }); } public static Func MatchesSummary( diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/RelationshipTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/RelationshipTests.cs index e6a662963..6cc6cca17 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/RelationshipTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/RelationshipTests.cs @@ -44,4 +44,4 @@ public void ShouldEqualIfIdEquals() // TODO: The following test is currently not supported by Moq //rel1.GetHashCode().Should().Be(rel3.GetHashCode()); } -} \ No newline at end of file +} diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Result/RecordTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Result/RecordTests.cs index f70b641e1..49fb4d52f 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Result/RecordTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Result/RecordTests.cs @@ -82,10 +82,10 @@ public void TryGet_IsCaseSensitive() { _record.TryGet("Key1", out var value).Should().BeTrue(); value.Should().Be("Value1"); - _record.TryGet("KEY1", out _).Should().BeFalse(); + _record.TryGet("KEY1", out var _).Should().BeFalse(); _record.TryGet("Key2", out value).Should().BeTrue(); value.Should().Be("Value2"); - _record.TryGet("KEY2", out _).Should().BeFalse(); + _record.TryGet("KEY2", out var _).Should().BeFalse(); } [Fact] @@ -161,7 +161,7 @@ public void TryGetValue_ReturnsCorrectResult() var dictionary = _record as IReadOnlyDictionary; dictionary.TryGetValue("Key1", out var value).Should().BeTrue(); value.Should().Be("Value1"); - dictionary.TryGetValue("NonExistentKey", out _).Should().BeFalse(); + dictionary.TryGetValue("NonExistentKey", out var _).Should().BeFalse(); } [Fact] diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Result/ResultCursorBuilderTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Result/ResultCursorBuilderTests.cs index b35379c64..d298b0bc0 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Result/ResultCursorBuilderTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Result/ResultCursorBuilderTests.cs @@ -32,8 +32,14 @@ public class ResultCursorBuilderTests public void ShouldStartInRunRequestedStateRx() { var builder = - new ResultCursorBuilder(CreateSummaryBuilder(), CreateTaskQueue(), null, null, null, - 1000, true, + new ResultCursorBuilder( + CreateSummaryBuilder(), + CreateTaskQueue(), + null, + null, + null, + 1000, + true, new Mock().Object); builder.CurrentState.Should().Be(ResultCursorBuilder.State.RunRequested); @@ -43,8 +49,14 @@ public void ShouldStartInRunRequestedStateRx() public void ShouldStartInRunAndRecordsRequestedState() { var builder = - new ResultCursorBuilder(CreateSummaryBuilder(), CreateTaskQueue(), null, null, null, - 1000, false, + new ResultCursorBuilder( + CreateSummaryBuilder(), + CreateTaskQueue(), + null, + null, + null, + 1000, + false, new Mock().Object); builder.CurrentState.Should().Be(ResultCursorBuilder.State.RunAndRecordsRequested); @@ -54,7 +66,14 @@ public void ShouldStartInRunAndRecordsRequestedState() public void ShouldTransitionToRunCompletedWhenRunCompletedRx() { var builder = - new ResultCursorBuilder(CreateSummaryBuilder(), CreateTaskQueue(), null, null, null, 1000, true, + new ResultCursorBuilder( + CreateSummaryBuilder(), + CreateTaskQueue(), + null, + null, + null, + 1000, + true, new Mock().Object); builder.CurrentState.Should().Be(ResultCursorBuilder.State.RunRequested); @@ -67,7 +86,12 @@ public void ShouldTransitionToRunCompletedWhenRunCompletedRx() public void ShouldNotTransitionToRunCompletedWhenRunCompleted() { var builder = - new ResultCursorBuilder(CreateSummaryBuilder(), CreateTaskQueue(), null, null, null, + new ResultCursorBuilder( + CreateSummaryBuilder(), + CreateTaskQueue(), + null, + null, + null, 1000, false, new Mock().Object); @@ -82,7 +106,12 @@ public void ShouldNotTransitionToRunCompletedWhenRunCompleted() public void ShouldTransitionToRecordsStreamingStreamingWhenRecordIsPushedRx() { var builder = - new ResultCursorBuilder(CreateSummaryBuilder(), CreateTaskQueue(), null, null, null, + new ResultCursorBuilder( + CreateSummaryBuilder(), + CreateTaskQueue(), + null, + null, + null, 1000, true, new Mock().Object); @@ -100,7 +129,12 @@ public void ShouldTransitionToRecordsStreamingStreamingWhenRecordIsPushedRx() public void ShouldTransitionToRecordsStreamingStreamingWhenRecordIsPushed() { var builder = - new ResultCursorBuilder(CreateSummaryBuilder(), CreateTaskQueue(), null, null, null, + new ResultCursorBuilder( + CreateSummaryBuilder(), + CreateTaskQueue(), + null, + null, + null, 1000, false, new Mock().Object); @@ -118,7 +152,12 @@ public void ShouldTransitionToRecordsStreamingStreamingWhenRecordIsPushed() public void ShouldTransitionToRunCompletedWhenPullCompletedWithHasMore() { var builder = - new ResultCursorBuilder(CreateSummaryBuilder(), CreateTaskQueue(), null, null, null, + new ResultCursorBuilder( + CreateSummaryBuilder(), + CreateTaskQueue(), + null, + null, + null, 1000, false, new Mock().Object) @@ -134,7 +173,12 @@ public void ShouldTransitionToRunCompletedWhenPullCompletedWithHasMore() public void ShouldTransitionToCompletedWhenPullCompleted() { var builder = - new ResultCursorBuilder(CreateSummaryBuilder(), CreateTaskQueue(), null, null, null, + new ResultCursorBuilder( + CreateSummaryBuilder(), + CreateTaskQueue(), + null, + null, + null, 1000, false, new Mock().Object) @@ -454,10 +498,10 @@ public async Task ShouldReturnFirstBatchOfRecordsAndCancel() [Fact] public async Task ShouldThrowIfTranasactionTerminatedOnFetch() { - var expected = new ClientException("Neo.Broken.Db","it's broken!") as Exception; + var expected = new ClientException("Neo.Broken.Db", "it's broken!") as Exception; var mockTx = new Mock(); mockTx.Setup(x => x.IsErrored(out expected)).Returns(true).Verifiable(); - + var builder = new ResultCursorBuilder( CreateSummaryBuilder(), @@ -468,6 +512,7 @@ public async Task ShouldThrowIfTranasactionTerminatedOnFetch() 1000, true, mockTx.Object); + var cursor = builder.CreateCursor(); var exception = await Record.ExceptionAsync(() => cursor.FetchAsync()); diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Result/ResultTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Result/ResultTests.cs index 00c0d3dfe..94016e736 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Result/ResultTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Result/ResultTests.cs @@ -207,8 +207,7 @@ public IEnumerable Records { while (i == _records.Count) { - _output.WriteLine( - $"{DateTime.Now:HH:mm:ss.fff} -> Waiting for more Records"); + _output.WriteLine($"{DateTime.Now:HH:mm:ss.fff} -> Waiting for more Records"); Thread.Sleep(50); } @@ -229,8 +228,7 @@ public IEnumerable RecordsWithAutoLoad { while (i == _records.Count) { - _output.WriteLine( - $"{DateTime.Now:HH:mm:ss.fff} -> Waiting for more Records"); + _output.WriteLine($"{DateTime.Now:HH:mm:ss.fff} -> Waiting for more Records"); Thread.Sleep(500); AddNew(1); diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Routing/ClusterConnectionPoolTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Routing/ClusterConnectionPoolTests.cs index 328153a46..e45dbd6f9 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Routing/ClusterConnectionPoolTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Routing/ClusterConnectionPoolTests.cs @@ -110,7 +110,7 @@ public async Task ShouldReturnExistingConnectionPoolIfUriAlreadyExist() // Then connection.Should().NotBeNull(); var exception = - await Record.ExceptionAsync(() => connection.InitAsync(null)); + await Record.ExceptionAsync(() => connection.InitAsync()); mockedConnection.Verify( c => c.InitAsync(It.IsAny(), CancellationToken.None), diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Routing/ClusterDiscoveryTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Routing/ClusterDiscoveryTests.cs index 231e233a1..1bd58c2dc 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Routing/ClusterDiscoveryTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Routing/ClusterDiscoveryTests.cs @@ -75,10 +75,11 @@ public async Task ShouldParseRoutingTableResult() table.Readers.Should().BeEquivalentTo([new Uri("neo4j://localhost:7689")]); table.Writers.Should().BeEquivalentTo([new Uri("neo4j://anotherServer:7687")]); table.Routers.Should() - .BeEquivalentTo([ + .BeEquivalentTo( + [ new Uri("neo4j://localhost:7689"), new Uri("neo4j://anotherServer:7687") - ]); + ]); table.ExpireAfterSeconds.Should().Be(15000L); } diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Routing/LoadBalancerTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Routing/LoadBalancerTests.cs index 93291d912..9f97ec608 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Routing/LoadBalancerTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Routing/LoadBalancerTests.cs @@ -120,7 +120,14 @@ public async Task ShouldReturnConnectionWithCorrectMode(AccessMode mode) mockedConn.Setup(x => x.Mode).Returns(mode); var conn = mockedConn.Object; clusterPoolMock - .Setup(x => x.AcquireAsync(uri, mode, It.IsAny(), It.IsAny(), Bookmarks.Empty, false)) + .Setup( + x => x.AcquireAsync( + uri, + mode, + It.IsAny(), + It.IsAny(), + Bookmarks.Empty, + false)) .ReturnsAsync(conn); var balancer = new LoadBalancer(clusterPoolMock.Object, mock.Object); @@ -192,7 +199,12 @@ public void ShouldForgetServerWhenFailedToEstablishConn(AccessMode mode) var clusterConnPoolMock = new Mock(); clusterConnPoolMock.Setup( - x => x.AcquireAsync(uri, mode, It.IsAny(), It.IsAny(), Bookmarks.Empty, + x => x.AcquireAsync( + uri, + mode, + It.IsAny(), + It.IsAny(), + Bookmarks.Empty, false)) .Returns(Task.FromException(new ServiceUnavailableException("failed init"))); @@ -223,7 +235,12 @@ public async Task ShouldThrowErrorDirectlyIfSecurityError(AccessMode mode) var clusterConnPoolMock = new Mock(); clusterConnPoolMock.Setup( - x => x.AcquireAsync(uri, mode, It.IsAny(), It.IsAny(), Bookmarks.Empty, + x => x.AcquireAsync( + uri, + mode, + It.IsAny(), + It.IsAny(), + Bookmarks.Empty, false)) .Returns( Task.FromException( @@ -262,8 +279,14 @@ public void ShouldThrowErrorDirectlyIfProtocolError(AccessMode mode) var clusterConnPoolMock = new Mock(); clusterConnPoolMock - .Setup(x => x.AcquireAsync(uri, mode, It.IsAny(), It.IsAny(), Bookmarks.Empty, - false)) + .Setup( + x => x.AcquireAsync( + uri, + mode, + It.IsAny(), + It.IsAny(), + Bookmarks.Empty, + false)) .Returns(Task.FromException(new ProtocolException("do not understand struct 0x01"))); var balancer = new LoadBalancer(clusterConnPoolMock.Object, mock.Object); diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Routing/RoundRobinArrayIndexTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Routing/RoundRobinArrayIndexTests.cs index a8f51b81c..4dcb07533 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Routing/RoundRobinArrayIndexTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Routing/RoundRobinArrayIndexTests.cs @@ -61,4 +61,4 @@ public void ShouldHandleOverflow() roundRobinIndex.Next(arrayLength).Should().Be(1); roundRobinIndex.Next(arrayLength).Should().Be(2); } -} \ No newline at end of file +} diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Routing/RoutingTableManagerTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Routing/RoutingTableManagerTests.cs index e3b418446..8d8741718 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Routing/RoutingTableManagerTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Routing/RoutingTableManagerTests.cs @@ -283,8 +283,10 @@ public async Task ShouldForgetAndTryNextRouterWhenFailedWithConnectionError() // This ensures that uri and uri2 will return in order var routingTable = new RoutingTable(null, new List { uriA, uriB }); var poolManagerMock = new Mock(); - poolManagerMock.SetupSequence(x => x.CreateClusterConnectionAsync(It.IsAny(), - It.IsAny())) + poolManagerMock.SetupSequence( + x => x.CreateClusterConnectionAsync( + It.IsAny(), + It.IsAny())) .ReturnsAsync(connA) .ReturnsAsync(connB); @@ -380,8 +382,7 @@ public async Task ShouldPropagateInvalidBookmarkException() .ReturnsAsync(new Mock().Object); var discovery = new Mock(); - discovery.Setup( - x => x.DiscoverAsync(It.IsAny(), "", null, Bookmarks.From("Invalid bookmark"))) + discovery.Setup(x => x.DiscoverAsync(It.IsAny(), "", null, Bookmarks.From("Invalid bookmark"))) .Throws(error); var logger = new Mock(); @@ -420,8 +421,10 @@ public async Task ShouldTryNextRouterIfNoReader() var routingTable = new RoutingTable(null, new List { uriA, uriB }); var poolManagerMock = new Mock(); - poolManagerMock.SetupSequence(x => x.CreateClusterConnectionAsync(It.IsAny(), - It.IsAny())) + poolManagerMock.SetupSequence( + x => x.CreateClusterConnectionAsync( + It.IsAny(), + It.IsAny())) .ReturnsAsync(connA) .ReturnsAsync(connB); @@ -854,7 +857,8 @@ public async Task ShouldIsolateEntriesFromFailures() routingTable1.Should().Be(defaultRoutingTable); routingTable2.Should().Be(fooRoutingTable); - await manager.Awaiting(m => m.EnsureRoutingTableForModeAsync(AccessMode.Write, "bar", null, Bookmarks.Empty)) + await manager.Awaiting( + m => m.EnsureRoutingTableForModeAsync(AccessMode.Write, "bar", null, Bookmarks.Empty)) .Should() .ThrowAsync(); @@ -885,7 +889,6 @@ public async Task ShouldThrowOnFatalDiscovery() Mock.Of(), TimeSpan.MaxValue); - manager.Awaiting(m => m.EnsureRoutingTableForModeAsync(AccessMode.Write, "bar", null, Bookmarks.Empty)) .Should() .ThrowAsync() diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Routing/RoutingTableTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Routing/RoutingTableTests.cs index 52de13371..2a58c2b38 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Routing/RoutingTableTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Routing/RoutingTableTests.cs @@ -346,19 +346,23 @@ public void ShouldRemoveFromWritersOnly() routingTable.Database.Should().Be("foo"); routingTable.Routers.Should() - .BeEquivalentTo([ + .BeEquivalentTo( + [ new Uri("bolt://my-server-1"), new Uri("neo4j://my-server-2"), - new Uri("http://my-server-3")]); + new Uri("http://my-server-3") + ]); routingTable.Writers.Should() .BeEquivalentTo([new Uri("bolt://my-server-1"), new Uri("http://my-server-3")]); routingTable.Readers.Should() - .BeEquivalentTo([ + .BeEquivalentTo( + [ new Uri("bolt://my-server-1"), new Uri("neo4j://my-server-2"), - new Uri("http://my-server-3")]); + new Uri("http://my-server-3") + ]); routingTable.ExpireAfterSeconds.Should().Be(10); } @@ -406,10 +410,12 @@ public void ShouldUnionAll() routingTable.All() .Should() - .BeEquivalentTo([ + .BeEquivalentTo( + [ new Uri("bolt://my-server-1"), new Uri("neo4j://my-server-2"), - new Uri("http://my-server-3")]); + new Uri("http://my-server-3") + ]); } [Fact] diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/SessionConfigBuilderTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/SessionConfigBuilderTests.cs index 1f312a4de..a6349705b 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/SessionConfigBuilderTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/SessionConfigBuilderTests.cs @@ -14,7 +14,6 @@ // limitations under the License. using System; -using System.Collections.Generic; using FluentAssertions; using Neo4j.Driver.Internal.Types; using Xunit; @@ -116,7 +115,9 @@ public void WithNotifications_ShouldSetMultipleClassifications() { var configBuilder = new SessionConfigBuilder(new SessionConfig()); - configBuilder.WithNotifications(null, disabledClassifications: [Classification.Deprecation, Classification.Hint]); + configBuilder.WithNotifications( + null, + disabledClassifications: [Classification.Deprecation, Classification.Hint]); var config = configBuilder.Build() .NotificationsConfig.Should() diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/TestDriverContext.cs b/Neo4j.Driver/Neo4j.Driver.Tests/TestDriverContext.cs index 5cba8fe7c..d0f2bced7 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/TestDriverContext.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/TestDriverContext.cs @@ -22,7 +22,9 @@ internal static class TestDriverContext { static TestDriverContext() { - MockContext = new DriverContext(new Uri("bolt://localhost:7687"), AuthTokenManagers.None, + MockContext = new DriverContext( + new Uri("bolt://localhost:7687"), + AuthTokenManagers.None, new ConfigBuilder(new Config()).Build()); } diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/TestUtil/CollectionExtensionsTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/TestUtil/CollectionExtensionsTests.cs index 1af4a4899..23dc54651 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/TestUtil/CollectionExtensionsTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/TestUtil/CollectionExtensionsTests.cs @@ -308,8 +308,7 @@ public void ShouldHandleCollectionsOfArbitraryObjects() innerCollection.Should() .Contain( o => o is IDictionary && - ((IDictionary)o).Contains( - new KeyValuePair("Key1", "value1"))); + ((IDictionary)o).Contains(new KeyValuePair("Key1", "value1"))); } [Fact] @@ -464,4 +463,4 @@ IEnumerator IEnumerable.GetEnumerator() return GetEnumerator(); } } -} \ No newline at end of file +} diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/TestUtil/MockExtensionsTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/TestUtil/MockExtensionsTests.cs index 00747ef67..f51e3344f 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/TestUtil/MockExtensionsTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/TestUtil/MockExtensionsTests.cs @@ -21,11 +21,6 @@ namespace Neo4j.Driver.Tests.TestUtil; public class MockExtensionsTests { - public interface IntGetter - { - int Value { get; } - } - [Fact] public void ShouldSetupSequentialReturns() { @@ -36,4 +31,9 @@ public void ShouldSetupSequentialReturns() mock.Object.Value.Should().Be(2); mock.Object.Value.Should().Be(3); } + + public interface IntGetter + { + int Value { get; } + } } diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/TestUtil/TestRecord.cs b/Neo4j.Driver/Neo4j.Driver.Tests/TestUtil/TestRecord.cs index 1c51c254a..a7e3d0d1d 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/TestUtil/TestRecord.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/TestUtil/TestRecord.cs @@ -1,12 +1,12 @@ // Copyright (c) "Neo4j" // Neo4j Sweden AB [https://neo4j.com] -// +// // Licensed under the Apache License, Version 2.0 (the "License"). // You may not use this file except in compliance with the License. // You may obtain a copy of the License at -// +// // http://www.apache.org/licenses/LICENSE-2.0 -// +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/TransactionTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/TransactionTests.cs index 6d9bd0165..2292fe120 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/TransactionTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/TransactionTests.cs @@ -64,7 +64,9 @@ public async Task ShouldDelegateToProtocolBeginTxMethod() { var protocol = new Mock(); var mockConn = NewMockedConnection(protocol); - var tx = new AsyncTransaction(mockConn.Object, Mock.Of(), + var tx = new AsyncTransaction( + mockConn.Object, + Mock.Of(), NullLogger.Instance); await tx.BeginTransactionAsync( @@ -105,8 +107,11 @@ public async void ShouldDelegateToBoltProtocol() public async void ShouldThrowExceptionIfPreviousTxFailed() { var mockConn = new Mock(); - var tx = new AsyncTransaction(mockConn.Object, Mock.Of(), + var tx = new AsyncTransaction( + mockConn.Object, + Mock.Of(), NullLogger.Instance); + tx.TransactionError = new Exception(); await tx.MarkToCloseAsync(); @@ -119,8 +124,11 @@ public async void ShouldThrowExceptionIfFailedToRunAndFetchResult() { var mockProtocol = new Mock(); var mockConn = NewMockedConnection(mockProtocol); - var tx = new AsyncTransaction(mockConn.Object, Mock.Of(), + var tx = new AsyncTransaction( + mockConn.Object, + Mock.Of(), NullLogger.Instance); + var query = new Query("lala"); mockProtocol.Setup( @@ -188,8 +196,11 @@ public class MarkToClosedMethod public async Task ShouldNotEnqueueMoreMessagesAfterMarkToClosed() { var mockConn = NewMockedConnection(); - var tx = new AsyncTransaction(mockConn.Object, Mock.Of(), + var tx = new AsyncTransaction( + mockConn.Object, + Mock.Of(), NullLogger.Instance); + mockConn.Invocations.Clear(); await tx.MarkToCloseAsync(); @@ -202,8 +213,11 @@ public async Task ShouldNotEnqueueMoreMessagesAfterMarkToClosed() public async Task ShouldThrowExceptionToRunAfterMarkToClosed() { var mockConn = NewMockedConnection(); - var tx = new AsyncTransaction(mockConn.Object, Mock.Of(), + var tx = new AsyncTransaction( + mockConn.Object, + Mock.Of(), NullLogger.Instance); + mockConn.Invocations.Clear(); tx.TransactionError = new Exception(); await tx.MarkToCloseAsync(); @@ -220,8 +234,11 @@ public async Task ShouldThrowExceptionToRunAfterMarkToClosed() public async Task ShouldNotEnqueueMoreMessagesAfterMarkToClosedInCommitAsync() { var mockConn = NewMockedConnection(); - var tx = new AsyncTransaction(mockConn.Object, Mock.Of(), + var tx = new AsyncTransaction( + mockConn.Object, + Mock.Of(), NullLogger.Instance); + mockConn.Invocations.Clear(); tx.TransactionError = new Exception(); await tx.MarkToCloseAsync(); @@ -237,8 +254,11 @@ await tx.Awaiting(t => t.CommitAsync()) public async Task ShouldNotEnqueueMoreMessagesAfterMarkToClosedInRollbackAsync() { var mockConn = NewMockedConnection(); - var tx = new AsyncTransaction(mockConn.Object, Mock.Of(), + var tx = new AsyncTransaction( + mockConn.Object, + Mock.Of(), NullLogger.Instance); + mockConn.Invocations.Clear(); await tx.MarkToCloseAsync(); @@ -267,7 +287,9 @@ await tx.BeginTransactionAsync( public async Task ShouldBeOpenWhenRun() { var mockConn = NewMockedConnection(); - var tx = new AsyncTransaction(mockConn.Object, Mock.Of(), + var tx = new AsyncTransaction( + mockConn.Object, + Mock.Of(), NullLogger.Instance); await tx.BeginTransactionAsync( @@ -283,7 +305,9 @@ await tx.BeginTransactionAsync( public async Task ShouldBeClosedWhenFailed() { var mockConn = NewMockedConnection(); - var tx = new AsyncTransaction(mockConn.Object, Mock.Of(), + var tx = new AsyncTransaction( + mockConn.Object, + Mock.Of(), NullLogger.Instance); await tx.BeginTransactionAsync( @@ -299,7 +323,9 @@ await tx.BeginTransactionAsync( public async Task ShouldBeClosedWhenCommitted() { var mockConn = NewMockedConnection(); - var tx = new AsyncTransaction(mockConn.Object, Mock.Of(), + var tx = new AsyncTransaction( + mockConn.Object, + Mock.Of(), NullLogger.Instance); await tx.BeginTransactionAsync( @@ -315,7 +341,9 @@ await tx.BeginTransactionAsync( public async Task ShouldBeClosedWhenRollBacked() { var mockConn = NewMockedConnection(); - var tx = new AsyncTransaction(mockConn.Object, Mock.Of(), + var tx = new AsyncTransaction( + mockConn.Object, + Mock.Of(), NullLogger.Instance); await tx.BeginTransactionAsync( diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Types/DurationTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Types/DurationTests.cs index 32c934bcf..0502706b9 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Types/DurationTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Types/DurationTests.cs @@ -268,4 +268,4 @@ public void ShouldThrowWhenConversionIsNotSupported() testAction.Should().Throw(); } } -} \ No newline at end of file +} diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Types/LocalTimeTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Types/LocalTimeTests.cs index abcf11295..30eebd46a 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Types/LocalTimeTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Types/LocalTimeTests.cs @@ -310,4 +310,4 @@ public void ShouldThrowWhenConversionIsNotSupported() testAction.Should().Throw(); } } -} \ No newline at end of file +} diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Types/NotificationTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Types/NotificationTests.cs index 1b04cfa7c..070f6b5ad 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Types/NotificationTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Types/NotificationTests.cs @@ -32,25 +32,27 @@ public void ShouldSerialize() new InputPosition(0, 1, 2), "WARNING", "HINT"); - + var text = JsonConvert.SerializeObject(notification, Formatting.Indented).ReplaceLineEndings(); - - text.Should().BeEquivalentTo(""" - { - "RawSeverityLevel": "WARNING", - "SeverityLevel": 1, - "RawCategory": "HINT", - "Category": 1, - "Code": "code", - "Title": "title", - "Description": "description", - "Position": { - "Offset": 0, - "Line": 1, - "Column": 2 - }, - "Severity": "WARNING" - } - """.ReplaceLineEndings()); + + text.Should() + .BeEquivalentTo( + """ + { + "RawSeverityLevel": "WARNING", + "SeverityLevel": 1, + "RawCategory": "HINT", + "Category": 1, + "Code": "code", + "Title": "title", + "Description": "description", + "Position": { + "Offset": 0, + "Line": 1, + "Column": 2 + }, + "Severity": "WARNING" + } + """.ReplaceLineEndings()); } } diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Types/ZonedDateTimeWithOffsetTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Types/ZonedDateTimeWithOffsetTests.cs index 4f4a576ca..4a35a0851 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Types/ZonedDateTimeWithOffsetTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Types/ZonedDateTimeWithOffsetTests.cs @@ -467,4 +467,4 @@ public void ShouldCreateMaxZonedDateTimeFromComponents() var zone = new ZonedDateTime(999_999_999, 12, 31, 23, 59, 59, Zone.Of(0)); zone.UtcSeconds.Should().Be(TemporalHelpers.MaxUtcForZonedDateTime); } -} \ No newline at end of file +} diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Types/ZonedDateTimeWithZoneIdTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Types/ZonedDateTimeWithZoneIdTests.cs index 43f20e1a0..aa21d18ad 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Types/ZonedDateTimeWithZoneIdTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Types/ZonedDateTimeWithZoneIdTests.cs @@ -158,8 +158,7 @@ public void ShouldThrowOnInvalidSecond(int second) [InlineData(999_999_999 + 1)] public void ShouldThrowOnInvalidNanosecond(int nanosecond) { - var ex = Record.Exception( - () => new ZonedDateTime(1990, 1, 1, 0, 0, 0, nanosecond, Zone.Of("Europe/Athens"))); + var ex = Record.Exception(() => new ZonedDateTime(1990, 1, 1, 0, 0, 0, nanosecond, Zone.Of("Europe/Athens"))); ex.Should().NotBeNull().And.BeOfType(); } @@ -452,6 +451,7 @@ public void ShouldThrowExceptionWhenNonMonotonicTimeProvidedAndUnknownZoneId(Fun public void ShouldNotThrowExceptionWhenNonMonotonicTimeProvidedAndUnknownZoneId() { Record.Exception(() => new ZonedDateTime(new LocalDateTime(DateTime.Now), new ZoneId("Europe/Neo4j"))) - .Should().BeNull(); + .Should() + .BeNull(); } } diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/ValueExtensionsTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/ValueExtensionsTests.cs index a8be70b32..96c17b7db 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/ValueExtensionsTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/ValueExtensionsTests.cs @@ -351,7 +351,7 @@ public void ShouldConvertToPath() node.Properties["key1"].As().Should().Be("value1"); node.Properties["key2"].As().Should().Be("2"); - obj.As().Should().Be($"Path with 0 segments"); + obj.As().Should().Be("Path with 0 segments"); } } } From b44cada59369f6a46f1ac184606c154052ee4196 Mon Sep 17 00:00:00 2001 From: Grant Lodge <6323995+thelonelyvulpes@users.noreply.github.com> Date: Mon, 20 Jan 2025 17:57:14 +0000 Subject: [PATCH 3/6] integrations tests --- .../Direct/AuthenticationIT.cs | 2 +- .../Direct/BoltV4IT.cs | 12 ++++++------ .../Direct/CertificateTrustIT.cs | 2 +- .../Direct/EncryptionIT.cs | 2 +- .../Reactive/SummaryIT.cs | 19 ++++++++++--------- .../Mapping/DictAsRecordTests.cs | 2 +- 6 files changed, 20 insertions(+), 19 deletions(-) diff --git a/Neo4j.Driver/Neo4j.Driver.Tests.Integration/Direct/AuthenticationIT.cs b/Neo4j.Driver/Neo4j.Driver.Tests.Integration/Direct/AuthenticationIT.cs index f60a7dfad..09dc4ef16 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests.Integration/Direct/AuthenticationIT.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests.Integration/Direct/AuthenticationIT.cs @@ -92,6 +92,6 @@ private static async Task VerifyConnectivity(Uri address, IAuthToken token) var cursor = await session.RunAsync("RETURN 2 as Number"); var records = await cursor.ToListAsync(r => r["Number"].As()); - records.Should().BeEquivalentTo(2); + records.Should().BeEquivalentTo(new []{2}); } } diff --git a/Neo4j.Driver/Neo4j.Driver.Tests.Integration/Direct/BoltV4IT.cs b/Neo4j.Driver/Neo4j.Driver.Tests.Integration/Direct/BoltV4IT.cs index 45901ef25..0a82be957 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests.Integration/Direct/BoltV4IT.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests.Integration/Direct/BoltV4IT.cs @@ -156,7 +156,7 @@ public void ShouldThrowForNonExistentDatabase() { this.Awaiting(_ => VerifyDatabaseNameOnSummary("bar", "bar")) .Should() - .Throw() + .ThrowAsync() .WithMessage("*database does not exist.*"); } @@ -165,7 +165,7 @@ public void ShouldThrowForNonExistentDatabaseInTx() { this.Awaiting(_ => VerifyDatabaseNameOnSummaryTx("bar", "bar")) .Should() - .Throw() + .ThrowAsync() .WithMessage("*database does not exist.*"); } @@ -174,7 +174,7 @@ public void ShouldThrowForNonExistentDatabaseInTxFunc() { this.Awaiting(_ => VerifyDatabaseNameOnSummaryTxFunc("bar", "bar")) .Should() - .Throw() + .ThrowAsync() .WithMessage("*database does not exist.*"); } @@ -183,7 +183,7 @@ public void ShouldThrowWhenDatabaseIsSpecified() { this.Awaiting(_ => VerifyDatabaseNameOnSummary("bar", "bar")) .Should() - .Throw() + .ThrowAsync() .WithMessage("*to a server that does not support multiple databases.*"); } @@ -192,7 +192,7 @@ public void ShouldThrowWhenDatabaseIsSpecifiedInTx() { this.Awaiting(_ => VerifyDatabaseNameOnSummaryTx("bar", "bar")) .Should() - .Throw() + .ThrowAsync() .WithMessage("*to a server that does not support multiple databases.*"); } @@ -201,7 +201,7 @@ public void ShouldThrowWhenDatabaseIsSpecifiedInTxFunc() { this.Awaiting(_ => VerifyDatabaseNameOnSummaryTxFunc("bar", "bar")) .Should() - .Throw() + .ThrowAsync() .WithMessage("*to a server that does not support multiple databases.*"); } diff --git a/Neo4j.Driver/Neo4j.Driver.Tests.Integration/Direct/CertificateTrustIT.cs b/Neo4j.Driver/Neo4j.Driver.Tests.Integration/Direct/CertificateTrustIT.cs index 414fede8e..dcdcfa672 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests.Integration/Direct/CertificateTrustIT.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests.Integration/Direct/CertificateTrustIT.cs @@ -159,7 +159,7 @@ private async Task TestConnectivity(Uri target, Config config) var cursor = await session.RunAsync("RETURN 1"); var records = await cursor.ToListAsync(r => r[0].As()); - records.Should().BeEquivalentTo(1); + records.Should().BeEquivalentTo(new []{1}); } private IDriver SetupWithCustomResolver(Uri overridenUri, Config config) diff --git a/Neo4j.Driver/Neo4j.Driver.Tests.Integration/Direct/EncryptionIT.cs b/Neo4j.Driver/Neo4j.Driver.Tests.Integration/Direct/EncryptionIT.cs index e508f58ff..aa716624d 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests.Integration/Direct/EncryptionIT.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests.Integration/Direct/EncryptionIT.cs @@ -56,6 +56,6 @@ private static async Task VerifyConnectivity(IDriver driver) var cursor = await session.RunAsync("RETURN 2 as Number"); var records = await cursor.ToListAsync(r => r["Number"].As()); - records.Should().BeEquivalentTo(2); + records.Should().BeEquivalentTo(new []{2}); } } diff --git a/Neo4j.Driver/Neo4j.Driver.Tests.Integration/Reactive/SummaryIT.cs b/Neo4j.Driver/Neo4j.Driver.Tests.Integration/Reactive/SummaryIT.cs index 0b3a0f28f..a2f324241 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests.Integration/Reactive/SummaryIT.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests.Integration/Reactive/SummaryIT.cs @@ -17,6 +17,7 @@ using System.Linq; using System.Reactive.Linq; using FluentAssertions; +using FluentAssertions.Equivalency; using Microsoft.Reactive.Testing; using Neo4j.Driver.IntegrationTests.Internals; using Neo4j.Driver.Internal; @@ -236,9 +237,9 @@ public void ShouldReturnPlanButNoProfile() HasProfile = false, Profile = default(IProfiledPlan) }, - opts => opts.Excluding(x => x.SelectedMemberPath == "Plan.OperatorType") - .Excluding(x => x.SelectedMemberPath == "Plan.Arguments") - .Excluding(x => x.SelectedMemberPath == "Plan.Children"))); + opts => opts.Excluding(x => x.Path == "Plan.OperatorType") + .Excluding(x => x.Path == "Plan.Arguments") + .Excluding(x => x.Path == "Plan.Children"))); } [RequireServerFact("4.0.0", GreaterThanOrEqualTo)] @@ -271,9 +272,9 @@ public void ShouldReturnNotifications() } }, options => options.ExcludingMissingMembers() - .Excluding(x => x.SelectedMemberPath == "Notifications[0].Position") - .Excluding(x => x.SelectedMemberPath == "Notifications[0].Title") - .Excluding(x => x.SelectedMemberPath == "Notifications[0].Description"))); + .Excluding(x => x.Path == "Notifications[0].Position") + .Excluding(x => x.Path == "Notifications[0].Title") + .Excluding(x => x.Path == "Notifications[0].Description"))); } @@ -298,9 +299,9 @@ public void ShouldReturnNotificationsWithCategory() } }, options => options.ExcludingMissingMembers() - .Excluding(x => x.SelectedMemberPath == "Notifications[0].Position") - .Excluding(x => x.SelectedMemberPath == "Notifications[0].Title") - .Excluding(x => x.SelectedMemberPath == "Notifications[0].Description"))); + .Excluding(x => x.Path == "Notifications[0].Position") + .Excluding(x => x.Path == "Notifications[0].Title") + .Excluding(x => x.Path == "Notifications[0].Description"))); } private void VerifySummaryQueryTextAndParams(string query, object parameters) diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/DictAsRecordTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/DictAsRecordTests.cs index cf3c0b01c..3e9a18be2 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/DictAsRecordTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/DictAsRecordTests.cs @@ -263,7 +263,7 @@ public void IReadOnlyDict_CountShouldReturnCorrectCount() var subject = new DictAsRecord(dict, originalRecord); - subject.Count.Should().Be(2); + subject.Should().HaveCount(2); } [Fact] From 46683e2b7f4d564d5209aae8d4a696a4ffbf8bdf Mon Sep 17 00:00:00 2001 From: Grant Lodge <6323995+thelonelyvulpes@users.noreply.github.com> Date: Mon, 20 Jan 2025 19:21:20 +0000 Subject: [PATCH 4/6] fix tests that broke from reformat --- .../Mapping/RecordMappingTests.cs | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/RecordMappingTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/RecordMappingTests.cs index d4cbfd7cb..3ea2be225 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/RecordMappingTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/RecordMappingTests.cs @@ -538,7 +538,7 @@ private class TestPerson [MappingOptional] [MappingSource("hobbies")] - public List Hobbies { get; } = null!; + public List Hobbies { get; set; } = null!; } private class SimpleTestPerson @@ -558,7 +558,7 @@ private class SimpleTestPerson private class PersonInDict { [MappingSource("person.name")] - public string Name { get; } = ""; + public string Name { get; set; } = ""; [MappingSource("person.born")] public int Born { get; set; } @@ -580,7 +580,7 @@ private class Movie private class Person { [MappingSource("name")] - public string Name { get; } = ""; + public string Name { get; set; } = ""; [MappingSource("born")] public int? Born { get; set; } @@ -589,43 +589,43 @@ private class Person private class ProducingCareer { [MappingSource("person")] - public Person Producer { get; } = null!; + public Person Producer { get; set; } = null!; [MappingSource("titles")] - public List MovieTitleIdeas { get; } = null!; + public List MovieTitleIdeas { get; set; } = null!; [MappingSource("movies")] - public List HistoricalMovies { get; } = null!; + public List HistoricalMovies { get; set; } = null!; [MappingSource("moviesDict")] - public List OtherMovies { get; } = null!; + public List OtherMovies { get; set; } = null!; } private class CarAndPainting { [MappingSource("car")] - public Car Car { get; } = null!; + public Car Car { get; set; } = null!; [MappingSource("painting")] - public Painting Painting { get; } = null!; + public Painting Painting { get; set; } = null!; } private class Painting { [MappingSource("painting.artist")] - public string Artist { get; } = ""; + public string Artist { get; set; } = ""; [MappingSource("painting.title")] - public string Title { get; } = ""; + public string Title { get; set; } = ""; } private class Car { [MappingSource("car.make")] - public string Make { get; } = ""; + public string Make { get; set; } = ""; [MappingSource("car.model")] - public string Model { get; } = ""; + public string Model { get; set; } = ""; [MappingDefaultValue("unset")] [MappingSource("car.madeup")] @@ -635,7 +635,7 @@ private class Car private class PersonWithoutBornSetter { [MappingSource("name")] - public string Name { get; } = ""; + public string Name { get; set; } = ""; public int? Born { get; } = 1999; // no setter } @@ -643,10 +643,10 @@ private class PersonWithoutBornSetter private class TestPersonWithoutBornMapped { [MappingSource("name")] - public string Name { get; } = "A. Test Name"; + public string Name { get; set; } = "A. Test Name"; [MappingIgnored] - public int? Born { get; } = 9999; + public int? Born { get; set; } = 9999; } private class Book @@ -672,7 +672,7 @@ private record Song( private class ClassWithInitProperties { [MappingSource("name")] - public string Name { get; } = ""; + public string Name { get; init; } = ""; [MappingSource("age")] public int Age { get; init; } From f0ea0dd9604cfbda004d6ca269f3f6b1a9c9faf2 Mon Sep 17 00:00:00 2001 From: Grant Lodge <6323995+thelonelyvulpes@users.noreply.github.com> Date: Mon, 20 Jan 2025 21:28:53 +0000 Subject: [PATCH 5/6] fix missed unit tests --- .../Neo4j.Driver.Tests/Mapping/DefaultMapperTests.cs | 2 +- .../Neo4j.Driver.Tests/Mapping/MappingProviderTests.cs | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/DefaultMapperTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/DefaultMapperTests.cs index 8c54e0228..206abcc4f 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/DefaultMapperTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/DefaultMapperTests.cs @@ -224,7 +224,7 @@ public void ShouldThrowIfClassHasNoConstructors() private class SimpleClass { public int Id { get; set; } - public string Name { get; } = null!; + public string Name { get; set; } = null!; } private class ConstructorClass diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/MappingProviderTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/MappingProviderTests.cs index c0485905f..86446f927 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/MappingProviderTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Mapping/MappingProviderTests.cs @@ -124,7 +124,7 @@ private class TestObject public int IntValue { get; set; } [MappingSource("stringValue")] - public string Text { get; } = null!; + public string Text { get; set; } = null!; } private class SecondTestObject @@ -135,14 +135,14 @@ private class SecondTestObject private class ThirdTestObject { - public int IntValue { get; } = -1; - public string StringValue { get; } = "unset"; + public int IntValue { get; set; } = -1; + public string StringValue { get; set; } = "unset"; } private class PersonWithAge { [MappingSource("name")] - public string Name { get; } = null!; + public string Name { get; set; } = null!; [MappingOptional] public int Age { get; set; } @@ -228,7 +228,7 @@ private string GetTranslatedPropertyName(string fieldName) private class NameAndGuid { - public string Name { get; } = null!; + public string Name { get; set; } = null!; public Guid Guid { get; set; } } From 56a1ca6ff36471327136dd203ce1fffd4ed2f938 Mon Sep 17 00:00:00 2001 From: Grant Lodge <6323995+thelonelyvulpes@users.noreply.github.com> Date: Mon, 20 Jan 2025 21:46:21 +0000 Subject: [PATCH 6/6] fix integration tests --- .../Direct/SessionIT.cs | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/Neo4j.Driver/Neo4j.Driver.Tests.Integration/Direct/SessionIT.cs b/Neo4j.Driver/Neo4j.Driver.Tests.Integration/Direct/SessionIT.cs index bce89d73e..de12bb4cc 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests.Integration/Direct/SessionIT.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests.Integration/Direct/SessionIT.cs @@ -59,9 +59,9 @@ public async Task DisallowNewSessionAfterDriverDispose() } // Then - var error = Record.Exception(() => driver.AsyncSession()); - error.Should() - .BeOfType() + var createSession = () => driver.AsyncSession(); + createSession.Should() + .Throw() .Which .Message.Should() .Contain("Cannot open a new session on a driver that is already disposed."); @@ -77,12 +77,12 @@ public async Task DisallowRunInSessionAfterDriverDispose() driver.Dispose(); - var error = await Record.ExceptionAsync(() => session.RunAsync("RETURN 1")); - error.Should() - .BeOfType() - .Which - .Message.Should() - .StartWith("Failed to acquire a new connection as the driver has already been disposed."); + await session.Awaiting(x => x.RunAsync("RETURN 1")) + .Should() + .ThrowAsync() + .Where( + x => x.Message.StartsWith( + "Failed to acquire a new connection as the driver has already been disposed.")); await session.CloseAsync(); } @@ -126,9 +126,11 @@ public async Task TheSessionErrorShouldBeClearedForEachSession() { await using (var session = Driver.AsyncSession()) { - var ex = await Record.ExceptionAsync(() => session.RunAndConsumeAsync("Invalid Cypher")); + var exc = await session.Awaiting(x => x.RunAndConsumeAsync("Invalid Cypher")) + .Should() + .ThrowAsync(); - ex.Should().BeOfType().Which.Code.Should().Be("Neo.ClientError.Statement.SyntaxError"); + exc.Which.Code.Should().Be("Neo.ClientError.Statement.SyntaxError"); } await using (var session = Driver.AsyncSession())