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

Make StubbedPropertySetup.IsMatch less picky #1260

Merged
merged 3 commits into from May 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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