Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Oct 25, 2024
1 parent 074f34a commit 264e346
Show file tree
Hide file tree
Showing 23 changed files with 401 additions and 135 deletions.
43 changes: 43 additions & 0 deletions docs/combinations.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ To change this file edit the source file and then run MarkdownSnippets.

# VerifyCombinations

VerifyCombinations allows all combinations of the given input lists to be executed, and the results all written to one file.


## Method being tested

Expand Down Expand Up @@ -70,6 +72,10 @@ public Task BuildAddressTest()

## CaptureExceptions

By default exceptions are not captured.

To enable exception capture use `captureExceptions = true`

<!-- snippet: CombinationSample_CaptureExceptions -->
<a id='snippet-CombinationSample_CaptureExceptions'></a>
```cs
Expand Down Expand Up @@ -153,3 +159,40 @@ Actual value was 0.,
```
<sup><a href='/src/Verify.Tests/VerifyCombinationsSample.BuildAddressExceptionsTest.verified.txt#L1-L54' title='Snippet source file'>snippet source</a> | <a href='#snippet-VerifyCombinationsSample.BuildAddressExceptionsTest.verified.txt' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


### Global CaptureExceptions

Exception capture can be enable globally:

<!-- snippet: GlobalCaptureExceptions -->
<a id='snippet-GlobalCaptureExceptions'></a>
```cs
[ModuleInitializer]
public static void Initialize() =>
VerifyCombinationSettings.CaptureExceptions();
```
<sup><a href='/src/StaticSettingsTests/VerifyCombinationsTests.cs#L4-L10' title='Snippet source file'>snippet source</a> | <a href='#snippet-GlobalCaptureExceptions' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

If exception capture has been enabled globally, it can be disable at the method test level using `captureExceptions: false`.

<!-- snippet: CombinationSample_CaptureExceptionsFalse -->
<a id='snippet-CombinationSample_CaptureExceptionsFalse'></a>
```cs
[Fact]
public Task BuildAddressExceptionsDisabledTest()
{
int[] streetNumbers = [1, 10];
string[] streets = ["Smith St", "Wallace St"];
string[] cities = ["Sydney", "Chicago"];
return VerifyCombinations(
BuildAddress,
streetNumbers,
streets,
cities,
captureExceptions: false);
}
```
<sup><a href='/src/StaticSettingsTests/VerifyCombinationsTests.cs#L68-L84' title='Snippet source file'>snippet source</a> | <a href='#snippet-CombinationSample_CaptureExceptionsFalse' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->
19 changes: 18 additions & 1 deletion docs/mdsource/combinations.source.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# VerifyCombinations

VerifyCombinations allows all combinations of the given input lists to be executed, and the results all written to one file.


## Method being tested

Expand All @@ -18,9 +20,24 @@ snippet: VerifyCombinationsSample.BuildAddressTest.verified.txt

## CaptureExceptions

By default exceptions are not captured.

To enable exception capture use `captureExceptions = true`

snippet: CombinationSample_CaptureExceptions


### Result

snippet: VerifyCombinationsSample.BuildAddressExceptionsTest.verified.txt
snippet: VerifyCombinationsSample.BuildAddressExceptionsTest.verified.txt


### Global CaptureExceptions

Exception capture can be enable globally:

snippet: GlobalCaptureExceptions

If exception capture has been enabled globally, it can be disable at the method test level using `captureExceptions: false`.

snippet: CombinationSample_CaptureExceptionsFalse
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
1, Smith St , Sydney : 1 Smith St, Sydney,
1, Smith St , Chicago: 1 Smith St, Chicago,
1, Wallace St, Sydney : 1 Wallace St, Sydney,
1, Wallace St, Chicago: 1 Wallace St, Chicago,
10, Smith St , Sydney : 10 Smith St, Sydney,
10, Smith St , Chicago: 10 Smith St, Chicago,
10, Wallace St, Sydney : 10 Wallace St, Sydney,
10, Wallace St, Chicago: 10 Wallace St, Chicago
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
A: a,
b: b,
C: c
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
A: a,
b: ArgumentException: B is not allowed,
C: c
}
85 changes: 85 additions & 0 deletions src/StaticSettingsTests/VerifyCombinationsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#pragma warning disable VerifyCombinations
public class VerifyCombinationsTests
{
#region GlobalCaptureExceptions

[ModuleInitializer]
public static void Initialize() =>
VerifyCombinationSettings.CaptureExceptions();

#endregion

[Fact]
public Task Defaults()
{
string[] list = ["A", "b", "C"];
return VerifyCombinations(
_ => _.ToLower(),
list);
}

[Fact]
public Task WithCaptureExceptions()
{
string[] a = ["A", "b", "C"];
return VerifyCombinations(
a =>
{
if (a == "b")
{
throw new ArgumentException("B is not allowed");
}

return a.ToLower();
},
a,
captureExceptions: true);
}

[Fact]
public Task WithNoCaptureExceptions()
{
string[] a = ["A", "b", "C"];
return Assert.ThrowsAsync<ArgumentException>(() =>
{
return VerifyCombinations(
a =>
{
if (a == "b")
{
throw new ArgumentException("B is not allowed");
}

return a.ToLower();
},
a,
captureExceptions: false);
});
}
public static string BuildAddress(int streetNumber, string street, string city)
{
ArgumentException.ThrowIfNullOrWhiteSpace(street);
ArgumentException.ThrowIfNullOrWhiteSpace(city);
ArgumentOutOfRangeException.ThrowIfLessThan(streetNumber, 1);

return $"{streetNumber} {street}, {city}";
}

#region CombinationSample_CaptureExceptionsFalse

[Fact]
public Task BuildAddressExceptionsDisabledTest()
{
int[] streetNumbers = [1, 10];
string[] streets = ["Smith St", "Wallace St"];
string[] cities = ["Sydney", "Chicago"];
return VerifyCombinations(
BuildAddress,
streetNumbers,
streets,
cities,
captureExceptions: false);
}

#endregion
}
18 changes: 9 additions & 9 deletions src/Verify.Expecto/Verifier_Combination.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static Task<VerifyResult> VerifyCombinations<A>(
string name,
Func<A, object?> method,
IEnumerable<A> a,
bool captureExceptions = false,
bool? captureExceptions = null,
VerifySettings? settings = null,
[CallerFilePath] string sourceFile = "") =>
Verify(
Expand All @@ -25,7 +25,7 @@ public static Task<VerifyResult> VerifyCombinations<A, B>(
Func<A, B, object?> method,
IEnumerable<A> a,
IEnumerable<B> b,
bool captureExceptions = false,
bool? captureExceptions = null,
VerifySettings? settings = null,
[CallerFilePath] string sourceFile = "") =>
Verify(
Expand All @@ -42,7 +42,7 @@ public static Task<VerifyResult> VerifyCombinations<A, B, C>(
IEnumerable<A> a,
IEnumerable<B> b,
IEnumerable<C> c,
bool captureExceptions = false,
bool? captureExceptions = null,
VerifySettings? settings = null,
[CallerFilePath] string sourceFile = "") =>
Verify(
Expand All @@ -60,7 +60,7 @@ public static Task<VerifyResult> VerifyCombinations<A, B, C, D>(
IEnumerable<B> b,
IEnumerable<C> c,
IEnumerable<D> d,
bool captureExceptions = false,
bool? captureExceptions = null,
VerifySettings? settings = null,
[CallerFilePath] string sourceFile = "") =>
Verify(
Expand All @@ -79,7 +79,7 @@ public static Task<VerifyResult> VerifyCombinations<A, B, C, D, E>(
IEnumerable<C> c,
IEnumerable<D> d,
IEnumerable<E> e,
bool captureExceptions = false,
bool? captureExceptions = null,
VerifySettings? settings = null,
[CallerFilePath] string sourceFile = "") =>
Verify(
Expand All @@ -99,7 +99,7 @@ public static Task<VerifyResult> VerifyCombinations<A, B, C, D, E, F>(
IEnumerable<D> d,
IEnumerable<E> e,
IEnumerable<F> f,
bool captureExceptions = false,
bool? captureExceptions = null,
VerifySettings? settings = null,
[CallerFilePath] string sourceFile = "") =>
Verify(
Expand All @@ -120,7 +120,7 @@ public static Task<VerifyResult> VerifyCombinations<A, B, C, D, E, F, G>(
IEnumerable<E> e,
IEnumerable<F> f,
IEnumerable<G> g,
bool captureExceptions = false,
bool? captureExceptions = null,
VerifySettings? settings = null,
[CallerFilePath] string sourceFile = "") =>
Verify(
Expand All @@ -142,7 +142,7 @@ public static Task<VerifyResult> VerifyCombinations<A, B, C, D, E, F, G, H>(
IEnumerable<F> f,
IEnumerable<G> g,
IEnumerable<H> h,
bool captureExceptions = false,
bool? captureExceptions = null,
VerifySettings? settings = null,
[CallerFilePath] string sourceFile = "") =>
Verify(
Expand All @@ -157,7 +157,7 @@ public static Task<VerifyResult> VerifyCombinations(
string name,
Func<object?[], object?> method,
List<IEnumerable<object?>> lists,
bool captureExceptions = false,
bool? captureExceptions = null,
VerifySettings? settings = null,
[CallerFilePath] string sourceFile = "") =>
Verify(
Expand Down
18 changes: 9 additions & 9 deletions src/Verify.Fixie/Verifier_Combination.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public static partial class Verifier
public static SettingsTask VerifyCombinations<A>(
Func<A, object?> method,
IEnumerable<A> a,
bool captureExceptions = false,
bool? captureExceptions = null,
VerifySettings? settings = null,
[CallerFilePath] string sourceFile = "") =>
Verify(
Expand All @@ -22,7 +22,7 @@ public static SettingsTask VerifyCombinations<A, B>(
Func<A, B, object?> method,
IEnumerable<A> a,
IEnumerable<B> b,
bool captureExceptions = false,
bool? captureExceptions = null,
VerifySettings? settings = null,
[CallerFilePath] string sourceFile = "") =>
Verify(
Expand All @@ -37,7 +37,7 @@ public static SettingsTask VerifyCombinations<A, B, C>(
IEnumerable<A> a,
IEnumerable<B> b,
IEnumerable<C> c,
bool captureExceptions = false,
bool? captureExceptions = null,
VerifySettings? settings = null,
[CallerFilePath] string sourceFile = "") =>
Verify(
Expand All @@ -53,7 +53,7 @@ public static SettingsTask VerifyCombinations<A, B, C, D>(
IEnumerable<B> b,
IEnumerable<C> c,
IEnumerable<D> d,
bool captureExceptions = false,
bool? captureExceptions = null,
VerifySettings? settings = null,
[CallerFilePath] string sourceFile = "") =>
Verify(
Expand All @@ -70,7 +70,7 @@ public static SettingsTask VerifyCombinations<A, B, C, D, E>(
IEnumerable<C> c,
IEnumerable<D> d,
IEnumerable<E> e,
bool captureExceptions = false,
bool? captureExceptions = null,
VerifySettings? settings = null,
[CallerFilePath] string sourceFile = "") =>
Verify(
Expand All @@ -88,7 +88,7 @@ public static SettingsTask VerifyCombinations<A, B, C, D, E, F>(
IEnumerable<D> d,
IEnumerable<E> e,
IEnumerable<F> f,
bool captureExceptions = false,
bool? captureExceptions = null,
VerifySettings? settings = null,
[CallerFilePath] string sourceFile = "") =>
Verify(
Expand All @@ -107,7 +107,7 @@ public static SettingsTask VerifyCombinations<A, B, C, D, E, F, G>(
IEnumerable<E> e,
IEnumerable<F> f,
IEnumerable<G> g,
bool captureExceptions = false,
bool? captureExceptions = null,
VerifySettings? settings = null,
[CallerFilePath] string sourceFile = "") =>
Verify(
Expand All @@ -127,7 +127,7 @@ public static SettingsTask VerifyCombinations<A, B, C, D, E, F, G, H>(
IEnumerable<F> f,
IEnumerable<G> g,
IEnumerable<H> h,
bool captureExceptions = false,
bool? captureExceptions = null,
VerifySettings? settings = null,
[CallerFilePath] string sourceFile = "") =>
Verify(
Expand All @@ -140,7 +140,7 @@ public static SettingsTask VerifyCombinations<A, B, C, D, E, F, G, H>(
public static SettingsTask VerifyCombinations(
Func<object?[], object?> method,
List<IEnumerable<object?>> lists,
bool captureExceptions = false,
bool? captureExceptions = null,
VerifySettings? settings = null,
[CallerFilePath] string sourceFile = "") =>
Verify(
Expand Down
Loading

0 comments on commit 264e346

Please sign in to comment.