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

Fix SetupAllProperties for properties named Item #878

Merged
merged 2 commits into from
Aug 8, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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