diff --git a/src/Analyzers/MSTest.Analyzers/DynamicDataShouldBeValidAnalyzer.cs b/src/Analyzers/MSTest.Analyzers/DynamicDataShouldBeValidAnalyzer.cs index ec3599737a..115600daca 100644 --- a/src/Analyzers/MSTest.Analyzers/DynamicDataShouldBeValidAnalyzer.cs +++ b/src/Analyzers/MSTest.Analyzers/DynamicDataShouldBeValidAnalyzer.cs @@ -12,6 +12,9 @@ namespace MSTest.Analyzers; +/// +/// MSTEST0018: . +/// [DiagnosticAnalyzer(LanguageNames.CSharp, LanguageNames.VisualBasic)] public sealed class DynamicDataShouldBeValidAnalyzer : DiagnosticAnalyzer { @@ -202,8 +205,7 @@ private static void AnalyzeDataSource(SymbolAnalysisContext context, AttributeDa return; } - if (!member.IsStatic - || member.DeclaredAccessibility != Accessibility.Public) + if (!member.IsStatic) { context.ReportDiagnostic(attributeSyntax.CreateDiagnostic(DataMemberSignatureRule, declaringType.Name, memberName)); return; diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/DynamicDataShouldBeValidAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/DynamicDataShouldBeValidAnalyzerTests.cs index c5967776f1..ec3b1d5491 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/DynamicDataShouldBeValidAnalyzerTests.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/DynamicDataShouldBeValidAnalyzerTests.cs @@ -547,7 +547,7 @@ await VerifyCS.VerifyAnalyzerAsync( VerifyCS.Diagnostic(DynamicDataShouldBeValidAnalyzer.DataMemberSignatureRule).WithLocation(1).WithArguments("MyTestClass", "GetData")); } - public async Task MemberIsNotPublic_Diagnostic() + public async Task MemberIsNotPublic_NoDiagnostic() { string code = """ using System; @@ -557,13 +557,13 @@ public async Task MemberIsNotPublic_Diagnostic() [TestClass] public class MyTestClass { - [{|#0:DynamicData("Data")|}] + [DynamicData("Data")] [TestMethod] public void TestMethod1(object[] o) { } - [{|#1:DynamicData("GetData", DynamicDataSourceType.Method)|}] + [DynamicData("GetData", DynamicDataSourceType.Method)] [TestMethod] public void TestMethod2(object[] o) { @@ -574,10 +574,7 @@ public void TestMethod2(object[] o) } """; - await VerifyCS.VerifyAnalyzerAsync( - code, - VerifyCS.Diagnostic(DynamicDataShouldBeValidAnalyzer.DataMemberSignatureRule).WithLocation(0).WithArguments("MyTestClass", "Data"), - VerifyCS.Diagnostic(DynamicDataShouldBeValidAnalyzer.DataMemberSignatureRule).WithLocation(1).WithArguments("MyTestClass", "GetData")); + await VerifyCS.VerifyAnalyzerAsync(code); } public async Task MethodHasParameters_Diagnostic()