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

Support Mock.Get(mock, exp) syntax #229

Closed
davidshen84 opened this issue Dec 20, 2015 · 5 comments
Closed

Support Mock.Get(mock, exp) syntax #229

davidshen84 opened this issue Dec 20, 2015 · 5 comments

Comments

@davidshen84
Copy link

Currently, functional style is only supported in this form:

var mockSomeType = Mock.Of<SomeType>(t => t.Prop == "test")

After that, if I want to add more Setup on mockSomeType, I have to use Setup method many times:

Mock.Get(mockSomeType).Setup(...);
Mock.Get(mockSomeType).Setup(...);
...

I think it would be more convenient if we can support:

Mock.Get(mockSomeType, t => t.Prop == "other test")
@stakx
Copy link
Contributor

stakx commented Jun 16, 2017

I'd like to understand the motivation for this a little better. Why would you choose not to just specify all setups initially using &&, e.g. Mock.Of<T>(foo => foo.A == 1 && foo.M() == 2)?

My understanding is that Mock.Get(obj) is simply the reverse of Mock.Object. To me personally, it doesn't make too much sense mixing this up with setting up a mock...?

@davidshen84
Copy link
Author

What I want to address is convenience here.

For example if I have the following settings that work in most cases:

var mockSomeType = Mock.Of<SomeType>(t => t.Prop == "prop1" && t.Attr == "attr1")

But I need to modify this mockSomeType, in some other cases. I want to modify the mock in a similar syntax.

Of course, I can just refactor the mock setting logic in the initialize function to separate the logic.

@stakx
Copy link
Contributor

stakx commented Jun 20, 2017

I think #293 asks for the same thing. The question there by kzu about how updates should be combined with the original setup / mock definition is valid here, too. What is your opinion on this question?

@davidshen84
Copy link
Author

#293 asks for a way to update current mock settings. What I want is a simple syntax utility to keep adding definitions to the mock.

But @kzu 's comment do have a point. If allow adding, soon, people will asking for replacing...deleting...

@stakx
Copy link
Contributor

stakx commented Sep 23, 2017

I still think your issue could be subsumed under the other one. In Moq, there's already a precedent showing how updating existing & adding more setups should work: Setup. The rule is simple: Setup will replace previous setups with the new one if the invocation "shapes" described by both setup expressions match; if not, a new setup is added. mock.Get(object, Expression) / mock.Update(Expression) (or whatever the exact syntax would be) should follow the same pattern or things are bound to get confusing and hard to explain.

So you see, just as it is with Setup, there's no reason to distinguish between "adding" and "updating". For this reason, I'd like to close this issue in favour of #293. Please don't hesitate to post back if you disagree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants