From 2f9426395c96f2543bdbea86d2ec2e4453a19856 Mon Sep 17 00:00:00 2001 From: Anthony Simmon Date: Sun, 2 Oct 2022 12:14:25 -0400 Subject: [PATCH 1/2] Use Microsoft.CodeAnalysis.PublicApiAnalyzers to track public APIs changes --- .../IsExternalInit.cs | 13 ---------- .../MongoRunnerTests.cs | 18 ++++++++++++- .../EphemeralMongo.Core.csproj | 4 +++ src/EphemeralMongo.Core/IsExternalInit.cs | 13 ---------- src/EphemeralMongo.Core/MongoRunner.cs | 2 +- src/EphemeralMongo.Core/MongoRunnerOptions.cs | 24 ++++++++--------- src/EphemeralMongo.Core/PublicAPI.Shipped.txt | 26 +++++++++++++++++++ .../PublicAPI.Unshipped.txt | 1 + 8 files changed, 61 insertions(+), 40 deletions(-) delete mode 100644 src/EphemeralMongo.Core.Tests/IsExternalInit.cs delete mode 100644 src/EphemeralMongo.Core/IsExternalInit.cs create mode 100644 src/EphemeralMongo.Core/PublicAPI.Shipped.txt create mode 100644 src/EphemeralMongo.Core/PublicAPI.Unshipped.txt diff --git a/src/EphemeralMongo.Core.Tests/IsExternalInit.cs b/src/EphemeralMongo.Core.Tests/IsExternalInit.cs deleted file mode 100644 index 547308f..0000000 --- a/src/EphemeralMongo.Core.Tests/IsExternalInit.cs +++ /dev/null @@ -1,13 +0,0 @@ -#if NET462 || NETCOREAPP3_1 -// ReSharper disable once CheckNamespace -namespace System.Runtime.CompilerServices; - -// ReSharper disable once RedundantNameQualifier -using System.ComponentModel; - -// Allows using init properties in netstandard2.0 -[EditorBrowsable(EditorBrowsableState.Never)] -internal static class IsExternalInit -{ -} -#endif \ No newline at end of file diff --git a/src/EphemeralMongo.Core.Tests/MongoRunnerTests.cs b/src/EphemeralMongo.Core.Tests/MongoRunnerTests.cs index 5a6d07a..7f147bc 100644 --- a/src/EphemeralMongo.Core.Tests/MongoRunnerTests.cs +++ b/src/EphemeralMongo.Core.Tests/MongoRunnerTests.cs @@ -21,6 +21,7 @@ public void Run_Fails_When_BinaryDirectory_Does_Not_Exist() StandardOuputLogger = x => this.Logger.LogInformation("{X}", x), StandardErrorLogger = x => this.Logger.LogInformation("{X}", x), BinaryDirectory = Guid.NewGuid().ToString(), + AdditionalArguments = string.Empty, }; IMongoRunner? runner = null; @@ -116,5 +117,20 @@ public void Import_Export_Works(bool useSingleNodeReplicaSet) } } - private sealed record Person(string Id, string Name); + private sealed class Person + { + public Person() + { + } + + public Person(string id, string name) + { + this.Id = id; + this.Name = name; + } + + public string Id { get; set; } = string.Empty; + + public string Name { get; set; } = string.Empty; + } } \ No newline at end of file diff --git a/src/EphemeralMongo.Core/EphemeralMongo.Core.csproj b/src/EphemeralMongo.Core/EphemeralMongo.Core.csproj index cb18f31..8637419 100644 --- a/src/EphemeralMongo.Core/EphemeralMongo.Core.csproj +++ b/src/EphemeralMongo.Core/EphemeralMongo.Core.csproj @@ -11,6 +11,10 @@ + + all + runtime; build; native; contentfiles; analyzers + diff --git a/src/EphemeralMongo.Core/IsExternalInit.cs b/src/EphemeralMongo.Core/IsExternalInit.cs deleted file mode 100644 index 4dcd1b4..0000000 --- a/src/EphemeralMongo.Core/IsExternalInit.cs +++ /dev/null @@ -1,13 +0,0 @@ -#if NETSTANDARD2_0 -// ReSharper disable once CheckNamespace -namespace System.Runtime.CompilerServices; - -// ReSharper disable once RedundantNameQualifier -using System.ComponentModel; - -// Allows using init properties in netstandard2.0 -[EditorBrowsable(EditorBrowsableState.Never)] -internal static class IsExternalInit -{ -} -#endif \ No newline at end of file diff --git a/src/EphemeralMongo.Core/MongoRunner.cs b/src/EphemeralMongo.Core/MongoRunner.cs index 9e4fcc1..f763d1c 100644 --- a/src/EphemeralMongo.Core/MongoRunner.cs +++ b/src/EphemeralMongo.Core/MongoRunner.cs @@ -61,7 +61,7 @@ private IMongoRunner RunInternal() var arguments = string.Format(CultureInfo.InvariantCulture, "--dbpath {0} --port {1} --bind_ip 127.0.0.1", ProcessArgument.Escape(this._dataDirectory), this._options.MongoPort); arguments += RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? string.Empty : " --tlsMode disabled"; arguments += this._options.UseSingleNodeReplicaSet ? " --replSet " + this._options.ReplicaSetName : string.Empty; - arguments += this._options.AdditionalArguments == null ? string.Empty : " " + this._options.AdditionalArguments; + arguments += string.IsNullOrWhiteSpace(this._options.AdditionalArguments) ? string.Empty : " " + this._options.AdditionalArguments; this._process = this._processFactory.CreateMongoProcess(this._options, MongoProcessKind.Mongod, executablePath, arguments); this._process.Start(); diff --git a/src/EphemeralMongo.Core/MongoRunnerOptions.cs b/src/EphemeralMongo.Core/MongoRunnerOptions.cs index 52a8d17..73f636e 100644 --- a/src/EphemeralMongo.Core/MongoRunnerOptions.cs +++ b/src/EphemeralMongo.Core/MongoRunnerOptions.cs @@ -2,42 +2,42 @@ public sealed class MongoRunnerOptions { - private readonly string? _dataDirectory; - private readonly string? _binaryDirectory; - private readonly TimeSpan _connectionTimeout = TimeSpan.FromSeconds(30); - private readonly TimeSpan _replicaSetSetupTimeout = TimeSpan.FromSeconds(10); + private string? _dataDirectory; + private string? _binaryDirectory; + private TimeSpan _connectionTimeout = TimeSpan.FromSeconds(30); + private TimeSpan _replicaSetSetupTimeout = TimeSpan.FromSeconds(10); public string? DataDirectory { get => this._dataDirectory; - init => this._dataDirectory = CheckDirectoryPathFormat(value) is { } ex ? throw new ArgumentException(nameof(this.DataDirectory), ex) : value; + set => this._dataDirectory = CheckDirectoryPathFormat(value) is { } ex ? throw new ArgumentException(nameof(this.DataDirectory), ex) : value; } public string? BinaryDirectory { get => this._binaryDirectory; - init => this._binaryDirectory = CheckDirectoryPathFormat(value) is { } ex ? throw new ArgumentException(nameof(this.BinaryDirectory), ex) : value; + set => this._binaryDirectory = CheckDirectoryPathFormat(value) is { } ex ? throw new ArgumentException(nameof(this.BinaryDirectory), ex) : value; } - public string? AdditionalArguments { get; init; } + public string? AdditionalArguments { get; set; } public TimeSpan ConnectionTimeout { get => this._connectionTimeout; - init => this._connectionTimeout = value >= TimeSpan.Zero ? value : throw new ArgumentOutOfRangeException(nameof(this.ConnectionTimeout)); + set => this._connectionTimeout = value >= TimeSpan.Zero ? value : throw new ArgumentOutOfRangeException(nameof(this.ConnectionTimeout)); } - public bool UseSingleNodeReplicaSet { get; init; } + public bool UseSingleNodeReplicaSet { get; set; } public TimeSpan ReplicaSetSetupTimeout { get => this._replicaSetSetupTimeout; - init => this._replicaSetSetupTimeout = value >= TimeSpan.Zero ? value : throw new ArgumentOutOfRangeException(nameof(this.ReplicaSetSetupTimeout)); + set => this._replicaSetSetupTimeout = value >= TimeSpan.Zero ? value : throw new ArgumentOutOfRangeException(nameof(this.ReplicaSetSetupTimeout)); } - public Logger? StandardOuputLogger { get; init; } + public Logger? StandardOuputLogger { get; set; } - public Logger? StandardErrorLogger { get; init; } + public Logger? StandardErrorLogger { get; set; } // Internal properties start here internal string ReplicaSetName { get; set; } = "singleNodeReplSet"; diff --git a/src/EphemeralMongo.Core/PublicAPI.Shipped.txt b/src/EphemeralMongo.Core/PublicAPI.Shipped.txt new file mode 100644 index 0000000..4e2c10e --- /dev/null +++ b/src/EphemeralMongo.Core/PublicAPI.Shipped.txt @@ -0,0 +1,26 @@ +#nullable enable +EphemeralMongo.IMongoRunner +EphemeralMongo.IMongoRunner.ConnectionString.get -> string! +EphemeralMongo.IMongoRunner.Export(string! database, string! collection, string! outputFilePath, string? additionalArguments = null) -> void +EphemeralMongo.IMongoRunner.Import(string! database, string! collection, string! inputFilePath, string? additionalArguments = null, bool drop = false) -> void +EphemeralMongo.Logger +EphemeralMongo.MongoRunner +EphemeralMongo.MongoRunnerOptions +EphemeralMongo.MongoRunnerOptions.AdditionalArguments.get -> string? +EphemeralMongo.MongoRunnerOptions.AdditionalArguments.set -> void +EphemeralMongo.MongoRunnerOptions.BinaryDirectory.get -> string? +EphemeralMongo.MongoRunnerOptions.BinaryDirectory.set -> void +EphemeralMongo.MongoRunnerOptions.ConnectionTimeout.get -> System.TimeSpan +EphemeralMongo.MongoRunnerOptions.ConnectionTimeout.set -> void +EphemeralMongo.MongoRunnerOptions.DataDirectory.get -> string? +EphemeralMongo.MongoRunnerOptions.DataDirectory.set -> void +EphemeralMongo.MongoRunnerOptions.MongoRunnerOptions() -> void +EphemeralMongo.MongoRunnerOptions.ReplicaSetSetupTimeout.get -> System.TimeSpan +EphemeralMongo.MongoRunnerOptions.ReplicaSetSetupTimeout.set -> void +EphemeralMongo.MongoRunnerOptions.StandardErrorLogger.get -> EphemeralMongo.Logger? +EphemeralMongo.MongoRunnerOptions.StandardErrorLogger.set -> void +EphemeralMongo.MongoRunnerOptions.StandardOuputLogger.get -> EphemeralMongo.Logger? +EphemeralMongo.MongoRunnerOptions.StandardOuputLogger.set -> void +EphemeralMongo.MongoRunnerOptions.UseSingleNodeReplicaSet.get -> bool +EphemeralMongo.MongoRunnerOptions.UseSingleNodeReplicaSet.set -> void +static EphemeralMongo.MongoRunner.Run(EphemeralMongo.MongoRunnerOptions? options = null) -> EphemeralMongo.IMongoRunner! \ No newline at end of file diff --git a/src/EphemeralMongo.Core/PublicAPI.Unshipped.txt b/src/EphemeralMongo.Core/PublicAPI.Unshipped.txt new file mode 100644 index 0000000..91b0e1a --- /dev/null +++ b/src/EphemeralMongo.Core/PublicAPI.Unshipped.txt @@ -0,0 +1 @@ +#nullable enable \ No newline at end of file From f756a1cd9ba9e19143bb3130148d22842b40e417 Mon Sep 17 00:00:00 2001 From: Anthony Simmon Date: Sun, 2 Oct 2022 12:33:38 -0400 Subject: [PATCH 2/2] Implement equality in test document --- src/EphemeralMongo.Core.Tests/MongoRunnerTests.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/EphemeralMongo.Core.Tests/MongoRunnerTests.cs b/src/EphemeralMongo.Core.Tests/MongoRunnerTests.cs index 7f147bc..f2957ad 100644 --- a/src/EphemeralMongo.Core.Tests/MongoRunnerTests.cs +++ b/src/EphemeralMongo.Core.Tests/MongoRunnerTests.cs @@ -132,5 +132,15 @@ public Person(string id, string name) public string Id { get; set; } = string.Empty; public string Name { get; set; } = string.Empty; + + private bool Equals(Person other) + { + return this.Id == other.Id && this.Name == other.Name; + } + + public override bool Equals(object? obj) + { + return ReferenceEquals(this, obj) || (obj is Person other && this.Equals(other)); + } } } \ No newline at end of file