diff --git a/src/nunit.analyzers.tests/WithinUsage/WithinUsageAnalyzerTests.cs b/src/nunit.analyzers.tests/WithinUsage/WithinUsageAnalyzerTests.cs index 6bbb1a40..9f74f542 100644 --- a/src/nunit.analyzers.tests/WithinUsage/WithinUsageAnalyzerTests.cs +++ b/src/nunit.analyzers.tests/WithinUsage/WithinUsageAnalyzerTests.cs @@ -273,6 +273,31 @@ public void AnalyzeOnNonGenericCollection() RoslynAssert.Valid(analyzer, testCode); } + [Test] + public void AnalyzeNonGenericSubclassOfGenericIEnumerable() + { + string testCode = TestUtility.WrapClassInNamespaceAndAddUsing(@" + [TestFixture] + public class TestClass + { + public void TestMethod() + { + Assert.That(new DoubleCollection(1), Is.EqualTo(new DoubleCollection(2)).Within(0.001)); + } + + private sealed class DoubleCollection : IEnumerable + { + public DoubleCollection(params double[] numbers) { } + public IEnumerator GetEnumerator() => throw new NotImplementedException(); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + } + }", + additionalUsings: @"using System.Collections; + using System.Collections.Generic;"); + + RoslynAssert.Valid(analyzer, testCode); + } + [TestCase("double")] [TestCase("int")] [TestCase("TimeSpan")] diff --git a/src/nunit.analyzers/WithinUsage/WithinUsageAnalyzer.cs b/src/nunit.analyzers/WithinUsage/WithinUsageAnalyzer.cs index 9519a5f5..09c2e9b3 100644 --- a/src/nunit.analyzers/WithinUsage/WithinUsageAnalyzer.cs +++ b/src/nunit.analyzers/WithinUsage/WithinUsageAnalyzer.cs @@ -117,7 +117,7 @@ private static bool IsTypeSupported(ITypeSymbol type, HashSet? chec string interfaceTypeName = interfaceType.GetFullMetadataName(); if (interfaceTypeName.StartsWith("System.Collections.Generic.IEnumerable`", StringComparison.Ordinal)) { - return IsTypeSupported(namedType.TypeArguments[0], checkedTypes); + return IsTypeSupported(interfaceType.TypeArguments[0], checkedTypes); } if (interfaceTypeName.Equals("System.Collections.IEnumerable", StringComparison.Ordinal))