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

Setup gets included in Verify despite being "unreachable" #703

Closed
stakx opened this issue Oct 8, 2018 · 1 comment · Fixed by #761
Closed

Setup gets included in Verify despite being "unreachable" #703

stakx opened this issue Oct 8, 2018 · 1 comment · Fixed by #761
Assignees
Labels
Milestone

Comments

@stakx
Copy link
Contributor

stakx commented Oct 8, 2018

Reproduction code:

public interface IX
{
    IX X { get; }
}

var mock = new Mock<IX>();
mock.Setup(m => m.X.X).Verifiable("1");
mock.Setup(m => m.X).Verifiable("2");
_ = mock.Object.X;

mock.Verify();

Actual behavior:

Verify throws a MockException with message:

The following setups on mock 'Mock<IX:00000002>' were not matched:
1: IX m => m.X.X

Expected behavior:

No exception should be thrown, since setup 2 overrides the "root" of setup 1 (m.X) and there's no longer any way of getting at 2's m.X.X through mock (on which verification is triggered).

@stakx stakx added the bug label Oct 8, 2018
@stakx stakx self-assigned this Feb 21, 2019
@stakx
Copy link
Contributor Author

stakx commented Feb 24, 2019

Another similar case:

var mock = new Mock<IX> { DefaultValue = DefaultValue.Mock };
mock.SetupAllProperties();
(mock.Object.X).Setup(m => m.X).Verifiable();
mock.Object.X = null;

mock.Verify();

In the above example, the mock associated with the initial value of mock.Object.X keeps being tracked even though it becomes unreachable later when mock.Object.X is reset.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
1 participant