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
4 changes: 2 additions & 2 deletions TUnit.Analyzers.CodeFixers/XUnitMigrationCodeFixProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand Down
76 changes: 76 additions & 0 deletions TUnit.Analyzers.Tests/XUnitMigrationAnalyzerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;"));
Expand Down
Loading