Skip to content

Commit

Permalink
Merge pull request #878 from stakx/setupallproperties
Browse files Browse the repository at this point in the history
Fix `SetupAllProperties` for properties named `Item`
  • Loading branch information
stakx committed Aug 8, 2019
2 parents 6ed6078 + a107271 commit 86bab00
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Moq/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ public static bool IsPropertyGetter(this MethodInfo method)

public static bool IsPropertyIndexerGetter(this MethodInfo method)
{
return method.IsSpecialName && method.Name.Equals("get_Item", StringComparison.Ordinal);
return method.IsSpecialName && method.Name.StartsWith("get_", StringComparison.Ordinal) && method.GetParameters().Length > 0;
}

public static bool IsPropertyIndexerSetter(this MethodInfo method)
{
return method.IsSpecialName && method.Name.Equals("set_Item", StringComparison.Ordinal);
return method.IsSpecialName && method.Name.StartsWith("set_", StringComparison.Ordinal) && method.GetParameters().Length > 1;
}

public static bool IsPropertySetter(this MethodInfo method)
Expand Down
14 changes: 14 additions & 0 deletions tests/Moq.Tests/Regressions/IssueReportsFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2705,10 +2705,24 @@ public void SetupAllProperties_can_process_Items_property_3()
Assert.NotNull(httpContext.Object.Items);
}

[Fact]
public void SetupAllProperties_can_process_Item_property()
{
var mock = new Mock<IFoo>();
mock.SetupAllProperties();
mock.Object.Item = "value";
Assert.Equal("value", mock.Object.Item);
}

public abstract partial class HttpContext
{
public abstract IDictionary<object, object> Items { get; set; }
}

public interface IFoo
{
string Item { get; set; }
}
}

#endregion
Expand Down

0 comments on commit 86bab00

Please sign in to comment.