Skip to content

Assertions for Func<Task<T>> #990

@jnyrup

Description

@jnyrup

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions