|
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 |
|
@@ -26,11 +29,13 @@ public IMongoRunner Get()
|
26 | 29 | {
|
27 | 30 | if (_runner == null)
|
28 | 31 | {
|
| 32 | + BsonSerializer.RegisterSerializer(new GuidSerializer(GuidRepresentation.Standard)); |
| 33 | + |
29 | 34 | var runnerOptions = new MongoRunnerOptions
|
30 | 35 | {
|
31 | 36 | // Single-node replica set mode is required for transaction support in MongoDB.
|
32 | 37 | UseSingleNodeReplicaSet = true,
|
33 |
| - AdditionalArguments = "--quiet" |
| 38 | + AdditionalArguments = ["--quiet"] |
34 | 39 | };
|
35 | 40 |
|
36 | 41 | _runner = MongoRunner.Run(runnerOptions);
|
@@ -65,18 +70,36 @@ private sealed class MongoRunnerWrapper(MongoRunnerProvider owner, IMongoRunner
|
65 | 70 |
|
66 | 71 | public string ConnectionString => _underlyingMongoRunner?.ConnectionString ?? throw new ObjectDisposedException(nameof(IMongoRunner));
|
67 | 72 |
|
68 |
| - public void Import(string database, string collection, string inputFilePath, string? additionalArguments = null, bool drop = false) |
| 73 | + public void Import(string database, string collection, string inputFilePath, string[]? additionalArguments = null, bool drop = false, |
| 74 | + CancellationToken cancellationToken = default) |
| 75 | + { |
| 76 | + ObjectDisposedException.ThrowIf(_underlyingMongoRunner == null, this); |
| 77 | + |
| 78 | + _underlyingMongoRunner.Import(database, collection, inputFilePath, additionalArguments, drop, cancellationToken); |
| 79 | + } |
| 80 | + |
| 81 | + public async Task ImportAsync(string database, string collection, string inputFilePath, string[]? additionalArguments = null, bool drop = false, |
| 82 | + CancellationToken cancellationToken = default) |
| 83 | + { |
| 84 | + ObjectDisposedException.ThrowIf(_underlyingMongoRunner == null, this); |
| 85 | + |
| 86 | + await _underlyingMongoRunner.ImportAsync(database, collection, inputFilePath, additionalArguments, drop, cancellationToken); |
| 87 | + } |
| 88 | + |
| 89 | + public void Export(string database, string collection, string outputFilePath, string[]? additionalArguments = null, |
| 90 | + CancellationToken cancellationToken = default) |
69 | 91 | {
|
70 | 92 | ObjectDisposedException.ThrowIf(_underlyingMongoRunner == null, this);
|
71 | 93 |
|
72 |
| - _underlyingMongoRunner.Import(database, collection, inputFilePath, additionalArguments, drop); |
| 94 | + _underlyingMongoRunner.Export(database, collection, outputFilePath, additionalArguments, cancellationToken); |
73 | 95 | }
|
74 | 96 |
|
75 |
| - public void Export(string database, string collection, string outputFilePath, string? additionalArguments = null) |
| 97 | + public async Task ExportAsync(string database, string collection, string outputFilePath, string[]? additionalArguments = null, |
| 98 | + CancellationToken cancellationToken = default) |
76 | 99 | {
|
77 | 100 | ObjectDisposedException.ThrowIf(_underlyingMongoRunner == null, this);
|
78 | 101 |
|
79 |
| - _underlyingMongoRunner.Export(database, collection, outputFilePath, additionalArguments); |
| 102 | + await _underlyingMongoRunner.ExportAsync(database, collection, outputFilePath, additionalArguments, cancellationToken); |
80 | 103 | }
|
81 | 104 |
|
82 | 105 | public void Dispose()
|
|
0 commit comments