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

Making assertions against indexers produces NS1004 (argument matcher used with a non-virtual member of a class) errors #191

Closed
simonmckenzie opened this issue Sep 5, 2022 · 1 comment

Comments

@simonmckenzie
Copy link

simonmckenzie commented Sep 5, 2022

If I try to make an assertion against an indexer, I receive an NS1004 error - this seems to be a false positive.

Example:

interface IInterfaceWithIndexer
{
    string this[int index] { get; set; }

    string SetSomething(int index, string value);
}

[Fact]
public void MockInterfaceWithIndexer()
{
    var mock = Substitute.For<IInterfaceWithIndexer>();

    mock.Received()[5] = Arg.Is("five");
    
    mock.Received().SetSomething(5, Arg.Is("five"));
}

screenshot of NS1004 error in Visual Studio

There's no problem with the assertion against the method, only against the indexer.

I think I'm using the correct syntax for asserting against indexers - I used the guide here: https://nsubstitute.github.io/help/received-calls/#checking-calls-to-indexers

@simonmckenzie
Copy link
Author

My apologies - this appears to have been resolved in 1.0.15 (I was using 1.0.14)

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

1 participant