Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds ReturnAsync extention method that accepts a Func<TResult> #297

Merged
merged 4 commits into from
Nov 10, 2016

Conversation

joeenzminger
Copy link
Contributor

No description provided.

{
return mock.Returns(() =>
{
var tcs = new TaskCompletionSource<TResult>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not return Task.FromResult(value()) instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That works as well (at least it passes the tests). I was just trying to be consistent with the method used in the extension methods that were already there. Not sure if there is an advantage/disadvantage either way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like Task.FromResult() is probably the "newer" way to go.

http://stackoverflow.com/questions/21256110/task-fromresult-vs-taskcompletionsource-setresult

@tomasaschan
Copy link

I had just started implementing this too, when I found this PR :)

I've extended it with implementations for Funcs that take arguments here - they basically just forward to the already existing Returns method, wrapping the result in a Task. That builds on this PR - would you prefer I make a pull request against @joeenzminger's master to get it here, or file a separate PR directly with moq/moq4?

@kzu
Copy link
Member

kzu commented Nov 5, 2016

Far better to have a single PR than to have to pick a "winner" 😉

On Fri, Nov 4, 2016, 2:36 AM Tomas Lycken notifications@github.com wrote:

I had just started implementing this too, when I found this PR :)

I've extended it with implementations for Funcs that take arguments here
tomasaschan@27d548d

  • they basically just forward to the already existing Returns method,
    wrapping the result in a Task. That builds on this PR - would you prefer
    I make a pull request against @joeenzminger
    https://github.com/joeenzminger's master to get it here, or file a
    separate PR directly with moq/moq4?


You are receiving this because you commented.

Reply to this email directly, view it on GitHub
#297 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAKW62nfIQhAi4_d_k38ivRB2sd8OTDwks5q6uCBgaJpZM4KcZ7n
.

/kzu from mobile

@tomasaschan
Copy link

Done :)

When joeenzminger#1 merges, it should show up here; if you have comments or suggestions for improvement, feel free to raise them there or here.

T4-generated overloads for ReturnsAsync(Func<T1, T2, ... TResult> value)
Copy link
Member

@kzu kzu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@kzu kzu merged commit 8adccf1 into devlooped:master Nov 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants