diff --git a/CHANGELOG.md b/CHANGELOG.md index fa02dde..f060906 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # CHANGELOG https://keepachangelog.com/en/1.0.0/ +## [1.27.1] - 2025-02-22 +- `TestMethodWithoutTestAttribute`: Don't trigger when `NUnit.TestCase` or `NUnit.TestCaseSource` is present on a method + ## [1.27.0] - 2025-01-09 - `ElementaryMethodsOfTypeInCollectionNotOverridden`: Don't exclude all `System` assembly types, exclude only structs diff --git a/Directory.Build.props b/Directory.Build.props index afd7096..28c948e 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -4,5 +4,6 @@ 11.0 true latest + NU1902;NU1903;NU1904 diff --git a/README.md b/README.md index 411e953..92dc62e 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ or add a reference yourself: ```xml - + ``` diff --git a/SharpSource/SharpSource.Package/SharpSource.Package.csproj b/SharpSource/SharpSource.Package/SharpSource.Package.csproj index a12b157..151a1ac 100644 --- a/SharpSource/SharpSource.Package/SharpSource.Package.csproj +++ b/SharpSource/SharpSource.Package/SharpSource.Package.csproj @@ -9,7 +9,7 @@ SharpSource - 1.27.0 + 1.27.1 Jeroen Vannevel https://github.com/Vannevelj/SharpSource/blob/master/LICENSE.md https://github.com/Vannevelj/SharpSource diff --git a/SharpSource/SharpSource.Test/TestMethodWithoutTestAttributeTests.cs b/SharpSource/SharpSource.Test/TestMethodWithoutTestAttributeTests.cs index dd6acd2..78c86cb 100644 --- a/SharpSource/SharpSource.Test/TestMethodWithoutTestAttributeTests.cs +++ b/SharpSource/SharpSource.Test/TestMethodWithoutTestAttributeTests.cs @@ -304,7 +304,7 @@ public IEnumerator GetEnumerator() } [TestMethod] - public async Task TestMethodWithoutTestAttribute_OtherAttributeIsTestRelated_TestCase() + public async Task TestMethodWithoutTestAttribute_Nunit_TestCase() { var original = @" using System; @@ -321,11 +321,11 @@ class MyClass } "; - await VerifyCS.VerifyDiagnosticWithoutFix(original, VerifyCS.Diagnostic().WithMessage("Method MyMethod might be missing a test attribute")); + await VerifyCS.VerifyNoDiagnostic(original); } [TestMethod] - public async Task TestMethodWithoutTestAttribute_OtherAttributeIsTestRelated_TestCaseSource() + public async Task TestMethodWithoutTestAttribute_NUnit_TestCaseSource() { var original = @" using System; @@ -348,7 +348,27 @@ private static IEnumerable DataSource() } "; - await VerifyCS.VerifyDiagnosticWithoutFix(original, VerifyCS.Diagnostic().WithMessage("Method MyMethod might be missing a test attribute")); + await VerifyCS.VerifyNoDiagnostic(original); + } + + [TestMethod] + public async Task TestMethodWithoutTestAttribute_Nunit_WithoutTestFixture_TestCase() + { + var original = @" +using System; +using NUnit.Framework; + +class MyClass +{ + [TestCase(3)] + public void {|#0:MyMethod|}(int x) + { + + } +} +"; + + await VerifyCS.VerifyNoDiagnostic(original); } [BugVerificationTest(IssueUrl = "https://github.com/Vannevelj/SharpSource/issues/22")] diff --git a/SharpSource/SharpSource/Diagnostics/TestMethodWithoutTestAttributeAnalyzer.cs b/SharpSource/SharpSource/Diagnostics/TestMethodWithoutTestAttributeAnalyzer.cs index a2631c5..211ebc2 100644 --- a/SharpSource/SharpSource/Diagnostics/TestMethodWithoutTestAttributeAnalyzer.cs +++ b/SharpSource/SharpSource/Diagnostics/TestMethodWithoutTestAttributeAnalyzer.cs @@ -34,7 +34,9 @@ public override void Initialize(AnalysisContext context) var testMethodAttributeSymbols = ImmutableArray.Create( compilationContext.Compilation.GetTypeByMetadataName("Xunit.FactAttribute"), - compilationContext.Compilation.GetTypeByMetadataName("Xunit.TheoryAttribute") + compilationContext.Compilation.GetTypeByMetadataName("Xunit.TheoryAttribute"), + compilationContext.Compilation.GetTypeByMetadataName("NUnit.Framework.TestCaseAttribute"), + compilationContext.Compilation.GetTypeByMetadataName("NUnit.Framework.TestCaseSourceAttribute") ); var taskTypes = ImmutableArray.Create( @@ -45,9 +47,7 @@ public override void Initialize(AnalysisContext context) var allowedAdditionalAttributes = ImmutableArray.Create( compilationContext.Compilation.GetTypeByMetadataName("Xunit.ClassDataAttribute"), compilationContext.Compilation.GetTypeByMetadataName("Xunit.InlineDataAttribute"), - compilationContext.Compilation.GetTypeByMetadataName("Microsoft.VisualStudio.TestTools.UnitTesting.DataRowAttribute"), - compilationContext.Compilation.GetTypeByMetadataName("NUnit.Framework.TestCaseAttribute"), - compilationContext.Compilation.GetTypeByMetadataName("NUnit.Framework.TestCaseSourceAttribute") + compilationContext.Compilation.GetTypeByMetadataName("Microsoft.VisualStudio.TestTools.UnitTesting.DataRowAttribute") ); compilationContext.RegisterSymbolAction(context => Analyze(context, testClassAttributeSymbols, testMethodAttributeSymbols, taskTypes, allowedAdditionalAttributes), SymbolKind.Method);