-
-
Notifications
You must be signed in to change notification settings - Fork 121
[Feature]: ReturnsAsync factory with actual method parameters for mocks #5361
Copy link
Copy link
Closed
Labels
enhancementNew feature or requestNew feature or request
Description
Problem Statement
The Returns method allows you to pass a factory through which you can access the arguments passed to the method. However, it seems that this feature is missing from ReturnsAsync.
Proposed Solution
A ReturnsAsync overload which allows to pass in a factory method and return a Task<T> from the method parameters:
mock
.DoSomethingAsync(Any<Func<Task<string>>>())
.ReturnsAsync(factory => factory.Invoke());Alternatives Considered
It is possible to use .Returns and return Task<T>.Result:
mock
.DoSomethingAsync(Any<Func<Task<string>>>())
.Returns(factory => factory.Invoke().Result); // Exists but requires `Task<T>.Result`Feature Category
Other
How important is this feature to you?
Nice to have - would improve my experience
Additional Context
No response
Contribution
- I'm willing to submit a pull request for this feature
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request