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

Projects
None yet
3 participants
@ejball
Copy link
Contributor

commented Mar 31, 2019

For issue #1015.

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

This comment has been minimized.

Copy link
@dennisdoomen

dennisdoomen Mar 31, 2019

Member

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

This comment has been minimized.

Copy link
@ejball

ejball Mar 31, 2019

Author Contributor

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:

This comment has been minimized.

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

This comment has been minimized.

Copy link
@jnyrup

jnyrup Mar 31, 2019

Collaborator

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

This comment has been minimized.

Copy link
@ejball

ejball Mar 31, 2019

Author Contributor

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;

This comment has been minimized.

Copy link
@jnyrup

jnyrup Mar 31, 2019

Collaborator

@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();

This comment has been minimized.

Copy link
@jnyrup

jnyrup Mar 31, 2019

Collaborator

typo: Missing > after ArgumentNullException.

This comment has been minimized.

Copy link
@ejball

ejball Mar 31, 2019

Author Contributor

Good catch! Fixed: 0459a63

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

This comment has been minimized.

Copy link
@jnyrup

jnyrup Mar 31, 2019

Collaborator

typo: Missing > after ArgumentNullException.

@ejball

This comment has been minimized.

Copy link
Contributor Author

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

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
@jnyrup

This comment has been minimized.

Copy link
Collaborator

commented Mar 31, 2019

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

@ejball ejball deleted the ejball:fluent-action branch Mar 31, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.