-
-
Notifications
You must be signed in to change notification settings - Fork 804
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
Async Method Support Clean-up #384
Comments
At first glance, and without considering any other (possibly more arcane) use cases involving You are welcome to send a PR. Let me just mention three points that you're probably already aware of:
Thank you! |
Some various related things to be tracked along with this issue (I might expand this list later on): |
I've got the basics in place but with two Setup() and SetupAsync() it means double the tests. |
I've finished doing some necessary cleaning up. I've noticed that it is possible to use Setup() to do normal methods and async methods. .Net is capable of identifing one from the other based on the return argument. This makes development a lot more friendlier but there are two things to consider.
Let me know your toughts. So in that case tests will look like: |
Regarding your two points:
@kzu, what's your opinion on (1) above? Would you prefer full integration of all async setup methods into the regular |
Previously I've talked about the unittests. What approuch would you prefer? |
Regarding the unit tests, I first need to take a look at what unit tests we are talking about here. I'll get back to you on that! |
I've pushed the current code with the original requirements (explicit) to: |
|
I've found an issue with the ThrowAsync extensions. They are returning IReturnResults<Type> fluentapi interface. It's my understanding they should return IThrowsResult. |
I've been struggling to implement the async FluentApi due to the current design. At the same time I've noticed some issues with FluentApi. So I've decided to refactor the methodcall classes and fluentapi functionality. Implementng separation of concerns and giving FluentApi full freedom for future implementations. |
I've noticed IOccurrence was decomission and Verify() was put in place. Doesn't that break the idea of a clear Setup() functionality with FluentApi support previously discussed? |
Hi @Robydev, sorry for not getting back to you sooner. I'm going to set aside some time later this week to look at the work you've done so far, and try to answer your questions. Thanks for being patient! |
Maybe I can answer the occasional question right now:
Not having the ability to specify a
I haven't yet looked into the work you've done on this, but generally speaking, you could isolate that refactoring out into a separate PR that precedes the work you're doing on async. If you think keeping those two works separate from one another would help understanding and traceability later on, that would probably be the way to go. |
Some news on that work ? Then I found that post and see that there is no activity here since 11 months... |
I have checked in the code a long time ago and I didn't hear any feedback. |
Ok without more reactivity from moq team, let chose to publish an extension package: Sources and exemples are here: |
Hi @rbdevr. Your issue is one of the few that sort of fell by the wayside during the issue burnination sprint I did between June 2017 and February 2018. Your issue was/is one with a comparatively large scope, and judging from your own responses (above), it's one that isn't straightforward and demands some potentially tricky decisions. I was simply too busy with other issues back then to allocate more of my own resources for this, so I posted the brief response above, hoping that might get you a little further. I'd like to apologize to you that I didn't communicate better at the time. Do feel free to keep working on this. One word of caution, though: At present, it might pay off more to direct any improvements at the upcoming version 5 of Moq (https://github.com/moq/moq). Right now, for the time being, Moq 4's API is frozen so Moq 5 can be finalized. I can do the occasional review for you guys and give feedback / suggestions if you'd like, however until perhaps the second half of June I won't have a lot of free capacity as I'm currently busy working through the whole stack underneath Moq (Mono/.NET/.NET Core and Castle DynamicProxy) trying to ensure Moq 4 will be able to deal with the new C# 7 language features. |
OK so I let you work on Moq 5 to integrate a clean SetupAsync with a reworked API. And if final implementation in Moq 5 is not to far from the one in the package, we can hope that migration would be transparent or at least scriptable. I've already write some Roslyn code fix to perform such type of migration. So I'll will keep an eye on your progression to provide such code fix if necessary. |
It has been rather quiet in here for a while. Last time some work was done on this, things turned out to be a little more difficult than expected because of overload conflicts. So for the protocol, if anyone picks this up in the future, here's something to think about: It might be a good idea to implement a cleaned-up async API as extension methods in a separate namespace, say Another option would be to do something similar as |
And introducing a new
Is that justified to have an Furthermore I think that having a scope is less discover-able, than adding a new specialized For |
For one thing, because I'd like to avoid new method names. True, in this case it would probably be only Ideally (IMHO), the new methods would be called simply Which brings me to the reason I mentioned above: if we went with just That's how and why I ended up thinking about
We could of course do I do agree, however, that discoverability is an important consideration, and I'm not sure |
I'm going to close this issue in favor of #1007. By adding an |
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
The text was updated successfully, but these errors were encountered: