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

SetupAllProperties tries to set up inaccessible properties #498

Closed
stakx opened this issue Oct 22, 2017 · 0 comments
Closed

SetupAllProperties tries to set up inaccessible properties #498

stakx opened this issue Oct 22, 2017 · 0 comments
Assignees
Labels
Milestone

Comments

@stakx
Copy link
Contributor

stakx commented Oct 22, 2017

#455 made Moq more strict with regard to inaccessible methods: if an attempt is made to set up such a one, setup methods now throw an exception. What was forgotten back then is that mock.SetupAllProperties() will try to set even inaccessible methods (it doesn't perform the appropriate check), leading to exceptions in use cases such as #491 or the following:

internal interface IFooInternals
{
	object C { get; }
	object D { get; }
}

public abstract class Foo : IFooInternals
{
	public virtual object C => "C";
	public object D => "D";
}

[Fact] // does not pass
public void SetupAllProperties_skips_inaccessible_properties_instead_of_throwing()
{
    var mock = new Mock<Foo>();

    var exception = Record.Exception(() =>
    {
        mock.SetupAllProperties();
    });

    Assert.Null(exception);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant