Skip to content

Commit

Permalink
StubbedPropertySetup.IsMatch is too picky
Browse files Browse the repository at this point in the history
Comparing `MethodInfo`s using the `==` operator appears to go wrong more
often than not. (In this case, this method fails to identify a positive
match of `Base.Property` as the implementation for `IBase.Property`).

Let's make this test much more imprecise by simply comparing accessor
method names (and thus completely ignoring the type hierarchy; if we're
lucky, the .NET compilers will already guarantee valid polymorphic type
relationships).
  • Loading branch information
stakx committed May 12, 2022
1 parent 8f69c60 commit 2c14374
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Moq/StubbedPropertySetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ public override int GetHashCode()

public override bool IsMatch(Invocation invocation)
{
var method = invocation.Method;
return method == this.getter || method == this.setter;
var methodName = invocation.Method.Name;
return methodName == this.getter.Name || methodName == this.setter.Name;
}
}
}
Expand Down

0 comments on commit 2c14374

Please sign in to comment.