Skip to content

Fluent assertions lock 7.0 #836

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: 5.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>());

records.Should().BeEquivalentTo(2);
records.Should().BeEquivalentTo(new []{2});
}
}
12 changes: 6 additions & 6 deletions Neo4j.Driver/Neo4j.Driver.Tests.Integration/Direct/BoltV4IT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public void ShouldThrowForNonExistentDatabase()
{
this.Awaiting(_ => VerifyDatabaseNameOnSummary("bar", "bar"))
.Should()
.Throw<ClientException>()
.ThrowAsync<ClientException>()
.WithMessage("*database does not exist.*");
}

Expand All @@ -165,7 +165,7 @@ public void ShouldThrowForNonExistentDatabaseInTx()
{
this.Awaiting(_ => VerifyDatabaseNameOnSummaryTx("bar", "bar"))
.Should()
.Throw<ClientException>()
.ThrowAsync<ClientException>()
.WithMessage("*database does not exist.*");
}

Expand All @@ -174,7 +174,7 @@ public void ShouldThrowForNonExistentDatabaseInTxFunc()
{
this.Awaiting(_ => VerifyDatabaseNameOnSummaryTxFunc("bar", "bar"))
.Should()
.Throw<ClientException>()
.ThrowAsync<ClientException>()
.WithMessage("*database does not exist.*");
}

Expand All @@ -183,7 +183,7 @@ public void ShouldThrowWhenDatabaseIsSpecified()
{
this.Awaiting(_ => VerifyDatabaseNameOnSummary("bar", "bar"))
.Should()
.Throw<ClientException>()
.ThrowAsync<ClientException>()
.WithMessage("*to a server that does not support multiple databases.*");
}

Expand All @@ -192,7 +192,7 @@ public void ShouldThrowWhenDatabaseIsSpecifiedInTx()
{
this.Awaiting(_ => VerifyDatabaseNameOnSummaryTx("bar", "bar"))
.Should()
.Throw<ClientException>()
.ThrowAsync<ClientException>()
.WithMessage("*to a server that does not support multiple databases.*");
}

Expand All @@ -201,7 +201,7 @@ public void ShouldThrowWhenDatabaseIsSpecifiedInTxFunc()
{
this.Awaiting(_ => VerifyDatabaseNameOnSummaryTxFunc("bar", "bar"))
.Should()
.Throw<ClientException>()
.ThrowAsync<ClientException>()
.WithMessage("*to a server that does not support multiple databases.*");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>());

records.Should().BeEquivalentTo(1);
records.Should().BeEquivalentTo(new []{1});
}

private IDriver SetupWithCustomResolver(Uri overridenUri, Config config)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>());

records.Should().BeEquivalentTo(2);
records.Should().BeEquivalentTo(new []{2});
}
}
24 changes: 13 additions & 11 deletions Neo4j.Driver/Neo4j.Driver.Tests.Integration/Direct/SessionIT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ public async Task DisallowNewSessionAfterDriverDispose()
}

// Then
var error = Record.Exception(() => driver.AsyncSession());
error.Should()
.BeOfType<ObjectDisposedException>()
var createSession = () => driver.AsyncSession();
createSession.Should()
.Throw<ObjectDisposedException>()
.Which
.Message.Should()
.Contain("Cannot open a new session on a driver that is already disposed.");
Expand All @@ -77,12 +77,12 @@ public async Task DisallowRunInSessionAfterDriverDispose()

driver.Dispose();

var error = await Record.ExceptionAsync(() => session.RunAsync("RETURN 1"));
error.Should()
.BeOfType<ObjectDisposedException>()
.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<ObjectDisposedException>()
.Where(
x => x.Message.StartsWith(
"Failed to acquire a new connection as the driver has already been disposed."));

await session.CloseAsync();
}
Expand Down Expand Up @@ -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<ClientException>();

ex.Should().BeOfType<ClientException>().Which.Code.Should().Be("Neo.ClientError.Statement.SyntaxError");
exc.Which.Code.Should().Be("Neo.ClientError.Statement.SyntaxError");
}

await using (var session = Driver.AsyncSession())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<ItemGroup>
<Content Include="App.config" />
<PackageReference Include="Castle.Core" Version="5.1.1" />
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="FluentAssertions" Version="[7.0.0]" />
<PackageReference Include="Microsoft.Reactive.Testing" Version="5.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
<PackageReference Include="Moq" Version="4.20.69" />
Expand Down
19 changes: 10 additions & 9 deletions Neo4j.Driver/Neo4j.Driver.Tests.Integration/Reactive/SummaryIT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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")));
}


Expand All @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions Neo4j.Driver/Neo4j.Driver.Tests/AsyncSessionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ internal static Mock<IConnection> MockedConnectionWithSuccessResponse(IBoltProto
It.IsAny<IRequestMessage>(),
It.IsAny<IResponseHandler>()))
.Returns(Task.CompletedTask)
.Callback(
(IRequestMessage _, IResponseHandler h1) => { h1.OnSuccess(new Dictionary<string, object>()); });
.Callback((IRequestMessage _, IResponseHandler h1) => { h1.OnSuccess(new Dictionary<string, object>()); });

if (protocol == null)
{
Expand Down Expand Up @@ -299,7 +298,9 @@ public async void PipelinedShouldBeginWithoutBlocking()
false,
false);

await session.PipelinedExecuteReadAsync(_ => Task.FromResult(null as EagerResult<IRecord[]>), new TransactionConfig());
await session.PipelinedExecuteReadAsync(
_ => Task.FromResult(null as EagerResult<IRecord[]>),
new TransactionConfig());

mockProtocol.Verify(
x =>
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -44,7 +42,8 @@ public async Task ShouldCacheToken()
{
var (authData, _) = GetTwoAuthTokens();

int callCount = 0;
var callCount = 0;

ValueTask<AuthTokenAndExpiration> TokenProvider()
{
callCount++;
Expand Down
2 changes: 1 addition & 1 deletion Neo4j.Driver/Neo4j.Driver.Tests/BookmarkTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,4 @@ public void ShouldUnionValues(string[] values1, string[] values2, string[] value
}
}
}
}
}
4 changes: 2 additions & 2 deletions Neo4j.Driver/Neo4j.Driver.Tests/ConfigTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion Neo4j.Driver/Neo4j.Driver.Tests/ConnectionPoolTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -291,6 +291,7 @@ private Mock<IConnectionValidator> MockValidator(Action<Mock<IConnectionValidato
validator.Setup(x => x.GetConnectionLifetimeStatus(It.IsAny<IPooledConnection>()))
.Returns(AcquireStatus.Healthy);
}

return validator;
}

Expand Down
34 changes: 18 additions & 16 deletions Neo4j.Driver/Neo4j.Driver.Tests/ConnectionValidatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IPooledConnection> conn, Mock<ITimer> idle, Mock<ITimer> life) Mock()
{
var conn = new Mock<IPooledConnection>();
conn.Setup(x => x.Version).Returns(BoltProtocolVersion.V5_1);

var idleTimer = new Mock<ITimer>();
var lifeTimer = new Mock<ITimer>();

conn.Setup(x => x.IdleTimer).Returns(idleTimer.Object);
conn.Setup(x => x.LifetimeTimer).Returns(lifeTimer.Object);
return (conn, idleTimer, lifeTimer);
}

public class IsConnectionReusableTests
Expand Down Expand Up @@ -131,17 +146,4 @@ public void ShouldRequireLiveness()
idleTimer.Verify(x => x.Reset(), Times.Once);
}
}

private static (Mock<IPooledConnection> conn, Mock<ITimer> idle, Mock<ITimer> life) Mock()
{
var conn = new Mock<IPooledConnection>();
conn.Setup(x => x.Version).Returns(BoltProtocolVersion.V5_1);

var idleTimer = new Mock<ITimer>();
var lifeTimer = new Mock<ITimer>();

conn.Setup(x => x.IdleTimer).Returns(idleTimer.Object);
conn.Setup(x => x.LifetimeTimer).Returns(lifeTimer.Object);
return (conn, idleTimer, lifeTimer);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,4 @@ internal static SuccessMessage SuccessMessage(IDictionary<string, object> fields
? new SuccessMessage(new Dictionary<string, object>())
: new SuccessMessage(fields);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private static (Mock<ITcpSocketClient>, Mock<IConnectionIoFactory>) CreateMockIo
mockIoFactory
.Setup(x => x.TcpSocketClient(It.IsAny<DriverContext>(), It.IsAny<ILogger>()))
.Returns(connMock.Object);

configureFactory?.Invoke(mockIoFactory);

return (connMock, mockIoFactory);
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -337,4 +336,4 @@ public async Task ShouldCallDisconnectAsyncOnTheTcpSocketClientWhenStoppedAsync(
client.IsOpen.Should().BeFalse();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,13 @@ public async Task ShouldConnectClient()
var bpFactory = new Mock<IBoltProtocolFactory>();
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);
Expand All @@ -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<IOException>();
error.Message.Should().Be("I will stop socket conn from initialization");
Expand Down Expand Up @@ -227,7 +229,7 @@ public async Task ShouldEnqueueBoth()
var h1 = new Mock<IResponseHandler>();
var m2 = new Mock<IRequestMessage>();
var h2 = new Mock<IResponseHandler>();

await con.EnqueueAsync(m1.Object, h1.Object, m2.Object, h2.Object);

con.Messages[0].Should().Be(m1.Object);
Expand Down
Loading