diff --git a/Meziantou.FluentAssertionsAnalyzers.Tests/NUnit4ToFluentAssertionsAnalyzerUnitTests.cs b/Meziantou.FluentAssertionsAnalyzers.Tests/NUnit4ToFluentAssertionsAnalyzerUnitTests.cs index 6c0bf6c..fe5edef 100644 --- a/Meziantou.FluentAssertionsAnalyzers.Tests/NUnit4ToFluentAssertionsAnalyzerUnitTests.cs +++ b/Meziantou.FluentAssertionsAnalyzers.Tests/NUnit4ToFluentAssertionsAnalyzerUnitTests.cs @@ -847,4 +847,66 @@ public void MyTest() } """); } + + [Fact] + public Task Assert_AreEqual_on_assemblies() + { + return Assert( + """ + using NUnit.Framework.Legacy; + using System.Reflection; + + class Test + { + public void MyTest(Assembly assembly1, Assembly assembly2) + { + [|ClassicAssert.AreEqual(assembly1, assembly2)|]; + } + } + """, + """ + using System.Reflection; + using FluentAssertions; + using NUnit.Framework.Legacy; + + class Test + { + public void MyTest(Assembly assembly1, Assembly assembly2) + { + assembly2.Should().BeSameAs(assembly1); + } + } + """); + } + + [Fact] + public Task Assert_AreNotEqual_on_assemblies() + { + return Assert( + """ + using NUnit.Framework.Legacy; + using System.Reflection; + + class Test + { + public void MyTest(Assembly assembly1, Assembly assembly2) + { + [|ClassicAssert.AreNotEqual(assembly1, assembly2)|]; + } + } + """, + """ + using System.Reflection; + using FluentAssertions; + using NUnit.Framework.Legacy; + + class Test + { + public void MyTest(Assembly assembly1, Assembly assembly2) + { + assembly2.Should().NotBeSameAs(assembly1); + } + } + """); + } } diff --git a/Meziantou.FluentAssertionsAnalyzers/Meziantou.FluentAssertionsAnalyzers.csproj b/Meziantou.FluentAssertionsAnalyzers/Meziantou.FluentAssertionsAnalyzers.csproj index 1c5c8a6..7354b4d 100644 --- a/Meziantou.FluentAssertionsAnalyzers/Meziantou.FluentAssertionsAnalyzers.csproj +++ b/Meziantou.FluentAssertionsAnalyzers/Meziantou.FluentAssertionsAnalyzers.csproj @@ -2,7 +2,7 @@ netstandard2.0 - 1.0.20 + 1.0.21 false true A Roslyn analyzer to help migrate from Xunit / NUnit assertions to FluentAssertions diff --git a/Meziantou.FluentAssertionsAnalyzers/NunitAssertAnalyzerCodeFixProvider.cs b/Meziantou.FluentAssertionsAnalyzers/NunitAssertAnalyzerCodeFixProvider.cs index cdd6c87..ab4a60a 100644 --- a/Meziantou.FluentAssertionsAnalyzers/NunitAssertAnalyzerCodeFixProvider.cs +++ b/Meziantou.FluentAssertionsAnalyzers/NunitAssertAnalyzerCodeFixProvider.cs @@ -192,6 +192,10 @@ private static async Task Rewrite(Document document, SyntaxNode nodeTo { result = rewrite.UsingShould(right, "Equal", ArgumentList(left, arguments.Skip(2))); } + else if (leftType.SpecialType != SpecialType.System_String && leftType.IsReferenceType) + { + result = rewrite.UsingShould(right, "BeSameAs", ArgumentList(left, arguments.Skip(2))); + } else { var useBeApproximately = leftType.SpecialType is SpecialType.System_Double or SpecialType.System_Single @@ -216,6 +220,10 @@ private static async Task Rewrite(Document document, SyntaxNode nodeTo { result = rewrite.UsingShould(right, "NotEqual", ArgumentList(left, arguments.Skip(2))); } + else if (leftType.SpecialType != SpecialType.System_String && leftType.IsReferenceType) + { + result = rewrite.UsingShould(right, "NotBeSameAs", ArgumentList(left, arguments.Skip(2))); + } else { result = rewrite.UsingShould(right, "NotBe", ArgumentList(left, arguments.Skip(2)));