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

DictionaryShouldContainsKey is triggered on custom ContainsKey #65

Closed
jnyrup opened this issue Jul 5, 2018 · 0 comments · Fixed by #69
Closed

DictionaryShouldContainsKey is triggered on custom ContainsKey #65

jnyrup opened this issue Jul 5, 2018 · 0 comments · Fixed by #69
Labels

Comments

@jnyrup
Copy link
Member

jnyrup commented Jul 5, 2018

Description

I have a custom dictionary that has a method with the signature: public bool ContainsKey(TKey1 key1, TKey2 key2).

This incorrectly triggers DictionaryShouldContainsKey.

Complete minimal example reproducing the issue

class MyDict<TKey, TValue>
{
    public bool ContainsKey(TKey key) => false;
}
var dict = new MyDict<int, string>();
dict.ContainsKey(0).Should().BeTrue();

is transformed into

dict.Should().ContainKey(0);

As dict is not a Dictionary, Should() returns an ObjectAssertions which does not have the ContainKey() assertion.

class MyDict2<TKey1, TKey2, TValue> : Dictionary<TKey1, TValue>
{
    public bool ContainsKey(TKey1 key1, TKey2 key2) => false;
}
var dict2 = new MyDict2<int, int, string>();
dict2.ContainsKey(0, 0).Should().BeTrue();

is

var dict2 = new MyDict2<int, int, string>();
dict2.Should().ContainKey(0, 0);

but there is no such ContainKey(0, 0) on GenericDictionaryAssertions

Expected behavior:

The analyzer should not be triggered.

Actual behavior:

The analyzer was triggered

Versions

Fluent Assertions Analyzers 0.11.2
.NET framework 4.6.1

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