Skip to content

Commit

Permalink
Merge pull request #9 from asimmon/feature/copy-options
Browse files Browse the repository at this point in the history
Copy options to prevent options modifications after initialization
  • Loading branch information
asimmon authored Oct 8, 2022
2 parents cdd9da3 + ceea035 commit 1217009
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/EphemeralMongo.Core/MongoRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ private MongoRunner(IFileSystem fileSystem, IPortFactory portFactory, IMongoExec

public static IMongoRunner Run(MongoRunnerOptions? options = null)
{
var runner = new MongoRunner(new FileSystem(), new PortFactory(), new MongoExecutableLocator(), new MongoProcessFactory(), options ?? new MongoRunnerOptions());
var optionsCopy = options == null ? new MongoRunnerOptions() : new MongoRunnerOptions(options);
var runner = new MongoRunner(new FileSystem(), new PortFactory(), new MongoExecutableLocator(), new MongoProcessFactory(), optionsCopy);
return runner.RunInternal();
}

Expand Down
24 changes: 24 additions & 0 deletions src/EphemeralMongo.Core/MongoRunnerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,30 @@ public sealed class MongoRunnerOptions
private TimeSpan _connectionTimeout = TimeSpan.FromSeconds(30);
private TimeSpan _replicaSetSetupTimeout = TimeSpan.FromSeconds(10);

public MongoRunnerOptions()
{
}

public MongoRunnerOptions(MongoRunnerOptions options)
{
if (options == null)
{
throw new ArgumentNullException(nameof(options));
}

this._dataDirectory = options._dataDirectory;
this._binaryDirectory = options._binaryDirectory;
this._connectionTimeout = options._connectionTimeout;
this._replicaSetSetupTimeout = options._replicaSetSetupTimeout;

this.AdditionalArguments = options.AdditionalArguments;
this.UseSingleNodeReplicaSet = options.UseSingleNodeReplicaSet;
this.StandardOuputLogger = options.StandardOuputLogger;
this.StandardErrorLogger = options.StandardErrorLogger;
this.ReplicaSetName = options.ReplicaSetName;
this.MongoPort = options.MongoPort;
}

public string? DataDirectory
{
get => this._dataDirectory;
Expand Down
3 changes: 2 additions & 1 deletion src/EphemeralMongo.Core/PublicAPI.Shipped.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#nullable enable
#nullable enable
EphemeralMongo.IMongoRunner
EphemeralMongo.IMongoRunner.ConnectionString.get -> string!
EphemeralMongo.IMongoRunner.Export(string! database, string! collection, string! outputFilePath, string? additionalArguments = null) -> void
Expand All @@ -15,6 +15,7 @@ EphemeralMongo.MongoRunnerOptions.ConnectionTimeout.set -> void
EphemeralMongo.MongoRunnerOptions.DataDirectory.get -> string?
EphemeralMongo.MongoRunnerOptions.DataDirectory.set -> void
EphemeralMongo.MongoRunnerOptions.MongoRunnerOptions() -> void
EphemeralMongo.MongoRunnerOptions.MongoRunnerOptions(EphemeralMongo.MongoRunnerOptions! options) -> void
EphemeralMongo.MongoRunnerOptions.ReplicaSetSetupTimeout.get -> System.TimeSpan
EphemeralMongo.MongoRunnerOptions.ReplicaSetSetupTimeout.set -> void
EphemeralMongo.MongoRunnerOptions.StandardErrorLogger.get -> EphemeralMongo.Logger?
Expand Down

0 comments on commit 1217009

Please sign in to comment.