Argument matchers fail if null passed in to an out parameter of a generic derived type #828
Labels
bug
Reported problem with NSubstitute behaviour
help wanted
Core team needs help with this! If you've got some time, please volunteer to take a look.
Describe the bug
Argument matchers for generic
out
parameters fail for derived methods where theout
is a derived type andnull
is passed in.(The reproduce code should make it clearer)
To Reproduce
CodeUnderTest.csproj
SomeClass.cs
TestProject.csproj
TestSomeClass.cs
Expected behaviour
The test
TestMethod
to pass correctly, asserting that one call was received by each method.Actually both asserts will fail as they are unable to differentiate between the two calls even though the generics do not match.
Environment:
See csproj files.
This was originally seen on .NET 472 and NSubstitute 4.2.1 but when creating the minimal example above it was confirmed to still be present in .NET 8 and NSubstitute 5.1.0
Additional context
.Returns(..)
and it was seen that the incorrect mocks were being hit by the code being tested, i.e. both interface calls would go to the same mock.When().Do()
to create the mocks resulted in both mocks being hit in sequence. So both interface calls would hit both mocksIOutBase
orIOutDerived
is passed in to the out parameter then the correct mock would get hitThe text was updated successfully, but these errors were encountered: