-
Notifications
You must be signed in to change notification settings - Fork 108
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
No way to capture all method calls when parameters are required. #42
Comments
It would seem libraries like Moq use the following syntax. mock.Setup(x => x.DoSomething(It.IsAny<string>())).Returns((string s) => s.ToLower()); This is contrary to the fluent API. Also doesn't seem possible with the fluent API design. Anyone have any thoughts on how this could be implemented? |
It's not the best approach but you can realize something like this:
IElement = T The "Is.Any"-Function could return an object that implements "T" (IElement) and another interface like:
The class could look like:
The class should implement "T" via the virtual Interface class (so an instance of this class could be passed to the setup-Call of your method): On finding a behavior, you could check if the behavior-parameter supports the filter-interface, execute it with the methods-parameter as parameter for "ParameterMatch" and if it returns true, use this behavior. I hope it's clear what I mean. |
Another idea for the syntax of the fluent API: In this way, the Is.Any-Returns the IParameterFilter-Interface directly an every call of IParameterFilter returns a "U" (IElement). |
Could you not handle it slightly differently, like the following: mockVisitor.Setup.Expect.Once.WhenAny.Visit When I need to test a method is called, I write this as mockVisitor.Setup.ExpectExactly( 'Visit', 1) |
Closing since we've not been able to implement this in any usable way. |
When there is a mock required for a class or interface and a setup is required on a particular method. If that method has parameters it becomes very hard to give the correct parameters to link the setup with.
For example if we have the following interface and class to mock.
There is a problem trying to capture all calls to Visit, or even Accept. This means the following mock setup call needs to know the class or interface instance which is passed to the mock call.
The above case has been reduced for brevity sake, the constructor has been removed. Also the element might be the instance to pass in. But if element has more children, and we were to visit all of them this would then make this call fail.
There needs to be away to specify conditions the parameters should meet for the expectation to be met, return result to be returned, etc.
It would be nice to be able to write something along the lines of:
I don't believe this is possible at present however as there is no way to reverse where the value came from. Also there is no generic way to override methods to have funcs defined for all parameters.
The text was updated successfully, but these errors were encountered: