shouldly / shouldly

Should testing for .NET—the way assertions should be!

Home Page:https://docs.shouldly.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support task result assertion

VicenzoMartinelli opened this issue · comments

Would be a great additions if Shouldly endured the assertion of tasks results.
My suggestion is something like that:

await anyTaskRetuningValue(params).ShouldReturnAsync(assertionComparer)
await anyTaskRetuningValue(params).ShouldNotReturnNullAsync()

And for tasks without returning value:

await anyTaskWithoutReturningValue().ShouldRunSuccessfully()

Thanks for the amazing project!

Very nice issue bro

Hi, thanks for the suggestion!

It looks like this could lead to an explosion of new methods: ShouldReturnAsync for ShouldBe, ShouldNotReturnNullAsync for ShouldNotBe, etc. There is already existing composability:

(await TaskReturningMethod(params)).ShouldBe(expectedResult);
(await TaskReturningMethod(params)).ShouldNotBeNull();

And for tasks with a void result:

await TaskReturningMethod(params);

Have you found there to be friction using the current composable building blocks shown above?

We probably don't want to do something that would essentially duplicate the number of extension methods we'd have to maintain, not to mention tripling because ValueTask support has been requested in an existing open issue. But if we can identify the pain points, maybe we can do something more focused that helps diminish the identified pain.

Converting discussion issues to GitHub discussions.