Skip to content
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
17 changes: 0 additions & 17 deletions docs/mdsource/ignore-class-arguments.include.md

This file was deleted.

17 changes: 17 additions & 0 deletions docs/mdsource/ignore-constructor-parameters.include.md
Original file line number Diff line number Diff line change
@@ -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();
```
4 changes: 2 additions & 2 deletions docs/mdsource/parameterised-nunit.source.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions docs/mdsource/parameterised-tunit.source.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions docs/parameterised-nunit.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,24 +250,24 @@ public Task IgnoreParametersForVerifiedFluent(string arg) =>
<!-- endSnippet -->


## Ignore class arguments for verified filename
## Ignore constructor parameters for verified filename

### Ignore class arguments<!-- include: ignore-class-arguments. path: /docs/mdsource/ignore-class-arguments.include.md -->
### Ignore constructor parameters<!-- include: ignore-constructor-parameters. path: /docs/mdsource/ignore-constructor-parameters.include.md -->

`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();
```
<!-- endInclude -->

Expand Down
12 changes: 6 additions & 6 deletions docs/parameterised-tunit.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,24 +197,24 @@ public Task IgnoreParametersForVerifiedFluent(string arg) =>
<!-- endSnippet -->


## Ignore class arguments for verified filename
## Ignore constructor parameters for verified filename

### Ignore class arguments<!-- include: ignore-class-arguments. path: /docs/mdsource/ignore-class-arguments.include.md -->
### Ignore constructor parameters<!-- include: ignore-constructor-parameters. path: /docs/mdsource/ignore-constructor-parameters.include.md -->

`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();
```
<!-- endInclude -->

Expand Down
4 changes: 2 additions & 2 deletions src/StaticSettingsTests/IgnoreClassArgumentsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/Verify/Naming/FileNameBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static (Action<StringBuilder>?, Action<StringBuilder>?) GetParameterText(
}
}

if (settings.ignoreClassArguments || VerifierSettings.GlobalIgnoreClassArguments)
if (settings.ignoreConstructorParameters || VerifierSettings.GlobalIgnoreConstructorParameters)
{
var classArgCount = settings.classArgumentCount;
if (classArgCount > 0)
Expand Down
18 changes: 13 additions & 5 deletions src/Verify/Naming/VerifierSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -362,15 +362,23 @@ public static void IgnoreParameters(params string[] parameterNames)
GlobalIgnoredParameters = parameterNames.ToHashSet();
}

internal static bool GlobalIgnoreClassArguments;
internal static bool GlobalIgnoreConstructorParameters;

/// <summary>
/// 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.
/// </summary>
public static void IgnoreClassArguments()
public static void IgnoreConstructorParameters()
{
InnerVerifier.ThrowIfVerifyHasBeenRun();
GlobalIgnoreClassArguments = true;
GlobalIgnoreConstructorParameters = true;
}

/// <summary>
/// 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.
/// </summary>
[Obsolete("Use IgnoreConstructorParameters")]
public static void IgnoreClassArguments() =>
IgnoreConstructorParameters();
}
12 changes: 10 additions & 2 deletions src/Verify/Naming/VerifySettings_Parameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,22 @@ public void IgnoreParameters(params string[] parameterNames) =>
internal void SetClassArgumentCount(int count) =>
classArgumentCount = count;

internal bool ignoreClassArguments;
internal bool ignoreConstructorParameters;

/// <summary>
/// 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.
/// </summary>
public void IgnoreConstructorParameters() =>
ignoreConstructorParameters = true;

/// <summary>
/// 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.
/// </summary>
[Obsolete("Use IgnoreConstructorParameters")]
public void IgnoreClassArguments() =>
ignoreClassArguments = true;
IgnoreConstructorParameters();

internal bool ignoreParametersForVerified;

Expand Down
2 changes: 1 addition & 1 deletion src/Verify/Serialization/VerifierSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ internal static void Reset()
addAttachments = true;
GlobalScrubbers.Clear();
GlobalIgnoredParameters = null;
GlobalIgnoreClassArguments = false;
GlobalIgnoreConstructorParameters = false;
}

public static void UseStrictJson()
Expand Down
11 changes: 10 additions & 1 deletion src/Verify/SettingsTask_Parameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,20 @@ public SettingsTask IgnoreParameters(params string[] parameterNames)
return this;
}

/// <inheritdoc cref="VerifySettings.IgnoreConstructorParameters()"/>
[Pure]
public SettingsTask IgnoreConstructorParameters()
{
CurrentSettings.IgnoreConstructorParameters();
return this;
}

/// <inheritdoc cref="VerifySettings.IgnoreClassArguments()"/>
[Obsolete("Use IgnoreConstructorParameters")]
[Pure]
public SettingsTask IgnoreClassArguments()
{
CurrentSettings.IgnoreClassArguments();
CurrentSettings.IgnoreConstructorParameters();
return this;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Verify/VerifySettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading