<!--
GENERATED FILE - DO NOT EDIT
This file was generated by [MarkdownSnippets](https://github.com/SimonCropp/MarkdownSnippets).
Source File: /docs/mdsource/parameterised-xunitv2.source.md
To change this file edit the source file and then run MarkdownSnippets.
-->

# Xunit V2 Parameterised Tests


## UseParameters()

`UseParameters()` controls what parameters are used when naming files.

Verify.Xunit does not detect the parametrised arguments, as such `UseParameters()` is required.


### Usage:

For the above scenarios where parameters are not automatically detected: 

<!-- snippet: UseParametersXunit -->
<a id='snippet-UseParametersXunit'></a>
```cs
[Theory]
[InlineData("Value1")]
[InlineData("Value2")]
public Task UseParametersUsage(string arg)
{
    var somethingToVerify = $"{arg} some text";
    return Verify(somethingToVerify)
        .UseParameters(arg);
}
```
<sup><a href='/src/Verify.Xunit.Tests/Snippets/ParametersSample.cs#L142-L154' title='Snippet source file'>snippet source</a> | <a href='#snippet-UseParametersXunit' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

If not all parameters are required, a subset can be passed in. In this scenario, the parameters passed in will match with the method parameter names from the start. For example the following will result in a file named `ParametersSample.UseParametersSubSet_arg1=Value1_arg2=Value2.verified.txt`

<!-- snippet: UseParametersSubSetXunit -->
<a id='snippet-UseParametersSubSetXunit'></a>
```cs
[Theory]
[InlineData("Value1", "Value2", "Value3")]
public Task UseParametersSubSet(string arg1, string arg2, string arg3)
{
    var somethingToVerify = $"{arg1} {arg2} {arg3} some text";
    return Verify(somethingToVerify)
        .UseParameters(arg1, arg2);
}
```
<sup><a href='/src/Verify.Xunit.Tests/Snippets/ParametersSample.cs#L156-L167' title='Snippet source file'>snippet source</a> | <a href='#snippet-UseParametersSubSetXunit' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

If the number of parameters passed to `UseParameters()` is greater than the number of parameters in the test method, an exception will be thrown.


### InlineData


#### Instance

<!-- snippet: InlineDataInstanceXunit -->
<a id='snippet-InlineDataInstanceXunit'></a>
```cs
[Theory]
[InlineData("Value1")]
[InlineData("Value2")]
public Task InlineDataUsage(string arg)
{
    var settings = new VerifySettings();
    settings.UseParameters(arg);
    return Verify(arg, settings);
}
```
<sup><a href='/src/Verify.Xunit.Tests/Snippets/ParametersSample.cs#L117-L129' title='Snippet source file'>snippet source</a> | <a href='#snippet-InlineDataInstanceXunit' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


#### Fluent

<!-- snippet: InlineDataFluentXunit -->
<a id='snippet-InlineDataFluentXunit'></a>
```cs
[Theory]
[InlineData("Value1")]
[InlineData("Value2")]
public Task InlineDataUsageFluent(string arg) =>
    Verify(arg)
        .UseParameters(arg);
```
<sup><a href='/src/Verify.Xunit.Tests/Snippets/ParametersSample.cs#L131-L140' title='Snippet source file'>snippet source</a> | <a href='#snippet-InlineDataFluentXunit' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


### MemberData

Given the following MemberData

<!-- snippet: MemberDataGetDataXunit -->
<a id='snippet-MemberDataGetDataXunit'></a>
```cs
public static IEnumerable<object[]> GetData()
{
    yield return
    [
        "Value1"
    ];
    yield return
    [
        "Value2"
    ];
}
```
<sup><a href='/src/Verify.Xunit.Tests/Snippets/ParametersSample.cs#L192-L206' title='Snippet source file'>snippet source</a> | <a href='#snippet-MemberDataGetDataXunit' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


#### Instance

<!-- snippet: MemberDataInstanceXunit -->
<a id='snippet-MemberDataInstanceXunit'></a>
```cs
[Theory]
[MemberData(nameof(GetData))]
public Task MemberDataUsage(string arg)
{
    var settings = new VerifySettings();
    settings.UseParameters(arg);
    return Verify(arg, settings);
}
```
<sup><a href='/src/Verify.Xunit.Tests/Snippets/ParametersSample.cs#L169-L180' title='Snippet source file'>snippet source</a> | <a href='#snippet-MemberDataInstanceXunit' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


#### Fluent

<!-- snippet: MemberDataFluentXunit -->
<a id='snippet-MemberDataFluentXunit'></a>
```cs
[Theory]
[MemberData(nameof(GetData))]
public Task MemberDataUsageFluent(string arg) =>
    Verify(arg)
        .UseParameters(arg);
```
<sup><a href='/src/Verify.Xunit.Tests/Snippets/ParametersSample.cs#L182-L190' title='Snippet source file'>snippet source</a> | <a href='#snippet-MemberDataFluentXunit' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


### Unknown parameter types

For unknown types the parameter information cannot be derived. In these scenarios `ToString()` is used. To use custom text for a parameter use `NameForParameter()`.<!-- singleLineInclude: name-for-parameters. path: /docs/mdsource/name-for-parameters.include.md -->

<!-- snippet: NameForParametersXunit -->
<a id='snippet-NameForParametersXunit'></a>
```cs
public class ComplexParametersSample
{
    [ModuleInitializer]
    public static void Initialize()
    {
        VerifierSettings.NameForParameter<ComplexData>(_ => _.Value);
        VerifierSettings.NameForParameter<ComplexStructData>(_ => _.Value);
    }

    [Theory]
    [MemberData(nameof(GetData))]
    public Task ComplexMemberData(ComplexData arg)
    {
        var settings = new VerifySettings();
        settings.UseParameters(arg);
        return Verify(arg, settings);
    }

    [Theory]
    [MemberData(nameof(GetData))]
    public Task ComplexMemberDataFluent(ComplexData arg) =>
        Verify(arg)
            .UseParameters(arg);

    [Theory]
    [MemberData(nameof(GetData))]
    public Task ComplexMemberNullableData(ComplexData arg)
    {
        var settings = new VerifySettings();
        settings.UseParameters(arg);
        return Verify(arg, settings);
    }

    [Theory]
    [MemberData(nameof(GetData))]
    public Task ComplexMemberNullableDataFluent(ComplexData arg) =>
        Verify(arg)
            .UseParameters(arg);

    public static IEnumerable<object[]> GetData()
    {
        yield return
        [
            new ComplexData("Value1")
        ];
        yield return
        [
            new ComplexData("Value2")
        ];
    }

    public record ComplexData(string Value);

    [Theory]
    [MemberData(nameof(GetStructData))]
    public Task ComplexMemberStructData(ComplexStructData arg)
    {
        var settings = new VerifySettings();
        settings.UseParameters(arg);
        return Verify(arg, settings);
    }

    [Theory]
    [MemberData(nameof(GetStructData))]
    public Task ComplexMemberStructDataFluent(ComplexStructData arg) =>
        Verify(arg)
            .UseParameters(arg);

    [Theory]
    [MemberData(nameof(GetStructData))]
    public Task ComplexMemberNullableStructData(ComplexStructData arg)
    {
        var settings = new VerifySettings();
        settings.UseParameters(arg);
        return Verify(arg, settings);
    }

    [Theory]
    [MemberData(nameof(GetStructData))]
    public Task ComplexMemberNullableStructDataFluent(ComplexStructData arg) =>
        Verify(arg)
            .UseParameters(arg);

    public static IEnumerable<object[]> GetStructData()
    {
        yield return [new ComplexStructData("Value1")];
        yield return [new ComplexStructData("Value2")];
    }

    public record ComplexStructData(string Value);
}
```
<sup><a href='/src/Verify.Xunit.Tests/Snippets/ComplexParametersSample.cs#L1-L95' title='Snippet source file'>snippet source</a> | <a href='#snippet-NameForParametersXunit' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


## Overriding text used for parameters

`UseTextForParameters()` can be used to override the substitution text used for the `{Parameters}` part of the file convention.<!-- include: override-parameters-text. path: /docs/mdsource/override-parameters-text.include.md -->

```
{Directory}/{TestClassName}.{TestMethodName}_{Parameters}_{UniqueFor1}_{UniqueFor2}_{UniqueForX}.verified.{extension}
```

The below samples produce:

For the instance case:

 * TheTest.UseTextForParameters_Value1.verified.txt
 * TheTest.UseTextForParameters_Value2.verified.txt

For the fluent case:

 * TheTest.UseTextForParametersFluent_Value1.verified.txt
 * TheTest.UseTextForParametersFluent_Value2.verified.txt<!-- endInclude -->


### Instance

<!-- snippet: UseTextForParametersInstanceXunit -->
<a id='snippet-UseTextForParametersInstanceXunit'></a>
```cs
[Theory]
[InlineData("Value1")]
[InlineData("Value2")]
public Task UseTextForParameters(string arg)
{
    var settings = new VerifySettings();
    settings.UseTextForParameters(arg);
    return Verify(arg + "UseTextForParameters", settings);
}
```
<sup><a href='/src/Verify.Xunit.Tests/Snippets/ParametersSample.cs#L208-L220' title='Snippet source file'>snippet source</a> | <a href='#snippet-UseTextForParametersInstanceXunit' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


### Fluent

<!-- snippet: UseTextForParametersFluentXunit -->
<a id='snippet-UseTextForParametersFluentXunit'></a>
```cs
[Theory]
[InlineData("Value1")]
[InlineData("Value2")]
public Task UseTextForParametersFluent(string arg) =>
    Verify(arg + "UseTextForParametersFluent")
        .UseTextForParameters(arg);
```
<sup><a href='/src/Verify.Xunit.Tests/Snippets/ParametersSample.cs#L222-L231' title='Snippet source file'>snippet source</a> | <a href='#snippet-UseTextForParametersFluentXunit' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


## Ignore parameters for verified filename

By default, Verify expects every parameterized case to have a unique [file name](/docs/naming.md) with the parameters appended to the file name. This behavior can be overridden by using `IgnoreParametersForVerified()`. In this case, the verified file name does not contain the parameter values, meaning it is the same for each testcase.<!-- include: ignore-parameters. path: /docs/mdsource/ignore-parameters.include.md -->

`IgnoreParametersForVerified` accepts an array for passing through the parameters. These values are passed to [UseParameters](#UseParameters). This is required for MSTest, and xUnit. Parameters should not be passed for NUnit, TUnit and Fixie since they are automatically detected.

The below samples produce:

For the instance case:

 * NamerTests.IgnoreParametersForVerified_arg=One.received.txt
 * NamerTests.IgnoreParametersForVerified_arg=Two.received.txt
 * NamerTests.IgnoreParametersForVerified.verified.txt

For the fluent case:

 * NamerTests.IgnoreParametersForVerifiedFluent_arg=One.received.txt
 * NamerTests.IgnoreParametersForVerifiedFluent_arg=Two.received.txt
 * NamerTests.IgnoreParametersForVerifiedFluent.verified.txt<!-- endInclude -->


### Instance

<!-- snippet: IgnoreParametersForVerifiedXunit -->
<a id='snippet-IgnoreParametersForVerifiedXunit'></a>
```cs
[Theory]
[InlineData("One")]
[InlineData("Two")]
public Task IgnoreParametersForVerified(string arg)
{
    var settings = new VerifySettings();
    settings.IgnoreParametersForVerified(arg);
    return Verify("value", settings);
}
```
<sup><a href='/src/Verify.Xunit.Tests/Snippets/ParametersSample.cs#L11-L23' title='Snippet source file'>snippet source</a> | <a href='#snippet-IgnoreParametersForVerifiedXunit' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


### Fluent

<!-- snippet: IgnoreParametersForVerifiedFluentXunit -->
<a id='snippet-IgnoreParametersForVerifiedFluentXunit'></a>
```cs
[Theory]
[InlineData("One")]
[InlineData("Two")]
public Task IgnoreParametersForVerifiedFluent(string arg) =>
    Verify("value")
        .IgnoreParametersForVerified(arg);
```
<sup><a href='/src/Verify.Xunit.Tests/Snippets/ParametersSample.cs#L25-L34' title='Snippet source file'>snippet source</a> | <a href='#snippet-IgnoreParametersForVerifiedFluentXunit' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


## IgnoreParametersForVerified with override parameters

The parameters passed to IgnoreParametersForVerified can be used pass custom parameters to [UseParameters](#UseParameters).


### Instance

<!-- snippet: IgnoreParametersForVerifiedCustomParamsXunit -->
<a id='snippet-IgnoreParametersForVerifiedCustomParamsXunit'></a>
```cs
[Theory]
[InlineData("One")]
[InlineData("Two")]
public Task IgnoreParametersForVerifiedCustomParams(string arg)
{
    var settings = new VerifySettings();
    settings.IgnoreParametersForVerified($"Number{arg}");
    return Verify("value", settings);
}
```
<sup><a href='/src/Verify.Xunit.Tests/Snippets/ParametersSample.cs#L36-L48' title='Snippet source file'>snippet source</a> | <a href='#snippet-IgnoreParametersForVerifiedCustomParamsXunit' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


### Fluent

<!-- snippet: IgnoreParametersForVerifiedCustomParamsFluentXunit -->
<a id='snippet-IgnoreParametersForVerifiedCustomParamsFluentXunit'></a>
```cs
[Theory]
[InlineData("One")]
[InlineData("Two")]
public Task IgnoreParametersForVerifiedCustomParamsFluent(string arg) =>
    Verify("value")
        .IgnoreParametersForVerified($"Number{arg}");
```
<sup><a href='/src/Verify.Xunit.Tests/Snippets/ParametersSample.cs#L50-L59' title='Snippet source file'>snippet source</a> | <a href='#snippet-IgnoreParametersForVerifiedCustomParamsFluentXunit' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


## Hashing parameters

Parameters can be hashed as an alternative to being stringified. This is useful when the parameters are large and could potentially generate file names that exceed allowances of the OS.<!-- include: hashing-parameters. path: /docs/mdsource/hashing-parameters.include.md -->

Hashing parameter is achieved by using `HashParameters`.

[Overriding text used for parameters](#overriding-text-used-for-parameters) is respected when generating the hash.

[XxHash64](https://learn.microsoft.com/en-us/dotnet/api/system.io.hashing.xxhash64) is used to perform the hash.<!-- endInclude -->


### Instance

<!-- snippet: UseParametersHashInstanceXunit -->
<a id='snippet-UseParametersHashInstanceXunit'></a>
```cs
[Theory]
[InlineData("Value1")]
[InlineData("Value2")]
public Task HashParametersUsage(string arg)
{
    var settings = new VerifySettings();
    settings.UseParameters(arg);
    settings.HashParameters();
    return Verify(arg, settings);
}
```
<sup><a href='/src/Verify.Xunit.Tests/Snippets/ParametersHashSample.cs#L3-L16' title='Snippet source file'>snippet source</a> | <a href='#snippet-UseParametersHashInstanceXunit' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


### Fluent

<!-- snippet: UseParametersHashFluentXunit -->
<a id='snippet-UseParametersHashFluentXunit'></a>
```cs
[Theory]
[InlineData("Value1")]
[InlineData("Value2")]
public Task HashParametersUsageFluent(string arg) =>
    Verify(arg)
        .UseParameters(arg)
        .HashParameters();
```
<sup><a href='/src/Verify.Xunit.Tests/Snippets/ParametersHashSample.cs#L18-L28' title='Snippet source file'>snippet source</a> | <a href='#snippet-UseParametersHashFluentXunit' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->