bitblack / moq

Automatically exported from code.google.com/p/moq
Other
0 stars 0 forks source link

Swapped method arguments will overwrite previous method setup #365

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
When method with two arguments of same type is setup another setup call with 
swapped arguments will lead to situation where previous setup is removed.

What is the expected output? What do you see instead?
In case when arguments are swapped Mock should still hold reference to two 
different versions of method invocation setup. First which will get instance A 
as first argument and B as second argument. Second which have B as first 
argument and A as second argument.

Please reffer to attached simple code example which will simulate issue very 
easily.

What version of the product are you using? On what operating system?
v4.0.20926

Please provide any additional information below.
Please see attached code example which will lead to incorrect behaviour.

Original issue reported on code.google.com by silve...@gmail.com on 5 Jun 2013 at 5:42

Attachments:

GoogleCodeExporter commented 9 years ago
The bug is in the ExpressionKey nested class of Interceptor.
Equals method returns true for 2 setup expressions with the same arguments 
swapped.

var eq = key.fixedString == this.fixedString && key.values.Count == 
this.values.Count;

var index = 0;
while (eq && index < this.values.Count)
{
    eq |= this.values[index] == key.values[index];
    index++;
}

The code says, that 2 expressions keys are equal if they have the same number 
of arguments OR at least 2 arguments on the same position in the list are equal.
The | needs to be replaced with & or SequenceEquals can be used instead.

Nevertheless, GetHashCode method returns the same value for 2 different 
ExpressionKeys having the arguments swapped, so I assume that needs to be fixed 
as well.

Original comment by vlado.n...@gmail.com on 17 Sep 2013 at 8:45

GoogleCodeExporter commented 9 years ago
Hi,

Thank You  for all this information's, however I need to say that we are 
interested in fix and not root cost analysis.

Original comment by silve...@gmail.com on 17 Sep 2013 at 11:49