Skip to content
This repository was archived by the owner on Jul 19, 2024. It is now read-only.
This repository was archived by the owner on Jul 19, 2024. It is now read-only.

Async events are not awaitable. #35

@Portikus

Description

@Portikus

Hi,

I want to stub a Interface containing a event with a delegate which returns a Task.

delegate Task AsyncEventHandler(object sender, EventArgs eventArgs);
event AsyncEventHandler AsyncEvent;

If I now try to generate a stub, SimpleStubs handles this event like a normal event and creates a AsyncEvent_Raise method with return type void. But of corse this wont work if I want to await the raised event in my unit tests.

I created a extension method to raise such an async event in my code (see AsyncEventHandlerExtension in repo solution). There you can see what to do if an event delagate is having a Task as return type.

But maybe you just return an IEnumerable<T> to handle every return type and let it to the user to handle the return type.

Repo solution: SimpleStubsAndAsyncEvent.zip

Repo steps:

  1. Restore nuget packages
  2. Build solution
    => build error "can not await void" in TestClass.cs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions