Skip to content

Mock throwing an exception for async methods #609

@a-l-e-x-n-k

Description

@a-l-e-x-n-k

The problem is described here in comments under the answer: https://stackoverflow.com/questions/38338906/nsubstitute-mock-throwing-an-exception-in-method-returning-task

The problem with this is that the exception is thrown at the wrong time.
var t = AsyncMethod(); (actual behavior: exception will be raised here)
await t; (expected behavior: exception will be raised here)

With an async method the exception should be thrown when awaiting the task, Current approach throws the exception immediately.

Current behavior little bit unexpected in some cases. It would be great to correct it. Or may there is more elegant way to solve the problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature-requestRequest for a new NSubstitute feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions