Comments (11)
I don't know what AsyncResult()
is supposed do 🤔
await foo.GetSomething().AsyncResult().Should().BeWhatever();
#1478 added WithResult
to help for the simple cases.
We don't want to make async variants of everything in the core library as that would double the API surface.
If you like to chain BeWhatever
on Task
methods have a look at https://github.com/fluentassertions/fluentassertions/blob/develop/Src/FluentAssertions/AsyncAssertionsExtensions.cs to see how you can implement it in your code base.
await foor.GetSomething().AsyncResult().Should().ThrowWhatever();
This API will not work if GetSomething()
throws an exception in a sync part before entering the async part.
That exception will be thrown before reaching Should()
.
Some alternative available syntaxes:
var act = () => foo.GetSomething();
await act.Should()..ThrowAsyncWhatever();
using static FluentAssertions.FluentActions;
await Awaiting(() => foo.GetSomething()).ThrowAsyncWhatever();
from fluentassertions.
With AsyncReslt()
it could be just the signal to FA that assertions are not for the task but its result.
I'll take a look, thanks.
from fluentassertions.
Maybe AsyncResult()
can be even a trigger for source interceptor ;-)
from fluentassertions.
Why not just use Result
then?
from fluentassertions.
@dennisdoomen With Result
it's difficult to understand the intention. Whether we want to block and get the result of the task and then assert against it, or we want some magic to keet the assertion async and easily changeable from result vs exception assertion.
from fluentassertions.
So you are suggesting that we add overloads of all Should
methods that work on the Task<T>
? That would take a hell of a lot of work.
from fluentassertions.
Well... What do you think about this approach to asserting exceptions?
https://github.com/voroninp/FluentAssertionsInterception
from fluentassertions.
That's kind of the same. Adding overloads for everything. I don't see much value in that over just using Result
from fluentassertions.
Huh? Overloads for everything to assert exceptions? Why?
from fluentassertions.
Ah yes, you just introduced the Method
extension method. Meh, not something I like.
await foo.GetSomething().AsyncResult().Should().BeWhatever();
This would mean that Should()
or BeWhatever
is going to be Task
aware, which as @jnyrup said, is potentially increase (or double) the number of APIs we need to support. A simple Result
should do the trick as well. And for exceptions we already have complete async
support.
from fluentassertions.
Closing as there was no follow-up
from fluentassertions.
Related Issues (20)
- Library is not compatible with .NET MAUI 8.0.6 HOT 4
- Add feature to check if an XElement or XAttribute is absent within the XDocument HOT 24
- Null reference exception when using custom comparer in equivalency options HOT 7
- [Feature]: Multi dimension arrays assertions HOT 10
- WithInnerException<T>() needs the type as a parameter HOT 2
- `Should().BeEquivalentTo` failing for identical objects HOT 3
- FluetntAssertion doesn't work correctly for records HOT 8
- Equivalency assertion option Excluding outputs "value(...<>c__DisplayClass).variableName" in some instances HOT 2
- Add string-option for ignoring newline style HOT 2
- Unexpected default equivalency behaviour with interfaces HOT 3
- ArgumentOutOfRangeException in FluentAssertions.Equivalency.Tracing.StringBuilderTraceWriter.ToString() HOT 8
- FluentAssertions: using a NullorEqual string EqualityComparer still returns a type difference error HOT 2
- [API Proposal]: Allow to assert RegEx matched groups HOT 3
- BeXmlSerializable does not respect XmlIgnoreAttribute HOT 5
- Use StringSyntaxAttribute to provide IDE support for proper reasons HOT 2
- [API Proposal]: Parsability of strings HOT 18
- Add AllSatisfyOrEmpty for GenericCollection HOT 4
- AssertionScope w/explicit name AND DetermineCallerIdentity doesn't work as expected
- [Feature]: SetEquals, unordered equal for collections HOT 1
- [Feature]: Compile time warning/error for chaining Should() after a null conditional (?.) HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fluentassertions.