@@ -107,7 +107,8 @@ private static void AnalyzeSymbol(SymbolAnalysisContext context)
107107
108108 private static bool IsTestMethod ( IMethodSymbol methodSymbol )
109109 {
110- // Test framework namespaces - checking namespace is more flexible than specific attribute names
110+ // Test framework namespaces - any method decorated with an attribute from these namespaces
111+ // is considered a test method and exempt from PascalCase validation
111112 string [ ] testFrameworkNamespaces =
112113 [
113114 "Xunit" , // xUnit (note: namespace is "Xunit", not "XUnit")
@@ -116,7 +117,8 @@ private static bool IsTestMethod(IMethodSymbol methodSymbol)
116117 "TUnit.Core" // TUnit
117118 ] ;
118119
119- // Fallback attribute names for test environments where namespace metadata may be incomplete
120+ // Fallback attribute names - needed because our test infrastructure (DiagnosticVerifier)
121+ // doesn't add references to test framework assemblies, so ContainingNamespace would be null
120122 string [ ] commonTestAttributeNames =
121123 [
122124 "TestMethod" , "TestMethodAttribute" , // MSTest
@@ -135,15 +137,15 @@ private static bool IsTestMethod(IMethodSymbol methodSymbol)
135137 return false ;
136138 }
137139
138- // Check namespace first (more robust for production code )
140+ // Check namespace first (works in production with proper assembly references )
139141 string containingNamespace = attribute . AttributeClass . ContainingNamespace ? . ToDisplayString ( ) ;
140142 if ( containingNamespace != null &&
141143 testFrameworkNamespaces . Any ( ns => containingNamespace . StartsWith ( ns , StringComparison . Ordinal ) ) )
142144 {
143145 return true ;
144146 }
145147
146- // Fallback: check attribute name for common test attributes
148+ // Fallback: check attribute name (needed for test environment)
147149 string attributeName = attribute . AttributeClass . Name ;
148150 return commonTestAttributeNames . Contains ( attributeName ) ;
149151 } ) ;
0 commit comments