Skip to content

Commit a63cdc6

Browse files
Update code base remove warnings. (#685)
* remove warnings. * few more tidyings
1 parent 04861d6 commit a63cdc6

File tree

109 files changed

+1945
-4567
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+1945
-4567
lines changed

Neo4j.Driver/Neo4j.Driver.Tests.Integration/Direct/AuthenticationIT.cs

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@
1919
using System.Collections.Generic;
2020
using System.Threading.Tasks;
2121
using FluentAssertions;
22+
using Neo4j.Driver.IntegrationTests.Internals;
2223
using Neo4j.Driver.Internal;
2324
using Xunit;
2425
using Xunit.Abstractions;
2526

2627
namespace Neo4j.Driver.IntegrationTests.Direct;
2728

28-
public class AuthenticationIT : DirectDriverTestBase
29+
public sealed class AuthenticationIT : DirectDriverTestBase
2930
{
3031
public AuthenticationIT(ITestOutputHelper output, StandAloneIntegrationTestFixture fixture)
3132
: base(output, fixture)
@@ -35,24 +36,15 @@ public AuthenticationIT(ITestOutputHelper output, StandAloneIntegrationTestFixtu
3536
[RequireServerFact]
3637
public async Task AuthenticationErrorIfWrongAuthToken()
3738
{
38-
using (var driver = GraphDatabase.Driver(ServerEndPoint, AuthTokens.Basic("fake", "fake")))
39-
{
40-
var session = driver.AsyncSession();
41-
try
42-
{
43-
var exc = await Record.ExceptionAsync(() => session.RunAsync("Return 1"));
39+
await using var driver = GraphDatabase.Driver(ServerEndPoint, AuthTokens.Basic("fake", "fake"));
40+
await using var session = driver.AsyncSession();
41+
var exc = await Record.ExceptionAsync(() => session.RunAsync("Return 1"));
4442

45-
exc.Should()
46-
.BeOfType<AuthenticationException>()
47-
.Which
48-
.Message.Should()
49-
.Contain("The client is unauthorized due to authentication failure.");
50-
}
51-
finally
52-
{
53-
await session.CloseAsync();
54-
}
55-
}
43+
exc.Should()
44+
.BeOfType<AuthenticationException>()
45+
.Which
46+
.Message.Should()
47+
.Contain("The client is unauthorized due to authentication failure.");
5648
}
5749

5850
[RequireServerFact]
@@ -96,21 +88,12 @@ public async Task ShouldCreateCustomAuthTokenWithAdditionalParameters()
9688

9789
private static async Task VerifyConnectivity(Uri address, IAuthToken token)
9890
{
99-
using (var driver = GraphDatabase.Driver(address, token))
100-
{
101-
var session = driver.AsyncSession();
91+
await using var driver = GraphDatabase.Driver(address, token);
92+
await using var session = driver.AsyncSession();
10293

103-
try
104-
{
105-
var cursor = await session.RunAsync("RETURN 2 as Number");
106-
var records = await cursor.ToListAsync(r => r["Number"].As<int>());
94+
var cursor = await session.RunAsync("RETURN 2 as Number");
95+
var records = await cursor.ToListAsync(r => r["Number"].As<int>());
10796

108-
records.Should().BeEquivalentTo(2);
109-
}
110-
finally
111-
{
112-
await session.CloseAsync();
113-
}
114-
}
97+
records.Should().BeEquivalentTo(2);
11598
}
11699
}

Neo4j.Driver/Neo4j.Driver.Tests.Integration/Direct/BoltV4IT.cs

Lines changed: 30 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,17 @@
1515
// See the License for the specific language governing permissions and
1616
// limitations under the License.
1717

18-
using System;
1918
using System.Threading.Tasks;
2019
using FluentAssertions;
2120
using Neo4j.Driver.IntegrationTests.Internals;
2221
using Neo4j.Driver.Internal.Util;
2322
using Xunit.Abstractions;
24-
using static Neo4j.Driver.IntegrationTests.VersionComparison;
25-
using static Neo4j.Driver.IntegrationTests.DatabaseExtensions;
23+
using static Neo4j.Driver.IntegrationTests.Internals.VersionComparison;
24+
using static Neo4j.Driver.IntegrationTests.Extensions.DatabaseExtensions;
2625

2726
namespace Neo4j.Driver.IntegrationTests.Direct;
2827

29-
public class BoltV4IT : DirectDriverTestBase
28+
public sealed class BoltV4IT : DirectDriverTestBase
3029
{
3130
public BoltV4IT(ITestOutputHelper output, StandAloneIntegrationTestFixture fixture)
3231
: base(output, fixture)
@@ -122,7 +121,7 @@ public async Task ShouldReturnDatabaseInfoForDefaultDatabaseInTxFunc()
122121
[RequireServerFact("4.0.0", GreaterThanOrEqualTo)]
123122
public async Task ShouldReturnDatabaseInfoForDefaultDatabaseWhenSpecifiedInTxFunc()
124123
{
125-
Console.WriteLine($"Version = {ServerVersion.From(BoltkitHelper.ServerVersion())}");
124+
Output.WriteLine($"Version = {ServerVersion.From(BoltkitHelper.ServerVersion())}");
126125
await VerifyDatabaseNameOnSummaryTxFunc("neo4j", "neo4j");
127126
}
128127

@@ -210,83 +209,49 @@ public void ShouldThrowWhenDatabaseIsSpecifiedInTxFunc()
210209

211210
private async Task VerifyDatabaseNameOnSummary(string name, string expected)
212211
{
213-
var session = Server.Driver.AsyncSession(
214-
o =>
215-
{
216-
if (!string.IsNullOrEmpty(name))
217-
{
218-
o.WithDatabase(name);
219-
}
220-
});
212+
await using var session = Server.Driver.AsyncSession(o => { ConfigureDb(o, name); });
221213

222-
try
223-
{
224-
var cursor = await session.RunAsync("RETURN 1");
225-
var summary = await cursor.ConsumeAsync();
214+
var cursor = await session.RunAsync("RETURN 1");
215+
var summary = await cursor.ConsumeAsync();
226216

227-
summary.Database.Should().NotBeNull();
228-
summary.Database.Name.Should().Be(expected);
229-
}
230-
finally
231-
{
232-
await session.CloseAsync();
233-
}
217+
summary.Database.Should().NotBeNull();
218+
summary.Database.Name.Should().Be(expected);
234219
}
235220

236221
private async Task VerifyDatabaseNameOnSummaryTx(string name, string expected)
237222
{
238-
var session = Server.Driver.AsyncSession(
239-
o =>
240-
{
241-
if (!string.IsNullOrEmpty(name))
242-
{
243-
o.WithDatabase(name);
244-
}
245-
});
223+
await using var session = Server.Driver.AsyncSession(o => { ConfigureDb(o, name); });
246224

247-
try
248-
{
249-
var txc = await session.BeginTransactionAsync();
250-
var cursor = await txc.RunAsync("RETURN 1");
251-
var summary = await cursor.ConsumeAsync();
225+
var txc = await session.BeginTransactionAsync();
226+
var cursor = await txc.RunAsync("RETURN 1");
227+
var summary = await cursor.ConsumeAsync();
252228

253-
summary.Database.Should().NotBeNull();
254-
summary.Database.Name.Should().Be(expected);
229+
summary.Database.Should().NotBeNull();
230+
summary.Database.Name.Should().Be(expected);
255231

256-
await txc.CommitAsync();
257-
}
258-
finally
232+
await txc.CommitAsync();
233+
}
234+
235+
private static void ConfigureDb(SessionConfigBuilder o, string name)
236+
{
237+
if (!string.IsNullOrEmpty(name))
259238
{
260-
await session.CloseAsync();
239+
o.WithDatabase(name);
261240
}
262241
}
263242

264243
private async Task VerifyDatabaseNameOnSummaryTxFunc(string name, string expected)
265244
{
266-
var session = Server.Driver.AsyncSession(
267-
o =>
245+
await using var session = Server.Driver.AsyncSession(o => { ConfigureDb(o, name); });
246+
247+
var summary = await session.ExecuteReadAsync(
248+
async txc =>
268249
{
269-
if (!string.IsNullOrEmpty(name))
270-
{
271-
o.WithDatabase(name);
272-
}
250+
var cursor = await txc.RunAsync("RETURN 1");
251+
return await cursor.ConsumeAsync();
273252
});
274253

275-
try
276-
{
277-
var summary = await session.ReadTransactionAsync(
278-
async txc =>
279-
{
280-
var cursor = await txc.RunAsync("RETURN 1");
281-
return await cursor.ConsumeAsync();
282-
});
283-
284-
summary.Database.Should().NotBeNull();
285-
summary.Database.Name.Should().Be(expected);
286-
}
287-
finally
288-
{
289-
await session.CloseAsync();
290-
}
254+
summary.Database.Should().NotBeNull();
255+
summary.Database.Name.Should().Be(expected);
291256
}
292257
}

Neo4j.Driver/Neo4j.Driver.Tests.Integration/Direct/BookmarkIT.cs

Lines changed: 33 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,14 @@
1717

1818
using System.Threading.Tasks;
1919
using FluentAssertions;
20+
using Neo4j.Driver.IntegrationTests.Internals;
2021
using Xunit;
2122
using Xunit.Abstractions;
2223

2324
namespace Neo4j.Driver.IntegrationTests.Direct;
2425

25-
public class BookmarkIT : DirectDriverTestBase
26+
public sealed class BookmarkIT : DirectDriverTestBase
2627
{
27-
private const string BookmarkHeader = "neo4j:bookmark:v1:tx";
28-
2928
public BookmarkIT(ITestOutputHelper output, StandAloneIntegrationTestFixture fixture) : base(output, fixture)
3029
{
3130
}
@@ -35,81 +34,60 @@ public BookmarkIT(ITestOutputHelper output, StandAloneIntegrationTestFixture fix
3534
[RequireServerFact("3.1.0", VersionComparison.GreaterThanOrEqualTo)]
3635
public async Task ShouldContainLastBookmarkAfterTx()
3736
{
38-
var session = Driver.AsyncSession();
37+
await using var session = Driver.AsyncSession();
3938

40-
try
41-
{
42-
session.LastBookmark.Should().BeNull();
39+
session.LastBookmarks.Should().BeNull();
4340

44-
await CreateNodeInTx(session, 1);
41+
await CreateNodeInTx(session, 1);
4542

46-
session.LastBookmark.Should().NotBeNull();
47-
session.LastBookmark.Values.Should().NotBeEmpty();
48-
}
49-
finally
50-
{
51-
await session.CloseAsync();
52-
}
43+
session.LastBookmarks.Should().NotBeNull();
44+
session.LastBookmarks.Values.Should().NotBeEmpty();
5345
}
5446

5547
[RequireServerFact("3.1.0", VersionComparison.GreaterThanOrEqualTo)]
5648
public async Task BookmarkUnchangedAfterRolledBackTx()
5749
{
58-
var session = Driver.AsyncSession();
59-
try
60-
{
61-
await CreateNodeInTx(session, 1);
50+
await using var session = Driver.AsyncSession();
51+
await CreateNodeInTx(session, 1);
6252

63-
var bookmark = session.LastBookmark;
64-
bookmark.Should().NotBeNull();
65-
bookmark.Values.Should().NotBeEmpty();
53+
var bookmark = session.LastBookmarks;
54+
bookmark.Should().NotBeNull();
55+
bookmark.Values.Should().NotBeEmpty();
6656

67-
var tx = await session.BeginTransactionAsync();
68-
try
69-
{
70-
await tx.RunAsync("CREATE (a:Person)");
71-
}
72-
finally
73-
{
74-
await tx.RollbackAsync();
75-
}
76-
77-
session.LastBookmark.Should().Be(bookmark);
57+
var tx = await session.BeginTransactionAsync();
58+
try
59+
{
60+
await tx.RunAsync("CREATE (a:Person)");
7861
}
7962
finally
8063
{
81-
await session.CloseAsync();
64+
await tx.RollbackAsync();
8265
}
66+
67+
session.LastBookmarks.Should().Be(bookmark);
8368
}
8469

8570
[RequireServerFact("3.1.0", VersionComparison.GreaterThanOrEqualTo)]
8671
public async Task BookmarkUnchangedAfterTxFailure()
8772
{
88-
var session = Driver.AsyncSession();
89-
try
90-
{
91-
await CreateNodeInTx(session, 1);
73+
await using var session = Driver.AsyncSession();
74+
await CreateNodeInTx(session, 1);
9275

93-
var bookmark = session.LastBookmark;
94-
bookmark.Should().NotBeNull();
95-
bookmark.Values.Should().NotBeEmpty();
76+
var bookmark = session.LastBookmarks;
77+
bookmark.Should().NotBeNull();
78+
bookmark.Values.Should().NotBeEmpty();
9679

97-
var tx = await session.BeginTransactionAsync();
98-
var exc = await Record.ExceptionAsync(
99-
async () =>
100-
{
101-
await tx.RunAsync("RETURN");
102-
await tx.CommitAsync();
103-
});
80+
var tx = await session.BeginTransactionAsync();
81+
var exc = await Record.ExceptionAsync(
82+
async () =>
83+
{
84+
await tx.RunAsync("RETURN");
85+
await tx.CommitAsync();
86+
});
10487

105-
exc.Should().BeOfType<ClientException>();
88+
exc.Should().BeOfType<ClientException>();
10689

107-
session.LastBookmark.Should().Be(bookmark);
108-
}
109-
finally
110-
{
111-
await session.CloseAsync();
112-
}
90+
session.LastBookmarks.Should().Be(bookmark);
11391
}
11492

11593
private static async Task CreateNodeInTx(IAsyncSession session, int id)
@@ -126,29 +104,4 @@ private static async Task CreateNodeInTx(IAsyncSession session, int id)
126104
throw;
127105
}
128106
}
129-
130-
private static async Task<int> CountNodeInTx(IDriver driver, int id, Bookmarks bookmarks = null)
131-
{
132-
var session = driver.AsyncSession(o => o.WithBookmarks(bookmarks));
133-
try
134-
{
135-
var tx = await session.BeginTransactionAsync();
136-
try
137-
{
138-
var cursor = await tx.RunAsync("MATCH (a:Person {id: $id}) RETURN a", new { id });
139-
var records = await cursor.ToListAsync();
140-
await tx.CommitAsync();
141-
return records.Count;
142-
}
143-
catch
144-
{
145-
await tx.RollbackAsync();
146-
throw;
147-
}
148-
}
149-
finally
150-
{
151-
await session.CloseAsync();
152-
}
153-
}
154107
}

0 commit comments

Comments
 (0)