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
Assertions for Func<Task<T>> #990
Comments
Yeah, sounds like a good idea. |
I would like to combine this extension with an additional feature: func.Should().Complete(TimeSpan.FromMilliseconds(100)); The test would fail if the Task does not complete within specified time span. What do you think about such feature? |
That's a nice idea, and a very useful one as well. |
While thinking about the implementation I would like to check whether my "Complete" extension should be based on this.myServer.OpenAsync().Should().Complete(TimeSpan.FromMilliseconds(100)); In this case my changes would not touch anymore the refactoring mentioned by @jnyrup. |
@lg2de I would prefer if you opened a new issue with an API proposal describing the purpose of the functions and their function signatures. |
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
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
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
Currently both
Func<Task>
andFunc<Task<T>>
are handled byAsyncFunctionAssertions
which has aSubject
of typeFunc<Task>
and hence ignores the return value forFunc<Task<T>>
.If we split
AsyncFunctionAssertions
into:AsyncFunctionAssertions
forFunc<Task<T>>
, andAsyncActionAssertions
forFunc<Task>
That should enable us to return the result of
Task<T>
for further assertions, similar to what was implement ed forFunc<T>
in #951, such as:This was inspired by this question
The text was updated successfully, but these errors were encountered: