Skip to content

Commit 99ba578

Browse files
Improve code readability by extracting attribute names to array
Co-authored-by: BenjaminMichaelis <22186029+BenjaminMichaelis@users.noreply.github.com>
1 parent b2fe63a commit 99ba578

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

IntelliTect.Analyzer/IntelliTect.Analyzer/Analyzers/NamingMethodPascal.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,23 @@ private static bool IsTestMethod(IMethodSymbol methodSymbol)
111111
// Test framework namespaces - checking namespace is more flexible than specific attribute names
112112
string[] testFrameworkNamespaces =
113113
[
114-
"Xunit", // xUnit
114+
"Xunit", // xUnit (note: namespace is "Xunit", not "XUnit")
115115
"NUnit.Framework", // NUnit
116116
"Microsoft.VisualStudio.TestTools.UnitTesting", // MSTest
117117
"TUnit.Core" // TUnit
118118
];
119119

120+
// Fallback attribute names for test environments where namespace metadata may be incomplete
121+
string[] commonTestAttributeNames =
122+
[
123+
"TestMethod", "TestMethodAttribute", // MSTest
124+
"Fact", "FactAttribute", // xUnit
125+
"Theory", "TheoryAttribute", // xUnit
126+
"Test", "TestAttribute", // NUnit
127+
"TestCase", "TestCaseAttribute", // NUnit
128+
"TestCaseSource", "TestCaseSourceAttribute" // NUnit
129+
];
130+
120131
ImmutableArray<AttributeData> attributes = methodSymbol.GetAttributes();
121132
return attributes.Any(attribute =>
122133
{
@@ -134,14 +145,8 @@ private static bool IsTestMethod(IMethodSymbol methodSymbol)
134145
}
135146

136147
// Fallback: check attribute name for common test attributes
137-
// This helps in test environments where namespace metadata may be incomplete
138148
string attributeName = attribute.AttributeClass.Name;
139-
return attributeName == "TestMethod" || attributeName == "TestMethodAttribute" ||
140-
attributeName == "Fact" || attributeName == "FactAttribute" ||
141-
attributeName == "Theory" || attributeName == "TheoryAttribute" ||
142-
attributeName == "Test" || attributeName == "TestAttribute" ||
143-
attributeName == "TestCase" || attributeName == "TestCaseAttribute" ||
144-
attributeName == "TestCaseSource" || attributeName == "TestCaseSourceAttribute";
149+
return commonTestAttributeNames.Contains(attributeName);
145150
});
146151
}
147152
}

0 commit comments

Comments
 (0)