Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions TUnit.Analyzers.CodeFixers/NUnitMigrationCodeFixProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ protected override bool IsFrameworkAttribute(string attributeName)
{
return attributeName switch
{
"Test" or "TestCase" or "TestCaseSource" or
"Test" or "TestCase" or "TestCaseSource" or
"SetUp" or "TearDown" or "OneTimeSetUp" or "OneTimeTearDown" or
"TestFixture" or "Category" or "Ignore" or "Explicit" or "Apartment" => true,
"TestFixture" or "Category" or "Ignore" or "Explicit" or "Apartment" or
"Platform" or "Theory" or "Description" => true,
_ => false
};
}
Expand Down
70 changes: 70 additions & 0 deletions TUnit.Analyzers.Tests/NUnitMigrationAnalyzerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2474,6 +2474,76 @@ public async Task TestMethod()
);
}

[Test]
public async Task NUnit_Platform_Attribute_Removed()
{
await CodeFixer.VerifyCodeFixAsync(
"""
using NUnit.Framework;

public class MyClass
{
{|#0:[Test]|}
[Platform(Include = "Win")]
public void TestMethod()
{
}
}
""",
Verifier.Diagnostic(Rules.NUnitMigration).WithLocation(0),
"""
using TUnit.Core;
using TUnit.Assertions;
using static TUnit.Assertions.Assert;
using TUnit.Assertions.Extensions;

public class MyClass
{
[Test]
public void TestMethod()
{
}
}
""",
ConfigureNUnitTest
);
}

[Test]
public async Task NUnit_Description_Attribute_Removed()
{
await CodeFixer.VerifyCodeFixAsync(
"""
using NUnit.Framework;

public class MyClass
{
{|#0:[Test]|}
[Description("This is a test description")]
public void TestMethod()
{
}
}
""",
Verifier.Diagnostic(Rules.NUnitMigration).WithLocation(0),
"""
using TUnit.Core;
using TUnit.Assertions;
using static TUnit.Assertions.Assert;
using TUnit.Assertions.Extensions;

public class MyClass
{
[Test]
public void TestMethod()
{
}
}
""",
ConfigureNUnitTest
);
}

[Test]
public async Task NUnit_InterfaceImplementation_NotConvertedToAsync()
{
Expand Down
6 changes: 5 additions & 1 deletion TUnit.Analyzers/Migrators/Base/MigrationHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@ public static string ConvertTestAttributeName(string attributeName, string frame
"NUnit" => attributeName switch
{
"Test" => "Test",
"Theory" => "Test", // NUnit [Theory] is same as [Test]
"TestCase" => "Arguments",
"TestCaseSource" => "MethodDataSource",
"SetUp" => "Before",
"TearDown" => "After",
"OneTimeSetUp" => "Before",
"OneTimeTearDown" => "After",
"TestFixture" => null!, // Remove
"Ignore" => "Skip", // NUnit [Ignore] -> TUnit [Skip]
"Description" => null!, // Remove - no direct equivalent, use [Property] if needed
"Platform" => null!, // Remove - no direct equivalent, use runtime checks
"Apartment" => "STAThreadExecutor", // Special handling in attribute rewriter
_ => attributeName
},
Expand Down Expand Up @@ -116,7 +120,7 @@ public static bool ShouldRemoveAttribute(string attributeName, string framework)
{
return framework switch
{
"NUnit" => attributeName is "TestFixture",
"NUnit" => attributeName is "TestFixture" or "Platform" or "Description",
"MSTest" => attributeName is "TestClass",
_ => false
};
Expand Down
Loading