diff options
author | Sebastien Pouliot <sebastien@ximian.com> | 2008-02-15 21:53:42 +0300 |
---|---|---|
committer | Sebastien Pouliot <sebastien@ximian.com> | 2008-02-15 21:53:42 +0300 |
commit | 7cae4892c6a6c1b2d154cd46bb3e46fc89c44339 (patch) | |
tree | e3feb7e7734e6b31f2cf498e04443761dc9b5072 /gendarme/rules | |
parent | d7967e2385b4fb3c8af16029c2bd8896de8371b8 (diff) |
2008-02-15 Sebastien Pouliot <sebastien@ximian.com>
* AbstractTypesShouldNotHavePublicConstructorsTest.cs
* AttributeArgumentsShouldHaveAccessorsTest.cs
* AvoidEmptyInterfaceTest.cs
* AvoidPropertiesWithoutGetAccessorTest.cs
* AvoidPublicInstanceFieldsTest.cs
* ConsiderConvertingMethodToPropertyTest.cs
* DisposableFieldsShouldBeDisposedTest.cs
* DisposableTypesShouldHaveFinalizerTest.cs
* DontDeclareProtectedFieldsInSealedClassTest.cs
* EnsureSymmetryForOverloadedOperatorsTest.cs
* EnumsShouldDefineAZeroValueTest.cs
* EnumsShouldUseInt32Test.cs
* FinalizersShouldBeProtectedTest.cs
* FinalizersShouldCallBaseClassFinalizerTest.cs
* FlagsShouldNotDefineAZeroValueTest.cs
* ImplementEqualsAndGetHashCodeInPairTest.cs
* MainShouldNotBePublicTest.cs
* MissingAttributeUsageOnCustomAttributeTest.cs
* OperatorEqualsShouldBeOverloadedTest.cs
* OverrideEqualsMethodTest.cs
* ProvideAlternativeNamesForOperatorOverloadsTest.cs
* TypesShouldBeInsideNamespacesTest.cs
* TypesWithDisposableFieldsShouldBeDisposableTest.cs
* TypesWithNativeFieldsShouldBeDisposableTest.cs
* UsingCloneWithoutImplementingICloneableTest.cs:
Update unit tests wrt framework changes
svn path=/trunk/mono-tools/; revision=95786
Diffstat (limited to 'gendarme/rules')
26 files changed, 483 insertions, 347 deletions
diff --git a/gendarme/rules/Gendarme.Rules.Design/Test/AbstractTypesShouldNotHavePublicConstructorsTest.cs b/gendarme/rules/Gendarme.Rules.Design/Test/AbstractTypesShouldNotHavePublicConstructorsTest.cs index 065c45a3..ac87a7a7 100644 --- a/gendarme/rules/Gendarme.Rules.Design/Test/AbstractTypesShouldNotHavePublicConstructorsTest.cs +++ b/gendarme/rules/Gendarme.Rules.Design/Test/AbstractTypesShouldNotHavePublicConstructorsTest.cs @@ -4,7 +4,7 @@ // Authors: // Sebastien Pouliot <sebastien@ximian.com> // -// 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 @@ -85,7 +85,7 @@ namespace Test.Rules.Design { private ITypeRule rule; private AssemblyDefinition assembly; - private Runner runner; + private TestRunner runner; [TestFixtureSetUp] public void FixtureSetUp () @@ -93,7 +93,7 @@ namespace Test.Rules.Design { string unit = Assembly.GetExecutingAssembly ().Location; assembly = AssemblyFactory.GetAssembly (unit); rule = new AbstractTypesShouldNotHavePublicConstructorsRule (); - runner = new MinimalRunner (); + runner = new TestRunner (rule); } private TypeDefinition GetType (string name) @@ -106,30 +106,36 @@ namespace Test.Rules.Design { public void WithNoConstructors () { TypeDefinition type = GetType ("PublicAbstractClass"); - Assert.IsNull (rule.CheckType (type, runner), "PublicAbstractClass"); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult1"); + Assert.AreEqual (0, runner.Defects.Count, "Count1"); type = GetType ("AbstractTypesShouldNotHavePublicConstructorsTest/NestedPublicAbstractClass"); - Assert.IsNull (rule.CheckType (type, runner), "NestedPublicAbstractClass"); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult2"); + Assert.AreEqual (0, runner.Defects.Count, "Count2"); } [Test] public void WithPublicConstructors () { TypeDefinition type = GetType ("PublicAbstractClassWithPublicCtor"); - Assert.AreEqual (1, rule.CheckType (type, runner).Count, "PublicAbstractClassWithPublicCtor"); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult1"); + Assert.AreEqual (1, runner.Defects.Count, "Count1"); type = GetType ("AbstractTypesShouldNotHavePublicConstructorsTest/NestedPublicAbstractClassWithPublicCtors"); - Assert.AreEqual (2, rule.CheckType (type, runner).Count, "NestedPublicAbstractClassWithPublicCtors"); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult2"); + Assert.AreEqual (2, runner.Defects.Count, "Count2"); } [Test] public void WithProtectedConstructors () { TypeDefinition type = GetType ("PublicAbstractClassWithProtectedCtor"); - Assert.IsNull (rule.CheckType (type, runner), "PublicAbstractClassWithProtectedCtor"); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult1"); + Assert.AreEqual (0, runner.Defects.Count, "Count1"); type = GetType ("AbstractTypesShouldNotHavePublicConstructorsTest/NestedPublicAbstractClassWithProtectedCtors"); - Assert.IsNull (rule.CheckType (type, runner), "NestedPublicAbstractClassWithProtectedCtors"); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult2"); + Assert.AreEqual (0, runner.Defects.Count, "Count2"); } } } diff --git a/gendarme/rules/Gendarme.Rules.Design/Test/AttributeArgumentsShouldHaveAccessorsTest.cs b/gendarme/rules/Gendarme.Rules.Design/Test/AttributeArgumentsShouldHaveAccessorsTest.cs index a354ee65..0fd2be2a 100644 --- a/gendarme/rules/Gendarme.Rules.Design/Test/AttributeArgumentsShouldHaveAccessorsTest.cs +++ b/gendarme/rules/Gendarme.Rules.Design/Test/AttributeArgumentsShouldHaveAccessorsTest.cs @@ -205,8 +205,7 @@ namespace Test.Rules.Design { private ITypeRule rule; private AssemblyDefinition assembly; - private Runner runner; - + private TestRunner runner; [TestFixtureSetUp] public void FixtureSetUp () @@ -214,7 +213,7 @@ namespace Test.Rules.Design { string unit = System.Reflection.Assembly.GetExecutingAssembly ().Location; assembly = AssemblyFactory.GetAssembly (unit); rule = new AttributeArgumentsShouldHaveAccessorsRule (); - runner = new MinimalRunner (); + runner = new TestRunner (rule); } private TypeDefinition GetTest<T> () @@ -225,68 +224,73 @@ namespace Test.Rules.Design { [Test] public void TestEmptyAttribute () { - MessageCollection messages = rule.CheckType (GetTest<EmptyAttribute> (), runner); - Assert.IsNull (messages); + TypeDefinition type = GetTest<EmptyAttribute> (); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void TestJustClass () { - MessageCollection messages = rule.CheckType (GetTest<JustClass> (), runner); - Assert.IsNull (messages); + TypeDefinition type = GetTest<JustClass> (); + Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void TestMultiConstructorNoAccessorsMissingAttribute () { - MessageCollection messages = rule.CheckType (GetTest<MultiConstructorNoAccessorsMissingAttribute> (), runner); - Assert.IsNull (messages); + TypeDefinition type = GetTest<MultiConstructorNoAccessorsMissingAttribute> (); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void TestMultiConstructorOneAccessorMissingAttribute () { - MessageCollection messages = rule.CheckType (GetTest<MultiConstructorOneAccessorMissingAttribute> (), runner); - Assert.IsNotNull (messages); - Assert.AreEqual (1, messages.Count); + TypeDefinition type = GetTest<MultiConstructorOneAccessorMissingAttribute> (); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } [Test] public void TestMultiConstructorTwoAccessorsMissingAttribute () { - MessageCollection messages = rule.CheckType (GetTest<MultiConstructorTwoAccessorsMissingAttribute> (), runner); - Assert.IsNotNull (messages); - Assert.AreEqual (2, messages.Count); + TypeDefinition type = GetTest<MultiConstructorTwoAccessorsMissingAttribute> (); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (2, runner.Defects.Count, "Count"); } [Test] public void TestNearlyEmptyttribute () { - MessageCollection messages = rule.CheckType (GetTest<NearlyEmptyAttribute> (), runner); - Assert.IsNull (messages); + TypeDefinition type = GetTest<NearlyEmptyAttribute> (); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void TestNoAccessorsMissingAttribute () { - MessageCollection messages = rule.CheckType (GetTest<NoAccessorsMissingAttribute> (), runner); - Assert.IsNull (messages); + TypeDefinition type = GetTest<NoAccessorsMissingAttribute> (); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void TestOneAccessorMissingAttribute () { - MessageCollection messages = rule.CheckType (GetTest<OneAccessorMissingAttribute> (), runner); - Assert.IsNotNull (messages); - Assert.AreEqual (1, messages.Count); + TypeDefinition type = GetTest<OneAccessorMissingAttribute> (); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } [Test] public void TestTwoAccessorsMissingAttribute () { - MessageCollection messages = rule.CheckType (GetTest<TwoAccessorsMissingAttribute> (), runner); - Assert.IsNotNull (messages); - Assert.AreEqual (2, messages.Count); + TypeDefinition type = GetTest<TwoAccessorsMissingAttribute> (); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (2, runner.Defects.Count, "Count"); } } } diff --git a/gendarme/rules/Gendarme.Rules.Design/Test/AvoidEmptyInterfaceTest.cs b/gendarme/rules/Gendarme.Rules.Design/Test/AvoidEmptyInterfaceTest.cs index 9a8f030b..16033311 100644 --- a/gendarme/rules/Gendarme.Rules.Design/Test/AvoidEmptyInterfaceTest.cs +++ b/gendarme/rules/Gendarme.Rules.Design/Test/AvoidEmptyInterfaceTest.cs @@ -4,7 +4,7 @@ // Authors: // Sebastien Pouliot <sebastien@ximian.com> // -// 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 @@ -51,7 +51,7 @@ namespace Test.Rules.Design { private ITypeRule rule; private AssemblyDefinition assembly; - private Runner runner; + private TestRunner runner; [TestFixtureSetUp] public void FixtureSetUp () @@ -59,7 +59,7 @@ namespace Test.Rules.Design { string unit = Assembly.GetExecutingAssembly ().Location; assembly = AssemblyFactory.GetAssembly (unit); rule = new AvoidEmptyInterfaceRule (); - runner = new MinimalRunner (); + runner = new TestRunner (rule); } private TypeDefinition GetTest (string name) @@ -72,24 +72,28 @@ namespace Test.Rules.Design { public void NotAnInterface () { TypeDefinition type = GetTest (String.Empty); - Assert.IsNull (rule.CheckType (type, runner)); + Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void Empty () { TypeDefinition type = GetTest ("/IAmEmpty"); - Assert.IsNotNull (rule.CheckType (type, runner)); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } [Test] public void NotEmpty () { TypeDefinition type = GetTest ("/IAmNotEmpty"); - Assert.IsNull (rule.CheckType (type, runner), "IAmNotEmpty"); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult1"); + Assert.AreEqual (0, runner.Defects.Count, "Count1"); type = GetTest ("/IImplementSeveralInterfaces"); - Assert.IsNull (rule.CheckType (type, runner), "IImplementSeveralInterfaces"); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult2"); + Assert.AreEqual (0, runner.Defects.Count, "Count2"); } } } diff --git a/gendarme/rules/Gendarme.Rules.Design/Test/AvoidPropertiesWithoutGetAccessorTest.cs b/gendarme/rules/Gendarme.Rules.Design/Test/AvoidPropertiesWithoutGetAccessorTest.cs index 24cde825..6773da4e 100644 --- a/gendarme/rules/Gendarme.Rules.Design/Test/AvoidPropertiesWithoutGetAccessorTest.cs +++ b/gendarme/rules/Gendarme.Rules.Design/Test/AvoidPropertiesWithoutGetAccessorTest.cs @@ -4,7 +4,7 @@ // Authors: // Sebastien Pouliot <sebastien@ximian.com> // -// 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 @@ -118,10 +118,9 @@ namespace Test.Rules.Design { [TestFixture] public class AvoidPropertiesWithoutGetAccessorTest { - - private IMethodRule rule; + private ITypeRule rule; private AssemblyDefinition assembly; - private Runner runner; + private TestRunner runner; [TestFixtureSetUp] public void FixtureSetUp () @@ -129,7 +128,7 @@ namespace Test.Rules.Design { string unit = Assembly.GetExecutingAssembly ().Location; assembly = AssemblyFactory.GetAssembly (unit); rule = new AvoidPropertiesWithoutGetAccessorRule (); - runner = new MinimalRunner (); + runner = new TestRunner (rule); } private TypeDefinition GetType (string name) @@ -142,81 +141,67 @@ namespace Test.Rules.Design { public void WithNoProperties () { TypeDefinition type = GetType ("AvoidPropertiesWithoutGetAccessorTest"); - foreach (MethodDefinition method in type.Methods) { - Assert.IsNull (rule.CheckMethod (method, runner), method.Name); - } + Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void WithBothGetAndSet () { TypeDefinition type = GetType ("PublicAbstract"); - foreach (MethodDefinition method in type.Methods) { - Assert.IsNull (rule.CheckMethod (method, runner), method.ToString ()); - } + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult1"); + Assert.AreEqual (0, runner.Defects.Count, "Count1"); type = GetType ("IPublic"); - foreach (MethodDefinition method in type.Methods) { - Assert.IsNull (rule.CheckMethod (method, runner), method.ToString ()); - } + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult2"); + Assert.AreEqual (0, runner.Defects.Count, "Count2"); type = GetType ("PublicClass"); - foreach (MethodDefinition method in type.Methods) { - Assert.IsNull (rule.CheckMethod (method, runner), method.ToString ()); - } + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult3"); + Assert.AreEqual (0, runner.Defects.Count, "Count3"); type = GetType ("PublicClassExplicitInterface"); - foreach (MethodDefinition method in type.Methods) { - Assert.IsNull (rule.CheckMethod (method, runner), method.ToString ()); - } + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult4"); + Assert.AreEqual (0, runner.Defects.Count, "Count4"); type = GetType ("PublicClassInterface"); - foreach (MethodDefinition method in type.Methods) { - Assert.IsNull (rule.CheckMethod (method, runner), method.ToString ()); - } + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult5"); + Assert.AreEqual (0, runner.Defects.Count, "Count5"); } [Test] public void WithOnlyGet () { TypeDefinition type = GetType ("PublicAbstractGetOnly"); - foreach (MethodDefinition method in type.Methods) { - Assert.IsNull (rule.CheckMethod (method, runner), method.ToString ()); - } - - type = GetType ("IPublicGetOnly"); - foreach (MethodDefinition method in type.Methods) { - Assert.IsNull (rule.CheckMethod (method, runner), method.ToString ()); - } + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult1"); + Assert.AreEqual (0, runner.Defects.Count, "Count1"); + + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult2"); + Assert.AreEqual (0, runner.Defects.Count, "Count2"); } [Test] public void WithOnlySet () { TypeDefinition type = GetType ("PublicAbstractSetOnly"); - foreach (MethodDefinition method in type.Methods) { - Assert.IsNotNull (rule.CheckMethod (method, runner), method.ToString ()); - } + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult1"); + Assert.AreEqual (1, runner.Defects.Count, "Count1"); type = GetType ("IPublicSetOnly"); - foreach (MethodDefinition method in type.Methods) { - Assert.IsNotNull (rule.CheckMethod (method, runner), method.ToString ()); - } + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult2"); + Assert.AreEqual (1, runner.Defects.Count, "Count2"); type = GetType ("PublicSetOnlyInheritClass"); - foreach (MethodDefinition method in type.Methods) { - Assert.IsNotNull (rule.CheckMethod (method, runner), method.ToString ()); - } + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult3"); + Assert.AreEqual (1, runner.Defects.Count, "Count3"); type = GetType ("PublicSetOnlyImplementClass"); - foreach (MethodDefinition method in type.Methods) { - Assert.IsNotNull (rule.CheckMethod (method, runner), method.ToString ()); - } + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult4"); + Assert.AreEqual (1, runner.Defects.Count, "Count4"); type = GetType ("PublicSetIsNotASetterClass"); - foreach (MethodDefinition method in type.Methods) { - Assert.IsNull (rule.CheckMethod (method, runner), method.ToString ()); - } + Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type), "RuleResult5"); + Assert.AreEqual (0, runner.Defects.Count, "Count5"); } } } diff --git a/gendarme/rules/Gendarme.Rules.Design/Test/AvoidPublicInstanceFieldsTest.cs b/gendarme/rules/Gendarme.Rules.Design/Test/AvoidPublicInstanceFieldsTest.cs index 9098869c..96c77529 100644 --- a/gendarme/rules/Gendarme.Rules.Design/Test/AvoidPublicInstanceFieldsTest.cs +++ b/gendarme/rules/Gendarme.Rules.Design/Test/AvoidPublicInstanceFieldsTest.cs @@ -78,18 +78,18 @@ namespace Test.Rules.Design { private ITypeRule rule; + private TestRunner runner; private AssemblyDefinition assembly; private TypeDefinition type; - private ModuleDefinition module; [TestFixtureSetUp] public void FixtureSetUp () { string unit = Assembly.GetExecutingAssembly ().Location; assembly = AssemblyFactory.GetAssembly (unit); - module = assembly.MainModule; - type = module.Types ["Test.Rules.Design.AvoidPublicInstanceFieldsTest"]; + type = assembly.MainModule.Types ["Test.Rules.Design.AvoidPublicInstanceFieldsTest"]; rule = new AvoidPublicInstanceFieldsRule (); + runner = new TestRunner (rule); } private TypeDefinition GetTest (string name) @@ -102,56 +102,64 @@ namespace Test.Rules.Design { public void TestShouldBeCaught () { TypeDefinition type = GetTest ("ShouldBeCaught"); - Assert.IsNotNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } [Test] public void TestShouldBeIgnored () { TypeDefinition type = GetTest ("ShouldBeIgnored"); - Assert.IsNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void TestArraySpecialCase () { TypeDefinition type = GetTest ("ArraySpecialCase"); - Assert.IsNotNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (2, runner.Defects.Count, "Count"); } [Test] public void TestEnum () { TypeDefinition type = GetTest ("Enum"); - Assert.IsNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void TestFlags () { TypeDefinition type = GetTest ("Flags"); - Assert.IsNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void TestStaticSpecialCase () { TypeDefinition type = GetTest ("StaticSpecialCase"); - Assert.IsNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void TestConstSpecialCase () { TypeDefinition type = GetTest ("ConstSpecialCase"); - Assert.IsNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void TestReadOnlySpecialCase () { TypeDefinition type = GetTest ("ReadOnlySpecialCase"); - Assert.IsNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } } } diff --git a/gendarme/rules/Gendarme.Rules.Design/Test/ChangeLog b/gendarme/rules/Gendarme.Rules.Design/Test/ChangeLog index 71964a54..218e0eb3 100644 --- a/gendarme/rules/Gendarme.Rules.Design/Test/ChangeLog +++ b/gendarme/rules/Gendarme.Rules.Design/Test/ChangeLog @@ -1,3 +1,32 @@ +2008-02-15 Sebastien Pouliot <sebastien@ximian.com> + + * AbstractTypesShouldNotHavePublicConstructorsTest.cs + * AttributeArgumentsShouldHaveAccessorsTest.cs + * AvoidEmptyInterfaceTest.cs + * AvoidPropertiesWithoutGetAccessorTest.cs + * AvoidPublicInstanceFieldsTest.cs + * ConsiderConvertingMethodToPropertyTest.cs + * DisposableFieldsShouldBeDisposedTest.cs + * DisposableTypesShouldHaveFinalizerTest.cs + * DontDeclareProtectedFieldsInSealedClassTest.cs + * EnsureSymmetryForOverloadedOperatorsTest.cs + * EnumsShouldDefineAZeroValueTest.cs + * EnumsShouldUseInt32Test.cs + * FinalizersShouldBeProtectedTest.cs + * FinalizersShouldCallBaseClassFinalizerTest.cs + * FlagsShouldNotDefineAZeroValueTest.cs + * ImplementEqualsAndGetHashCodeInPairTest.cs + * MainShouldNotBePublicTest.cs + * MissingAttributeUsageOnCustomAttributeTest.cs + * OperatorEqualsShouldBeOverloadedTest.cs + * OverrideEqualsMethodTest.cs + * ProvideAlternativeNamesForOperatorOverloadsTest.cs + * TypesShouldBeInsideNamespacesTest.cs + * TypesWithDisposableFieldsShouldBeDisposableTest.cs + * TypesWithNativeFieldsShouldBeDisposableTest.cs + * UsingCloneWithoutImplementingICloneableTest.cs: + Update unit tests wrt framework changes + 2008-02-07 Sebastien Pouliot <sebastien@ximian.com> * EnumsShouldUseInt32Test.cs: New. Unit tests. diff --git a/gendarme/rules/Gendarme.Rules.Design/Test/ConsiderConvertingMethodToPropertyTest.cs b/gendarme/rules/Gendarme.Rules.Design/Test/ConsiderConvertingMethodToPropertyTest.cs index 61a56dae..a6da6cc7 100644 --- a/gendarme/rules/Gendarme.Rules.Design/Test/ConsiderConvertingMethodToPropertyTest.cs +++ b/gendarme/rules/Gendarme.Rules.Design/Test/ConsiderConvertingMethodToPropertyTest.cs @@ -81,15 +81,15 @@ namespace Test.Rules.Design { private IMethodRule rule; private AssemblyDefinition assembly; - private ModuleDefinition module; + private TestRunner runner; [TestFixtureSetUp] public void FixtureSetUp () { string unit = Assembly.GetExecutingAssembly ().Location; assembly = AssemblyFactory.GetAssembly (unit); - module = assembly.MainModule; rule = new ConsiderConvertingMethodToPropertyRule (); + runner = new TestRunner (rule); } private TypeDefinition GetTest (string name) @@ -102,16 +102,20 @@ namespace Test.Rules.Design { public void TestShouldBeCaught () { TypeDefinition type = GetTest ("ShouldBeCaught"); - foreach (MethodDefinition md in type.Methods) - Assert.IsNotNull (rule.CheckMethod (md, new MinimalRunner ()), md.Name); + foreach (MethodDefinition md in type.Methods) { + Assert.AreEqual (RuleResult.Failure, runner.CheckMethod (md), "RuleResult." + md.Name); + Assert.AreEqual (1, runner.Defects.Count, "Count." + md.Name); + } } [Test] public void TestShouldBeIgnored () { TypeDefinition type = GetTest ("ShouldBeIgnored"); - foreach (MethodDefinition md in type.Methods) - Assert.IsNull (rule.CheckMethod (md, new MinimalRunner ()), md.Name); + foreach (MethodDefinition md in type.Methods) { + Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckMethod (md), "RuleResult." + md.Name); + Assert.AreEqual (0, runner.Defects.Count, "Count." + md.Name); + } } [Test] @@ -121,10 +125,12 @@ namespace Test.Rules.Design { foreach (MethodDefinition md in type.Methods) { switch (md.Name) { case "GetMyValue": - Assert.IsNotNull (rule.CheckMethod (md, new MinimalRunner ()), md.Name); + Assert.AreEqual (RuleResult.Failure, runner.CheckMethod (md), "RuleResult1"); + Assert.AreEqual (1, runner.Defects.Count, "Count1"); break; case "SetMyValue": - Assert.IsNull (rule.CheckMethod (md, new MinimalRunner ()), md.Name); + Assert.AreEqual (RuleResult.Success, runner.CheckMethod (md), "RuleResult2"); + Assert.AreEqual (0, runner.Defects.Count, "Count2"); break; } } @@ -135,7 +141,8 @@ namespace Test.Rules.Design { { TypeDefinition type = GetTest ("GetConstructor"); foreach (MethodDefinition md in type.Constructors) { - Assert.IsNull (rule.CheckMethod (md, new MinimalRunner ()), md.Name); + Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckMethod (md), "RuleResult." + md.Name); + Assert.AreEqual (0, runner.Defects.Count, "Count." + md.Name); } } } diff --git a/gendarme/rules/Gendarme.Rules.Design/Test/DisposableFieldsShouldBeDisposedTest.cs b/gendarme/rules/Gendarme.Rules.Design/Test/DisposableFieldsShouldBeDisposedTest.cs index 41430b49..fe2db553 100644 --- a/gendarme/rules/Gendarme.Rules.Design/Test/DisposableFieldsShouldBeDisposedTest.cs +++ b/gendarme/rules/Gendarme.Rules.Design/Test/DisposableFieldsShouldBeDisposedTest.cs @@ -44,7 +44,7 @@ namespace Test.Rules.Design { private DisposableFieldsShouldBeDisposedRule rule; private AssemblyDefinition assembly; - + private TestRunner runner; [TestFixtureSetUp] public void FixtureSetUp () @@ -52,6 +52,7 @@ namespace Test.Rules.Design { string unit = Assembly.GetExecutingAssembly ().Location; assembly = AssemblyFactory.GetAssembly (unit); rule = new DisposableFieldsShouldBeDisposedRule (); + runner = new TestRunner (rule); } public TypeDefinition GetTest (string name) @@ -78,7 +79,8 @@ namespace Test.Rules.Design { 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"); } @@ -94,7 +96,8 @@ namespace Test.Rules.Design { public void TestDisposable () { TypeDefinition type = GetTest ("Disposable"); - Assert.IsNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } @@ -109,7 +112,8 @@ namespace Test.Rules.Design { public void TestExtendsDispose () { TypeDefinition type = GetTest ("ExtendsDispose"); - Assert.IsNotNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } @@ -124,7 +128,8 @@ namespace Test.Rules.Design { public void TestExtendsDisposeCallsBase () { TypeDefinition type = GetTest ("ExtendsDisposeCallsBase"); - Assert.IsNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } @@ -140,7 +145,8 @@ namespace Test.Rules.Design { public void TestExtendsDispose2 () { TypeDefinition type = GetTest ("ExtendsDispose2"); - Assert.IsNotNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } @@ -158,7 +164,8 @@ namespace Test.Rules.Design { public void TestDisposeableFieldsCorrect () { TypeDefinition type = GetTest ("DisposeableFieldsCorrect"); - Assert.IsNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } @@ -178,7 +185,8 @@ namespace Test.Rules.Design { public void TestMultipleDisposeableFieldsCorrect () { TypeDefinition type = GetTest ("MultipleDisposeableFieldsCorrect"); - Assert.IsNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } @@ -197,7 +205,8 @@ namespace Test.Rules.Design { public void TestDisposeableFieldsIncorrect () { TypeDefinition type = GetTest ("DisposeableFieldsIncorrect"); - Assert.IsNotNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } @@ -221,7 +230,8 @@ namespace Test.Rules.Design { public void TestDisposeableFieldsDisposePattern () { TypeDefinition type = GetTest ("DisposeableFieldsDisposePattern"); - Assert.IsNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } @@ -240,7 +250,8 @@ namespace Test.Rules.Design { public void TestDisposeableFieldsExplicit () { TypeDefinition type = GetTest ("DisposeableFieldsExplicit"); - Assert.IsNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } @@ -263,7 +274,8 @@ namespace Test.Rules.Design { public void TestDisposeableFieldsTwoCorrect () { TypeDefinition type = GetTest ("DisposeableFieldsTwoCorrect"); - Assert.IsNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } class DisposeableFieldsTwoIncorrect : IDisposable { @@ -285,7 +297,8 @@ namespace Test.Rules.Design { public void TestDisposeableFieldsTwoIncorrect () { TypeDefinition type = GetTest ("DisposeableFieldsTwoIncorrect"); - Assert.IsNotNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } @@ -304,7 +317,8 @@ namespace Test.Rules.Design { public void TestDisposeableFieldsWithStaticExplicit () { TypeDefinition type = GetTest ("DisposeableFieldsWithStaticExplicit"); - Assert.IsNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } } } diff --git a/gendarme/rules/Gendarme.Rules.Design/Test/DisposableTypesShouldHaveFinalizerTest.cs b/gendarme/rules/Gendarme.Rules.Design/Test/DisposableTypesShouldHaveFinalizerTest.cs index 8b863f17..4d5f8563 100644 --- a/gendarme/rules/Gendarme.Rules.Design/Test/DisposableTypesShouldHaveFinalizerTest.cs +++ b/gendarme/rules/Gendarme.Rules.Design/Test/DisposableTypesShouldHaveFinalizerTest.cs @@ -87,7 +87,7 @@ namespace Test.Rules.Design { private DisposableTypesShouldHaveFinalizerRule rule; private AssemblyDefinition assembly; - + private TestRunner runner; [TestFixtureSetUp] public void FixtureSetUp () @@ -95,6 +95,7 @@ namespace Test.Rules.Design { string unit = Assembly.GetExecutingAssembly ().Location; assembly = AssemblyFactory.GetAssembly (unit); rule = new DisposableTypesShouldHaveFinalizerRule (); + runner = new TestRunner (rule); } public TypeDefinition GetTest (string name) @@ -106,42 +107,48 @@ namespace Test.Rules.Design { public void TestHasFinalizer () { TypeDefinition type = GetTest ("Test.Rules.Design.HasFinalizer"); - Assert.IsNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void TestNoFinalizer () { TypeDefinition type = GetTest ("Test.Rules.Design.NoFinalizer"); - Assert.IsNotNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } [Test] public void TestNotDisposable () { TypeDefinition type = GetTest ("Test.Rules.Design.NotDisposable"); - Assert.IsNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void TestNoNativeFields () { TypeDefinition type = GetTest ("Test.Rules.Design.NoNativeField"); - Assert.IsNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void TestNativeFieldArray () { TypeDefinition type = GetTest ("Test.Rules.Design.NativeFieldArray"); - Assert.IsNotNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } [Test] public void TestNotDisposableBecauseStatic () { TypeDefinition type = GetTest ("Test.Rules.Design.NotDisposableBecauseStatic"); - Assert.IsNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } } } diff --git a/gendarme/rules/Gendarme.Rules.Design/Test/DontDeclareProtectedFieldsInSealedClassTest.cs b/gendarme/rules/Gendarme.Rules.Design/Test/DontDeclareProtectedFieldsInSealedClassTest.cs index 6423b82a..e5466aef 100644 --- a/gendarme/rules/Gendarme.Rules.Design/Test/DontDeclareProtectedFieldsInSealedClassTest.cs +++ b/gendarme/rules/Gendarme.Rules.Design/Test/DontDeclareProtectedFieldsInSealedClassTest.cs @@ -1,10 +1,12 @@ // -// Unit tests for DontDeclareProtectedFieldsInSealedClassRule +// Unit tests for DoNotDeclareProtectedFieldsInSealedTypeRule // // Authors: // Nidhi Rawal <sonu2404@gmail.com> +// Sebastien Pouliot <sebastien@ximian.com> // // Copyright (c) <2007> Nidhi Rawal +// Copyright (C) 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 @@ -35,7 +37,7 @@ using NUnit.Framework; namespace Test.Rules.Design { [TestFixture] - public class DontDeclareProtectedFieldsInSealedClassTest { + public class DoNotDeclareProtectedFieldsInSealedTypeTest { public sealed class UnInheritableClassWithProtectedField { @@ -55,18 +57,18 @@ namespace Test.Rules.Design protected int j; } - private ITypeRule typeRule; + private ITypeRule 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); - typeRule = new DontDeclareProtectedFieldsInSealedClassRule(); - messageCollection = null; + rule = new DoNotDeclareProtectedFieldsInSealedTypeRule (); + runner = new TestRunner (rule); } private TypeDefinition GetTest (string name) @@ -79,25 +81,24 @@ namespace Test.Rules.Design public void unInheritableClassWithProtectedFieldTest () { type = GetTest ("UnInheritableClassWithProtectedField"); - messageCollection = typeRule.CheckType (type, new MinimalRunner ()); - Assert.IsNotNull (messageCollection); - Assert.AreEqual (2, messageCollection.Count); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (2, runner.Defects.Count, "Count"); } [Test] public void unInheritableClassWithoutProtectedFieldsTest () { type = GetTest ("UnInheritableClassWithoutProtectedFields"); - 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] public void inheritableClassWithProtectedFieldsTest () { type = GetTest ("InheritableClassWithProtectedFields"); - messageCollection = typeRule.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 +} diff --git a/gendarme/rules/Gendarme.Rules.Design/Test/EnsureSymmetryForOverloadedOperatorsTest.cs b/gendarme/rules/Gendarme.Rules.Design/Test/EnsureSymmetryForOverloadedOperatorsTest.cs index 85007f77..da697952 100644 --- a/gendarme/rules/Gendarme.Rules.Design/Test/EnsureSymmetryForOverloadedOperatorsTest.cs +++ b/gendarme/rules/Gendarme.Rules.Design/Test/EnsureSymmetryForOverloadedOperatorsTest.cs @@ -41,6 +41,7 @@ namespace Test.Rules.Design { private EnsureSymmetryForOverloadedOperatorsRule rule; private AssemblyDefinition assembly; private TypeDefinition type; + private TestRunner runner; [TestFixtureSetUp] public void FixtureSetUp () @@ -49,6 +50,7 @@ namespace Test.Rules.Design { assembly = AssemblyFactory.GetAssembly (unit); type = assembly.MainModule.Types ["Test.Rules.Design.EnsureSymmetryForOverloadedOperatorsTest"]; rule = new EnsureSymmetryForOverloadedOperatorsRule (); + runner = new TestRunner (rule); } public TypeDefinition GetTest (string name) @@ -69,7 +71,6 @@ namespace Test.Rules.Design { for (int i = 0; i < parameterCount; i++) mDef.Parameters.Add (new ParameterDefinition (testType)); testType.Methods.Add (mDef); - } return testType; } @@ -82,7 +83,8 @@ namespace Test.Rules.Design { 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"); } class EverythingOK { @@ -106,7 +108,8 @@ namespace Test.Rules.Design { public void TestEverythingOK () { TypeDefinition type = GetTest ("EverythingOK"); - Assert.IsNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } class Missing1 { @@ -118,9 +121,8 @@ namespace Test.Rules.Design { public void TestMissing1 () { TypeDefinition type = GetTest ("Missing1"); - MessageCollection results = rule.CheckType (type, new MinimalRunner ()); - Assert.IsNotNull (results); - Assert.AreEqual (2, results.Count); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (2, runner.Defects.Count, "Count"); } class Missing2 { @@ -132,72 +134,65 @@ namespace Test.Rules.Design { public void TestMissing2 () { TypeDefinition type = GetTest ("Missing2"); - MessageCollection results = rule.CheckType (type, new MinimalRunner ()); - Assert.IsNotNull (results); - Assert.AreEqual (3, results.Count); // divide fires for multiply and modulus + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (3, runner.Defects.Count, "Count"); + // divide fires for multiply and modulus } [Test] public void TestModulus () { TypeDefinition type = this.CreateType ("Modulus", new string [] { "op_Modulus" }, 2); - MessageCollection results = rule.CheckType (type, new MinimalRunner ()); - Assert.IsNotNull (results); - Assert.AreEqual (1, results.Count); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } [Test] public void TestGreater () { TypeDefinition type = this.CreateType ("Greater", new string [] { "op_GreaterThan", "op_GreaterThanOrEqual" }, 2); - MessageCollection results = rule.CheckType (type, new MinimalRunner ()); - Assert.IsNotNull (results); - Assert.AreEqual (2, results.Count); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (2, runner.Defects.Count, "Count"); } [Test] public void TestLess () { TypeDefinition type = this.CreateType ("Less", new string [] { "op_LessThan", "op_LessThanOrEqual" }, 2); - MessageCollection results = rule.CheckType (type, new MinimalRunner ()); - Assert.IsNotNull (results); - Assert.AreEqual (2, results.Count); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (2, runner.Defects.Count, "Count"); } [Test] public void TestEquality () { TypeDefinition type = this.CreateType ("Equality", new string [] { "op_Equality" }, 2); - MessageCollection results = rule.CheckType (type, new MinimalRunner ()); - Assert.IsNotNull (results); - Assert.AreEqual (1, results.Count); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } [Test] public void TestInequality () { TypeDefinition type = this.CreateType ("Inequality", new string [] { "op_Inequality" }, 2); - MessageCollection results = rule.CheckType (type, new MinimalRunner ()); - Assert.IsNotNull (results); - Assert.AreEqual (1, results.Count); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } [Test] public void TestTrue () { TypeDefinition type = this.CreateType ("True", new string [] { "op_True" }, 1); - MessageCollection results = rule.CheckType (type, new MinimalRunner ()); - Assert.IsNotNull (results); - Assert.AreEqual (1, results.Count); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } [Test] public void TestFalse () { TypeDefinition type = this.CreateType ("False", new string [] { "op_False" }, 1); - MessageCollection results = rule.CheckType (type, new MinimalRunner ()); - Assert.IsNotNull (results); - Assert.AreEqual (1, results.Count); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } } } diff --git a/gendarme/rules/Gendarme.Rules.Design/Test/EnumsShouldDefineAZeroValueTest.cs b/gendarme/rules/Gendarme.Rules.Design/Test/EnumsShouldDefineAZeroValueTest.cs index 4013fbaf..7da3bc66 100644 --- a/gendarme/rules/Gendarme.Rules.Design/Test/EnumsShouldDefineAZeroValueTest.cs +++ b/gendarme/rules/Gendarme.Rules.Design/Test/EnumsShouldDefineAZeroValueTest.cs @@ -4,7 +4,7 @@ // Authors: // Sebastien Pouliot <sebastien@ximian.com> // -// 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 @@ -70,7 +70,7 @@ namespace Test.Rules.Design { private ITypeRule rule; private AssemblyDefinition assembly; - private Runner runner; + private TestRunner runner; [TestFixtureSetUp] public void FixtureSetUp () @@ -78,7 +78,7 @@ namespace Test.Rules.Design { string unit = Assembly.GetExecutingAssembly ().Location; assembly = AssemblyFactory.GetAssembly (unit); rule = new EnumsShouldDefineAZeroValueRule (); - runner = new MinimalRunner (); + runner = new TestRunner (rule); } private TypeDefinition GetTest (string name) @@ -91,31 +91,36 @@ namespace Test.Rules.Design { public void NotAnEnumType () { TypeDefinition type = GetTest ("EnumsShouldDefineAZeroValueTest"); - Assert.IsNull (rule.CheckType (type, runner)); + Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void EnumWithZeroValue () { TypeDefinition type = GetTest ("PrivateEnumWithZeroValue"); - Assert.IsNull (rule.CheckType (type, runner), "PrivateEnumWithZeroValue"); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult1"); + Assert.AreEqual (0, runner.Defects.Count, "Count1"); type = GetTest ("EnumsShouldDefineAZeroValueTest/NestedPublicEnumWithZeroValue"); - Assert.IsNull (rule.CheckType (type, runner), "NestedPublicEnumWithZeroValue"); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult2"); + Assert.AreEqual (0, runner.Defects.Count, "Count2"); } [Test] public void EnumWithoutZeroValue () { TypeDefinition type = GetTest ("InternalEnumWithoutZeroValue"); - Assert.IsNotNull (rule.CheckType (type, runner)); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } [Test] public void FlagWithoutZeroValue () { TypeDefinition type = GetTest ("EnumsShouldDefineAZeroValueTest/NestedPrivateFlagsWithoutZeroValue"); - Assert.IsNull (rule.CheckType (type, runner)); + Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] @@ -123,7 +128,8 @@ namespace Test.Rules.Design { { // flags are ignored by the rule TypeDefinition type = GetTest ("EnumsShouldDefineAZeroValueTest/NestedInternalFlagsWithZeroValue"); - Assert.IsNull (rule.CheckType (type, runner)); + Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } } } diff --git a/gendarme/rules/Gendarme.Rules.Design/Test/EnumsShouldUseInt32Test.cs b/gendarme/rules/Gendarme.Rules.Design/Test/EnumsShouldUseInt32Test.cs index bf30d661..9b33e383 100644 --- a/gendarme/rules/Gendarme.Rules.Design/Test/EnumsShouldUseInt32Test.cs +++ b/gendarme/rules/Gendarme.Rules.Design/Test/EnumsShouldUseInt32Test.cs @@ -68,7 +68,7 @@ namespace Test.Rules.Design { private ITypeRule rule; private AssemblyDefinition assembly; - private Runner runner; + private TestRunner runner; [TestFixtureSetUp] public void FixtureSetUp () @@ -76,7 +76,7 @@ namespace Test.Rules.Design { string unit = Assembly.GetExecutingAssembly ().Location; assembly = AssemblyFactory.GetAssembly (unit); rule = new EnumsShouldUseInt32Rule (); - runner = new MinimalRunner (); + runner = new TestRunner (rule); } private TypeDefinition GetTest (string name) @@ -89,17 +89,20 @@ namespace Test.Rules.Design { public void NotAnEnum () { TypeDefinition type = GetTest (String.Empty); - Assert.IsNull (rule.CheckType (type, runner)); + Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void Ok () { TypeDefinition type = GetTest ("/DefaultEnum"); - Assert.IsNull (rule.CheckType (type, runner), "DefaultEnum"); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult1"); + Assert.AreEqual (0, runner.Defects.Count, "Count1"); type = GetTest ("/IntEnum"); - Assert.IsNull (rule.CheckType (type, runner), "IntEnum"); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult2"); + Assert.AreEqual (0, runner.Defects.Count, "Count2"); } [Test] @@ -108,13 +111,16 @@ namespace Test.Rules.Design { // CLS compliant types: Byte, Int16 or Int64 (Int32 is CLS but Ok) TypeDefinition type = GetTest ("/ByteEnum"); - Assert.IsNotNull (rule.CheckType (type, runner), "ByteEnum"); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult1"); + Assert.AreEqual (1, runner.Defects.Count, "Count1"); type = GetTest ("/ShortEnum"); - Assert.IsNotNull (rule.CheckType (type, runner), "ShortEnum"); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult2"); + Assert.AreEqual (1, runner.Defects.Count, "Count2"); type = GetTest ("/LongEnum"); - Assert.IsNotNull (rule.CheckType (type, runner), "LongEnum"); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult3"); + Assert.AreEqual (1, runner.Defects.Count, "Count3"); } [Test] @@ -123,16 +129,20 @@ namespace Test.Rules.Design { // i.e. using non-CLS compliant types, SByte, UInt16, UInt32 or UInt64 TypeDefinition type = GetTest ("/SignedByteEnum"); - Assert.IsNotNull (rule.CheckType (type, runner), "SignedByteEnum"); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult1"); + Assert.AreEqual (1, runner.Defects.Count, "Count1"); type = GetTest ("/UnsignedShortEnum"); - Assert.IsNotNull (rule.CheckType (type, runner), "UnsignedShortEnum"); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult2"); + Assert.AreEqual (1, runner.Defects.Count, "Count2"); type = GetTest ("/UnsignedIntEnum"); - Assert.IsNotNull (rule.CheckType (type, runner), "UnsignedIntEnum"); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult3"); + Assert.AreEqual (1, runner.Defects.Count, "Count3"); type = GetTest ("/UnsignedLongEnum"); - Assert.IsNotNull (rule.CheckType (type, runner), "UnsignedLongEnum"); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult4"); + Assert.AreEqual (1, runner.Defects.Count, "Count4"); } } } diff --git a/gendarme/rules/Gendarme.Rules.Design/Test/FinalizersShouldBeProtectedTest.cs b/gendarme/rules/Gendarme.Rules.Design/Test/FinalizersShouldBeProtectedTest.cs index 3aa94562..7d683dd7 100644 --- a/gendarme/rules/Gendarme.Rules.Design/Test/FinalizersShouldBeProtectedTest.cs +++ b/gendarme/rules/Gendarme.Rules.Design/Test/FinalizersShouldBeProtectedTest.cs @@ -61,8 +61,7 @@ namespace Test.Rules.Design { private ITypeRule rule; private AssemblyDefinition assembly; - private Runner runner; - + private TestRunner runner; [TestFixtureSetUp] public void FixtureSetUp () @@ -70,7 +69,7 @@ namespace Test.Rules.Design { string unit = System.Reflection.Assembly.GetExecutingAssembly ().Location; assembly = AssemblyFactory.GetAssembly (unit); rule = new FinalizersShouldCallBaseClassFinalizerRule (); - runner = new MinimalRunner (); + runner = new TestRunner (rule); } private TypeDefinition GetTest<T> () @@ -81,15 +80,17 @@ namespace Test.Rules.Design { [Test] public void TestNoFinalizerDefinedClass () { - MessageCollection messages = rule.CheckType (GetTest<NoFinalizerDefinedClass> (), runner); - Assert.IsNull (messages); + TypeDefinition type = GetTest<NoFinalizerDefinedClass> (); + Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void TestFinalizerCallingBaseFinalizerClass () { - MessageCollection messages = rule.CheckType (GetTest<FinalizerCallingBaseFinalizerClass> (), runner); - Assert.IsNull (messages); + TypeDefinition type = GetTest<FinalizerCallingBaseFinalizerClass> (); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] @@ -106,11 +107,9 @@ namespace Test.Rules.Design { break; } } - } - MessageCollection messages = rule.CheckType (typeDefinition, runner); - Assert.IsNotNull (messages); - Assert.AreEqual (1, messages.Count); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (typeDefinition), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } } } diff --git a/gendarme/rules/Gendarme.Rules.Design/Test/FinalizersShouldCallBaseClassFinalizerTest.cs b/gendarme/rules/Gendarme.Rules.Design/Test/FinalizersShouldCallBaseClassFinalizerTest.cs index 31a39261..67b4642d 100644 --- a/gendarme/rules/Gendarme.Rules.Design/Test/FinalizersShouldCallBaseClassFinalizerTest.cs +++ b/gendarme/rules/Gendarme.Rules.Design/Test/FinalizersShouldCallBaseClassFinalizerTest.cs @@ -30,6 +30,7 @@ using Mono.Cecil; using Mono.Cecil.Cil; using Gendarme.Framework; +using Gendarme.Framework.Helpers; using Gendarme.Framework.Rocks; using Gendarme.Rules.Design; @@ -49,8 +50,7 @@ namespace Test.Rules.Design { private ITypeRule rule; private AssemblyDefinition assembly; - private Runner runner; - + private TestRunner runner; [TestFixtureSetUp] public void FixtureSetUp () @@ -58,7 +58,7 @@ namespace Test.Rules.Design { string unit = System.Reflection.Assembly.GetExecutingAssembly ().Location; assembly = AssemblyFactory.GetAssembly (unit); rule = new FinalizersShouldBeProtectedRule (); - runner = new MinimalRunner (); + runner = new TestRunner (rule); } private TypeDefinition GetTest<T> () @@ -69,15 +69,17 @@ namespace Test.Rules.Design { [Test] public void TestNoFinalizerClass () { - MessageCollection messages = rule.CheckType (GetTest<NoFinalizerClass> (), runner); - Assert.IsNull (messages); + TypeDefinition type = GetTest<NoFinalizerClass> (); + Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void TestProtectedFinalizerClass () { - MessageCollection messages = rule.CheckType (GetTest<ProtectedFinalizerClass> (), runner); - Assert.IsNull (messages); + TypeDefinition type = GetTest<ProtectedFinalizerClass> (); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] @@ -88,9 +90,8 @@ namespace Test.Rules.Design { // make it non-protected (e.g. public) finalizer.IsPublic = true; - MessageCollection messages = rule.CheckType (typeDefinition, runner); - Assert.IsNotNull (messages); - Assert.AreEqual (1, messages.Count); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (typeDefinition), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } } } diff --git a/gendarme/rules/Gendarme.Rules.Design/Test/FlagsShouldNotDefineAZeroValueTest.cs b/gendarme/rules/Gendarme.Rules.Design/Test/FlagsShouldNotDefineAZeroValueTest.cs index 200801cf..1fe2b432 100644 --- a/gendarme/rules/Gendarme.Rules.Design/Test/FlagsShouldNotDefineAZeroValueTest.cs +++ b/gendarme/rules/Gendarme.Rules.Design/Test/FlagsShouldNotDefineAZeroValueTest.cs @@ -4,7 +4,7 @@ // Authors: // Sebastien Pouliot <sebastien@ximian.com> // -// 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 @@ -71,7 +71,7 @@ namespace Test.Rules.Design { private ITypeRule rule; private AssemblyDefinition assembly; - private Runner runner; + private TestRunner runner; [TestFixtureSetUp] public void FixtureSetUp () @@ -79,7 +79,7 @@ namespace Test.Rules.Design { string unit = Assembly.GetExecutingAssembly ().Location; assembly = AssemblyFactory.GetAssembly (unit); rule = new FlagsShouldNotDefineAZeroValueRule (); - runner = new MinimalRunner (); + runner = new TestRunner (rule); } private TypeDefinition GetTest (string name) @@ -92,34 +92,40 @@ namespace Test.Rules.Design { public void NotAnEnumType () { TypeDefinition type = GetTest ("FlagsShouldNotDefineAZeroValueTest"); - Assert.IsNull (rule.CheckType (type, runner)); + Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void NotAFlags () { TypeDefinition type = GetTest ("FlagsShouldNotDefineAZeroValueTest/NestedPublicEnumWithZeroValue"); - Assert.IsNull (rule.CheckType (type, runner), "NestedPublicEnumWithZeroValue"); + Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type), "RuleResult1"); + Assert.AreEqual (0, runner.Defects.Count, "Count1"); type = GetTest ("FlagsShouldNotDefineAZeroValueTest/NestedPrivateEnumWithoutZeroValue"); - Assert.IsNull (rule.CheckType (type, runner), "NestedPrivateEnumWithoutZeroValue"); + Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type), "RuleResult2"); + Assert.AreEqual (0, runner.Defects.Count, "Count2"); } [Test] public void FlagsWithoutZeroValue () { TypeDefinition type = GetTest ("InternalFlagsWithoutZeroValue"); - Assert.IsNull (rule.CheckType (type, runner), "InternalFlagsWithoutZeroValue"); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void FlagsWithZeroValue () { TypeDefinition type = GetTest ("PrivateFlagsWithZeroValue"); - Assert.IsNotNull (rule.CheckType (type, runner), "PrivateFlagsWithZeroValue"); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult1"); + Assert.AreEqual (1, runner.Defects.Count, "Count1"); type = GetTest ("FlagsShouldNotDefineAZeroValueTest/NestedInternalFlagsWithZeroValue"); - Assert.IsNotNull (rule.CheckType (type, runner), "NestedInternalFlagsWithZeroValue"); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult2"); + Assert.AreEqual (1, runner.Defects.Count, "Count2"); } } } diff --git a/gendarme/rules/Gendarme.Rules.Design/Test/ImplementEqualsAndGetHashCodeInPairTest.cs b/gendarme/rules/Gendarme.Rules.Design/Test/ImplementEqualsAndGetHashCodeInPairTest.cs index c84bad1f..7b0609ea 100644 --- a/gendarme/rules/Gendarme.Rules.Design/Test/ImplementEqualsAndGetHashCodeInPairTest.cs +++ b/gendarme/rules/Gendarme.Rules.Design/Test/ImplementEqualsAndGetHashCodeInPairTest.cs @@ -128,17 +128,17 @@ namespace Test.Rules.Design { } } - private ITypeRule typeRule; + private ITypeRule rule; private AssemblyDefinition assembly; - private Runner runner; + private TestRunner runner; [TestFixtureSetUp] public void FixtureSetUp () { string unit = Assembly.GetExecutingAssembly ().Location; assembly = AssemblyFactory.GetAssembly (unit); - typeRule = new ImplementEqualsAndGetHashCodeInPairRule (); - runner = new MinimalRunner (); + rule = new ImplementEqualsAndGetHashCodeInPairRule (); + runner = new TestRunner (rule); } private TypeDefinition GetTest (string name) @@ -151,71 +151,72 @@ namespace Test.Rules.Design { public void EqualsButNotGetHashCodeTest () { TypeDefinition type = GetTest ("ImplementsEqualsButNotGetHashCode"); - MessageCollection messageCollection = typeRule.CheckType (type, runner); - 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 GetHashCodeButNotEqualsTest () { TypeDefinition type = GetTest ("ImplementsGetHashCodeButNotEquals"); - MessageCollection messageCollection = typeRule.CheckType (type, runner); - 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 NoneOfThemTest () { TypeDefinition type = GetTest ("ImplementsNoneOfThem"); - Assert.IsNull (typeRule.CheckType (type, runner)); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void BothOfThemTest () { TypeDefinition type = GetTest ("ImplementsBothOfThem"); - Assert.IsNull (typeRule.CheckType (type, runner)); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void ImplementsEqualsUsesObjectGetHashCodeTest () { TypeDefinition type = GetTest ("ImplementsEqualsUsesObjectGetHashCode"); - MessageCollection messageCollection = typeRule.CheckType (type, runner); - 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 ImplementsEqualsReuseBaseGetHashCodeTest () { TypeDefinition type = GetTest ("ImplementsEqualsReuseBaseGetHashCode"); - Assert.IsNull (typeRule.CheckType (type, runner)); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void ImplementsGetHashCodeUsesObjectEqualsTest () { TypeDefinition type = GetTest ("ImplementsGetHashCodeUsesObjectEquals"); - MessageCollection messageCollection = typeRule.CheckType (type, runner); - 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 EqualsWithTwoArgsTest () { TypeDefinition type = GetTest ("ImplementingEqualsWithTwoArgs"); - Assert.IsNull (typeRule.CheckType (type, runner)); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void GetHashCodeWithOneArgTest () { TypeDefinition type = GetTest ("ImplementingGetHashCodeWithOneArg"); - Assert.IsNull (typeRule.CheckType (type, runner)); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } } } diff --git a/gendarme/rules/Gendarme.Rules.Design/Test/MainShouldNotBePublicTest.cs b/gendarme/rules/Gendarme.Rules.Design/Test/MainShouldNotBePublicTest.cs index 4432531b..a5cfffb8 100644 --- a/gendarme/rules/Gendarme.Rules.Design/Test/MainShouldNotBePublicTest.cs +++ b/gendarme/rules/Gendarme.Rules.Design/Test/MainShouldNotBePublicTest.cs @@ -39,7 +39,7 @@ namespace Test.Rules.Design { public class MainShouldNotBePublicTest { private IAssemblyRule rule; - private Runner runner; + private TestRunner runner; private AssemblyDefinition goodAssembly; private AssemblyDefinition anotherGoodAssembly; @@ -50,7 +50,7 @@ namespace Test.Rules.Design { public void FixtureSetUp () { rule = new MainShouldNotBePublicRule (); - runner = new MinimalRunner (); + runner = new TestRunner (rule); GenerateRequiredAssemblies (); } @@ -87,27 +87,29 @@ namespace Test.Rules.Design { [Test] public void TestAnotherGoodAssembly () { - Assert.IsNull (rule.CheckAssembly (anotherGoodAssembly, runner)); + Assert.AreEqual (RuleResult.Success, runner.CheckAssembly (anotherGoodAssembly)); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void TestGoodAssembly () { - Assert.IsNull (rule.CheckAssembly (goodAssembly, runner)); + Assert.AreEqual (RuleResult.Success, runner.CheckAssembly (goodAssembly)); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void TestBadAssembly () { - MessageCollection messages = rule.CheckAssembly (badAssembly, runner); - Assert.IsNotNull (messages); - Assert.AreEqual (1, messages.Count); + Assert.AreEqual (RuleResult.Failure, runner.CheckAssembly (badAssembly)); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } [Test] public void TestNoEntryPointAssembly () { - Assert.IsNull (rule.CheckAssembly (noEntryPointAssembly, runner)); + Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckAssembly (noEntryPointAssembly)); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } } } diff --git a/gendarme/rules/Gendarme.Rules.Design/Test/MissingAttributeUsageOnCustomAttributeTest.cs b/gendarme/rules/Gendarme.Rules.Design/Test/MissingAttributeUsageOnCustomAttributeTest.cs index 9fa77803..00d0b056 100644 --- a/gendarme/rules/Gendarme.Rules.Design/Test/MissingAttributeUsageOnCustomAttributeTest.cs +++ b/gendarme/rules/Gendarme.Rules.Design/Test/MissingAttributeUsageOnCustomAttributeTest.cs @@ -58,8 +58,7 @@ namespace Test.Rules.Design { private ITypeRule rule; private AssemblyDefinition assembly; - private Runner runner; - + private TestRunner runner; [TestFixtureSetUp] public void FixtureSetUp () @@ -67,7 +66,7 @@ namespace Test.Rules.Design { string unit = System.Reflection.Assembly.GetExecutingAssembly ().Location; assembly = AssemblyFactory.GetAssembly (unit); rule = new MissingAttributeUsageOnCustomAttributeRule (); - runner = new MinimalRunner (); + runner = new TestRunner (rule); } private TypeDefinition GetTest<T> () @@ -78,38 +77,41 @@ namespace Test.Rules.Design { [Test] public void TestNotAttribute () { - MessageCollection messages = rule.CheckType (GetTest<NotAttribute> (), runner); - Assert.IsNull (messages); + TypeDefinition type = GetTest<NotAttribute> (); + Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void TestNoUsageDefinedAttribute () { - MessageCollection messages = rule.CheckType (GetTest<NoUsageDefinedAttribute> (), runner); - Assert.IsNotNull (messages); - Assert.AreEqual (1, messages.Count); + TypeDefinition type = GetTest<NoUsageDefinedAttribute> (); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } [Test] public void TestNoUsageDefinedInheritsUsageDefinedAttribute () { - MessageCollection messages = rule.CheckType (GetTest<NoUsageDefinedInheritsUsageDefinedAttribute> (), runner); - Assert.IsNotNull (messages); - Assert.AreEqual (1, messages.Count); + TypeDefinition type = GetTest<NoUsageDefinedInheritsUsageDefinedAttribute> (); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } [Test] public void TestUsageDefinedAttribute () { - MessageCollection messages = rule.CheckType (GetTest<UsageDefinedAttribute> (), runner); - Assert.IsNull (messages); + TypeDefinition type = GetTest<UsageDefinedAttribute> (); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void TestUsageDefinedInheritsNoUsageDefinedAttribute () { - MessageCollection messages = rule.CheckType (GetTest<UsageDefinedInheritsNoUsageDefinedAttribute> (), runner); - Assert.IsNull (messages); + TypeDefinition type = GetTest<UsageDefinedInheritsNoUsageDefinedAttribute> (); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } } } diff --git a/gendarme/rules/Gendarme.Rules.Design/Test/OperatorEqualsShouldBeOverloadedTest.cs b/gendarme/rules/Gendarme.Rules.Design/Test/OperatorEqualsShouldBeOverloadedTest.cs index 31327361..82629e73 100644 --- a/gendarme/rules/Gendarme.Rules.Design/Test/OperatorEqualsShouldBeOverloadedTest.cs +++ b/gendarme/rules/Gendarme.Rules.Design/Test/OperatorEqualsShouldBeOverloadedTest.cs @@ -40,15 +40,16 @@ namespace Test.Rules.Design { public class OperatorEqualsShouldBeOverloadedTest { private OperatorEqualsShouldBeOverloadedRule rule; + private TestRunner runner; private AssemblyDefinition assembly; - [TestFixtureSetUp] public void FixtureSetUp () { string unit = Assembly.GetExecutingAssembly ().Location; assembly = AssemblyFactory.GetAssembly (unit); rule = new OperatorEqualsShouldBeOverloadedRule (); + runner = new TestRunner (rule); } public TypeDefinition GetTest (string name) @@ -68,7 +69,8 @@ namespace Test.Rules.Design { 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"); } class OnlyOneOperator { @@ -82,7 +84,8 @@ namespace Test.Rules.Design { public void TestOnlyOneOperator () { TypeDefinition type = GetTest ("OnlyOneOperator"); - Assert.IsNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } class EverythingOK { @@ -111,7 +114,8 @@ namespace Test.Rules.Design { public void TestEverythingOK () { TypeDefinition type = GetTest ("EverythingOK"); - Assert.IsNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } class NoEquals { @@ -130,7 +134,8 @@ namespace Test.Rules.Design { public void TestNoEquals () { TypeDefinition type = GetTest ("NoEquals"); - Assert.IsNotNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } struct StructFalsePositive { @@ -141,7 +146,8 @@ namespace Test.Rules.Design { public void TestStructFalsePositive () { TypeDefinition type = GetTest ("StructFalsePositive"); - Assert.IsNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } struct StructNoEquality { @@ -155,7 +161,8 @@ namespace Test.Rules.Design { public void TestStructNoEquality () { TypeDefinition type = GetTest ("StructNoEquality"); - 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.Design/Test/OverrideEqualsMethodTest.cs b/gendarme/rules/Gendarme.Rules.Design/Test/OverrideEqualsMethodTest.cs index b7c46ae9..0f4dfa8c 100644 --- a/gendarme/rules/Gendarme.Rules.Design/Test/OverrideEqualsMethodTest.cs +++ b/gendarme/rules/Gendarme.Rules.Design/Test/OverrideEqualsMethodTest.cs @@ -41,7 +41,7 @@ namespace Test.Rules.Design { private OverrideEqualsMethodRule rule; private AssemblyDefinition assembly; - + private TestRunner runner; [TestFixtureSetUp] public void FixtureSetUp () @@ -49,6 +49,7 @@ namespace Test.Rules.Design { string unit = Assembly.GetExecutingAssembly ().Location; assembly = AssemblyFactory.GetAssembly (unit); rule = new OverrideEqualsMethodRule (); + runner = new TestRunner (rule); } public TypeDefinition GetTest (string name) @@ -68,7 +69,8 @@ namespace Test.Rules.Design { 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"); } class EverythingOK { @@ -92,7 +94,8 @@ namespace Test.Rules.Design { public void TestEverythingOK () { TypeDefinition type = GetTest ("EverythingOK"); - Assert.IsNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } class NoEquals { @@ -111,7 +114,8 @@ namespace Test.Rules.Design { public void TestNoEquals () { TypeDefinition type = GetTest ("NoEquals"); - 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.Design/Test/ProvideAlternativeNamesForOperatorOverloadsTest.cs b/gendarme/rules/Gendarme.Rules.Design/Test/ProvideAlternativeNamesForOperatorOverloadsTest.cs index e1182a40..3a852810 100644 --- a/gendarme/rules/Gendarme.Rules.Design/Test/ProvideAlternativeNamesForOperatorOverloadsTest.cs +++ b/gendarme/rules/Gendarme.Rules.Design/Test/ProvideAlternativeNamesForOperatorOverloadsTest.cs @@ -41,6 +41,7 @@ namespace Test.Rules.Design { private ProvideAlternativeNamesForOperatorOverloadsRule rule; private AssemblyDefinition assembly; + private TestRunner runner; [TestFixtureSetUp] @@ -49,6 +50,7 @@ namespace Test.Rules.Design { string unit = Assembly.GetExecutingAssembly ().Location; assembly = AssemblyFactory.GetAssembly (unit); rule = new ProvideAlternativeNamesForOperatorOverloadsRule (); + runner = new TestRunner (rule); } public TypeDefinition GetTest (string name) @@ -68,7 +70,8 @@ namespace Test.Rules.Design { 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"); } class EverythingIsThere { @@ -138,7 +141,8 @@ namespace Test.Rules.Design { public void TestEverythingIsThere () { TypeDefinition type = GetTest ("EverythingIsThere"); - Assert.IsNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } class MissingCompare { @@ -154,9 +158,8 @@ namespace Test.Rules.Design { public void TestMissingCompare () { TypeDefinition type = GetTest ("MissingCompare"); - MessageCollection results = rule.CheckType (type, new MinimalRunner ()); - Assert.IsNotNull (results); - Assert.AreEqual (5, results.Count); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (5, runner.Defects.Count, "Count"); } class MissingUnary { @@ -175,9 +178,8 @@ namespace Test.Rules.Design { public void TestMissingUnary () { TypeDefinition type = GetTest ("MissingUnary"); - MessageCollection results = rule.CheckType (type, new MinimalRunner ()); - Assert.IsNotNull (results); - Assert.AreEqual (8, results.Count); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (8, runner.Defects.Count, "Count"); } class MissingBinary { @@ -199,9 +201,8 @@ namespace Test.Rules.Design { public void TestMissingBinary () { TypeDefinition type = GetTest ("MissingBinary"); - MessageCollection results = rule.CheckType (type, new MinimalRunner ()); - Assert.IsNotNull (results); - Assert.AreEqual (10, results.Count); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (10, runner.Defects.Count, "Count"); } } } diff --git a/gendarme/rules/Gendarme.Rules.Design/Test/TypesShouldBeInsideNamespacesTest.cs b/gendarme/rules/Gendarme.Rules.Design/Test/TypesShouldBeInsideNamespacesTest.cs index 58ed4bf5..d859126a 100644 --- a/gendarme/rules/Gendarme.Rules.Design/Test/TypesShouldBeInsideNamespacesTest.cs +++ b/gendarme/rules/Gendarme.Rules.Design/Test/TypesShouldBeInsideNamespacesTest.cs @@ -81,7 +81,7 @@ namespace Test.Rules.Design { private ITypeRule rule; private AssemblyDefinition assembly; - private Runner runner; + private TestRunner runner; [TestFixtureSetUp] public void FixtureSetUp () @@ -89,7 +89,7 @@ namespace Test.Rules.Design { string unit = Assembly.GetExecutingAssembly ().Location; assembly = AssemblyFactory.GetAssembly (unit); rule = new TypesShouldBeInsideNamespacesRule (); - runner = new MinimalRunner (); + runner = new TestRunner (rule); } private TypeDefinition GetType (string name) @@ -101,58 +101,72 @@ namespace Test.Rules.Design { public void OutsideNamespace () { TypeDefinition type = GetType ("PublicTypeOutsideNamescape"); - Assert.IsNotNull (rule.CheckType (type, runner), "PublicTypeOutsideNamescape"); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult1"); + Assert.AreEqual (1, runner.Defects.Count, "Count1"); type = GetType ("InternalTypeOutsideNamespace"); - Assert.IsNull (rule.CheckType (type, runner), "InternalTypeOutsideNamespace"); + Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type), "RuleResult2"); + Assert.AreEqual (0, runner.Defects.Count, "Count2"); type = GetType ("PrivateClassOutsideNamespace"); - Assert.IsNull (rule.CheckType (type, runner), "PrivateClassOutsideNamespace"); + Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type), "RuleResult3"); + Assert.AreEqual (0, runner.Defects.Count, "Count3"); } [Test] public void NestedOutsideNamespace () { TypeDefinition type = GetType ("PublicTypeOutsideNamescape/NestedPublicTypeOutsideNamescape"); - Assert.IsNull (rule.CheckType (type, runner), "NestedPublicTypeOutsideNamescape"); + Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type), "RuleResult1"); + Assert.AreEqual (0, runner.Defects.Count, "Count1"); type = GetType ("PublicTypeOutsideNamescape/NestedProtectedTypeOutsideNamespace"); - Assert.IsNull (rule.CheckType (type, runner), "NestedProtectedTypeOutsideNamespace"); + Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type), "RuleResult2"); + Assert.AreEqual (0, runner.Defects.Count, "Count2"); type = GetType ("PublicTypeOutsideNamescape/NestedInternalTypeOutsideNamespace"); - Assert.IsNull (rule.CheckType (type, runner), "NestedInternalTypeInsideNamespace"); + Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type), "RuleResult3"); + Assert.AreEqual (0, runner.Defects.Count, "Count3"); type = GetType ("PublicTypeOutsideNamescape/NestedPrivateClassOutsideNamespace"); - Assert.IsNull (rule.CheckType (type, runner), "NestedPrivateClassInsideNamespace"); + Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type), "RuleResult4"); + Assert.AreEqual (0, runner.Defects.Count, "Count4"); } [Test] public void InsideNamespace () { TypeDefinition type = GetType ("Test.Rules.Design.PublicTypeInsideNamescape"); - Assert.IsNull (rule.CheckType (type, runner), "PublicTypeInsideNamescape"); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult1"); + Assert.AreEqual (0, runner.Defects.Count, "Count1"); type = GetType ("Test.Rules.Design.InternalTypeInsideNamespace"); - Assert.IsNull (rule.CheckType (type, runner), "InternalTypeInsideNamespace"); + Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type), "RuleResult2"); + Assert.AreEqual (0, runner.Defects.Count, "Count2"); type = GetType ("Test.Rules.Design.PrivateClassInsideNamespace"); - Assert.IsNull (rule.CheckType (type, runner), "PrivateClassInsideNamespace"); + Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type), "RuleResult3"); + Assert.AreEqual (0, runner.Defects.Count, "Count3"); } [Test] public void NestedInsideNamespace () { TypeDefinition type = GetType ("Test.Rules.Design.PublicTypeInsideNamescape/NestedPublicTypeInsideNamescape"); - Assert.IsNull (rule.CheckType (type, runner), "NestedPublicTypeInsideNamescape"); + Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type), "RuleResult1"); + Assert.AreEqual (0, runner.Defects.Count, "Count1"); type = GetType ("Test.Rules.Design.PublicTypeInsideNamescape/NestedProtectedTypeInsideNamespace"); - Assert.IsNull (rule.CheckType (type, runner), "NestedProtectedTypeInsideNamespace"); + Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type), "RuleResult2"); + Assert.AreEqual (0, runner.Defects.Count, "Count2"); type = GetType ("Test.Rules.Design.PublicTypeInsideNamescape/NestedInternalTypeInsideNamespace"); - Assert.IsNull (rule.CheckType (type, runner), "NestedInternalTypeInsideNamespace"); + Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type), "RuleResult3"); + Assert.AreEqual (0, runner.Defects.Count, "Count3"); type = GetType ("Test.Rules.Design.PublicTypeInsideNamescape/NestedPrivateClassInsideNamespace"); - Assert.IsNull (rule.CheckType (type, runner), "NestedPrivateClassInsideNamespace"); + Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type), "RuleResult4"); + Assert.AreEqual (0, runner.Defects.Count, "Count4"); } } } diff --git a/gendarme/rules/Gendarme.Rules.Design/Test/TypesWithDisposableFieldsShouldBeDisposableTest.cs b/gendarme/rules/Gendarme.Rules.Design/Test/TypesWithDisposableFieldsShouldBeDisposableTest.cs index f9e0e37f..1205ceac 100644 --- a/gendarme/rules/Gendarme.Rules.Design/Test/TypesWithDisposableFieldsShouldBeDisposableTest.cs +++ b/gendarme/rules/Gendarme.Rules.Design/Test/TypesWithDisposableFieldsShouldBeDisposableTest.cs @@ -113,7 +113,7 @@ namespace Test.Rules.Design { private TypesWithDisposableFieldsShouldBeDisposableRule rule; private AssemblyDefinition assembly; - + private TestRunner runner; [TestFixtureSetUp] public void FixtureSetUp () @@ -121,6 +121,7 @@ namespace Test.Rules.Design { string unit = Assembly.GetExecutingAssembly ().Location; assembly = AssemblyFactory.GetAssembly (unit); rule = new TypesWithDisposableFieldsShouldBeDisposableRule (); + runner = new TestRunner (rule); } public TypeDefinition GetTest (string name) @@ -132,56 +133,64 @@ namespace Test.Rules.Design { public void TestNoDisposeableFields () { TypeDefinition type = GetTest ("Test.Rules.Design.NoDisposeableFields"); - Assert.IsNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void TestDisposeableFieldsImplementsIDisposeable () { TypeDefinition type = GetTest ("Test.Rules.Design.DisposeableFieldsImplementsIDisposeable"); - Assert.IsNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void TestDisposeableFieldsExplicit () { TypeDefinition type = GetTest ("Test.Rules.Design.DisposeableFieldsExplicit"); - Assert.IsNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void TestDisposeableFieldsImplementsIDisposeableAbstract () { TypeDefinition type = GetTest ("Test.Rules.Design.DisposeableFieldsImplementsIDisposeableAbstract"); - Assert.IsNotNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (2, runner.Defects.Count, "Count"); } [Test] public void TestDisposeableFields () { TypeDefinition type = GetTest ("Test.Rules.Design.DisposeableFields"); - Assert.IsNotNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } [Test] public void TestDisposeableFieldsArray () { TypeDefinition type = GetTest ("Test.Rules.Design.DisposeableFieldsArray"); - Assert.IsNotNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } [Test] public void TestStructWithDisposeableFields () { TypeDefinition type = GetTest ("Test.Rules.Design.StructWithDisposeableFields"); - Assert.IsNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void TestDisposeableStaticFieldsArray () { TypeDefinition type = GetTest ("Test.Rules.Design.DisposeableStaticFieldsArray"); - Assert.IsNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } } } diff --git a/gendarme/rules/Gendarme.Rules.Design/Test/TypesWithNativeFieldsShouldBeDisposableTest.cs b/gendarme/rules/Gendarme.Rules.Design/Test/TypesWithNativeFieldsShouldBeDisposableTest.cs index b1424fa3..16d3ccc0 100644 --- a/gendarme/rules/Gendarme.Rules.Design/Test/TypesWithNativeFieldsShouldBeDisposableTest.cs +++ b/gendarme/rules/Gendarme.Rules.Design/Test/TypesWithNativeFieldsShouldBeDisposableTest.cs @@ -142,7 +142,7 @@ namespace Test.Rules.Design { private TypesWithNativeFieldsShouldBeDisposableRule rule; private AssemblyDefinition assembly; - + private TestRunner runner; [TestFixtureSetUp] public void FixtureSetUp () @@ -150,6 +150,7 @@ namespace Test.Rules.Design { string unit = Assembly.GetExecutingAssembly ().Location; assembly = AssemblyFactory.GetAssembly (unit); rule = new TypesWithNativeFieldsShouldBeDisposableRule (); + runner = new TestRunner (rule); } public TypeDefinition GetTest (string name) @@ -161,77 +162,88 @@ namespace Test.Rules.Design { public void TestNoNativeFields () { TypeDefinition type = GetTest ("Test.Rules.Design.NoNativeFields"); - Assert.IsNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void TestNativeFieldsImplementsIDisposeable () { TypeDefinition type = GetTest ("Test.Rules.Design.NativeFieldsImplementsIDisposeable"); - Assert.IsNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void TestNativeFieldsExplicit () { TypeDefinition type = GetTest ("Test.Rules.Design.NativeFieldsExplicit"); - Assert.IsNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void TestNativeFieldsIntPtr () { TypeDefinition type = GetTest ("Test.Rules.Design.NativeFieldsIntPtr"); - Assert.IsNotNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } [Test] public void TestNativeFieldsUIntPtr () { TypeDefinition type = GetTest ("Test.Rules.Design.NativeFieldsUIntPtr"); - Assert.IsNotNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } [Test] public void TestNativeFieldsHandleRef () { TypeDefinition type = GetTest ("Test.Rules.Design.NativeFieldsHandleRef"); - Assert.IsNotNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } [Test] public void TestAbstractNativeFields () { TypeDefinition type = GetTest ("Test.Rules.Design.AbstractNativeFields"); - Assert.IsNotNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (2, runner.Defects.Count, "Count"); } [Test] public void TestAbstractNativeFields2 () { TypeDefinition type = GetTest ("Test.Rules.Design.AbstractNativeFields2"); - Assert.IsNotNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (2, runner.Defects.Count, "Count"); } [Test] public void TestNativeFieldsArray () { TypeDefinition type = GetTest ("Test.Rules.Design.NativeFieldsArray"); - Assert.IsNotNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } [Test] public void TestStructWithNativeFields () { TypeDefinition type = GetTest ("Test.Rules.Design.StructWithNativeFields"); - Assert.IsNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void TestNativeStaticFieldsArray () { TypeDefinition type = GetTest ("Test.Rules.Design.NativeStaticFieldsArray"); - Assert.IsNull (rule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Success, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } } } diff --git a/gendarme/rules/Gendarme.Rules.Design/Test/UsingCloneWithoutImplementingICloneableTest.cs b/gendarme/rules/Gendarme.Rules.Design/Test/UsingCloneWithoutImplementingICloneableTest.cs index 09d7e5d8..5aad115c 100644 --- a/gendarme/rules/Gendarme.Rules.Design/Test/UsingCloneWithoutImplementingICloneableTest.cs +++ b/gendarme/rules/Gendarme.Rules.Design/Test/UsingCloneWithoutImplementingICloneableTest.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 @@ -112,18 +112,18 @@ namespace Test.Rules.Design } } - private ITypeRule typeRule; + private ITypeRule 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); - typeRule = new UsingCloneWithoutImplementingICloneableRule (); - messageCollection = null; + rule = new UsingCloneWithoutImplementingICloneableRule (); + runner = new TestRunner (rule); } private TypeDefinition GetTest (string name) @@ -136,70 +136,72 @@ namespace Test.Rules.Design public void usingCloneAndImplementingICloneableTest () { type = GetTest ("UsingCloneAndImplementingICloneable"); - 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 usingCloneWithoutImplementingICloneableTest () { type = GetTest ("UsingCloneWithoutImplementingICloneable"); - messageCollection = typeRule.CheckType (type, new MinimalRunner ()); - Assert.IsNotNull (messageCollection); - Assert.AreEqual (1, messageCollection.Count); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } [Test] public void neitherUsingCloneNorImplementingICloneableTest () { type = GetTest ("NeitherUsingCloneNorImplementingICloneable"); - 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] public void anotherExampleOfNotUsingBothTest () { type = GetTest ("AnotherExampleOfNotUsingBoth"); - 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] public void OneMoreExampleTest () { type = GetTest ("OneMoreExample"); - 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] public void CloneReturnTypeNotObject () { type = GetTest ("CloningType"); - Assert.IsNotNull (typeRule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.Failure, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (1, runner.Defects.Count, "Count"); } [Test] - [Ignore ("Type located outside this assembly - need AssemblyResolver")] public void InheritFromTypeOutsideAssembly () { type = GetTest ("MyArrayList"); - Assert.IsNull (typeRule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void InheritFromTypeImplementingICloneableButWithoutOverride () { type = GetTest ("SecondLevelClone"); - Assert.IsNull (typeRule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } [Test] public void InheritFromTypeImplementingICloneable () { type = GetTest ("SecondLevelCloneWithOverride"); - Assert.IsNull (typeRule.CheckType (type, new MinimalRunner ())); + Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type), "RuleResult"); + Assert.AreEqual (0, runner.Defects.Count, "Count"); } } } |