Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Sep 24, 2023
1 parent 796d2c2 commit ae671b0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
20 changes: 20 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,26 @@ And the test is re run it will fail.
The same approach can be used to verify the results and the change to `Sample.Test.verified.txt` is committed to source control along with the change to `ClassBeingTested`.


### Async

`Verify()` has overloads that accept `Task<T>`, `ValueTask<T>`, and `IAsyncEnumerable<T>`. These are `await`ed before verification.

There is also an overload that accepts `Func<Task<T>>`, which works well with `async` lambda expressions:

<!-- snippet: VerifyFuncOfTaskOfT -->
<a id='snippet-verifyfuncoftaskoft'></a>
```cs
await Verify(
async () => new
{
Foo = await repo.GetFoo(id),
Bars = await repo.GetBars(id),
});
```
<sup><a href='/src/Verify.Tests/Snippets/Snippets.cs#L153-L162' title='Snippet source file'>snippet source</a> | <a href='#snippet-verifyfuncoftaskoft' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


### VerifyJson

`VerifyJson` performs the following actions
Expand Down
2 changes: 1 addition & 1 deletion readme.source.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ The same approach can be used to verify the results and the change to `Sample.Te

There is also an overload that accepts `Func<Task<T>>`, which works well with `async` lambda expressions:

snippet VerifyFuncOfTaskOfT
snippet: VerifyFuncOfTaskOfT


### VerifyJson
Expand Down
13 changes: 8 additions & 5 deletions src/Verify.Tests/Snippets/Snippets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,19 +152,22 @@ async Task VerifyFuncOfTaskOfT()

#region VerifyFuncOfTaskOfT

await Verify(async () => new
{
Foo = await repo.GetFoo(id),
Bars = await repo.GetBars(id),
});
await Verify(
async () => new
{
Foo = await repo.GetFoo(id),
Bars = await repo.GetBars(id),
});

#endregion
}

class Repo
{
// ReSharper disable once MemberCanBeMadeStatic.Local
public Task<object> GetFoo(int id) => throw new NotImplementedException();

// ReSharper disable once MemberCanBeMadeStatic.Local
public Task<object> GetBars(int id) => throw new NotImplementedException();
}
}

0 comments on commit ae671b0

Please sign in to comment.