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

Recursive setup expression creates ghost setups that make VerifyAll fail #556

Closed
stakx opened this issue Dec 18, 2017 · 3 comments
Closed
Labels
Milestone

Comments

@stakx
Copy link
Contributor

stakx commented Dec 18, 2017

This has apparently been a problem with Moq for a long time:

public interface IFoo
{
    IBar Bar { get; }
}

public interface IBar
{
    int Value { get; set; }
}

var fooMock = new Mock<IFoo>();
fooMock.Setup(foo => foo.Bar.Value).Returns(42).Verifiable("my setup");
var bar = fooMock.Object.Bar;
fooMock.VerifyAll();
Moq.MockException: The following setups were not matched:
IBar m => m.Value
IBar m => m.Value
my setup: IFoo foo => foo.Bar.Value

The first two setups IBar m => m.Value should not be there, as there's no corresponding setup for them. (Where do those setups come from?) Their presence makes VerifyAll fail.

@stakx stakx added the bug label Dec 18, 2017
@stakx
Copy link
Contributor Author

stakx commented Jun 10, 2018

Where do those setups come from?

The two setups IBar m => m.Value are property get/set setups caused by SetupAllProperties caused by traversing the recursive ("fluent") mock expression in QueryableMockExtensions.FluentMock<T, TResult>(this Mock<T>, Expression<Func<T, TResult>>).

This issue would therefore likely be solved by #426.

@stakx
Copy link
Contributor Author

stakx commented Jul 13, 2018

Closing this, this problem will be tracked in #643 (together with a couple other related issues).

@stakx stakx closed this as completed Jul 13, 2018
@stakx
Copy link
Contributor Author

stakx commented Sep 7, 2018

Due to the decision made in #681 and the corresponding change made to SetupAllProperties in #684, this issue will be fixed in Moq version >4.9.0.

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