Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix AreEqual conversion on Assembly types #32

Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -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);
jairbubbles marked this conversation as resolved.
Show resolved Hide resolved
}
}
""");
}

[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);
}
}
""");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<Version>1.0.20</Version>
<Version>1.0.21</Version>
<IncludeBuildOutput>false</IncludeBuildOutput>
<developmentDependency>true</developmentDependency>
<Description>A Roslyn analyzer to help migrate from Xunit / NUnit assertions to FluentAssertions</Description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ private static async Task<Document> Rewrite(Document document, SyntaxNode nodeTo
{
result = rewrite.UsingShould(right, "Equal", ArgumentList(left, arguments.Skip(2)));
}
else if (leftType.Name == "Assembly" && leftType.ContainingNamespace.ToDisplayString() == "System.Reflection")
jairbubbles marked this conversation as resolved.
Show resolved Hide resolved
{
result = rewrite.UsingShould(right, "BeSameAs", ArgumentList(left, arguments.Skip(2)));
}
else
{
var useBeApproximately = leftType.SpecialType is SpecialType.System_Double or SpecialType.System_Single
Expand All @@ -216,6 +220,10 @@ private static async Task<Document> Rewrite(Document document, SyntaxNode nodeTo
{
result = rewrite.UsingShould(right, "NotEqual", ArgumentList(left, arguments.Skip(2)));
}
else if (leftType.Name == "Assembly" && leftType.ContainingNamespace.ToDisplayString() == "System.Reflection")
{
result = rewrite.UsingShould(right, "NotBeSameAs", ArgumentList(left, arguments.Skip(2)));
}
else
{
result = rewrite.UsingShould(right, "NotBe", ArgumentList(left, arguments.Skip(2)));
Expand Down