nunit / nunit.analyzers

Roslyn analyzers for writing unit tests with NUnit
MIT License
89 stars 33 forks source link

NUnit2021 false positive for IEquatable<T> #322

Closed pantosha closed 3 years ago

pantosha commented 3 years ago

NUnit2021 fires when different types T1 and T2 are compared, but T1 implements IEquatable<T2>:

using Microsoft.Extensions.Primitives;
using NUnit.Framework;

namespace UnitTests
{
    public class Tests
    {
        [Test]
        public void Test1()
        {
            var stringValues = new StringValues("abc");
            Assert.That(stringValues, Is.EqualTo("abc")); // <-- NUnit2021 fires here. Test passes ✅.
        }
    }
}
Dreamescaper commented 3 years ago

I'll take a look

manfred-brands commented 3 years ago

@Dreamescaper This is similar to the code for IComparable<T>. See ComparableTypesAnalyzer.IsIComparable.