Describe the bug
When a type implements generic interface multiple times, the order of specified types is important.
To Reproduce
var mock = Substitute.For<IMock>();
mock.Test.Returns(new StringInt());//this works
mock.Test.Returns(new IntString());//this fails
public interface IMock
{
IMyInterface<string> Test { get; }
}
public interface IMyInterface<T>;
class IntString : IMyInterface<int>, IMyInterface<string>;
class StringInt : IMyInterface<string>, IMyInterface<int>;
Expected behaviour
The Returns should work regardless of the order of IMyInterface specification
Environment:
- NSubstitute version: 5.3.0 (worked in 5.1.0)
Additional context
I believe the issue was introduced in commit 73818a6
See
foreach (var aCompatibleInstanceType in compatibleInstanceTypes)
{
if (aCompatibleInstanceType.IsGenericType &&
aCompatibleInstanceType.GetGenericTypeDefinition() == genericTypeDefinition)
{
// both are the same generic type. If their GenericTypeArguments match then they are equivalent
return CallSpecification.TypesAreAllEquivalent(
aCompatibleInstanceType.GenericTypeArguments, type.GenericTypeArguments);
}
}
Shouldn't there is something like "if true return true else continue"? Though I didn't study the code further, so I am not sure.