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

Support chaining NotThrowAfter and NotThrowAsync #1289

Merged
merged 1 commit into from Apr 10, 2020

Conversation

jnyrup
Copy link
Member

@jnyrup jnyrup commented Mar 29, 2020

This PR enables you to continue asserting on the result of Func<Task<int>> when it does not throw.

Func<Task<int>> func = () => Task.FromResult(42);

func.Should().NotThrow()
    .Which.Should().Be(42);

(await func.Should().NotThrowAsync())
    .Which.Should().Be(42);

func.Should().NotThrowAfter(10.Seconds(), 1.Seconds())
    .Which.Should().Be(42)

(await func.Should().NotThrowAfterAsync(10.Seconds(), 1.Seconds()))
    .Which.Should().Be(42);

The implementations and tests are mostly copied from the non-generic or sync versions.
To avoid the redefinitions of Subject in each class two changes in generics:

  • DelegateAssertions and AsyncFunctionAssertions are now generic in TAssertions.
  • AsyncFunctionAssertions is also generic in TTask : Task to support
    both Task and Task<T> equally.

This fixes #990

Copy link
Member

@dennisdoomen dennisdoomen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only some minor comments.

@jnyrup jnyrup force-pushed the FuncTaskT branch 2 times, most recently from 45dac8d to b2afe1f Compare March 30, 2020 16:49
@jnyrup
Copy link
Member Author

jnyrup commented Mar 30, 2020

Updated PR with more widespread changes.

This PR enables you to continue asserting on the result of `Func<Task<int>>` when it does not throw.

```c#
Func<Task<int>> func = () => Task.FromResult(42);

func.Should().NotThrow()
    .Which.Should().Be(42);

(await func.Should().NotThrowAsync())
    .Which.Should().Be(42);

func.Should().NotThrowAfter(10.Seconds(), 1.Seconds())
    .Which.Should().Be(42)

(await func.Should().NotThrowAfterAsync(10.Seconds(), 1.Seconds()))
    .Which.Should().Be(42);
```

The implementations and tests are mostly copied from the non-generic or sync versions.
To avoid the redefinitions of `Subject` in each class two changes in generics:
* `DelegateAssertions` and `AsyncFunctionAssertions` are now generic in `TAssertions`.
* `AsyncFunctionAssertions` is also generic in `TTask : Task` to support
  both `Task` and `Task<T>` equally.

This fixes fluentassertions#990
@jnyrup
Copy link
Member Author

jnyrup commented Apr 10, 2020

@dennisdoomen this should be ready for (another) review now.

In continuation of #1296 I've added more generics:

  • T to reuse T Subject from ReferenceAssertions<T>.
  • TAssertions to improve continuation on classes that inherits DelegateAssertions.

@jnyrup jnyrup merged commit 1baedd2 into fluentassertions:develop Apr 10, 2020
@jnyrup jnyrup deleted the FuncTaskT branch April 10, 2020 18:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Assertions for Func<Task<T>>
2 participants