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

CollectionShouldHaveElementAtCodeFix throws exception #66

Closed
jnyrup opened this issue Jul 5, 2018 · 1 comment · Fixed by #70
Closed

CollectionShouldHaveElementAtCodeFix throws exception #66

jnyrup opened this issue Jul 5, 2018 · 1 comment · Fixed by #70
Labels

Comments

@jnyrup
Copy link
Member

jnyrup commented Jul 5, 2018

Description

Applying the codefix for CollectionShouldHaveElementAtCodeFix

var list = new[] { " FOO " };

list[0].Trim().Should().Be("FOO");

gives this stacktrace

System.InvalidCastException : Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.InvocationExpressionSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.ElementAccessExpressionSyntax'.
   at FluentAssertions.Analyzers.NodeReplacement.RemoveAndRetrieveIndexerArgumentsNodeReplacement.ComputeNew(LinkedListNode`1 listNode)
   at FluentAssertions.Analyzers.FluentAssertionsCodeFixProvider.GetNewExpression(ExpressionSyntax expression,NodeReplacement replacement)
   at FluentAssertions.Analyzers.CollectionShouldHaveElementAtCodeFix.GetNewExpression(ExpressionSyntax expression,FluentAssertionsDiagnosticProperties properties)
   at async FluentAssertions.Analyzers.FluentAssertionsCodeFixProvider.RewriteAssertion(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.CodeActions.CodeAction.GetChangedSolutionAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.CodeActions.CodeAction.ComputeOperationsAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.CodeActions.CodeAction.ComputePreviewOperationsAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.CodeActions.CodeAction.GetPreviewOperationsAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.Editor.Implementation.Suggestions.SuggestedAction.GetPreviewResultAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.Editor.Implementation.Suggestions.SuggestedActionWithNestedFlavors.<>c__DisplayClass11_0.<GetPreviewAsync>b__0(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.Extensions.IExtensionManagerExtensions.PerformFunctionAsync[T](<Unknown Parameters>)

Expected behavior:

The analyzer should probably not be triggered.
At least I see no semantically equivalent using HaveElementAt()

Actual behavior:

The analyzer was triggered.

Versions

  • Fluent Assertions Analyzers 0.11.2
  • .NET framework 4.6.1
@Meir017 Meir017 added the bug label Jul 5, 2018
@Meir017
Copy link
Member

Meir017 commented Jul 5, 2018

looks like #68 solved this too :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants