Skip to content

Commit

Permalink
Update code base remove warnings. (#685)
Browse files Browse the repository at this point in the history
* remove warnings.
* few more tidyings
  • Loading branch information
thelonelyvulpes authored Feb 22, 2023
1 parent 04861d6 commit a63cdc6
Show file tree
Hide file tree
Showing 109 changed files with 1,945 additions and 4,567 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using FluentAssertions;
using Neo4j.Driver.IntegrationTests.Internals;
using Neo4j.Driver.Internal;
using Xunit;
using Xunit.Abstractions;

namespace Neo4j.Driver.IntegrationTests.Direct;

public class AuthenticationIT : DirectDriverTestBase
public sealed class AuthenticationIT : DirectDriverTestBase
{
public AuthenticationIT(ITestOutputHelper output, StandAloneIntegrationTestFixture fixture)
: base(output, fixture)
Expand All @@ -35,24 +36,15 @@ public AuthenticationIT(ITestOutputHelper output, StandAloneIntegrationTestFixtu
[RequireServerFact]
public async Task AuthenticationErrorIfWrongAuthToken()
{
using (var driver = GraphDatabase.Driver(ServerEndPoint, AuthTokens.Basic("fake", "fake")))
{
var session = driver.AsyncSession();
try
{
var exc = await Record.ExceptionAsync(() => session.RunAsync("Return 1"));
await using var driver = GraphDatabase.Driver(ServerEndPoint, AuthTokens.Basic("fake", "fake"));
await using var session = driver.AsyncSession();
var exc = await Record.ExceptionAsync(() => session.RunAsync("Return 1"));

exc.Should()
.BeOfType<AuthenticationException>()
.Which
.Message.Should()
.Contain("The client is unauthorized due to authentication failure.");
}
finally
{
await session.CloseAsync();
}
}
exc.Should()
.BeOfType<AuthenticationException>()
.Which
.Message.Should()
.Contain("The client is unauthorized due to authentication failure.");
}

[RequireServerFact]
Expand Down Expand Up @@ -96,21 +88,12 @@ public async Task ShouldCreateCustomAuthTokenWithAdditionalParameters()

private static async Task VerifyConnectivity(Uri address, IAuthToken token)
{
using (var driver = GraphDatabase.Driver(address, token))
{
var session = driver.AsyncSession();
await using var driver = GraphDatabase.Driver(address, token);
await using var session = driver.AsyncSession();

try
{
var cursor = await session.RunAsync("RETURN 2 as Number");
var records = await cursor.ToListAsync(r => r["Number"].As<int>());
var cursor = await session.RunAsync("RETURN 2 as Number");
var records = await cursor.ToListAsync(r => r["Number"].As<int>());

records.Should().BeEquivalentTo(2);
}
finally
{
await session.CloseAsync();
}
}
records.Should().BeEquivalentTo(2);
}
}
95 changes: 30 additions & 65 deletions Neo4j.Driver/Neo4j.Driver.Tests.Integration/Direct/BoltV4IT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,17 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using System;
using System.Threading.Tasks;
using FluentAssertions;
using Neo4j.Driver.IntegrationTests.Internals;
using Neo4j.Driver.Internal.Util;
using Xunit.Abstractions;
using static Neo4j.Driver.IntegrationTests.VersionComparison;
using static Neo4j.Driver.IntegrationTests.DatabaseExtensions;
using static Neo4j.Driver.IntegrationTests.Internals.VersionComparison;
using static Neo4j.Driver.IntegrationTests.Extensions.DatabaseExtensions;

namespace Neo4j.Driver.IntegrationTests.Direct;

public class BoltV4IT : DirectDriverTestBase
public sealed class BoltV4IT : DirectDriverTestBase
{
public BoltV4IT(ITestOutputHelper output, StandAloneIntegrationTestFixture fixture)
: base(output, fixture)
Expand Down Expand Up @@ -122,7 +121,7 @@ public async Task ShouldReturnDatabaseInfoForDefaultDatabaseInTxFunc()
[RequireServerFact("4.0.0", GreaterThanOrEqualTo)]
public async Task ShouldReturnDatabaseInfoForDefaultDatabaseWhenSpecifiedInTxFunc()
{
Console.WriteLine($"Version = {ServerVersion.From(BoltkitHelper.ServerVersion())}");
Output.WriteLine($"Version = {ServerVersion.From(BoltkitHelper.ServerVersion())}");
await VerifyDatabaseNameOnSummaryTxFunc("neo4j", "neo4j");
}

Expand Down Expand Up @@ -210,83 +209,49 @@ public void ShouldThrowWhenDatabaseIsSpecifiedInTxFunc()

private async Task VerifyDatabaseNameOnSummary(string name, string expected)
{
var session = Server.Driver.AsyncSession(
o =>
{
if (!string.IsNullOrEmpty(name))
{
o.WithDatabase(name);
}
});
await using var session = Server.Driver.AsyncSession(o => { ConfigureDb(o, name); });

try
{
var cursor = await session.RunAsync("RETURN 1");
var summary = await cursor.ConsumeAsync();
var cursor = await session.RunAsync("RETURN 1");
var summary = await cursor.ConsumeAsync();

summary.Database.Should().NotBeNull();
summary.Database.Name.Should().Be(expected);
}
finally
{
await session.CloseAsync();
}
summary.Database.Should().NotBeNull();
summary.Database.Name.Should().Be(expected);
}

private async Task VerifyDatabaseNameOnSummaryTx(string name, string expected)
{
var session = Server.Driver.AsyncSession(
o =>
{
if (!string.IsNullOrEmpty(name))
{
o.WithDatabase(name);
}
});
await using var session = Server.Driver.AsyncSession(o => { ConfigureDb(o, name); });

try
{
var txc = await session.BeginTransactionAsync();
var cursor = await txc.RunAsync("RETURN 1");
var summary = await cursor.ConsumeAsync();
var txc = await session.BeginTransactionAsync();
var cursor = await txc.RunAsync("RETURN 1");
var summary = await cursor.ConsumeAsync();

summary.Database.Should().NotBeNull();
summary.Database.Name.Should().Be(expected);
summary.Database.Should().NotBeNull();
summary.Database.Name.Should().Be(expected);

await txc.CommitAsync();
}
finally
await txc.CommitAsync();
}

private static void ConfigureDb(SessionConfigBuilder o, string name)
{
if (!string.IsNullOrEmpty(name))
{
await session.CloseAsync();
o.WithDatabase(name);
}
}

private async Task VerifyDatabaseNameOnSummaryTxFunc(string name, string expected)
{
var session = Server.Driver.AsyncSession(
o =>
await using var session = Server.Driver.AsyncSession(o => { ConfigureDb(o, name); });

var summary = await session.ExecuteReadAsync(
async txc =>
{
if (!string.IsNullOrEmpty(name))
{
o.WithDatabase(name);
}
var cursor = await txc.RunAsync("RETURN 1");
return await cursor.ConsumeAsync();
});

try
{
var summary = await session.ReadTransactionAsync(
async txc =>
{
var cursor = await txc.RunAsync("RETURN 1");
return await cursor.ConsumeAsync();
});

summary.Database.Should().NotBeNull();
summary.Database.Name.Should().Be(expected);
}
finally
{
await session.CloseAsync();
}
summary.Database.Should().NotBeNull();
summary.Database.Name.Should().Be(expected);
}
}
113 changes: 33 additions & 80 deletions Neo4j.Driver/Neo4j.Driver.Tests.Integration/Direct/BookmarkIT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@

using System.Threading.Tasks;
using FluentAssertions;
using Neo4j.Driver.IntegrationTests.Internals;
using Xunit;
using Xunit.Abstractions;

namespace Neo4j.Driver.IntegrationTests.Direct;

public class BookmarkIT : DirectDriverTestBase
public sealed class BookmarkIT : DirectDriverTestBase
{
private const string BookmarkHeader = "neo4j:bookmark:v1:tx";

public BookmarkIT(ITestOutputHelper output, StandAloneIntegrationTestFixture fixture) : base(output, fixture)
{
}
Expand All @@ -35,81 +34,60 @@ public BookmarkIT(ITestOutputHelper output, StandAloneIntegrationTestFixture fix
[RequireServerFact("3.1.0", VersionComparison.GreaterThanOrEqualTo)]
public async Task ShouldContainLastBookmarkAfterTx()
{
var session = Driver.AsyncSession();
await using var session = Driver.AsyncSession();

try
{
session.LastBookmark.Should().BeNull();
session.LastBookmarks.Should().BeNull();

await CreateNodeInTx(session, 1);
await CreateNodeInTx(session, 1);

session.LastBookmark.Should().NotBeNull();
session.LastBookmark.Values.Should().NotBeEmpty();
}
finally
{
await session.CloseAsync();
}
session.LastBookmarks.Should().NotBeNull();
session.LastBookmarks.Values.Should().NotBeEmpty();
}

[RequireServerFact("3.1.0", VersionComparison.GreaterThanOrEqualTo)]
public async Task BookmarkUnchangedAfterRolledBackTx()
{
var session = Driver.AsyncSession();
try
{
await CreateNodeInTx(session, 1);
await using var session = Driver.AsyncSession();
await CreateNodeInTx(session, 1);

var bookmark = session.LastBookmark;
bookmark.Should().NotBeNull();
bookmark.Values.Should().NotBeEmpty();
var bookmark = session.LastBookmarks;
bookmark.Should().NotBeNull();
bookmark.Values.Should().NotBeEmpty();

var tx = await session.BeginTransactionAsync();
try
{
await tx.RunAsync("CREATE (a:Person)");
}
finally
{
await tx.RollbackAsync();
}

session.LastBookmark.Should().Be(bookmark);
var tx = await session.BeginTransactionAsync();
try
{
await tx.RunAsync("CREATE (a:Person)");
}
finally
{
await session.CloseAsync();
await tx.RollbackAsync();
}

session.LastBookmarks.Should().Be(bookmark);
}

[RequireServerFact("3.1.0", VersionComparison.GreaterThanOrEqualTo)]
public async Task BookmarkUnchangedAfterTxFailure()
{
var session = Driver.AsyncSession();
try
{
await CreateNodeInTx(session, 1);
await using var session = Driver.AsyncSession();
await CreateNodeInTx(session, 1);

var bookmark = session.LastBookmark;
bookmark.Should().NotBeNull();
bookmark.Values.Should().NotBeEmpty();
var bookmark = session.LastBookmarks;
bookmark.Should().NotBeNull();
bookmark.Values.Should().NotBeEmpty();

var tx = await session.BeginTransactionAsync();
var exc = await Record.ExceptionAsync(
async () =>
{
await tx.RunAsync("RETURN");
await tx.CommitAsync();
});
var tx = await session.BeginTransactionAsync();
var exc = await Record.ExceptionAsync(
async () =>
{
await tx.RunAsync("RETURN");
await tx.CommitAsync();
});

exc.Should().BeOfType<ClientException>();
exc.Should().BeOfType<ClientException>();

session.LastBookmark.Should().Be(bookmark);
}
finally
{
await session.CloseAsync();
}
session.LastBookmarks.Should().Be(bookmark);
}

private static async Task CreateNodeInTx(IAsyncSession session, int id)
Expand All @@ -126,29 +104,4 @@ private static async Task CreateNodeInTx(IAsyncSession session, int id)
throw;
}
}

private static async Task<int> CountNodeInTx(IDriver driver, int id, Bookmarks bookmarks = null)
{
var session = driver.AsyncSession(o => o.WithBookmarks(bookmarks));
try
{
var tx = await session.BeginTransactionAsync();
try
{
var cursor = await tx.RunAsync("MATCH (a:Person {id: $id}) RETURN a", new { id });
var records = await cursor.ToListAsync();
await tx.CommitAsync();
return records.Count;
}
catch
{
await tx.RollbackAsync();
throw;
}
}
finally
{
await session.CloseAsync();
}
}
}
Loading

0 comments on commit a63cdc6

Please sign in to comment.