Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed May 25, 2022
1 parent 69e67e4 commit 075dfc0
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 3 deletions.
15 changes: 14 additions & 1 deletion docs/mdsource/parameterised.source.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ A test with two parameters `param1` + `param2`, and called twice with the values
Characters that cannot be used for a file name will be replaced with a dash (`-`).


## UseParameters

`UseParameters` is used to control what parameters are used when naming files. The usual usage is to pass though all parameters (in the same order) that the test method accepts:

snippet: UseParameters

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: UseParametersSubSet

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


## xUnit


Expand All @@ -33,7 +46,7 @@ snippet: xunitMemberData

### Complex MemberData

xUnit only exposes parameter information when the types certain types. For unknown types the parameter information cannot be retrieved from the xUnit context, and instead the parameters need to be explicitly passed in. This is done by calling `UseParameters()` on the base class.
xUnit only exposes parameter information when the types certain types. For unknown types the parameter information cannot be retrieved from the xUnit context, and instead the parameters need to be explicitly passed in. This is done by calling `UseParameters()`.

snippet: xunitComplexMemberData

Expand Down
44 changes: 42 additions & 2 deletions docs/parameterised.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,46 @@ A test with two parameters `param1` + `param2`, and called twice with the values
Characters that cannot be used for a file name will be replaced with a dash (`-`).


## UseParameters

`UseParameters` is used to control what parameters are used when naming files. The usual usage is to pass though all parameters (in the same order) that the test method accepts:

<!-- snippet: UseParameters -->
<a id='snippet-useparameters'></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#L53-L65' title='Snippet source file'>snippet source</a> | <a href='#snippet-useparameters' 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: UseParametersSubSet -->
<a id='snippet-useparameterssubset'></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#L67-L78' title='Snippet source file'>snippet source</a> | <a href='#snippet-useparameterssubset' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

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


## xUnit


Expand Down Expand Up @@ -86,13 +126,13 @@ public static IEnumerable<object[]> GetData()
};
}
```
<sup><a href='/src/Verify.Xunit.Tests/Snippets/ParametersSample.cs#L53-L82' title='Snippet source file'>snippet source</a> | <a href='#snippet-xunitmemberdata' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Xunit.Tests/Snippets/ParametersSample.cs#L80-L109' title='Snippet source file'>snippet source</a> | <a href='#snippet-xunitmemberdata' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


### Complex MemberData

xUnit only exposes parameter information when the types certain types. For unknown types the parameter information cannot be retrieved from the xUnit context, and instead the parameters need to be explicitly passed in. This is done by calling `UseParameters()` on the base class.
xUnit only exposes parameter information when the types certain types. For unknown types the parameter information cannot be retrieved from the xUnit context, and instead the parameters need to be explicitly passed in. This is done by calling `UseParameters()`.

<!-- snippet: xunitComplexMemberData -->
<a id='snippet-xunitcomplexmemberdata'></a>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Value1 Value2 Value3 some text
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Value1 some text
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Value2 some text
27 changes: 27 additions & 0 deletions src/Verify.Xunit.Tests/Snippets/ParametersSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,33 @@ public Task InlineDataUsageFluent(string arg) =>

#endregion

#region UseParameters

[Theory]
[InlineData("Value1")]
[InlineData("Value2")]
public Task UseParametersUsage(string arg)
{
var somethingToVerify = $"{arg} some text";
return Verify(somethingToVerify)
.UseParameters(arg);
}

#endregion

#region UseParametersSubSet

[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);
}

#endregion

#region xunitMemberData

[Theory]
Expand Down

0 comments on commit 075dfc0

Please sign in to comment.