question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Assertions for Func<Task<T>>

See original GitHub issue

Currently both Func<Task> and Func<Task<T>> are handled by AsyncFunctionAssertions which has a Subject of type Func<Task> and hence ignores the return value for Func<Task<T>>.

If we split AsyncFunctionAssertions into:

  • AsyncFunctionAssertions for Func<Task<T>>, and
  • AsyncActionAssertions for Func<Task>

That should enable us to return the result of Task<T> for further assertions, similar to what was implement ed for Func<T> in #951, such as:

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

// Assert
func.Should().NotThrow().Which.Should().Be(42);
(await func.Should().NotThrowAsync()).Which.Should().Be(42);

This was inspired by this question

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
lg2decommented, Feb 27, 2019

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?

0reactions
jnyrupcommented, Feb 28, 2019

@lg2de I would prefer if you opened a new issue with an API proposal describing the purpose of the functions and their function signatures.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Assertion Functions in TypeScript
An assertion function is a function that throws an error if something unexpected happened. Using assertion signatures, we can tell TypeScript ...
Read more >
Assert Function (The GNU Awk User's Guide)
The assert() function tests the condition parameter. If it is false, it prints a message to standard error, using the string parameter to...
Read more >
assert() — Verify Condition
The assert() function prints a diagnostic message to stderr and aborts the program if expression is false (zero). The diagnostic message has one...
Read more >
What is the "assert" function? - c++
It is a function that will halt program execution if the value it has evaluated is false. Usually it is surrounded by a...
Read more >
Playground Example - Assertion Functions
These are typically called assertions (or invariants) and they are small functions which raise errors early when your variables don't match up to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found