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

Ignore dictionary types from HaveElementAt #45

Merged
merged 2 commits into from
Jun 19, 2018
Merged

Ignore dictionary types from HaveElementAt #45

merged 2 commits into from
Jun 19, 2018

Conversation

samcragg
Copy link
Contributor

This fixes #44 (thanks for the pointer of where to fix it!)

@@ -27,6 +28,16 @@ protected override IEnumerable<FluentAssertionsCSharpSyntaxVisitor> Visitors
}
}

protected override bool ShouldAnalyzeVariableType(ITypeSymbol type)
{
if (type.AllInterfaces.Any(@interface => @interface.Name == "IReadOnlyDictionary" || @interface.Name == "IDictionary"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the dictionary assertions are on the type IDictionary I think this should not look for the readonly one

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's correct, however, this is preventing the HaveIndexAt one from incorrectly firing on dictionaries. Since IDictionary doesn't inherit IReadOnlyDictionary I've done two checks (I use IReadOnlyDictionary in my interfaces which is where I found the bug).

@@ -414,6 +414,14 @@ public class CollectionTests
[Implemented]
public void CollectionShouldNotBeNullOrEmpty_TestCodeFix(string oldAssertion, string newAssertion) => VerifyCSharpFixCodeBlock<CollectionShouldNotBeNullOrEmptyCodeFix, CollectionShouldNotBeNullOrEmptyAnalyzer>(oldAssertion, newAssertion);

[TestMethod]
[Implemented]
public void CollectionShouldHaveElementAt_ShouldIgnoreDictionaryTypes()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be in the sanity tests and linked to its github issue

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a problem, didn't see that file 🙂

@@ -27,6 +28,16 @@ protected override IEnumerable<FluentAssertionsCSharpSyntaxVisitor> Visitors
}
}

protected override bool ShouldAnalyzeVariableType(ITypeSymbol type)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move this to the collection analyzer without breaking tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we do want some of the collection ones to still trigger on dictionaries (e.g. Should().BeEmpty())

@Meir017 Meir017 merged commit 2d24434 into fluentassertions:master Jun 19, 2018
@Meir017
Copy link
Member

Meir017 commented Jun 19, 2018

@samcragg Thank you for your contribution 👍
This will be part of the 0.10.2 version

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

Successfully merging this pull request may close these issues.

Dictionary access incorrectly triggers CollectionShouldHaveElementAt suggestion
2 participants