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

Received.InOrder does not verify property getters #839

Open
RobSwDev opened this issue Nov 4, 2024 · 1 comment
Open

Received.InOrder does not verify property getters #839

RobSwDev opened this issue Nov 4, 2024 · 1 comment

Comments

@RobSwDev
Copy link

RobSwDev commented Nov 4, 2024

Describe the bug
Property getters are not checked inside Received.InOrder

To Reproduce
I would expect this test to fail. Nowhere is the substitute's Count property called.

    [Test]
    public void CheckPropertyGet()
    {
        var list = Substitute.For<ICollection<int>>();
        Received.InOrder(() =>
        {
            _ = list.Count;
            _ = list.Received().Count; // 2nd attempt to get it working - even though this upsets the analysers
        });
    }

Expected behaviour
This test should fail.
If for some technical reason property getters cannot be supported in Received.InOrder, then I guess the analyzers should highlight this

Environment:
NSubstitute 5.1.0
NSubstitute.Analyzers 1.0.17
Platform: Net8 on Windows

Additional context
Add any other context about the problem here.

@dtchepak
Copy link
Member

This is by design. IIRC including getters made some tests painful to write (e.g. nested subs; a.Nested.Call(), the a.Nested access would need to be in the exact order.) We could possibly include an overload with a parameter to adjust this behaviour.

Happy to accept doc updates here if you have time to send one through. 🙏

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

No branches or pull requests

2 participants