-
Notifications
You must be signed in to change notification settings - Fork 35
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
Remove null message in AreEqual code fix #698
Remove null message in AreEqual code fix #698
Conversation
``` Assert.AreEqual(2d, 3d, null); ``` would generate ``` Assert.That(3d, Is.EqualTo(2d), null); ``` which does not compile ``` The call is ambiguous between the following methods or properties: 'Assert.That<TActual>(TActual, IResolveConstraint, FormattableString, string, string)' and 'Assert.That<TActual>(TActual, IResolveConstraint, Func<string>, string, string)' ```
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With a small change, your fix would also work for the other use case.
// Remove null message to avoid ambiguous calls. | ||
if (arguments.Count == 3 && arguments[2].Expression.Kind() == SyntaxKind.NullLiteralExpression) | ||
{ | ||
arguments.RemoveAt(2); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to move after the call to UpdateArguments
below so that it also works if there is a tolerance value specified.
@@ -56,6 +56,22 @@ public void TestMethod() | |||
RoslynAssert.CodeFix(analyzer, fix, expectedDiagnostic, code, fixedCode, fixTitle: ClassicModelAssertUsageCodeFix.TransformToConstraintModelDescription); | |||
} | |||
|
|||
[Test] | |||
public void VerifyAreEqualFixWithNullMessage() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add another test with a tolerance value: ClassicAssert.AreEqual(2d, 3d, 0.1, null);
@@ -55,6 +55,12 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) | |||
// Now, replace the arguments. | |||
List<ArgumentSyntax> arguments = invocationNode.ArgumentList.Arguments.ToList(); | |||
|
|||
// Remove null message to avoid ambiguous calls. | |||
if (arguments.Count == 3 && arguments[2].Expression.Kind() == SyntaxKind.NullLiteralExpression) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (arguments.Count == 3 && arguments[2].Expression.Kind() == SyntaxKind.NullLiteralExpression) | |
if (arguments.Count == 3 && arguments[2].Expression.IsKind(SyntaxKind.NullLiteralExpression)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks you for your quick fix. Nothing else.
Fixes #700
would generate
which does not compile