diff --git a/docs/mdsource/ignore-class-arguments.include.md b/docs/mdsource/ignore-class-arguments.include.md deleted file mode 100644 index b22488a03..000000000 --- a/docs/mdsource/ignore-class-arguments.include.md +++ /dev/null @@ -1,17 +0,0 @@ -### Ignore class arguments - -`VerifierSettings.IgnoreClassArguments()` can be used to globally ignore class constructor arguments from the verified filename. This is useful when infrastructure fixtures (e.g. TUnit's `ClassConstructor` or NUnit's `TestFixtureSource`) are injected via the constructor and should not affect snapshot file names. It must be called before any test runs, typically in a `[ModuleInitializer]`. - -The received files still contain all class argument values. - -```cs -[ModuleInitializer] -public static void Init() => - VerifierSettings.IgnoreClassArguments(); -``` - -`IgnoreClassArguments` can also be used at the test level: - -```cs -await Verify(result).IgnoreClassArguments(); -``` diff --git a/docs/mdsource/ignore-constructor-parameters.include.md b/docs/mdsource/ignore-constructor-parameters.include.md new file mode 100644 index 000000000..af254eda0 --- /dev/null +++ b/docs/mdsource/ignore-constructor-parameters.include.md @@ -0,0 +1,17 @@ +### Ignore constructor parameters + +`VerifierSettings.IgnoreConstructorParameters()` can be used to globally ignore class constructor arguments from the verified filename. This is useful when infrastructure fixtures (e.g. TUnit's `ClassConstructor` or NUnit's `TestFixtureSource`) are injected via the constructor and should not affect snapshot file names. It must be called before any test runs, typically in a `[ModuleInitializer]`. + +The received files still contain all class argument values. + +```cs +[ModuleInitializer] +public static void Init() => + VerifierSettings.IgnoreConstructorParameters(); +``` + +`IgnoreConstructorParameters` can also be used at the test level: + +```cs +await Verify(result).IgnoreConstructorParameters(); +``` diff --git a/docs/mdsource/parameterised-nunit.source.md b/docs/mdsource/parameterised-nunit.source.md index 2f95ed7d5..a7a658ed9 100644 --- a/docs/mdsource/parameterised-nunit.source.md +++ b/docs/mdsource/parameterised-nunit.source.md @@ -68,9 +68,9 @@ snippet: IgnoreParametersForVerifiedNunit snippet: IgnoreParametersForVerifiedFluentNunit -## Ignore class arguments for verified filename +## Ignore constructor parameters for verified filename -include: ignore-class-arguments +include: ignore-constructor-parameters ## IgnoreParametersForVerified with override parameters diff --git a/docs/mdsource/parameterised-tunit.source.md b/docs/mdsource/parameterised-tunit.source.md index b509de531..14b7ae42d 100644 --- a/docs/mdsource/parameterised-tunit.source.md +++ b/docs/mdsource/parameterised-tunit.source.md @@ -56,9 +56,9 @@ snippet: IgnoreParametersForVerifiedTUnit snippet: IgnoreParametersForVerifiedFluentTUnit -## Ignore class arguments for verified filename +## Ignore constructor parameters for verified filename -include: ignore-class-arguments +include: ignore-constructor-parameters ## IgnoreParametersForVerified with override parameters diff --git a/docs/parameterised-nunit.md b/docs/parameterised-nunit.md index 20b4304c8..27069e6fb 100644 --- a/docs/parameterised-nunit.md +++ b/docs/parameterised-nunit.md @@ -250,24 +250,24 @@ public Task IgnoreParametersForVerifiedFluent(string arg) => -## Ignore class arguments for verified filename +## Ignore constructor parameters for verified filename -### Ignore class arguments +### Ignore constructor parameters -`VerifierSettings.IgnoreClassArguments()` can be used to globally ignore class constructor arguments from the verified filename. This is useful when infrastructure fixtures (e.g. TUnit's `ClassConstructor` or NUnit's `TestFixtureSource`) are injected via the constructor and should not affect snapshot file names. It must be called before any test runs, typically in a `[ModuleInitializer]`. +`VerifierSettings.IgnoreConstructorParameters()` can be used to globally ignore class constructor arguments from the verified filename. This is useful when infrastructure fixtures (e.g. TUnit's `ClassConstructor` or NUnit's `TestFixtureSource`) are injected via the constructor and should not affect snapshot file names. It must be called before any test runs, typically in a `[ModuleInitializer]`. The received files still contain all class argument values. ```cs [ModuleInitializer] public static void Init() => - VerifierSettings.IgnoreClassArguments(); + VerifierSettings.IgnoreConstructorParameters(); ``` -`IgnoreClassArguments` can also be used at the test level: +`IgnoreConstructorParameters` can also be used at the test level: ```cs -await Verify(result).IgnoreClassArguments(); +await Verify(result).IgnoreConstructorParameters(); ``` diff --git a/docs/parameterised-tunit.md b/docs/parameterised-tunit.md index 45e911de4..9a9caccc1 100644 --- a/docs/parameterised-tunit.md +++ b/docs/parameterised-tunit.md @@ -197,24 +197,24 @@ public Task IgnoreParametersForVerifiedFluent(string arg) => -## Ignore class arguments for verified filename +## Ignore constructor parameters for verified filename -### Ignore class arguments +### Ignore constructor parameters -`VerifierSettings.IgnoreClassArguments()` can be used to globally ignore class constructor arguments from the verified filename. This is useful when infrastructure fixtures (e.g. TUnit's `ClassConstructor` or NUnit's `TestFixtureSource`) are injected via the constructor and should not affect snapshot file names. It must be called before any test runs, typically in a `[ModuleInitializer]`. +`VerifierSettings.IgnoreConstructorParameters()` can be used to globally ignore class constructor arguments from the verified filename. This is useful when infrastructure fixtures (e.g. TUnit's `ClassConstructor` or NUnit's `TestFixtureSource`) are injected via the constructor and should not affect snapshot file names. It must be called before any test runs, typically in a `[ModuleInitializer]`. The received files still contain all class argument values. ```cs [ModuleInitializer] public static void Init() => - VerifierSettings.IgnoreClassArguments(); + VerifierSettings.IgnoreConstructorParameters(); ``` -`IgnoreClassArguments` can also be used at the test level: +`IgnoreConstructorParameters` can also be used at the test level: ```cs -await Verify(result).IgnoreClassArguments(); +await Verify(result).IgnoreConstructorParameters(); ``` diff --git a/src/StaticSettingsTests/IgnoreClassArgumentsTests.IgnoreClassArguments.verified.txt b/src/StaticSettingsTests/IgnoreClassArgumentsTests.IgnoreConstructorParameters.verified.txt similarity index 100% rename from src/StaticSettingsTests/IgnoreClassArgumentsTests.IgnoreClassArguments.verified.txt rename to src/StaticSettingsTests/IgnoreClassArgumentsTests.IgnoreConstructorParameters.verified.txt diff --git a/src/StaticSettingsTests/IgnoreClassArgumentsTests.cs b/src/StaticSettingsTests/IgnoreClassArgumentsTests.cs index a17de11b8..dab4cba5d 100644 --- a/src/StaticSettingsTests/IgnoreClassArgumentsTests.cs +++ b/src/StaticSettingsTests/IgnoreClassArgumentsTests.cs @@ -2,12 +2,12 @@ public class IgnoreClassArgumentsTests : BaseTest { public IgnoreClassArgumentsTests() => - VerifierSettings.IgnoreClassArguments(); + VerifierSettings.IgnoreConstructorParameters(); [Theory] [InlineData("One")] [InlineData("Two")] - public Task IgnoreClassArguments(string classArg) + public Task IgnoreConstructorParameters(string classArg) { var settings = new VerifySettings(); settings.UseParameters(classArg); diff --git a/src/Verify/Naming/FileNameBuilder.cs b/src/Verify/Naming/FileNameBuilder.cs index e33388c19..e35aa261a 100644 --- a/src/Verify/Naming/FileNameBuilder.cs +++ b/src/Verify/Naming/FileNameBuilder.cs @@ -67,7 +67,7 @@ public static (Action?, Action?) GetParameterText( } } - if (settings.ignoreClassArguments || VerifierSettings.GlobalIgnoreClassArguments) + if (settings.ignoreConstructorParameters || VerifierSettings.GlobalIgnoreConstructorParameters) { var classArgCount = settings.classArgumentCount; if (classArgCount > 0) diff --git a/src/Verify/Naming/VerifierSettings.cs b/src/Verify/Naming/VerifierSettings.cs index bee97fe82..0abe0351e 100644 --- a/src/Verify/Naming/VerifierSettings.cs +++ b/src/Verify/Naming/VerifierSettings.cs @@ -362,15 +362,23 @@ public static void IgnoreParameters(params string[] parameterNames) GlobalIgnoredParameters = parameterNames.ToHashSet(); } - internal static bool GlobalIgnoreClassArguments; + internal static bool GlobalIgnoreConstructorParameters; /// - /// Ignore class arguments in 'verified' filename resulting in the same verified file regardless of class constructor arguments. - /// Note that the 'received' files still contain the class arguments. + /// Ignore constructor parameters in 'verified' filename resulting in the same verified file regardless of class constructor arguments. + /// Note that the 'received' files still contain the constructor parameters. /// - public static void IgnoreClassArguments() + public static void IgnoreConstructorParameters() { InnerVerifier.ThrowIfVerifyHasBeenRun(); - GlobalIgnoreClassArguments = true; + GlobalIgnoreConstructorParameters = true; } + + /// + /// Ignore class arguments in 'verified' filename resulting in the same verified file regardless of class constructor arguments. + /// Note that the 'received' files still contain the class arguments. + /// + [Obsolete("Use IgnoreConstructorParameters")] + public static void IgnoreClassArguments() => + IgnoreConstructorParameters(); } \ No newline at end of file diff --git a/src/Verify/Naming/VerifySettings_Parameter.cs b/src/Verify/Naming/VerifySettings_Parameter.cs index f7fefd105..508ce55aa 100644 --- a/src/Verify/Naming/VerifySettings_Parameter.cs +++ b/src/Verify/Naming/VerifySettings_Parameter.cs @@ -87,14 +87,22 @@ public void IgnoreParameters(params string[] parameterNames) => internal void SetClassArgumentCount(int count) => classArgumentCount = count; - internal bool ignoreClassArguments; + internal bool ignoreConstructorParameters; + + /// + /// Ignore constructor parameters in 'verified' filename resulting in the same verified file regardless of class constructor arguments. + /// Note that the 'received' files still contain the constructor parameters. + /// + public void IgnoreConstructorParameters() => + ignoreConstructorParameters = true; /// /// Ignore class arguments in 'verified' filename resulting in the same verified file regardless of class constructor arguments. /// Note that the 'received' files still contain the class arguments. /// + [Obsolete("Use IgnoreConstructorParameters")] public void IgnoreClassArguments() => - ignoreClassArguments = true; + IgnoreConstructorParameters(); internal bool ignoreParametersForVerified; diff --git a/src/Verify/Serialization/VerifierSettings.cs b/src/Verify/Serialization/VerifierSettings.cs index 4d1bb8671..314a39e7c 100644 --- a/src/Verify/Serialization/VerifierSettings.cs +++ b/src/Verify/Serialization/VerifierSettings.cs @@ -167,7 +167,7 @@ internal static void Reset() addAttachments = true; GlobalScrubbers.Clear(); GlobalIgnoredParameters = null; - GlobalIgnoreClassArguments = false; + GlobalIgnoreConstructorParameters = false; } public static void UseStrictJson() diff --git a/src/Verify/SettingsTask_Parameters.cs b/src/Verify/SettingsTask_Parameters.cs index d8922e2d4..bb8e9a9a2 100644 --- a/src/Verify/SettingsTask_Parameters.cs +++ b/src/Verify/SettingsTask_Parameters.cs @@ -10,11 +10,20 @@ public SettingsTask IgnoreParameters(params string[] parameterNames) return this; } + /// + [Pure] + public SettingsTask IgnoreConstructorParameters() + { + CurrentSettings.IgnoreConstructorParameters(); + return this; + } + /// + [Obsolete("Use IgnoreConstructorParameters")] [Pure] public SettingsTask IgnoreClassArguments() { - CurrentSettings.IgnoreClassArguments(); + CurrentSettings.IgnoreConstructorParameters(); return this; } diff --git a/src/Verify/VerifySettings.cs b/src/Verify/VerifySettings.cs index e474d955e..7af23e441 100644 --- a/src/Verify/VerifySettings.cs +++ b/src/Verify/VerifySettings.cs @@ -50,7 +50,7 @@ public VerifySettings(VerifySettings? settings) parameters = settings.parameters; ignoredParameters = settings.ignoredParameters; classArgumentCount = settings.classArgumentCount; - ignoreClassArguments = settings.ignoreClassArguments; + ignoreConstructorParameters = settings.ignoreConstructorParameters; ignoreParametersForVerified = settings.ignoreParametersForVerified; parametersText = settings.parametersText; FileName = settings.FileName;