Code Monkey home page Code Monkey logo

Comments (11)

jnyrup avatar jnyrup commented on June 3, 2024

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.

voroninp avatar voroninp commented on June 3, 2024

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.

voroninp avatar voroninp commented on June 3, 2024

Maybe AsyncResult() can be even a trigger for source interceptor ;-)

from fluentassertions.

dennisdoomen avatar dennisdoomen commented on June 3, 2024

Why not just use Result then?

from fluentassertions.

voroninp avatar voroninp commented on June 3, 2024

@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.

dennisdoomen avatar dennisdoomen commented on June 3, 2024

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.

voroninp avatar voroninp commented on June 3, 2024

Well... What do you think about this approach to asserting exceptions?

https://github.com/voroninp/FluentAssertionsInterception

from fluentassertions.

dennisdoomen avatar dennisdoomen commented on June 3, 2024

That's kind of the same. Adding overloads for everything. I don't see much value in that over just using Result

from fluentassertions.

voroninp avatar voroninp commented on June 3, 2024

Huh? Overloads for everything to assert exceptions? Why?

from fluentassertions.

dennisdoomen avatar dennisdoomen commented on June 3, 2024

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.

dennisdoomen avatar dennisdoomen commented on June 3, 2024

Closing as there was no follow-up

from fluentassertions.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.