Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FluentAction for shorter syntax for exception assertions #1017

Merged
merged 6 commits into from Mar 31, 2019

Conversation

@ejball
Copy link
Contributor

@ejball ejball commented Mar 31, 2019

For issue #1015.

/// Contains static methods to help with exception assertions on actions.
/// </summary>
[DebuggerNonUserCode]
public static class FluentAction
Copy link
Member

@dennisdoomen dennisdoomen Mar 31, 2019

I think naming this class FluentActions would be better, since it is just a static container with static methods.

Copy link
Contributor Author

@ejball ejball Mar 31, 2019

Fair enough. Fixed: 0459a63

@@ -761,6 +761,22 @@ await act.Should().NotThrowAfterAsync(2.Seconds(), 100.Milliseconds());
act.Should().NotThrowAfter(2.Seconds(), 100.Milliseconds());
```
If you prefer single-statement assertions, consider using the `FluentAction` static class, which has `Invoking`, `Awaiting`, and `Enumerating` methods:
Copy link
Member

@dennisdoomen dennisdoomen Mar 31, 2019

👍

public static class FluentAction
{
/// <summary>
/// Invokes the specified action so that you can chain it with ShouldThrow, etc.
Copy link
Member

@jnyrup jnyrup Mar 31, 2019

Should().Throw()?
ShouldThrow() is pre-5.0.0 notation.

Copy link
Contributor Author

@ejball ejball Mar 31, 2019

Fixed: 03d3877

/// Invokes the specified action so that you can chain it with ShouldThrow, etc.
/// </summary>
[Pure]
public static Func<T> Invoking<T>(Func<T> func) => func;
Copy link
Member

@jnyrup jnyrup Mar 31, 2019

@dennisdoomen If we decide on the name Invoking for Fun<T> here, then #872 should also be named Invoking for consistency.

If you prefer single-statement assertions, consider using the `FluentAction` static class, which has `Invoking`, `Awaiting`, and `Enumerating` methods:
```csharp
FluentAction.Invoking(() => MyClass.Create(null)).Should().Throw<ArgumentNullException();
Copy link
Member

@jnyrup jnyrup Mar 31, 2019

typo: Missing > after ArgumentNullException.

Copy link
Contributor Author

@ejball ejball Mar 31, 2019

Good catch! Fixed: 0459a63

...
Invoking(() => MyClass.Create(null)).Should().Throw<ArgumentNullException();
Copy link
Member

@jnyrup jnyrup Mar 31, 2019

typo: Missing > after ArgumentNullException.

@ejball
Copy link
Contributor Author

@ejball ejball commented Mar 31, 2019

I also forgot to add the unit tests to the shared project. 😬 Fixed: 7a647b3

jnyrup
jnyrup approved these changes Mar 31, 2019
@jnyrup jnyrup merged commit 311aa0a into fluentassertions:master Mar 31, 2019
1 check passed
@jnyrup
Copy link
Member

@jnyrup jnyrup commented Mar 31, 2019

Thanks for the contribution @ejball.
Lookout for your name in the next release notes.

@ejball ejball deleted the fluent-action branch Mar 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants