Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy options to prevent options modifications after initialization #9

Merged
merged 1 commit into from
Oct 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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