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 and SetupProperty behave differently with respect to verification #850

Closed
stakx opened this issue Jun 20, 2019 · 1 comment

Comments

@stakx
Copy link
Contributor

stakx commented Jun 20, 2019

Steps to reproduce:

public interface IX
{
    object P { get; set; }
}

[Fact]
public void Property_stubbed_with_SetupAllProperties_is_excluded_from_verification()
{
        var mock = new Mock<IX>();
        mock.SetupAllProperties();
        mock.VerifyAll();  // passes
}

[Fact]
public void Property_stubbed_with_SetupProperty_is_excluded_from_verification()
{
        var mock = new Mock<IX>();
        mock.SetupProperty(m => m.P);
        mock.VerifyAll();  // fails
}

Expected outcome:

Stubbed properties are excluded from verification, regardless of whether they were stubbed with SetupAllProperties or SetupProperty. (From a user's perspective, it likely wouldn't be very intuitive if there were a difference between these two, other than that the former method is the batch version of the latter.)

That is, both tests should pass.

Actual outcome:

The second test (stubbing with SetupProperty) fails with this MockException:

Mock<IX:1>:
This mock failed verification due to the following:

   IX m => m.P:
   This setup was not matched.

   IX m => m.P = It.IsAny<object>():
   This setup was not matched.

   at Moq.Mock.VerifyAll()
   at ...
@stakx
Copy link
Contributor Author

stakx commented Jul 14, 2019

Having thought about this some more, it is perhaps a good thing that SetupProperty and SetupAllProperties behave differently: you'd only intentionally setup a property if you actually expected it to be set and queried. Otherwise, you'd be more specific and setup just the getter or the setter, or have no setup at all.

Closing this as "by design" until someone actually runs into problems because of it.

@stakx stakx closed this as completed Jul 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant