Skip to content

DictionaryShouldContainsKey is triggered on custom ContainsKey #85

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

Closed
jnyrup opened this issue Sep 16, 2019 · 1 comment · Fixed by #379
Closed

DictionaryShouldContainsKey is triggered on custom ContainsKey #85

jnyrup opened this issue Sep 16, 2019 · 1 comment · Fixed by #379
Labels

Comments

@jnyrup
Copy link
Member

jnyrup commented Sep 16, 2019

Description

When a class implements IDictionary and a custom ContainsKey(TKey1, TKey2), the analyzer does not distinguish between IDictionary.ContainsKey(TKey) and ContainsKey(TKey1, TKey2).
Related to #65

Complete minimal example reproducing the issue

public class MultiKeyDict<TKey1, TKey2, TValue> 
    : Dictionary<TKey1, Dictionary<TKey2, TValue>>
{
    public bool ContainsKey(TKey1 key1, TKey2 key2) => false;
}

[TestMethod]
public void MyTestMethod()
{
    var dict = new MultiKeyDict<int, int, string>();

    dict.ContainsKey(0, 1).Should().BeTrue();
}

Expected behavior:

No analyzer should be triggered.

Actual behavior:

DictionaryShouldContainsKey is suggested, but is not applicable as GenericDictionaryAssertions<TKey, TValue> does not implement ContainKey(TKey1, TKey2).

Versions

  • Which version of Fluent Assertions Analyzers are you using?
    • 0.11.4
  • Which .NET runtime and version are you targeting? E.g. .NET framework 4.6.1 or .NET Core 2.0.
    • net472
@Meir017
Copy link
Member

Meir017 commented Jul 19, 2024

@jnyrup looks like I missed this... lol.
I see this is still an issue, a more generic issue where we are not validating that the arguments match the arguments of the method we think is being used

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