1
1
using EphemeralMongo ;
2
+ using MongoDB . Bson ;
3
+ using MongoDB . Bson . Serialization ;
4
+ using MongoDB . Bson . Serialization . Serializers ;
2
5
3
6
namespace TestBuildingBlocks ;
4
7
5
8
// Based on https://gist.github.com/asimmon/612b2d54f1a0d2b4e1115590d456e0be.
6
9
internal sealed class MongoRunnerProvider
7
10
{
8
11
public static readonly MongoRunnerProvider Instance = new ( ) ;
12
+ private static readonly GuidSerializer StandardGuidSerializer = new ( GuidRepresentation . Standard ) ;
9
13
10
14
#if NET8_0
11
15
private readonly object _lockObject = new ( ) ;
@@ -26,11 +30,13 @@ public IMongoRunner Get()
26
30
{
27
31
if ( _runner == null )
28
32
{
33
+ BsonSerializer . TryRegisterSerializer ( StandardGuidSerializer ) ;
34
+
29
35
var runnerOptions = new MongoRunnerOptions
30
36
{
31
37
// Single-node replica set mode is required for transaction support in MongoDB.
32
38
UseSingleNodeReplicaSet = true ,
33
- AdditionalArguments = "--quiet"
39
+ AdditionalArguments = [ "--quiet" ]
34
40
} ;
35
41
36
42
_runner = MongoRunner . Run ( runnerOptions ) ;
@@ -65,18 +71,36 @@ private sealed class MongoRunnerWrapper(MongoRunnerProvider owner, IMongoRunner
65
71
66
72
public string ConnectionString => _underlyingMongoRunner ? . ConnectionString ?? throw new ObjectDisposedException ( nameof ( IMongoRunner ) ) ;
67
73
68
- public void Import ( string database , string collection , string inputFilePath , string ? additionalArguments = null , bool drop = false )
74
+ public void Import ( string database , string collection , string inputFilePath , string [ ] ? additionalArguments = null , bool drop = false ,
75
+ CancellationToken cancellationToken = default )
76
+ {
77
+ ObjectDisposedException . ThrowIf ( _underlyingMongoRunner == null , this ) ;
78
+
79
+ _underlyingMongoRunner . Import ( database , collection , inputFilePath , additionalArguments , drop , cancellationToken ) ;
80
+ }
81
+
82
+ public async Task ImportAsync ( string database , string collection , string inputFilePath , string [ ] ? additionalArguments = null , bool drop = false ,
83
+ CancellationToken cancellationToken = default )
84
+ {
85
+ ObjectDisposedException . ThrowIf ( _underlyingMongoRunner == null , this ) ;
86
+
87
+ await _underlyingMongoRunner . ImportAsync ( database , collection , inputFilePath , additionalArguments , drop , cancellationToken ) ;
88
+ }
89
+
90
+ public void Export ( string database , string collection , string outputFilePath , string [ ] ? additionalArguments = null ,
91
+ CancellationToken cancellationToken = default )
69
92
{
70
93
ObjectDisposedException . ThrowIf ( _underlyingMongoRunner == null , this ) ;
71
94
72
- _underlyingMongoRunner . Import ( database , collection , inputFilePath , additionalArguments , drop ) ;
95
+ _underlyingMongoRunner . Export ( database , collection , outputFilePath , additionalArguments , cancellationToken ) ;
73
96
}
74
97
75
- public void Export ( string database , string collection , string outputFilePath , string ? additionalArguments = null )
98
+ public async Task ExportAsync ( string database , string collection , string outputFilePath , string [ ] ? additionalArguments = null ,
99
+ CancellationToken cancellationToken = default )
76
100
{
77
101
ObjectDisposedException . ThrowIf ( _underlyingMongoRunner == null , this ) ;
78
102
79
- _underlyingMongoRunner . Export ( database , collection , outputFilePath , additionalArguments ) ;
103
+ await _underlyingMongoRunner . ExportAsync ( database , collection , outputFilePath , additionalArguments , cancellationToken ) ;
80
104
}
81
105
82
106
public void Dispose ( )
0 commit comments