11using EphemeralMongo ;
2+ using MongoDB . Bson ;
3+ using MongoDB . Bson . Serialization ;
4+ using MongoDB . Bson . Serialization . Serializers ;
25
36namespace TestBuildingBlocks ;
47
58// Based on https://gist.github.com/asimmon/612b2d54f1a0d2b4e1115590d456e0be.
69internal sealed class MongoRunnerProvider
710{
811 public static readonly MongoRunnerProvider Instance = new ( ) ;
12+ private static readonly GuidSerializer StandardGuidSerializer = new ( GuidRepresentation . Standard ) ;
913
1014#if NET8_0
1115 private readonly object _lockObject = new ( ) ;
@@ -26,11 +30,13 @@ public IMongoRunner Get()
2630 {
2731 if ( _runner == null )
2832 {
33+ BsonSerializer . TryRegisterSerializer ( StandardGuidSerializer ) ;
34+
2935 var runnerOptions = new MongoRunnerOptions
3036 {
3137 // Single-node replica set mode is required for transaction support in MongoDB.
3238 UseSingleNodeReplicaSet = true ,
33- AdditionalArguments = "--quiet"
39+ AdditionalArguments = [ "--quiet" ]
3440 } ;
3541
3642 _runner = MongoRunner . Run ( runnerOptions ) ;
@@ -65,18 +71,36 @@ private sealed class MongoRunnerWrapper(MongoRunnerProvider owner, IMongoRunner
6571
6672 public string ConnectionString => _underlyingMongoRunner ? . ConnectionString ?? throw new ObjectDisposedException ( nameof ( IMongoRunner ) ) ;
6773
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 )
6992 {
7093 ObjectDisposedException . ThrowIf ( _underlyingMongoRunner == null , this ) ;
7194
72- _underlyingMongoRunner . Import ( database , collection , inputFilePath , additionalArguments , drop ) ;
95+ _underlyingMongoRunner . Export ( database , collection , outputFilePath , additionalArguments , cancellationToken ) ;
7396 }
7497
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 )
76100 {
77101 ObjectDisposedException . ThrowIf ( _underlyingMongoRunner == null , this ) ;
78102
79- _underlyingMongoRunner . Export ( database , collection , outputFilePath , additionalArguments ) ;
103+ await _underlyingMongoRunner . ExportAsync ( database , collection , outputFilePath , additionalArguments , cancellationToken ) ;
80104 }
81105
82106 public void Dispose ( )
0 commit comments