`mock.Protected()` does not properly support indexers
@tonyhallett is already working on this.
Since Jul 20, 2021.
- Dominant language
- C#
- Stars
- 6.4k
- Forks
- 835
- PR merge metrics
- No merged PRs in 30d
Description
MoqProtected can be improved. MoqProtectedAs does not suffer these issues. I think that despite there being an alternative this should be addressed.
SetUpSet ignores the value parameter and uses ItExpr.IsAny()
This is contrary to the xml docs.
VerifySet also ignores the value parameter.
This behaviour is best shown with Moq's own tests
[Fact]
public void VerifySetAllowsProtectedInternalPropertySet()
{
var mock = new Mock<FooBase>();
mock.Object.ProtectedInternalValue = "foo";
mock.Protected().VerifySet<string>("ProtectedInternalValue", Times.Once(), "bar");
}
[Fact]
public void DoesNotThrowIfVerifySetPropertyTimesReached()
{
var mock = new Mock<FooBase>();
mock.Object.SetProtectedValue("foo");
mock.Object.SetProtectedValue("foo");
mock.Protected().VerifySet<string>("ProtectedValue", Times.Exactly(2), ItExpr.IsAny<int>());
}
Indexers are not properly supported.
These are not so important
https://github.com/moq/moq4/blob/a6fde8b6d79a7437bf642d115785b97f40779b6a/src/Moq/Protected/ProtectedMock.cs#L92
https://github.com/moq/moq4/blob/a6fde8b6d79a7437bf642d115785b97f40779b6a/src/Moq/Protected/ProtectedMock.cs#L186
https://github.com/moq/moq4/blob/a6fde8b6d79a7437bf642d115785b97f40779b6a/src/Moq/Protected/ProtectedMock.cs#L267
This ( and SetupSet ) should be supported.
should receive args to support indexers
It already does.
SetupGet and VerifyGet should also allow for indexers.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.
