-
-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mongo): Update mongo driver to v3 (#413)
* Ephemeral mongo won't work with the v3 driver and mongo2go fails. * Replaced with Testcontainers.MongoDb * Removed unused usings * Dropped netstandard 2.0 as mongo 3.0 removed target; it does support net472 but would require library to be built on windows agent * Update actions versions
- Loading branch information
1 parent
a5d246a
commit 5823ca5
Showing
55 changed files
with
128 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,27 @@ | ||
using System; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using Testcontainers.MongoDb; | ||
|
||
namespace Hangfire.Mongo.Sample.ASPNetCore | ||
{ | ||
public class MongoRunner : IDisposable | ||
public class MongoTestRunner : IAsyncDisposable | ||
{ | ||
private Mongo2Go.MongoDbRunner _runner; | ||
public readonly MongoDbContainer MongoDbContainer = | ||
new MongoDbBuilder() | ||
.WithImage("mongo:7.0") | ||
.Build(); | ||
|
||
public string ConnectionString => _runner?.ConnectionString; | ||
public MongoRunner Start() | ||
{ | ||
var homePath = Environment.OSVersion.Platform is PlatformID.Unix or PlatformID.MacOSX | ||
? Environment.GetEnvironmentVariable("HOME") | ||
: Environment.ExpandEnvironmentVariables("%HOMEDRIVE%%HOMEPATH%"); | ||
|
||
if (string.IsNullOrEmpty(homePath)) | ||
{ | ||
throw new InvalidOperationException("Could not locate home path"); | ||
} | ||
var dataDir = Path.Combine(homePath, "mongodb", "data"); | ||
for (int i = 0; i < 3; i++) | ||
{ | ||
try | ||
{ | ||
_runner = Mongo2Go.MongoDbRunner.StartForDebugging( | ||
singleNodeReplSet: true, | ||
dataDirectory: dataDir); | ||
} | ||
catch (Exception e) | ||
{ | ||
Console.WriteLine(e); | ||
} | ||
} | ||
|
||
public string MongoConnectionString { get; private set; } | ||
|
||
return this; | ||
public async Task Start() | ||
{ | ||
await MongoDbContainer.StartAsync(); | ||
MongoConnectionString = MongoDbContainer.GetConnectionString(); | ||
} | ||
|
||
public void Dispose() | ||
public async ValueTask DisposeAsync() | ||
{ | ||
_runner?.Dispose(); | ||
if (MongoDbContainer != null) await MongoDbContainer.DisposeAsync(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.Threading; | ||
|
||
namespace Hangfire.Mongo.Sample.ASPNetCore; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,27 @@ | ||
using System; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using Testcontainers.MongoDb; | ||
|
||
namespace Hangfire.Mongo.Sample.NETCore | ||
{ | ||
public class MongoRunner : IDisposable | ||
public class MongoTestRunner : IAsyncDisposable | ||
{ | ||
private Mongo2Go.MongoDbRunner _runner; | ||
public readonly MongoDbContainer MongoDbContainer = | ||
new MongoDbBuilder() | ||
.WithImage("mongo:7.0") | ||
.Build(); | ||
|
||
public string ConnectionString => _runner?.ConnectionString; | ||
public MongoRunner Start() | ||
{ | ||
var homePath = Environment.OSVersion.Platform is PlatformID.Unix or PlatformID.MacOSX | ||
? Environment.GetEnvironmentVariable("HOME") | ||
: Environment.ExpandEnvironmentVariables("%HOMEDRIVE%%HOMEPATH%"); | ||
|
||
if (string.IsNullOrEmpty(homePath)) | ||
{ | ||
throw new InvalidOperationException("Could not locate home path"); | ||
} | ||
var dataDir = Path.Combine(homePath, "mongodb", "data"); | ||
// try 3 times | ||
for (int i = 0; i < 3; i++) | ||
{ | ||
try | ||
{ | ||
_runner = Mongo2Go.MongoDbRunner.StartForDebugging( | ||
singleNodeReplSet: true, | ||
dataDirectory: dataDir); | ||
} | ||
catch (Exception e) | ||
{ | ||
Console.WriteLine(e); | ||
} | ||
} | ||
|
||
public string MongoConnectionString { get; private set; } | ||
|
||
return this; | ||
public async Task Start() | ||
{ | ||
await MongoDbContainer.StartAsync(); | ||
MongoConnectionString = MongoDbContainer.GetConnectionString(); | ||
} | ||
|
||
public void Dispose() | ||
public async ValueTask DisposeAsync() | ||
{ | ||
_runner?.Dispose(); | ||
if (MongoDbContainer != null) await MongoDbContainer.DisposeAsync(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.