Skip to content

Commit

Permalink
Merge pull request #1260 from stakx/bugfix/stubbedpropertysetup-ismatch
Browse files Browse the repository at this point in the history
Make `StubbedPropertySetup.IsMatch` less picky
  • Loading branch information
stakx committed May 12, 2022
2 parents 20eb04a + 7a7a76b commit a844d5e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -24,6 +24,7 @@ New major version of DynamicProxy (you may get better performance!), so please u

* Can't set up "private protected" properties (@RobSiklos, #1170)
* Using [...] an old version of `System.Net.Http` which is vulnerable to "DoS", "Spoofing", "Privilege Escalation", "Authentication Bypass" and "Information Exposure" (@sidseter, #1219)
* Regression with `SetupProperty` where Moq fails to match a property accessor implementation against its definition in an interface (@Naxemar, #1248)
* Failure when invoking a method with by-ref parameter & mockable return type on a mock with `CallBase` and `DefaultValue.Mock` configured (@IanKemp, #1249)


Expand Down
4 changes: 2 additions & 2 deletions src/Moq/StubbedPropertySetup.cs
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
36 changes: 36 additions & 0 deletions tests/Moq.Tests/Regressions/IssueReportsFixture.cs
Expand Up @@ -3781,6 +3781,42 @@ public void Property_on_submock_should_be_stubbed_2()

#endregion

#region 1248

public class Issue1248
{
public interface IBase
{
bool Property { get; set; }
}

public interface IDerived : IBase
{
}

public class Base : IBase
{
public virtual bool Property { get; set; }
}

[Fact]
public void Test()
{
var mock = new Mock<Base>();
var mockAsDerived = mock.As<IDerived>();
mockAsDerived.SetupProperty(x => x.Property, false);

mockAsDerived.Object.Property = true;

mock.VerifySet(x => x.Property = true, Times.Once());
mockAsDerived.VerifySet(x => x.Property = true, Times.Once());
Assert.True(mockAsDerived.Object.Property);
Assert.True(mock.Object.Property);
}
}

#endregion

#region 1249

public class Issue1249
Expand Down

0 comments on commit a844d5e

Please sign in to comment.