nsubstitute / NSubstitute.Analyzers

Roslyn analysers for NSubstitute.
MIT License
30 stars 7 forks source link

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

Closed ghost closed 2 years ago

ghost commented 2 years ago

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

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

ghost commented 2 years ago

Closed - I accidentally raised this with the wrong GitHub account 😳 Replaced by #191