Skip to content

Commit

Permalink
demonstrates bug in a type that implements both IDictionary and IColl…
Browse files Browse the repository at this point in the history
…ection -- preference for naming, if following FxCop conventions is XXXDictionary
  • Loading branch information
Iristyle committed Feb 17, 2011
1 parent 8f51653 commit 40bfb22
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions gendarme/rules/Gendarme.Rules.Naming/Test/UseCorrectSuffixTest.cs
Expand Up @@ -246,6 +246,15 @@ public class DictionaryIncorrect<T, V> : Dictionary<T, V> {
public class DictionaryIncorrectDerived<T, V> : DictionaryIncorrect<T, V> {
}

public class CorrectCollectionAndDictionary<T, V> : Dictionary<T, V>, ICollection<V> {
public void Add(V item) { throw new NotImplementedException(); }
public bool Contains(V item) { throw new NotImplementedException(); }
public void CopyTo(V[] array, int arrayIndex) { throw new NotImplementedException(); }
public bool IsReadOnly { get { throw new NotImplementedException(); } }
public bool Remove(V item) { throw new NotImplementedException(); }
public new IEnumerator<V> GetEnumerator() { throw new NotImplementedException(); }
}

[TestFixture]
public class UseCorrectSuffixTest : TypeRuleTestFixture<UseCorrectSuffixRule> {

Expand Down Expand Up @@ -305,7 +314,7 @@ public void TestInterfaceImplementerCorrectName ()
AssertRuleSuccess<CorrectICollectionCollection> ();
}

[Test]
[Test]
public void TestInterfaceImplementerIncorrectName ()
{
AssertRuleFailureWithLowConfidence<IncorrectICollectionCol> ();
Expand All @@ -323,7 +332,7 @@ public void TestMultipleInterfaceImplementerAnotherCorrectName ()
AssertRuleSuccess<CorrectMultipleInterfaceImplementerCollection> ();
}

[Test]
[Test]
public void TestMultipleInterfaceImplementerIncorrectName ()
{
AssertRuleFailureWithHighConfidence<MultipleInterfaceImplementer> ();
Expand Down Expand Up @@ -376,6 +385,8 @@ public void GenericCollection ()
public void GenericDictionary ()
{
AssertRuleSuccess<CorrectDictionary<int,int>> ();
//bug: to be consistent with FxCop, a class implementing IDictionary and ICollection should end in Dictionary
AssertRuleSuccess<CorrectCollectionAndDictionary<int, int>>();
AssertRuleFailureWithHighConfidence<DictionaryIncorrect<int,int>> ();
}

Expand Down

0 comments on commit 40bfb22

Please sign in to comment.