From ea13f85aae2d0638b5fd07d00ee1f0a5d0f3700b Mon Sep 17 00:00:00 2001 From: JohanLarsson Date: Sun, 26 Apr 2020 16:58:53 +0200 Subject: [PATCH] Add test for nameof(Containing.Member) when public. #229 --- .../REFL016UseNameofTests/CodeFix.cs | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/ReflectionAnalyzers.Tests/REFL016UseNameofTests/CodeFix.cs b/ReflectionAnalyzers.Tests/REFL016UseNameofTests/CodeFix.cs index bcd40f63..fd4823cb 100644 --- a/ReflectionAnalyzers.Tests/REFL016UseNameofTests/CodeFix.cs +++ b/ReflectionAnalyzers.Tests/REFL016UseNameofTests/CodeFix.cs @@ -473,5 +473,56 @@ class C : BaseClass RoslynAssert.CodeFix(Analyzer, Fix, ExpectedDiagnostic, new[] { baseClass, before }, after); } + + [Test] + public static void InNestedType() + { + var @base = @" +namespace N +{ + class Base + { + public void M1() { } + } +}"; + + var before = @" +namespace N +{ + using System; + using System.Reflection; + + class C : Base + { + class Nested + { + void M2() + { + typeof(Base).GetMethod(↓""M1""); + } + } + } +}"; + + var after = @" +namespace N +{ + using System; + using System.Reflection; + + class C : Base + { + class Nested + { + void M2() + { + typeof(Base).GetMethod(nameof(Base.M1)); + } + } + } +}"; + + RoslynAssert.CodeFix(Analyzer, Fix, ExpectedDiagnostic, new[] { @base, before }, after); + } } }