Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

-demonstrates a bug where nested private interfaces are considered eq…

…uivalent

-also documents another bug that needs a test written (didn't have time to determine whether the bug is in ConsiderAddingInterface or TypeRocks)
  • Loading branch information...
commit cbb217b82f86b390c6f619c07b5085684835de7f 1 parent 8469e3a
@Iristyle authored
View
49 gendarme/rules/Gendarme.Rules.Design/Test/ConsiderAddingInterfaceTest.cs
@@ -33,9 +33,12 @@
using System;
using System.Collections.Generic;
+using System.Linq;
using NUnit.Framework;
using Test.Rules.Fixtures;
using Test.Rules.Definitions;
+using Test.Rules.Helpers;
+using System.Reflection;
namespace Test.Rules.Design {
@@ -220,6 +223,31 @@ class ConstrainedSame {
}
}
+ class NestedParent
+ {
+ interface INestedInterface
+ {
+ DateTime GetCurrentDateTime();
+ }
+ class Nested : INestedInterface
+ {
+ public DateTime GetCurrentDateTime() { return DateTime.Now; }
+ }
+ }
+
+ class NestedParentTwo
+ {
+ //NOTE that if ILooksLikeNestedInterface is renamed to INestedInterface, then this is a success
+ interface ILooksLikeNestedInterface
+ {
+ DateTime GetCurrentDateTime();
+ }
+ class Nested : ILooksLikeNestedInterface
+ {
+ public DateTime GetCurrentDateTime() { return DateTime.Now; }
+ }
+ }
+
[TestFixture]
public class ConsiderAddingInterfaceTest : TypeRuleTestFixture<ConsiderAddingInterfaceRule> {
@@ -236,12 +264,21 @@ public void DoesNotApply ()
[Test]
public void Success ()
{
- AssertRuleSuccess<INeverImplementedInterface> ();
- AssertRuleSuccess<INeverImplementedInterface2> ();
- AssertRuleSuccess<IAlreadyImplementedInterface> ();
- AssertRuleSuccess<IBaseImplementedInterface> ();
- AssertRuleSuccess<INotPubliclyImplementedInterface> ();
- AssertRuleSuccess<IPartiallyImplementedInterface> ();
+ //rule fails to look at whether or not the interface is nested in a given type
+ foreach (var @interface in typeof(NestedParent).GetNestedTypes(BindingFlags.NonPublic).Where(t => t.IsInterface))
+ AssertRuleSuccess(DefinitionLoader.GetTypeDefinition(@interface));
+
+ //There is another bug above that manifests itself when the ILooksLikeNestedInterface is renamed
+ //to INestedInterface -- the code ultimately gets the right result, but for the wrong reason
+ // the bug is on line 170 of ConsiderAddingInterfaceRule.cs which calls out to line 260 of TypeRocks.cs -- if (type.IsInterface && Match (type, nameSpace, name))
+ // Test.Rules.Design.NestedParent/INestedInterface and Test.Rules.Design.NestedParentTwo/INestedInterface are treated as the same!
+
+ AssertRuleSuccess<INeverImplementedInterface>();
+ AssertRuleSuccess<INeverImplementedInterface2>();
+ AssertRuleSuccess<IAlreadyImplementedInterface>();
+ AssertRuleSuccess<IBaseImplementedInterface>();
+ AssertRuleSuccess<INotPubliclyImplementedInterface>();
+ AssertRuleSuccess<IPartiallyImplementedInterface>();
}
[Test]
Please sign in to comment.
Something went wrong with that request. Please try again.