diff options
author | Sebastien Pouliot <sebastien@ximian.com> | 2008-02-15 22:36:21 +0300 |
---|---|---|
committer | Sebastien Pouliot <sebastien@ximian.com> | 2008-02-15 22:36:21 +0300 |
commit | 1ad631f9e5e5836e94aa7003b2064b59144e757d (patch) | |
tree | 989ce12857419d70ead093ade890d22df42dc5b9 /gendarme/rules | |
parent | 9eabedc5bcd6023ee4c901d73d7a5c5980a03766 (diff) |
2008-02-15 Sebastien Pouliot <sebastien@ximian.com>
* DetectNonAlphaNumericsInTypeNamesTest.cs
* DoNotPrefixValuesWithEnumNameTest.cs
* DoNotUseReservedInEnumValueNamesTest.cs
* EnumNotEndsWithEnumOrFlagsSuffixTest.cs
* ParameterNamesShouldMatchOverridenMethodTest.cs
* UseCorrectCasingTest.cs
* UseCorrectPrefixTest.cs
* UseCorrectSuffixTest.cs
* UsePluralNameInEnumFlagsTest.cs
* UsePreferredTermsTest.cs
* UseSingularNameInEnumsUnlessAreFlagsTest.cs:
Update unit tests wrt framework changes.
svn path=/trunk/mono-tools/; revision=95801
Diffstat (limited to 'gendarme/rules')
12 files changed, 257 insertions, 330 deletions
diff --git a/gendarme/rules/Gendarme.Rules.Naming/Test/ChangeLog b/gendarme/rules/Gendarme.Rules.Naming/Test/ChangeLog index d1c081b9..bc50ff81 100644 --- a/gendarme/rules/Gendarme.Rules.Naming/Test/ChangeLog +++ b/gendarme/rules/Gendarme.Rules.Naming/Test/ChangeLog @@ -1,3 +1,18 @@ +2008-02-15 Sebastien Pouliot <sebastien@ximian.com> + + * DetectNonAlphaNumericsInTypeNamesTest.cs + * DoNotPrefixValuesWithEnumNameTest.cs + * DoNotUseReservedInEnumValueNamesTest.cs + * EnumNotEndsWithEnumOrFlagsSuffixTest.cs + * ParameterNamesShouldMatchOverridenMethodTest.cs + * UseCorrectCasingTest.cs + * UseCorrectPrefixTest.cs + * UseCorrectSuffixTest.cs + * UsePluralNameInEnumFlagsTest.cs + * UsePreferredTermsTest.cs + * UseSingularNameInEnumsUnlessAreFlagsTest.cs: + Update unit tests wrt framework changes. + 2008-01-14 Sebastien Pouliot <sebastien@ximian.com> * DoNotPrefixValuesWithEnumNameTest.cs: New. Unit tests from Andreas diff --git a/gendarme/rules/Gendarme.Rules.Naming/Test/DetectNonAlphaNumericsInTypeNamesTest.cs b/gendarme/rules/Gendarme.Rules.Naming/Test/DetectNonAlphaNumericsInTypeNamesTest.cs index 4a915902..469b27a0 100644 --- a/gendarme/rules/Gendarme.Rules.Naming/Test/DetectNonAlphaNumericsInTypeNamesTest.cs +++ b/gendarme/rules/Gendarme.Rules.Naming/Test/DetectNonAlphaNumericsInTypeNamesTest.cs @@ -6,7 +6,7 @@ // Sebastien Pouliot <sebastien@ximian.com> // // Copyright (c) <2007> Nidhi Rawal -// Copyright (C) 2007 Novell, Inc (http://www.novell.com) +// Copyright (C) 2007-2008 Novell, Inc (http://www.novell.com) // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -30,6 +30,7 @@ using System; using System.Reflection; using Gendarme.Framework; +using Gendarme.Framework.Rocks; using Gendarme.Rules.Naming; using Mono.Cecil; using NUnit.Framework; @@ -85,15 +86,13 @@ namespace Test.Rules.Naming { } } - class ClassContainingPrivateMethodWithUnderscore - { + public class ClassContainingPrivateMethodWithUnderscore { private void my_method () { } } - class ClassContainingPublicMethodWithUnderscore - { + public class ClassContainingPublicMethodWithUnderscore { public void methot_test () { } @@ -135,20 +134,18 @@ namespace Test.Rules.Naming { } - private IMethodRule methodRule; - private ITypeRule typeRule; + private IRule rule; private AssemblyDefinition assembly; private TypeDefinition type; - MessageCollection messageCollection; + private TestRunner runner; [TestFixtureSetUp] public void FixtureSetUp () { string unit = Assembly.GetExecutingAssembly ().Location; assembly = AssemblyFactory.GetAssembly (unit); - methodRule = new DetectNonAlphaNumericsInTypeNamesRule(); - typeRule = new DetectNonAlphaNumericsInTypeNamesRule(); - messageCollection = null; + rule = new DetectNonAlphanumericInTypeNamesRule(); + runner = new TestRunner (rule); } private TypeDefinition GetTest (string name) @@ -162,7 +159,8 @@ namespace Test.Rules.Naming { { type = GetTest ("ClassContainingProperty"); foreach (MethodDefinition method in type.Methods) { - Assert.IsNull (methodRule.CheckMethod (method, new MinimalRunner ()), method.Name); + Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckMethod (method), "RuleResult." + method.Name); + Assert.AreEqual (0, runner.Defects.Count, "Count." + method.Name); } } @@ -171,7 +169,8 @@ namespace Test.Rules.Naming { { type = GetTest ("ClassContainingEvent"); foreach (MethodDefinition method in type.Methods) { - Assert.IsNull (methodRule.CheckMethod (method, new MinimalRunner ()), method.Name); + Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckMethod (method), "RuleResult." + method.Name); + Assert.AreEqual (0, runner.Defects.Count, "Count." + method.Name); } } @@ -180,7 +179,8 @@ namespace Test.Rules.Naming { { type = GetTest ("ClassContainingConversionOperator"); foreach (MethodDefinition method in type.Methods) { - Assert.IsNull (methodRule.CheckMethod (method, new MinimalRunner ()), method.Name); + Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckMethod (method), "RuleResult." + method.Name); + Assert.AreEqual (0, runner.Defects.Count, "Count." + method.Name); } } @@ -188,8 +188,10 @@ namespace Test.Rules.Naming { public void privateMethodWithUnderscoreTest () { type = GetTest ("ClassContainingPrivateMethodWithUnderscore"); + Assert.AreEqual (1, type.Methods.Count, "Methods.Count"); foreach (MethodDefinition method in type.Methods) { - Assert.IsNull (methodRule.CheckMethod (method, new MinimalRunner ()), method.Name); + Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckMethod (method), "RuleResult." + method.Name); + Assert.AreEqual (0, runner.Defects.Count, "Count." + method.Name); } } @@ -198,51 +200,50 @@ namespace Test.Rules.Naming { { type = GetTest ("ClassContainingPublicMethodWithUnderscore"); Assert.AreEqual (1, type.Methods.Count, "Methods.Count"); - messageCollection = methodRule.CheckMethod (type.Methods [0], new MinimalRunner ()); - Assert.IsNotNull (messageCollection, "MessageCollection"); - Assert.AreEqual (messageCollection.Count, 1, "MessageCollection.Count"); + foreach (MethodDefinition method in type.Methods) { + Assert.AreEqual (RuleResult.Failure, runner.CheckMethod (method), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); + } } [Test] public void nestedPrivateClassWithUnderscoreTest () { type = GetTest ("NestedPrivateClassName_WithUnderscore"); - messageCollection = typeRule.CheckType (type, new MinimalRunner ()); - Assert.IsNull (messageCollection); + Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void nestedPublicClassWithUnderscoreTest () { type = GetTest ("NestedPublicClassName_WithUnderscore"); - messageCollection = typeRule.CheckType (type, new MinimalRunner ()); - Assert.IsNotNull (messageCollection); - Assert.AreEqual (messageCollection.Count, 1); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } [Test] public void nestedPrivateInterfaceWithUnderscoreTest () { type = GetTest ("NestedPrivateInterface_WithUnderscore"); - messageCollection = typeRule.CheckType (type, new MinimalRunner ()); - Assert.IsNull (messageCollection); + Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void nestedPublicInterfaceWithUnderscoreTest () { type = GetTest ("NestedPublicInterface_WithUnderscore"); - messageCollection = typeRule.CheckType (type, new MinimalRunner ()); - Assert.IsNotNull (messageCollection); - Assert.AreEqual (messageCollection.Count, 1); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } [Test] public void defaultPrivateClassTest () { type = GetTest ("DefaultPrivate_Class"); - messageCollection = typeRule.CheckType (type, new MinimalRunner ()); - Assert.IsNull (messageCollection); + Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] @@ -250,7 +251,8 @@ namespace Test.Rules.Naming { { type = GetTest ("DefaultPrivate_Class"); foreach (MethodDefinition method in type.Methods) { - Assert.IsNull (methodRule.CheckMethod (method, new MinimalRunner ()), method.Name); + Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckMethod (method), "RuleResult." + method.Name); + Assert.AreEqual (0, runner.Defects.Count, "Count." + method.Name); } } @@ -258,8 +260,8 @@ namespace Test.Rules.Naming { public void classWithoutUnderscoreTest () { type = GetTest ("ClassWithoutUnderscore"); - messageCollection = typeRule.CheckType (type, new MinimalRunner ()); - Assert.IsNull (messageCollection); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] @@ -267,7 +269,8 @@ namespace Test.Rules.Naming { { type = GetTest ("ClassWithoutUnderscore"); foreach (MethodDefinition method in type.Methods) { - Assert.IsNull (methodRule.CheckMethod (method, new MinimalRunner ()), method.Name); + Assert.AreEqual (RuleResult.Success, runner.CheckMethod (method), "RuleResult." + method.Name); + Assert.AreEqual (0, runner.Defects.Count, "Count." + method.Name); } } @@ -276,7 +279,9 @@ namespace Test.Rules.Naming { { type = GetTest ("ClassWithDelegate"); foreach (MethodDefinition method in type.Methods) { - Assert.IsNull (methodRule.CheckMethod (method, new MinimalRunner ()), method.Name); + RuleResult result = method.IsGeneratedCode () ? RuleResult.DoesNotApply : RuleResult.Success; + Assert.AreEqual (result, runner.CheckMethod (method), "RuleResult." + method.Name); + Assert.AreEqual (0, runner.Defects.Count, "Count." + method.Name); } } @@ -284,34 +289,32 @@ namespace Test.Rules.Naming { public void InternalClassWithUnderscoreTest () { type = assembly.MainModule.Types["Test.Rules.Naming.InternalClassName_WithUnderscore"]; - messageCollection = typeRule.CheckType (type, new MinimalRunner ()); - Assert.IsNull (messageCollection); + Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void PublicClassWithUnderscoreTest () { type = assembly.MainModule.Types["Test.Rules.Naming.PublicClassName_WithUnderscore"]; - messageCollection = typeRule.CheckType (type, new MinimalRunner ()); - Assert.IsNotNull (messageCollection); - Assert.AreEqual (messageCollection.Count, 1); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } [Test] public void InternalInterfaceWithUnderscoreTest () { type = assembly.MainModule.Types["Test.Rules.Naming.InternalInterface_WithUnderscore"]; - messageCollection = typeRule.CheckType (type, new MinimalRunner ()); - Assert.IsNull (messageCollection); + Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void PublicInterfaceWithUnderscoreTest () { type = assembly.MainModule.Types["Test.Rules.Naming.PublicInterface_WithUnderscore"]; - messageCollection = typeRule.CheckType (type, new MinimalRunner ()); - Assert.IsNotNull (messageCollection); - Assert.AreEqual (messageCollection.Count, 1); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } } } diff --git a/gendarme/rules/Gendarme.Rules.Naming/Test/DoNotPrefixValuesWithEnumNameTest.cs b/gendarme/rules/Gendarme.Rules.Naming/Test/DoNotPrefixValuesWithEnumNameTest.cs index b5fb599a..f9d90a06 100644 --- a/gendarme/rules/Gendarme.Rules.Naming/Test/DoNotPrefixValuesWithEnumNameTest.cs +++ b/gendarme/rules/Gendarme.Rules.Naming/Test/DoNotPrefixValuesWithEnumNameTest.cs @@ -43,7 +43,7 @@ namespace Test.Rules.Naming { private DoNotPrefixValuesWithEnumNameRule rule; private AssemblyDefinition assembly; private TypeDefinition type; - + private TestRunner runner; [TestFixtureSetUp] public void FixtureSetUp () @@ -52,6 +52,7 @@ namespace Test.Rules.Naming { assembly = AssemblyFactory.GetAssembly (unit); type = assembly.MainModule.Types ["Test.Rules.Naming.DoNotPrefixValuesWithEnumNameTest"]; rule = new DoNotPrefixValuesWithEnumNameRule (); + runner = new TestRunner (rule); } private TypeDefinition GetTest (string name) @@ -72,7 +73,8 @@ namespace Test.Rules.Naming { public void TestNonEnum () { TypeDefinition type = GetTest ("NonEnum"); - Assert.IsNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } @@ -86,7 +88,8 @@ namespace Test.Rules.Naming { public void TestFalsePositive () { TypeDefinition type = GetTest ("FalsePositive"); - Assert.IsNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } @@ -101,8 +104,8 @@ namespace Test.Rules.Naming { public void TestSameName () { TypeDefinition type = GetTest ("SameName"); - //Assert.IsNull (rule.CheckType (type, new MinimalRunner ())); - Assert.IsNotNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } @@ -116,7 +119,8 @@ namespace Test.Rules.Naming { public void TestReserved () { TypeDefinition type = GetTest ("Prefix"); - Assert.IsNotNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } } } diff --git a/gendarme/rules/Gendarme.Rules.Naming/Test/DoNotUseReservedInEnumValueNamesTest.cs b/gendarme/rules/Gendarme.Rules.Naming/Test/DoNotUseReservedInEnumValueNamesTest.cs index 4f0822f9..9f8b8822 100644 --- a/gendarme/rules/Gendarme.Rules.Naming/Test/DoNotUseReservedInEnumValueNamesTest.cs +++ b/gendarme/rules/Gendarme.Rules.Naming/Test/DoNotUseReservedInEnumValueNamesTest.cs @@ -43,7 +43,7 @@ namespace Test.Rules.Naming { private DoNotUseReservedInEnumValueNamesRule rule; private AssemblyDefinition assembly; private TypeDefinition type; - + private TestRunner runner; [TestFixtureSetUp] public void FixtureSetUp () @@ -52,6 +52,7 @@ namespace Test.Rules.Naming { assembly = AssemblyFactory.GetAssembly (unit); type = assembly.MainModule.Types ["Test.Rules.Naming.DoNotUseReservedInEnumValueNamesTest"]; rule = new DoNotUseReservedInEnumValueNamesRule (); + runner = new TestRunner (rule); } private TypeDefinition GetTest (string name) @@ -71,7 +72,8 @@ namespace Test.Rules.Naming { public void TestNonEnum () { TypeDefinition type = GetTest ("NonEnum"); - Assert.IsNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } enum FalsePositive { @@ -84,7 +86,8 @@ namespace Test.Rules.Naming { public void TestFalsePositive () { TypeDefinition type = GetTest ("FalsePositive"); - Assert.IsNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } enum Reserved { @@ -97,7 +100,8 @@ namespace Test.Rules.Naming { public void TestReserved () { TypeDefinition type = GetTest ("Reserved"); - Assert.IsNotNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } } } diff --git a/gendarme/rules/Gendarme.Rules.Naming/Test/EnumNotEndsWithEnumOrFlagsSuffixTest.cs b/gendarme/rules/Gendarme.Rules.Naming/Test/EnumNotEndsWithEnumOrFlagsSuffixTest.cs index 6f44ae4b..36d94c61 100644 --- a/gendarme/rules/Gendarme.Rules.Naming/Test/EnumNotEndsWithEnumOrFlagsSuffixTest.cs +++ b/gendarme/rules/Gendarme.Rules.Naming/Test/EnumNotEndsWithEnumOrFlagsSuffixTest.cs @@ -76,7 +76,7 @@ namespace Test.Rules.Naming { private ITypeRule rule; private AssemblyDefinition assembly; private TypeDefinition type; - private MessageCollection messageCollection; + private TestRunner runner; [TestFixtureSetUp] public void FixtureSetUp () @@ -84,72 +84,55 @@ namespace Test.Rules.Naming { string unit = Assembly.GetExecutingAssembly ().Location; assembly = AssemblyFactory.GetAssembly (unit); rule = new EnumNotEndsWithEnumOrFlagsSuffixRule (); - messageCollection = null; - } - - private void CheckMessageType (MessageCollection messageCollection, MessageType messageType) - { - IEnumerator enumerator = messageCollection.GetEnumerator (); - if (enumerator.MoveNext ()) { - Message message = (Message) enumerator.Current; - Assert.AreEqual (message.Type, messageType); - } + runner = new TestRunner (rule); } [Test] public void TestCorrectEnumName () { type = assembly.MainModule.Types ["Test.Rules.Naming.ReturnValue"]; - messageCollection = rule.CheckType (type, new MinimalRunner ()); - Assert.IsNull (messageCollection); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void TestIncorrectEnumName () { type = assembly.MainModule.Types ["Test.Rules.Naming.ReturnValueEnum"]; - messageCollection = rule.CheckType (type, new MinimalRunner ()); - Assert.IsNotNull (messageCollection); - Assert.AreEqual (messageCollection.Count, 1); - CheckMessageType (messageCollection, MessageType.Error); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } [Test] public void TestCorrectFlagsName () { type = assembly.MainModule.Types ["Test.Rules.Naming.ReturnValues"]; - messageCollection = rule.CheckType (type, new MinimalRunner ()); - Assert.IsNull (messageCollection); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void TestIncorrectFlagsName () { type = assembly.MainModule.Types ["Test.Rules.Naming.ReturnValuesFlags"]; - messageCollection = rule.CheckType (type, new MinimalRunner ()); - Assert.IsNotNull (messageCollection); - Assert.AreEqual (messageCollection.Count, 1); - CheckMessageType (messageCollection, MessageType.Error); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } [Test] public void TestIncorrectEnumNameInLower () { type = assembly.MainModule.Types ["Test.Rules.Naming.returnvalueenum"]; - messageCollection = rule.CheckType (type, new MinimalRunner ()); - Assert.IsNotNull (messageCollection); - Assert.AreEqual (messageCollection.Count, 1); - CheckMessageType (messageCollection, MessageType.Error); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } [Test] public void TestIncorrectFlagsNameInLower () { type = assembly.MainModule.Types ["Test.Rules.Naming.returnvaluesflags"]; - messageCollection = rule.CheckType (type, new MinimalRunner ()); - Assert.IsNotNull (messageCollection); - Assert.AreEqual (messageCollection.Count, 1); - CheckMessageType (messageCollection, MessageType.Error); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } } -}
\ No newline at end of file +} diff --git a/gendarme/rules/Gendarme.Rules.Naming/Test/ParameterNamesShouldMatchOverridenMethodTest.cs b/gendarme/rules/Gendarme.Rules.Naming/Test/ParameterNamesShouldMatchOverridenMethodTest.cs index 62617a6e..2edde003 100644 --- a/gendarme/rules/Gendarme.Rules.Naming/Test/ParameterNamesShouldMatchOverridenMethodTest.cs +++ b/gendarme/rules/Gendarme.Rules.Naming/Test/ParameterNamesShouldMatchOverridenMethodTest.cs @@ -75,10 +75,10 @@ namespace Test.Rules.Naming { [TestFixture] public class ParameterNamesShouldMatchOverridenMethodTest : BaseClass, ISomeInterface, ISomeInterface2 { - private ParameterNamesShouldMatchOverridenMethodRule rule; + private ParameterNamesShouldMatchOverriddenMethodRule rule; private AssemblyDefinition assembly; private TypeDefinition type; - + private TestRunner runner; [TestFixtureSetUp] public void FixtureSetUp () @@ -86,7 +86,8 @@ namespace Test.Rules.Naming { string unit = Assembly.GetExecutingAssembly ().Location; assembly = AssemblyFactory.GetAssembly (unit); type = assembly.MainModule.Types ["Test.Rules.Naming.ParameterNamesShouldMatchOverridenMethodTest"]; - rule = new ParameterNamesShouldMatchOverridenMethodRule (); + rule = new ParameterNamesShouldMatchOverriddenMethodRule (); + runner = new TestRunner (rule); } private MethodDefinition GetTest (string name) @@ -106,7 +107,8 @@ namespace Test.Rules.Naming { public void TestVirtualCorrect () { MethodDefinition method = GetTest ("VirtualCorrect"); - Assert.IsNull (rule.CheckMethod (method, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Success, runner.CheckMethod (method), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } protected override void VirtualIncorrect (int vi1, int vi2a) @@ -117,7 +119,8 @@ namespace Test.Rules.Naming { public void TestVirtualIncorrect () { MethodDefinition method = GetTest ("VirtualIncorrect"); - Assert.IsNotNull (rule.CheckMethod (method, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Failure, runner.CheckMethod (method), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } protected override void VirtualSuperIncorrect (int vsi1, bool vsi2_) @@ -128,7 +131,8 @@ namespace Test.Rules.Naming { public void TestVirtualSuperIncorrect () { MethodDefinition method = GetTest ("VirtualSuperIncorrect"); - Assert.IsNotNull (rule.CheckMethod (method, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Failure, runner.CheckMethod (method), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } protected override void AbstractCorrect (int ac1, int ac2) @@ -140,7 +144,8 @@ namespace Test.Rules.Naming { public void TestAbstractCorrect () { MethodDefinition method = GetTest ("AbstractCorrect"); - Assert.IsNull (rule.CheckMethod (method, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Success, runner.CheckMethod (method), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } protected override void AbstractIncorrect (int ai1, int ai2_) @@ -152,7 +157,8 @@ namespace Test.Rules.Naming { public void TestAbstractIncorrect () { MethodDefinition method = GetTest ("AbstractIncorrect"); - Assert.IsNotNull (rule.CheckMethod (method, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Failure, runner.CheckMethod (method), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } protected virtual void NoOverwrite (int a, int bb) @@ -163,7 +169,8 @@ namespace Test.Rules.Naming { public void TestNoOverwrite () { MethodDefinition method = GetTest ("NoOverwrite"); - Assert.IsNull (rule.CheckMethod (method, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Success, runner.CheckMethod (method), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } public bool InterfaceMethod (int im_) @@ -175,7 +182,8 @@ namespace Test.Rules.Naming { public void TestInterfaceMethod () { MethodDefinition method = GetTest ("InterfaceMethod"); - Assert.IsNotNull (rule.CheckMethod (method, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Failure, runner.CheckMethod (method), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } bool ISomeInterface2.InterfaceMethod2 (int im_) @@ -187,7 +195,8 @@ namespace Test.Rules.Naming { public void TestInterfaceMethod2 () { MethodDefinition method = GetTest ("Test.Rules.Naming.ISomeInterface2.InterfaceMethod2"); - Assert.IsNotNull (rule.CheckMethod (method, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Failure, runner.CheckMethod (method), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } } } diff --git a/gendarme/rules/Gendarme.Rules.Naming/Test/UseCorrectCasingTest.cs b/gendarme/rules/Gendarme.Rules.Naming/Test/UseCorrectCasingTest.cs index ff20090b..a0091f4c 100644 --- a/gendarme/rules/Gendarme.Rules.Naming/Test/UseCorrectCasingTest.cs +++ b/gendarme/rules/Gendarme.Rules.Naming/Test/UseCorrectCasingTest.cs @@ -84,7 +84,7 @@ namespace Test.Rules.Naming { private UseCorrectCasingRule rule; private AssemblyDefinition assembly; private TypeDefinition type; - private MessageCollection messageCollection; + private TestRunner runner; [TestFixtureSetUp] public void FixtureSetUp () @@ -92,16 +92,7 @@ namespace Test.Rules.Naming { string unit = Assembly.GetExecutingAssembly ().Location; assembly = AssemblyFactory.GetAssembly (unit); rule = new UseCorrectCasingRule (); - messageCollection = null; - } - - private void CheckMessageType (MessageCollection messageCollection, MessageType messageType) - { - IEnumerator enumerator = messageCollection.GetEnumerator (); - if (enumerator.MoveNext ()) { - Message message = (Message) enumerator.Current; - Assert.AreEqual (messageType, message.Type); - } + runner = new TestRunner (rule); } private MethodDefinition GetMethod (string name) @@ -117,74 +108,62 @@ namespace Test.Rules.Naming { public void TestCorrectCasedClass () { type = assembly.MainModule.Types ["Test.Rules.Naming.CorrectCasing"]; - messageCollection = rule.CheckType (type, new MinimalRunner ()); - Assert.IsNull (messageCollection); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void TestIncorrectCasedClass () { type = assembly.MainModule.Types ["Test.Rules.Naming.incorrectCasing"]; - messageCollection = rule.CheckType (type, new MinimalRunner ()); - Assert.IsNotNull (messageCollection); - Assert.AreEqual (1, messageCollection.Count); - CheckMessageType (messageCollection, MessageType.Error); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } [Test] public void TestCorrectCasedMethod () { type = assembly.MainModule.Types ["Test.Rules.Naming.CasingMethods"]; - messageCollection = rule.CheckMethod (GetMethod ("CorrectCasing"), new MinimalRunner ()); - Assert.IsNull (messageCollection); + MethodDefinition method = GetMethod ("CorrectCasing"); + Assert.AreEqual (RuleResult.Success, runner.CheckMethod (method), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void TestIncorrectCasedMethod () { type = assembly.MainModule.Types ["Test.Rules.Naming.CasingMethods"]; - messageCollection = rule.CheckMethod (GetMethod ("incorrectCasing"), new MinimalRunner ()); - Assert.IsNotNull (messageCollection); - Assert.AreEqual (1, messageCollection.Count); - CheckMessageType (messageCollection, MessageType.Error); + MethodDefinition method = GetMethod ("incorrectCasing"); + Assert.AreEqual (RuleResult.Failure, runner.CheckMethod (method), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } [Test] public void TestCorrectCasedMethodWithIncorrectCasedParameters () { type = assembly.MainModule.Types ["Test.Rules.Naming.CasingMethods"]; - messageCollection = rule.CheckMethod (GetMethod ("CorrectCasingWithTwoIncorrectParameters"), new MinimalRunner ()); - Assert.IsNotNull (messageCollection); - Assert.AreEqual (2, messageCollection.Count); - CheckMessageType (messageCollection, MessageType.Error); + MethodDefinition method = GetMethod ("CorrectCasingWithTwoIncorrectParameters"); + Assert.AreEqual (RuleResult.Failure, runner.CheckMethod (method), "RuleResult"); + Assert.AreEqual (2, runner.Defects.Count, "Count"); } [Test] public void TestIncorrectCasedMethodWithIncorrectCasedParameters () { type = assembly.MainModule.Types ["Test.Rules.Naming.CasingMethods"]; - messageCollection = rule.CheckMethod (GetMethod ("incorrectCasingWithTwoIncorrectParameters"), new MinimalRunner ()); - Assert.IsNotNull (messageCollection); - Assert.AreEqual (3, messageCollection.Count); - CheckMessageType (messageCollection, MessageType.Error); - } - - [Test] - public void TestIgnoringCctor () - { - type = assembly.MainModule.Types ["Test.Rules.Naming.MoreComplexCasing"]; - foreach (MethodDefinition method in type.Constructors) - if (method.Name == ".cctor") - messageCollection = rule.CheckMethod (method, new MinimalRunner ()); - Assert.IsNull (messageCollection); + MethodDefinition method = GetMethod ("incorrectCasingWithTwoIncorrectParameters"); + Assert.AreEqual (RuleResult.Failure, runner.CheckMethod (method), "RuleResult"); + Assert.AreEqual (3, runner.Defects.Count, "Count"); } [Test] public void TestIgnoringCtor () { type = assembly.MainModule.Types ["Test.Rules.Naming.MoreComplexCasing"]; + // .ctor and .cctor foreach (MethodDefinition method in type.Constructors) { - Assert.IsNull (rule.CheckMethod (method, new MinimalRunner ()), method.Name); + Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckMethod (method), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } } @@ -192,71 +171,69 @@ namespace Test.Rules.Naming { public void TestGoodProperty () { type = assembly.MainModule.Types ["Test.Rules.Naming.MoreComplexCasing"]; - messageCollection = rule.CheckMethod (GetMethod ("get_GoodProperty"), new MinimalRunner ()); - Assert.IsNull (messageCollection); - messageCollection = rule.CheckMethod (GetMethod ("set_GoodProperty"), new MinimalRunner ()); - Assert.IsNull (messageCollection); + MethodDefinition method = GetMethod ("get_GoodProperty"); + Assert.AreEqual (RuleResult.Success, runner.CheckMethod (method), "RuleResult1"); + Assert.AreEqual (0, runner.Defects.Count, "Count1"); + method = GetMethod ("set_GoodProperty"); + Assert.AreEqual (RuleResult.Success, runner.CheckMethod (method), "RuleResult2"); + Assert.AreEqual (0, runner.Defects.Count, "Count2"); } [Test] public void TestBadProperty () { type = assembly.MainModule.Types ["Test.Rules.Naming.MoreComplexCasing"]; - messageCollection = rule.CheckMethod (GetMethod ("get_badProperty"), new MinimalRunner ()); - Assert.IsNotNull (messageCollection); - Assert.AreEqual (1, messageCollection.Count); - CheckMessageType (messageCollection, MessageType.Error); - messageCollection = rule.CheckMethod (GetMethod ("set_badProperty"), new MinimalRunner ()); - Assert.IsNotNull (messageCollection); - Assert.AreEqual (1, messageCollection.Count); - CheckMessageType (messageCollection, MessageType.Error); + MethodDefinition method = GetMethod ("get_badProperty"); + Assert.AreEqual (RuleResult.Failure, runner.CheckMethod (method), "RuleResult1"); + Assert.AreEqual (1, runner.Defects.Count, "Count1"); + method = GetMethod ("set_badProperty"); + Assert.AreEqual (RuleResult.Failure, runner.CheckMethod (method), "RuleResult2"); + Assert.AreEqual (1, runner.Defects.Count, "Count2"); } [Test] public void TestGoodEventHandler () { type = assembly.MainModule.Types ["Test.Rules.Naming.MoreComplexCasing"]; - messageCollection = rule.CheckMethod (GetMethod ("add_GoodEvent"), new MinimalRunner ()); - Assert.IsNull (messageCollection); - messageCollection = rule.CheckMethod (GetMethod ("remove_GoodEvent"), new MinimalRunner ()); - Assert.IsNull (messageCollection); + MethodDefinition method = GetMethod ("add_GoodEvent"); + Assert.AreEqual (RuleResult.Success, runner.CheckMethod (method), "RuleResult1"); + Assert.AreEqual (0, runner.Defects.Count, "Count1"); + method = GetMethod ("remove_GoodEvent"); + Assert.AreEqual (RuleResult.Success, runner.CheckMethod (method), "RuleResult2"); + Assert.AreEqual (0, runner.Defects.Count, "Count2"); } [Test] public void TestBadEventHandler () { type = assembly.MainModule.Types ["Test.Rules.Naming.MoreComplexCasing"]; - messageCollection = rule.CheckMethod (GetMethod ("add_badEvent"), new MinimalRunner ()); - Assert.IsNotNull (messageCollection); - Assert.AreEqual (1, messageCollection.Count); - CheckMessageType (messageCollection, MessageType.Error); - messageCollection = rule.CheckMethod (GetMethod ("remove_badEvent"), new MinimalRunner ()); - Assert.IsNotNull (messageCollection); - Assert.AreEqual (1, messageCollection.Count); - CheckMessageType (messageCollection, MessageType.Error); + MethodDefinition method = GetMethod ("add_badEvent"); + Assert.AreEqual (RuleResult.Failure, runner.CheckMethod (method), "RuleResult1"); + Assert.AreEqual (1, runner.Defects.Count, "Count1"); + method = GetMethod ("remove_badEvent"); + Assert.AreEqual (RuleResult.Failure, runner.CheckMethod (method), "RuleResult2"); + Assert.AreEqual (1, runner.Defects.Count, "Count2"); } [Test] public void TestPropertyLikeMethods () { type = assembly.MainModule.Types ["Test.Rules.Naming.MoreComplexCasing"]; - messageCollection = rule.CheckMethod (GetMethod ("get_AccessorLike"), new MinimalRunner ()); - Assert.IsNotNull (messageCollection); - Assert.AreEqual (1, messageCollection.Count); - CheckMessageType (messageCollection, MessageType.Error); - messageCollection = rule.CheckMethod (GetMethod ("set_AccessorLike"), new MinimalRunner ()); - Assert.IsNotNull (messageCollection); - Assert.AreEqual (1, messageCollection.Count); - CheckMessageType (messageCollection, MessageType.Error); + MethodDefinition method = GetMethod ("get_AccessorLike"); + Assert.AreEqual (RuleResult.Failure, runner.CheckMethod (method), "RuleResult1"); + Assert.AreEqual (1, runner.Defects.Count, "Count1"); + method = GetMethod ("set_AccessorLike"); + Assert.AreEqual (RuleResult.Failure, runner.CheckMethod (method), "RuleResult2"); + Assert.AreEqual (1, runner.Defects.Count, "Count2"); } - [Test] public void TestIgnoringOperator () { type = assembly.MainModule.Types ["Test.Rules.Naming.MoreComplexCasing"]; - messageCollection = rule.CheckMethod (GetMethod ("op_Addition"), new MinimalRunner ()); - Assert.IsNull (messageCollection); + MethodDefinition method = GetMethod ("op_Addition"); + Assert.AreEqual (RuleResult.Success, runner.CheckMethod (method), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] @@ -275,7 +252,8 @@ namespace Test.Rules.Naming { // this isn't part of the test (but included with CSC) break; default: - Assert.IsNull (rule.CheckMethod (method, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Success, runner.CheckMethod (method), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); break; } } diff --git a/gendarme/rules/Gendarme.Rules.Naming/Test/UseCorrectPrefixTest.cs b/gendarme/rules/Gendarme.Rules.Naming/Test/UseCorrectPrefixTest.cs index 551bb608..75290362 100644 --- a/gendarme/rules/Gendarme.Rules.Naming/Test/UseCorrectPrefixTest.cs +++ b/gendarme/rules/Gendarme.Rules.Naming/Test/UseCorrectPrefixTest.cs @@ -67,7 +67,7 @@ namespace Test.Rules.Naming { private ITypeRule rule; private AssemblyDefinition assembly; private TypeDefinition type; - private MessageCollection messageCollection; + private TestRunner runner; [TestFixtureSetUp] public void FixtureSetUp () @@ -75,86 +75,71 @@ namespace Test.Rules.Naming { string unit = Assembly.GetExecutingAssembly ().Location; assembly = AssemblyFactory.GetAssembly (unit); rule = new UseCorrectPrefixRule (); - messageCollection = null; - } - - private void CheckMessageType (MessageCollection messageCollection, MessageType messageType) - { - IEnumerator enumerator = messageCollection.GetEnumerator (); - if (enumerator.MoveNext ()) { - Message message = (Message) enumerator.Current; - Assert.AreEqual (messageType, message.Type); - } + runner = new TestRunner (rule); } [Test] public void TestCorrectClass () { type = assembly.MainModule.Types ["Test.Rules.Naming.CorrectClass"]; - messageCollection = rule.CheckType (type, new MinimalRunner ()); - Assert.IsNull (messageCollection); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void TestAnotherCorrectClass () { type = assembly.MainModule.Types ["Test.Rules.Naming.AnotherCorrectClass"]; - messageCollection = rule.CheckType (type, new MinimalRunner ()); - Assert.IsNull (messageCollection); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void TestIncorrectClass () { type = assembly.MainModule.Types ["Test.Rules.Naming.CIncorrectClass"]; - messageCollection = rule.CheckType (type, new MinimalRunner ()); - Assert.IsNotNull (messageCollection); - Assert.AreEqual (1, messageCollection.Count); - CheckMessageType (messageCollection, MessageType.Error); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } [Test] public void TestCorrectInterface () { type = assembly.MainModule.Types ["Test.Rules.Naming.ICorrectInterface"]; - messageCollection = rule.CheckType (type, new MinimalRunner ()); - Assert.IsNull (messageCollection); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void TestIncorrectInterface () { type = assembly.MainModule.Types ["Test.Rules.Naming.IncorrectInterface"]; - messageCollection = rule.CheckType (type, new MinimalRunner ()); - Assert.IsNotNull (messageCollection); - Assert.AreEqual (1, messageCollection.Count); - CheckMessageType (messageCollection, MessageType.Error); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } [Test] public void TestAnotherIncorrectInterface () { type = assembly.MainModule.Types ["Test.Rules.Naming.AnotherIncorrectInterface"]; - messageCollection = rule.CheckType (type, new MinimalRunner ()); - Assert.IsNotNull (messageCollection); - Assert.AreEqual (1, messageCollection.Count); - CheckMessageType (messageCollection, MessageType.Error); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } [Test] public void TestClassAbbreviation () { type = assembly.MainModule.Types ["Test.Rules.Naming.CLSAbbreviation"]; - messageCollection = rule.CheckType (type, new MinimalRunner ()); - Assert.IsNull (messageCollection); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void TestInterfaceAbbreviation () { type = assembly.MainModule.Types ["Test.Rules.Naming.ICLSAbbreviation"]; - messageCollection = rule.CheckType (type, new MinimalRunner ()); - Assert.IsNull (messageCollection); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } } } diff --git a/gendarme/rules/Gendarme.Rules.Naming/Test/UseCorrectSuffixTest.cs b/gendarme/rules/Gendarme.Rules.Naming/Test/UseCorrectSuffixTest.cs index 09f2e324..ea34b520 100644 --- a/gendarme/rules/Gendarme.Rules.Naming/Test/UseCorrectSuffixTest.cs +++ b/gendarme/rules/Gendarme.Rules.Naming/Test/UseCorrectSuffixTest.cs @@ -208,7 +208,7 @@ namespace Test.Rules.Naming { private ITypeRule rule; private AssemblyDefinition assembly; private TypeDefinition type; - private MessageCollection messageCollection; + private TestRunner runner; [TestFixtureSetUp] public void FixtureSetUp () @@ -216,60 +216,47 @@ namespace Test.Rules.Naming { string unit = Assembly.GetExecutingAssembly ().Location; assembly = AssemblyFactory.GetAssembly (unit); rule = new UseCorrectSuffixRule (); - messageCollection = null; - } - - private void CheckMessageType (MessageCollection messageCollection, MessageType messageType) - { - IEnumerator enumerator = messageCollection.GetEnumerator (); - if (enumerator.MoveNext ()) { - Message message = (Message) enumerator.Current; - Assert.AreEqual (messageType, message.Type); - } + runner = new TestRunner (rule); } [Test] public void TestOneLevelInheritanceIncorrectName () { type = assembly.MainModule.Types ["Test.Rules.Naming.IncorrectAttr"]; - messageCollection = rule.CheckType (type, new MinimalRunner ()); - Assert.IsNotNull (messageCollection); - Assert.AreEqual (1, messageCollection.Count); - CheckMessageType (messageCollection, MessageType.Error); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } [Test] public void TestOneLevelInheritanceCorrectName () { type = assembly.MainModule.Types ["Test.Rules.Naming.CorrectAttribute"]; - messageCollection = rule.CheckType (type, new MinimalRunner ()); - Assert.IsNull (messageCollection); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void TestVariousLevelInheritanceCorrectName () { type = assembly.MainModule.Types ["Test.Rules.Naming.OtherAttribute"]; - messageCollection = rule.CheckType (type, new MinimalRunner ()); - Assert.IsNull (messageCollection); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void TestVariousLevelInheritanceIncorrectName () { type = assembly.MainModule.Types ["Test.Rules.Naming.OtherAttr"]; - messageCollection = rule.CheckType (type, new MinimalRunner ()); - Assert.IsNotNull (messageCollection); - Assert.AreEqual (1, messageCollection.Count); - CheckMessageType (messageCollection, MessageType.Error); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } [Test] public void TestVariousLevelInheritanceExternalTypeUndetermined () { type = assembly.MainModule.Types ["Test.Rules.Naming.CorrectContextStaticAttribute"]; - messageCollection = rule.CheckType (type, new MinimalRunner ()); - Assert.IsNull (messageCollection); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); //The System.ContextStaticAttribute class inherits from System.Attribute. //But we can retrieve that info from a TypeReference, because now //Gendarme doesn't support loading assemblies. @@ -279,16 +266,16 @@ namespace Test.Rules.Naming { public void TestOneLevelInheritanceExternalTypeNoApplyed () { type = assembly.MainModule.Types ["Test.Rules.Naming.OtherClass"]; - messageCollection = rule.CheckType (type, new MinimalRunner ()); - Assert.IsNull (messageCollection); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void TestVariousLevelInheritanceExternalTypeNoApplyed () { type = assembly.MainModule.Types ["Test.Rules.Naming.YetAnotherClass"]; - messageCollection = rule.CheckType (type, new MinimalRunner ()); - Assert.IsNull (messageCollection); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); // The System.Random class doesn't inherit from any defined classes. // But we can retrieve that info from a TypeReference, because now // Gendarme doesn't support loading assemblies. @@ -298,70 +285,64 @@ namespace Test.Rules.Naming { public void TestInterfaceImplementerCorrectName () { type = assembly.MainModule.Types ["Test.Rules.Naming.CorrectICollectionCollection"]; - messageCollection = rule.CheckType (type, new MinimalRunner ()); - Assert.IsNull (messageCollection); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void TestInterfaceImplementerIncorrectName () { type = assembly.MainModule.Types ["Test.Rules.Naming.IncorrectICollectionCol"]; - messageCollection = rule.CheckType (type, new MinimalRunner ()); - Assert.IsNotNull (messageCollection); - Assert.AreEqual (1, messageCollection.Count); - CheckMessageType (messageCollection, MessageType.Error); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } [Test] public void TestMultipleInterfaceImplementerCorrectName () { type = assembly.MainModule.Types ["Test.Rules.Naming.CorrectMultipleInterfaceImplementerPermission"]; - messageCollection = rule.CheckType (type, new MinimalRunner ()); - Assert.IsNull (messageCollection); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void TestMultipleInterfaceImplementerAnotherCorrectName () { type = assembly.MainModule.Types ["Test.Rules.Naming.CorrectMultipleInterfaceImplementerCollection"]; - messageCollection = rule.CheckType (type, new MinimalRunner ()); - Assert.IsNull (messageCollection); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void TestMultipleInterfaceImplementerIncorrectName () { type = assembly.MainModule.Types ["Test.Rules.Naming.IncorrectMultipleInterfaceImplementer"]; - messageCollection = rule.CheckType (type, new MinimalRunner ()); - Assert.IsNotNull (messageCollection); - Assert.AreEqual (1, messageCollection.Count); - CheckMessageType (messageCollection, MessageType.Error); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } [Test] public void TestDerivingClassImplementingInterfacesCorrectName () { type = assembly.MainModule.Types ["Test.Rules.Naming.CorrectDerivingClassImplementingInterfacesEventArgs"]; - messageCollection = rule.CheckType (type, new MinimalRunner ()); - Assert.IsNull (messageCollection); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void TestDerivingClassImplementingInterfacesIncorrectName () { type = assembly.MainModule.Types ["Test.Rules.Naming.IncorrectDerivingClassImplementingInterfaces"]; - messageCollection = rule.CheckType (type, new MinimalRunner ()); - Assert.AreEqual (1, messageCollection.Count); - CheckMessageType (messageCollection, MessageType.Error); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } [Test] public void TestDerivingClassImplementingInterfacesAnotherIncorrectName () { type = assembly.MainModule.Types ["Test.Rules.Naming.IncorrectDerivingClassImplementingInterfacesCollection"]; - messageCollection = rule.CheckType (type, new MinimalRunner ()); - Assert.AreEqual (1, messageCollection.Count); - CheckMessageType (messageCollection, MessageType.Error); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } } } diff --git a/gendarme/rules/Gendarme.Rules.Naming/Test/UsePluralNameInEnumFlagsTest.cs b/gendarme/rules/Gendarme.Rules.Naming/Test/UsePluralNameInEnumFlagsTest.cs index cd1c017d..a579743c 100644 --- a/gendarme/rules/Gendarme.Rules.Naming/Test/UsePluralNameInEnumFlagsTest.cs +++ b/gendarme/rules/Gendarme.Rules.Naming/Test/UsePluralNameInEnumFlagsTest.cs @@ -57,7 +57,7 @@ namespace Test.Rules.Naming { private ITypeRule rule; private AssemblyDefinition assembly; private TypeDefinition type; - private MessageCollection messageCollection; + private TestRunner runner; [TestFixtureSetUp] public void FixtureSetUp () @@ -65,34 +65,23 @@ namespace Test.Rules.Naming { string unit = Assembly.GetExecutingAssembly ().Location; assembly = AssemblyFactory.GetAssembly (unit); rule = new UsePluralNameInEnumFlagsRule (); - messageCollection = null; - } - - private void CheckMessageType (MessageCollection messageCollection, MessageType messageType) - { - IEnumerator enumerator = messageCollection.GetEnumerator (); - if (enumerator.MoveNext ()) { - Message message = (Message) enumerator.Current; - Assert.AreEqual (message.Type, messageType); - } + runner = new TestRunner (rule); } [Test] public void TestFlagsHasPluralName () { type = assembly.MainModule.Types ["Test.Rules.Naming.AppDomainManagerInitializationOptions"]; - messageCollection = rule.CheckType (type, new MinimalRunner ()); - Assert.IsNull (messageCollection); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void TestFlagsHasSingularName () { type = assembly.MainModule.Types ["Test.Rules.Naming.ConsoleModifier"]; - messageCollection = rule.CheckType (type, new MinimalRunner ()); - Assert.IsNotNull (messageCollection); - Assert.AreEqual (messageCollection.Count, 1); - CheckMessageType (messageCollection, MessageType.Error); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } } } diff --git a/gendarme/rules/Gendarme.Rules.Naming/Test/UsePreferredTermsTest.cs b/gendarme/rules/Gendarme.Rules.Naming/Test/UsePreferredTermsTest.cs index c3d36844..21795b85 100644 --- a/gendarme/rules/Gendarme.Rules.Naming/Test/UsePreferredTermsTest.cs +++ b/gendarme/rules/Gendarme.Rules.Naming/Test/UsePreferredTermsTest.cs @@ -57,7 +57,7 @@ namespace Test.Rules.Naming { private UsePreferredTermsRule rule; private AssemblyDefinition assembly; private TypeDefinition type; - private MessageCollection messageCollection; + private TestRunner runner; [TestFixtureSetUp] public void FixtureSetUp () @@ -65,16 +65,7 @@ namespace Test.Rules.Naming { string unit = Assembly.GetExecutingAssembly ().Location; assembly = AssemblyFactory.GetAssembly (unit); rule = new UsePreferredTermsRule (); - messageCollection = null; - } - - private void CheckMessageType (MessageCollection messageCollection, MessageType messageType) - { - IEnumerator enumerator = messageCollection.GetEnumerator (); - if (enumerator.MoveNext ()) { - Message message = (Message) enumerator.Current; - Assert.AreEqual (messageType, message.Type); - } + runner = new TestRunner (rule); } private MethodDefinition GetPropertyGetter (string name) @@ -100,44 +91,40 @@ namespace Test.Rules.Naming { public void TestOneObsoleteTerm () { type = assembly.MainModule.Types ["Test.Rules.Naming.SomeComPlusStuff"]; - messageCollection = rule.CheckType (type, new MinimalRunner ()); - Assert.IsNotNull (messageCollection); - Assert.AreEqual (1, messageCollection.Count); - CheckMessageType (messageCollection, MessageType.Error); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } [Test] public void TestTwoObsoleteTerms () { type = assembly.MainModule.Types ["Test.Rules.Naming.SomeComPlusAndIndicesStuff"]; - messageCollection = rule.CheckType (type, new MinimalRunner ()); - Assert.IsNotNull (messageCollection); - Assert.AreEqual (2, messageCollection.Count); - CheckMessageType (messageCollection, MessageType.Error); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (2, runner.Defects.Count, "Count"); } [Test] public void TestCorrectMethodsAndProperties () { type = assembly.MainModule.Types ["Test.Rules.Naming.TermsMethodsAndProperties"]; - messageCollection = rule.CheckMethod (GetMethod ("SignIn"), new MinimalRunner ()); - Assert.IsNull (messageCollection); - messageCollection = rule.CheckMethod (GetPropertyGetter ("Writable"), new MinimalRunner ()); - Assert.IsNull (messageCollection); + MethodDefinition method = GetMethod ("SignIn"); + Assert.AreEqual (RuleResult.Success, runner.CheckMethod (method), "RuleResult1"); + Assert.AreEqual (0, runner.Defects.Count, "Count1"); + method = GetMethod ("get_Writable"); + Assert.AreEqual (RuleResult.Success, runner.CheckMethod (method), "RuleResult2"); + Assert.AreEqual (0, runner.Defects.Count, "Count2"); } [Test] public void TestIncorrectMethodsAndProperties () { type = assembly.MainModule.Types ["Test.Rules.Naming.TermsMethodsAndProperties"]; - messageCollection = rule.CheckMethod (GetMethod ("SignOn"), new MinimalRunner ()); - Assert.IsNotNull (messageCollection); - Assert.AreEqual (1, messageCollection.Count); - CheckMessageType (messageCollection, MessageType.Error); - messageCollection = rule.CheckMethod (GetPropertyGetter ("Writeable"), new MinimalRunner ()); - Assert.IsNotNull (messageCollection); - Assert.AreEqual (1, messageCollection.Count); - CheckMessageType (messageCollection, MessageType.Error); + MethodDefinition method = GetMethod ("SignOn"); + Assert.AreEqual (RuleResult.Failure, runner.CheckMethod (method), "RuleResult1"); + Assert.AreEqual (1, runner.Defects.Count, "Count1"); + method = GetMethod ("get_Writeable"); + Assert.AreEqual (RuleResult.Failure, runner.CheckMethod (method), "RuleResult2"); + Assert.AreEqual (1, runner.Defects.Count, "Count2"); } } } diff --git a/gendarme/rules/Gendarme.Rules.Naming/Test/UseSingularNameInEnumsUnlessAreFlagsTest.cs b/gendarme/rules/Gendarme.Rules.Naming/Test/UseSingularNameInEnumsUnlessAreFlagsTest.cs index bdd2dbbc..2d962baf 100644 --- a/gendarme/rules/Gendarme.Rules.Naming/Test/UseSingularNameInEnumsUnlessAreFlagsTest.cs +++ b/gendarme/rules/Gendarme.Rules.Naming/Test/UseSingularNameInEnumsUnlessAreFlagsTest.cs @@ -66,50 +66,39 @@ namespace Test.Rules.Naming { private ITypeRule rule; private AssemblyDefinition assembly; private TypeDefinition type; - private MessageCollection messageCollection; - + private TestRunner runner; + [TestFixtureSetUp] public void FixtureSetUp () { string unit = Assembly.GetExecutingAssembly ().Location; assembly = AssemblyFactory.GetAssembly (unit); rule = new UseSingularNameInEnumsUnlessAreFlagsRule (); - messageCollection = null; - } - - private void CheckMessageType (MessageCollection messageCollection, MessageType messageType) - { - IEnumerator enumerator = messageCollection.GetEnumerator (); - if (enumerator.MoveNext ()) { - Message message = (Message) enumerator.Current; - Assert.AreEqual (message.Type, messageType); - } + runner = new TestRunner (rule); } [Test] public void TestEnumHasSingularName () { type = assembly.MainModule.Types ["Test.Rules.Naming.DayOfWeek"]; - messageCollection = rule.CheckType (type, new MinimalRunner ()); - Assert.IsNull (messageCollection); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void TestEnumHasPluralName () { type = assembly.MainModule.Types ["Test.Rules.Naming.DateTimeKinds"]; - messageCollection = rule.CheckType (type, new MinimalRunner ()); - Assert.IsNotNull (messageCollection); - Assert.AreEqual (messageCollection.Count, 1); - CheckMessageType (messageCollection, MessageType.Error); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } [Test] public void TestFlagsAllowedToHavePluralNames () { type = assembly.MainModule.Types ["Test.Rules.Naming.StringSplitOptions"]; - messageCollection = rule.CheckType (type, new MinimalRunner ()); - Assert.IsNull (messageCollection); + Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } - } -}
\ No newline at end of file + } +} |