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

Verify() fails on items not explicitely marked a Verifiable() #1073

Closed
killergege opened this issue Oct 13, 2020 · 1 comment · Fixed by #1075
Closed

Verify() fails on items not explicitely marked a Verifiable() #1073

killergege opened this issue Oct 13, 2020 · 1 comment · Fixed by #1075
Labels
Milestone

Comments

@killergege
Copy link

killergege commented Oct 13, 2020

I think the issue is similar to #1018

When using nested properties, it seems that Verify() is behaving as if Verifiable() was applied on the auto-generated properties.
The issue appeared in 4.14.

To reproduce:
Solution : https://github.com/killergege/moq_issue1073

public class Tests
    {
        [Test]
        public void Test1()
        {
            var mock = new Mock<IClassA>();
            mock.Setup(x => x.Items.Count).Returns(1);
            mock.Setup(x => x.Method()).Verifiable();

            mock.Object.Method();

            //Expected to pass
            //Passes in 4.13, but fails in 4.14 with "IClassA x => x.Items: This setup was not matched."
            mock.Verify();
        }
    }

    public interface IClassA
    {
        public IList<string> Items { get; set; }
        public void Method();
    }
@killergege killergege changed the title MockRepository.Verify() fails on items not explicitely marked a Verifiable() Verify() fails on items not explicitely marked a Verifiable() Oct 13, 2020
@stakx stakx added the bug label Oct 13, 2020
@stakx
Copy link
Contributor

stakx commented Oct 13, 2020

Thanks for reporting, @killergege. Yes, it's definitely related to #1018, or more precisely, to the automatic recursion algorithm that Moq uses for verification, which leads to quite a few unintuitive situations like this one.

I'm still investigating ways to give up recursive verification as safely as possible. It's quite a puzzle, so I'm afraid this is going to take some time.

@stakx stakx added this to the 4.15.0 milestone Oct 13, 2020
@stakx stakx modified the milestones: 4.15.0, 4.14.7 Oct 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants