diff --git a/TUnit.Analyzers.CodeFixers/XUnitMigrationCodeFixProvider.cs b/TUnit.Analyzers.CodeFixers/XUnitMigrationCodeFixProvider.cs index f566d0a81f..10b115a12e 100644 --- a/TUnit.Analyzers.CodeFixers/XUnitMigrationCodeFixProvider.cs +++ b/TUnit.Analyzers.CodeFixers/XUnitMigrationCodeFixProvider.cs @@ -569,9 +569,9 @@ protected override bool IsFrameworkAssertionNamespace(string namespaceName) // Reference assertions "Same" when arguments.Count >= 2 => - CreateTUnitAssertion("IsSameReference", arguments[1].Expression, arguments[0]), + CreateTUnitAssertion("IsSameReferenceAs", arguments[1].Expression, arguments[0]), "NotSame" when arguments.Count >= 2 => - CreateTUnitAssertion("IsNotSameReference", arguments[1].Expression, arguments[0]), + CreateTUnitAssertion("IsNotSameReferenceAs", arguments[1].Expression, arguments[0]), // String/Collection contains "Contains" when arguments.Count >= 2 => diff --git a/TUnit.Analyzers.Tests/XUnitMigrationAnalyzerTests.cs b/TUnit.Analyzers.Tests/XUnitMigrationAnalyzerTests.cs index 265731dd9b..5267105e04 100644 --- a/TUnit.Analyzers.Tests/XUnitMigrationAnalyzerTests.cs +++ b/TUnit.Analyzers.Tests/XUnitMigrationAnalyzerTests.cs @@ -861,6 +861,82 @@ public async Task MyTest() ); } + [Test] + public async Task Assert_Same_Can_Be_Converted() + { + await CodeFixer + .VerifyCodeFixAsync( + """ + {|#0:using TUnit.Core; + + public class MyClass + { + [Fact] + public void MyTest() + { + var expected = new object(); + var actual = expected; + Assert.Same(expected, actual); + } + }|} + """, + Verifier.Diagnostic(Rules.XunitMigration).WithLocation(0), + """ + using TUnit.Core; + + public class MyClass + { + [Test] + public async Task MyTest() + { + var expected = new object(); + var actual = expected; + await Assert.That(actual).IsSameReferenceAs(expected); + } + } + """, + ConfigureXUnitTest + ); + } + + [Test] + public async Task Assert_NotSame_Can_Be_Converted() + { + await CodeFixer + .VerifyCodeFixAsync( + """ + {|#0:using TUnit.Core; + + public class MyClass + { + [Fact] + public void MyTest() + { + var obj1 = new object(); + var obj2 = new object(); + Assert.NotSame(obj1, obj2); + } + }|} + """, + Verifier.Diagnostic(Rules.XunitMigration).WithLocation(0), + """ + using TUnit.Core; + + public class MyClass + { + [Test] + public async Task MyTest() + { + var obj1 = new object(); + var obj2 = new object(); + await Assert.That(obj2).IsNotSameReferenceAs(obj1); + } + } + """, + ConfigureXUnitTest + ); + } + private static void ConfigureXUnitTest(Verifier.Test test) { var globalUsings = ("GlobalUsings.cs", SourceText.From("global using Xunit;"));