-
-
Notifications
You must be signed in to change notification settings - Fork 798
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
Provide fluent interface #833
Comments
Hi @mu88, thanks for your suggestion. As this would be a fairly fundamental change to Moq's fluent API, we'll have to check with @kzu whether this would also stand a chance of being included in the upcoming Moq v5. (It would be a pity to do all the work to add it in v4 only to once again have it lacking in v5.) My initial reaction here is somewhat ambivalent:
Any thoughts or opinions? |
If all you're doing are Setup...Returns, you could just use Linq to Mocks instead:
As @stakx said already, of course :) |
Thanks to the two of you for sharing your ideas :) I absolutely understand your concerns. I didn't know about
|
The C# compiler has some unfortunate limitations of what it can convert to LINQ expression trees. (See dotnet/csharplang#158.) You could work around it as follows: -Mock.Of<IMyType>(async x => await x.DoSomethingAsync() == new CustomResult() )
+Mock.Of<IMyType>( x => x.DoSomethingAsync() == Task.FromResult(new CustomResult()))
It can be helpful to think about |
Could |
@kirinboy, a fluent API wouldn't work with |
I'm closing this issue, seeing that there is an existing & mostly viable alternative ( That being said, I'll think about some easy and inconspicuous extension points in the fluent API that would allow client code to add their own extension methods to make this work. (More specifically, if the interfaces making up the fluent setup API each made their current "context" accessible, e.g. via some (Exposing a |
It would be great if we could write something like the following:
The text was updated successfully, but these errors were encountered: