Skip to content

Async Method Support Clean-up #384

@rbdevr

Description

@rbdevr

Right now, Moq doesn't have a proper support for async methods. There are a few methods giving Moq some Async support. Those are spreaded through out Moq fluentApi like ReturnAsync() and ThrowAsync() but it's not developer friendly.
I suggest to implement FluentApi support for async methods starting from SetupAsync() and expose only async functionality.
At the same time, remove all the async methods from the current Setup().
Let me know your thoughts. Should I do a request pull and start working on it?
Regards

Example:
interface IComponent {
   int Process(int value);
   Task<int> ProcessAsync(int value);
}
componentMock.Setup(I => Process(It.Any<int>()).Return(1); // normal method
componentMock.Setup(I => Process(It.Any<int>()).Throw(new Exception()); // normal method
componentMock.Setup(I => Process(It.Any<int>()).Callback(i => capt = i); // normal method
componentMock.SetupAsync(I => ProcessAsync(It.Any<int>()).Return(1); // full async support
componentMock.SetupAsync(I => ProcessAsync(It.Any<int>()).Throw(new Exception()); // full async support
componentMock.SetupAsync(I => ProcessAsync(It.Any<int>()).Callback(i => capt = i); // full async support

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