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

Identical setups are now not considered the same (regression) #295

Closed
cyanite opened this issue Oct 19, 2016 · 2 comments
Closed

Identical setups are now not considered the same (regression) #295

cyanite opened this issue Oct 19, 2016 · 2 comments

Comments

@cyanite
Copy link

cyanite commented Oct 19, 2016

The (partial) fix for #278 causes a regression in how identical setups are handled. Internally, a dictionary is used to prevent duplicates (and to let identical setups override eachother), but with the new equality code, this will almost never work. The reason is that each argument is compared by reference equality, from a List<object>. Value types are boxed in order to be in this list, and will thus never be equal (consider that (object)1 != (object)1).

The equality and hash code should be reworked. Ideally only the string in the key should be used, and #278 should be solved by adding the appropriate arguments to the key string.

We're forced to downgrade Moq due to this bug, and due to a bug in Castle.Core 3.3.3 (used by this Moq version) involving default parameters.

MatKubicki added a commit to MatKubicki/moq4 that referenced this issue Jan 3, 2017
…oped#295.

There is still problematic code in the Interceptor for comparing the arguments of calls, but for now it no longer causes a problem with propeties with arguments as the expression string builder now reports the arguments for property reads.
I've added a comment explaining the flaws (as I see them) in the Interceptor code in the hope that it will help when someone next as a problem, or at least stops them missing the same thing as I did earlier.
@MatKubicki
Copy link
Contributor

I finally got back to taking a look at this.

The issue with comparing arguments by reference rather than by value has existed since long before my change, but my fix to make the comparison less buggy makes it more visible.

Since I haven't got the time to come up with a solution to the GetHashCode and Equals implmentations, i've fixed the problem I was trying to fix in a different way (by making the string key include the arguments for properties). I've also added a comment to the problematic code in the Interceptor covering both the issue I found and the issue @cyanite found in the hope that it will help the next person to look at this code.

To top it off I added a unit test for this issue.

kzu pushed a commit that referenced this issue Jan 9, 2017
* Fixes #278.  Only fixes some of the issue though.  Also adds new VB test assembly, hopefully in a way people will be happy with

* Another fix for issue #278 that no longer causes issue #295.
There is still problematic code in the Interceptor for comparing the arguments of calls, but for now it no longer causes a problem with propeties with arguments as the expression string builder now reports the arguments for property reads.
I've added a comment explaining the flaws (as I see them) in the Interceptor code in the hope that it will help when someone next as a problem, or at least stops them missing the same thing as I did earlier.
@kzu
Copy link
Contributor

kzu commented Feb 21, 2017

Please reopen if the mentioned commit/PR didn't fix the issue.

@kzu kzu closed this as completed Feb 21, 2017
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

No branches or pull requests

3 participants