-
-
Notifications
You must be signed in to change notification settings - Fork 839
Description
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