? servicesCo
protected override IHostBuilder CreateHostBuilder()
{
// @formatter:wrap_chained_method_calls chop_always
- // @formatter:keep_existing_linebreaks true
+ // @formatter:wrap_before_first_method_call true
- return Host.CreateDefaultBuilder(null)
+ return Host
+ .CreateDefaultBuilder(null)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.ConfigureServices(services =>
@@ -195,7 +179,7 @@ protected override IHostBuilder CreateHostBuilder()
});
// @formatter:keep_existing_linebreaks restore
- // @formatter:wrap_chained_method_calls restore
+ // @formatter:wrap_before_first_method_call restore
}
}
}
diff --git a/test/TestBuildingBlocks/MongoRunnerProvider.cs b/test/TestBuildingBlocks/MongoRunnerProvider.cs
new file mode 100644
index 0000000..9565815
--- /dev/null
+++ b/test/TestBuildingBlocks/MongoRunnerProvider.cs
@@ -0,0 +1,101 @@
+using EphemeralMongo;
+
+#pragma warning disable AV1553 // Do not use optional parameters with default value null for strings, collections or tasks
+
+namespace TestBuildingBlocks;
+
+// Based on https://gist.github.com/asimmon/612b2d54f1a0d2b4e1115590d456e0be.
+internal sealed class MongoRunnerProvider
+{
+ public static readonly MongoRunnerProvider Instance = new();
+
+ private readonly object _lockObject = new();
+ private IMongoRunner? _runner;
+ private int _useCounter;
+
+ private MongoRunnerProvider()
+ {
+ }
+
+ public IMongoRunner Get()
+ {
+ lock (_lockObject)
+ {
+ if (_runner == null)
+ {
+ var runnerOptions = new MongoRunnerOptions
+ {
+ // Single-node replica set mode is required for transaction support in MongoDB.
+ UseSingleNodeReplicaSet = true,
+ KillMongoProcessesWhenCurrentProcessExits = true,
+ AdditionalArguments = "--quiet"
+ };
+
+ _runner = MongoRunner.Run(runnerOptions);
+ }
+
+ _useCounter++;
+ return new MongoRunnerWrapper(this, _runner);
+ }
+ }
+
+ private void Detach()
+ {
+ lock (_lockObject)
+ {
+ if (_runner != null)
+ {
+ _useCounter--;
+
+ if (_useCounter == 0)
+ {
+ _runner.Dispose();
+ _runner = null;
+ }
+ }
+ }
+ }
+
+ private sealed class MongoRunnerWrapper : IMongoRunner
+ {
+ private readonly MongoRunnerProvider _owner;
+ private IMongoRunner? _underlyingMongoRunner;
+
+ public string ConnectionString => _underlyingMongoRunner?.ConnectionString ?? throw new ObjectDisposedException(nameof(IMongoRunner));
+
+ public MongoRunnerWrapper(MongoRunnerProvider owner, IMongoRunner underlyingMongoRunner)
+ {
+ _owner = owner;
+ _underlyingMongoRunner = underlyingMongoRunner;
+ }
+
+ public void Import(string database, string collection, string inputFilePath, string? additionalArguments = null, bool drop = false)
+ {
+ if (_underlyingMongoRunner == null)
+ {
+ throw new ObjectDisposedException(nameof(IMongoRunner));
+ }
+
+ _underlyingMongoRunner.Import(database, collection, inputFilePath, additionalArguments, drop);
+ }
+
+ public void Export(string database, string collection, string outputFilePath, string? additionalArguments = null)
+ {
+ if (_underlyingMongoRunner == null)
+ {
+ throw new ObjectDisposedException(nameof(IMongoRunner));
+ }
+
+ _underlyingMongoRunner.Export(database, collection, outputFilePath, additionalArguments);
+ }
+
+ public void Dispose()
+ {
+ if (_underlyingMongoRunner != null)
+ {
+ _underlyingMongoRunner = null;
+ _owner.Detach();
+ }
+ }
+ }
+}
diff --git a/test/TestBuildingBlocks/TestBuildingBlocks.csproj b/test/TestBuildingBlocks/TestBuildingBlocks.csproj
index 629c236..9d30f13 100644
--- a/test/TestBuildingBlocks/TestBuildingBlocks.csproj
+++ b/test/TestBuildingBlocks/TestBuildingBlocks.csproj
@@ -8,13 +8,18 @@
-
+
-
-
+
+
+
+
+
+
+
-
-
-
+
+
+
pFad - Phonifier reborn
Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy