()
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 4e59b38..ecb2125 100644
--- a/test/TestBuildingBlocks/TestBuildingBlocks.csproj
+++ b/test/TestBuildingBlocks/TestBuildingBlocks.csproj
@@ -10,11 +10,14 @@
+
+
+
+
-
From 76d82e192606793a52e1500b00b66619993d4c94 Mon Sep 17 00:00:00 2001
From: Bart Koelman <10324372+bkoelman@users.noreply.github.com>
Date: Tue, 26 Sep 2023 00:29:55 +0200
Subject: [PATCH 4/5] Run tests against the latest version of MongoDB.Driver
---
.github/dependabot.yml | 1 +
Directory.Build.props | 1 +
test/TestBuildingBlocks/TestBuildingBlocks.csproj | 1 +
3 files changed, 3 insertions(+)
diff --git a/.github/dependabot.yml b/.github/dependabot.yml
index ecd4217..53356ab 100644
--- a/.github/dependabot.yml
+++ b/.github/dependabot.yml
@@ -16,6 +16,7 @@ updates:
ignore:
# Block updates to all exposed dependencies of the NuGet packages we produce, as updating them would be a breaking change.
- dependency-name: 'JsonApiDotNetCore*'
+ - dependency-name: 'MongoDB.Driver*'
# Block major updates of packages that require a matching .NET version.
- dependency-name: 'Microsoft.AspNetCore*'
update-types: ["version-update:semver-major"]
diff --git a/Directory.Build.props b/Directory.Build.props
index b5169a9..c2e8807 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -31,6 +31,7 @@
2.3.*
1.3.*
2023.2.*
+ 2.21.*
1.1.*
17.7.*
2.5.*
diff --git a/test/TestBuildingBlocks/TestBuildingBlocks.csproj b/test/TestBuildingBlocks/TestBuildingBlocks.csproj
index ecb2125..9d30f13 100644
--- a/test/TestBuildingBlocks/TestBuildingBlocks.csproj
+++ b/test/TestBuildingBlocks/TestBuildingBlocks.csproj
@@ -18,6 +18,7 @@
+
From ba5d205afed227d6fe1e9dbcdc10307d8f12255d Mon Sep 17 00:00:00 2001
From: Bart Koelman <10324372+bkoelman@users.noreply.github.com>
Date: Tue, 26 Sep 2023 01:47:39 +0200
Subject: [PATCH 5/5] GitHub Actions build: fix version detection
---
.github/workflows/build.yml | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index c56fa3d..dc41703 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -92,7 +92,8 @@ jobs:
$versionSuffix = $segments.Length -eq 1 ? '' : $segments[1..$($segments.Length - 1)] -join '-'
[xml]$xml = Get-Content Directory.Build.props
- $configuredVersionPrefix = $xml.Project.PropertyGroup[0].JsonApiDotNetCoreMongoDbVersionPrefix
+ $configuredVersionPrefix = $xml.Project.PropertyGroup.JsonApiDotNetCoreMongoDbVersionPrefix | Select-Object -First 1
+
if ($configuredVersionPrefix -ne $versionPrefix) {
Write-Error "Version prefix from git release tag '$versionPrefix' does not match version prefix '$configuredVersionPrefix' stored in Directory.Build.props."
# To recover from this:
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