Skip to content

Commit fbd5b48

Browse files
Add transaction configuration constructors; add test to ensure it can be used with ExecutableQuery (#857)
* Add transaction configuration constructor with optional parameters, add test to ensure it can be used with ExecutableQuery * Make Metadata setter public to allow external modification of transaction metadata
1 parent 38af605 commit fbd5b48

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

Neo4j.Driver/Neo4j.Driver.Tests/ExecutableQuery/ExecutableQueryTests.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,10 +453,33 @@ await subject
453453
.BeEquivalentTo(person);
454454
}
455455

456-
457456
public class Person
458457
{
459458
public string Name { get; set; }
460459
public int Age { get; set; }
461460
}
461+
462+
[Fact]
463+
public async Task ShouldGetCorrectTransactionConfig()
464+
{
465+
var tc = new TransactionConfig(timeout: TimeSpan.FromSeconds(10));
466+
467+
var qc = new QueryConfig(transactionConfig: tc);
468+
var autoMock = new AutoMocker(MockBehavior.Loose);
469+
var driverMock = autoMock.GetMock<IDriverRowSource<int>>();
470+
471+
driverMock
472+
.Setup(x => x.GetRowsAsync(It.IsAny<Action<int>>(), It.IsAny<CancellationToken>()))
473+
.ReturnsAsync(new ExecutionSummary(null, null));
474+
475+
TransactionConfig configPassed = null;
476+
driverMock
477+
.Setup(x => x.SetConfig(It.IsAny<QueryConfig>()))
478+
.Callback<QueryConfig>(qc => configPassed = qc.TransactionConfig);
479+
480+
var subject = new ExecutableQuery<int, int>(driverMock.Object, i => i);
481+
await subject.WithConfig(qc).ExecuteAsync();
482+
483+
configPassed.Should().Be(tc);
484+
}
462485
}

Neo4j.Driver/Neo4j.Driver/Public/TransactionConfig.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ public sealed class TransactionConfig
2929
private IDictionary<string, object> _metadata = new Dictionary<string, object>();
3030
private TimeSpan? _timeout;
3131

32+
// constructor with two optional parameters
33+
public TransactionConfig(IDictionary<string, object> metadata = null, TimeSpan? timeout = null)
34+
{
35+
Metadata = metadata ?? new Dictionary<string, object>();
36+
Timeout = timeout;
37+
}
38+
3239
/// <summary>
3340
/// Transaction timeout. Transactions that execute longer than the configured timeout will be terminated by the
3441
/// database. This functionality allows user code to limit query/transaction execution time. The specified timeout
@@ -47,7 +54,7 @@ public sealed class TransactionConfig
4754
public TimeSpan? Timeout
4855
{
4956
get => _timeout;
50-
internal set
57+
set
5158
{
5259
if (!value.HasValue || value.Value == TimeSpan.MaxValue)
5360
{
@@ -84,7 +91,7 @@ internal set
8491
public IDictionary<string, object> Metadata
8592
{
8693
get => _metadata;
87-
internal set => _metadata =
94+
set => _metadata =
8895
value ?? throw new ArgumentNullException(nameof(value), "Transaction metadata should not be null");
8996
}
9097

0 commit comments

Comments
 (0)