-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve tests & result builder classes
1. Added tests for Session#RunAsync, Session#BeginTransactionAsync and Session#Dispose after async calls, 2. Added tests for Transaction#RunAsync, 3. Improved ResultBuilder & ResultReaderBuilder with a new base class including common members from both classes, 4. Added tests for ResultReaderBuilder & StatementResultReader, 5. Added Session#BeginTransactionAsync(string bookmark) method.
- Loading branch information
Showing
10 changed files
with
1,168 additions
and
441 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
153 changes: 153 additions & 0 deletions
153
Neo4j.Driver/Neo4j.Driver.Tests/Result/ResultReaderBuilderTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
// Copyright (c) 2002-2017 "Neo Technology," | ||
// Network Engine for Objects in Lund AB [http://neotechnology.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. | ||
// 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.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using FluentAssertions; | ||
using Neo4j.Driver.Internal.Result; | ||
using Neo4j.Driver.V1; | ||
using Xunit; | ||
|
||
namespace Neo4j.Driver.Tests | ||
{ | ||
public class ResultReaderBuilderTests | ||
{ | ||
private static ResultReaderBuilder GenerateBuilder(IDictionary<string, object> meta = null) | ||
{ | ||
var builder = new ResultReaderBuilder(); | ||
builder.CollectFields(meta ?? new Dictionary<string, object> { { "fields", new List<object> { "x" } } }); | ||
return builder; | ||
} | ||
|
||
private static Task AssertGetExpectResults(IStatementResultReader reader, int numberExpected, List<object> exspectedRecordsValues = null) | ||
{ | ||
int count = 0; | ||
var t = Task.Factory.StartNew(async () => | ||
{ | ||
// ReSharper disable once LoopCanBeConvertedToQuery | ||
while (await reader.ReadAsync()) | ||
{ | ||
if (exspectedRecordsValues != null) | ||
{ | ||
reader.Current().Values.First().Value.Should().Be(exspectedRecordsValues[count]); | ||
} | ||
count++; | ||
} | ||
count.Should().Be(numberExpected); | ||
}); | ||
return t; | ||
} | ||
|
||
public class CollectRecordMethod | ||
{ | ||
[Fact] | ||
public void ShouldStreamResults() | ||
{ | ||
var builder = GenerateBuilder(); | ||
var i = 0; | ||
builder.SetReceiveOneAction(() => | ||
{ | ||
if (i++ >= 3) | ||
{ | ||
builder.CollectSummary(null); | ||
} | ||
else | ||
{ | ||
builder.CollectRecord(new object[] {123 + i}); | ||
} | ||
return Task.CompletedTask; | ||
}); | ||
var result = builder.PreBuild(); | ||
|
||
var t = AssertGetExpectResults(result, 3, new List<object> {124, 125, 126}); | ||
|
||
t.Wait(); | ||
} | ||
|
||
[Fact] | ||
public void ShouldReturnNoResultsWhenNoneRecieved() | ||
{ | ||
var builder = GenerateBuilder(); | ||
builder.SetReceiveOneAction(() => | ||
{ | ||
builder.CollectSummary(null); | ||
return Task.CompletedTask; | ||
}); | ||
var result = builder.PreBuild(); | ||
|
||
var t = AssertGetExpectResults(result, 0); | ||
|
||
t.Wait(); | ||
} | ||
|
||
[Fact] | ||
public void ShouldReturnQueuedResultsWithExspectedValue() | ||
{ | ||
var builder = GenerateBuilder(); | ||
List<object> recordValues = new List<object> | ||
{ | ||
1, | ||
"Hello", | ||
false, | ||
10 | ||
}; | ||
for (int i = 0; i < recordValues.Count; i++) | ||
{ | ||
builder.CollectRecord(new[] { recordValues[i] }); | ||
} | ||
builder.CollectSummary(null); | ||
|
||
var result = builder.PreBuild(); | ||
|
||
var task = AssertGetExpectResults(result, recordValues.Count, recordValues); | ||
task.Wait(); | ||
} | ||
} | ||
|
||
public class InvalidateResultMethod | ||
{ | ||
[Fact] | ||
public void ShouldStopStreamingWhenResultIsInvalid() | ||
{ | ||
var builder = GenerateBuilder(); | ||
var i = 0; | ||
builder.SetReceiveOneAction(() => | ||
{ | ||
if (i++ >= 3) | ||
{ | ||
builder.DoneFailure(); | ||
} | ||
else | ||
{ | ||
builder.CollectRecord(new object[] {123 + i}); | ||
} | ||
return Task.CompletedTask; | ||
}); | ||
var result = builder.PreBuild(); | ||
|
||
var t = AssertGetExpectResults(result, 3, new List<object> { 124, 125, 126 }); | ||
t.Wait(); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.