From 2c14374046bbb3a546c31a04b481696812f3076e Mon Sep 17 00:00:00 2001 From: Dominique Schuppli Date: Thu, 12 May 2022 17:55:02 +0200 Subject: [PATCH] `StubbedPropertySetup.IsMatch` is too picky 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). --- src/Moq/StubbedPropertySetup.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Moq/StubbedPropertySetup.cs b/src/Moq/StubbedPropertySetup.cs index 17bcd5df6..afe2e0ae8 100644 --- a/src/Moq/StubbedPropertySetup.cs +++ b/src/Moq/StubbedPropertySetup.cs @@ -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; } } }