Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono-tools.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastien Pouliot <sebastien@ximian.com>2008-02-15 23:00:48 +0300
committerSebastien Pouliot <sebastien@ximian.com>2008-02-15 23:00:48 +0300
commit1c39cf1b85a4173813d283a1368adc0fea5a5316 (patch)
treeab2594bb88ea1674bca8de01cb1ce4ead782bf46 /gendarme/rules
parent62e2e332d1e50a146372237d304cff7fee415db0 (diff)
2008-02-15 Sebastien Pouliot <sebastien@ximian.com>
* ArrayFieldsShouldNotBeReadOnlyTest.cs * MethodCallWithSubsetLinkDemandTest.cs * NativeFieldsShouldNotBeVisibleTest.cs * NonVirtualMethodWithInheritanceDemandTest.cs * SealedTypeWithInheritanceDemandTest.cs * SecureGetObjectDataOverridesTest.cs * StaticConstructorsShouldBePrivateTest.cs * TypeExposeFieldsTest.cs * TypeIsNotSubsetOfMethodSecurityTest.cs * TypeLinkDemandTest.cs: Updated unit tests wrt framework changes. svn path=/trunk/mono-tools/; revision=95815
Diffstat (limited to 'gendarme/rules')
-rw-r--r--gendarme/rules/Gendarme.Rules.Security/Test/ArrayFieldsShouldNotBeReadOnlyTest.cs16
-rw-r--r--gendarme/rules/Gendarme.Rules.Security/Test/ChangeLog14
-rw-r--r--gendarme/rules/Gendarme.Rules.Security/Test/MethodCallWithSubsetLinkDemandTest.cs14
-rw-r--r--gendarme/rules/Gendarme.Rules.Security/Test/NativeFieldsShouldNotBeVisibleTest.cs21
-rw-r--r--gendarme/rules/Gendarme.Rules.Security/Test/NonVirtualMethodWithInheritanceDemandTest.cs26
-rw-r--r--gendarme/rules/Gendarme.Rules.Security/Test/SealedTypeWithInheritanceDemandTest.cs15
-rw-r--r--gendarme/rules/Gendarme.Rules.Security/Test/SecureGetObjectDataOverridesTest.cs43
-rw-r--r--gendarme/rules/Gendarme.Rules.Security/Test/StaticConstructorsShouldBePrivateTest.cs15
-rw-r--r--gendarme/rules/Gendarme.Rules.Security/Test/TypeExposeFieldsTest.cs18
-rw-r--r--gendarme/rules/Gendarme.Rules.Security/Test/TypeIsNotSubsetOfMethodSecurityTest.cs20
-rw-r--r--gendarme/rules/Gendarme.Rules.Security/Test/TypeLinkDemandTest.cs22
11 files changed, 112 insertions, 112 deletions
diff --git a/gendarme/rules/Gendarme.Rules.Security/Test/ArrayFieldsShouldNotBeReadOnlyTest.cs b/gendarme/rules/Gendarme.Rules.Security/Test/ArrayFieldsShouldNotBeReadOnlyTest.cs
index a6008762..1bc5d970 100644
--- a/gendarme/rules/Gendarme.Rules.Security/Test/ArrayFieldsShouldNotBeReadOnlyTest.cs
+++ b/gendarme/rules/Gendarme.Rules.Security/Test/ArrayFieldsShouldNotBeReadOnlyTest.cs
@@ -68,6 +68,7 @@ namespace Test.Rules.Security {
public class ArrayFieldsShouldNotBeReadOnlyTest {
private ArrayFieldsShouldNotBeReadOnlyRule rule;
+ private TestRunner runner;
private AssemblyDefinition assembly;
@@ -77,6 +78,7 @@ namespace Test.Rules.Security {
string unit = Assembly.GetExecutingAssembly ().Location;
assembly = AssemblyFactory.GetAssembly (unit);
rule = new ArrayFieldsShouldNotBeReadOnlyRule ();
+ runner = new TestRunner (rule);
}
public TypeDefinition GetTest (string name)
@@ -88,49 +90,49 @@ namespace Test.Rules.Security {
public void TestHasStaticPublicReadonlyArray ()
{
TypeDefinition type = GetTest ("Test.Rules.Security.HasStaticPublicReadonlyArray");
- Assert.IsNotNull (rule.CheckType (type, new MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Failure, runner.CheckType (type));
}
[Test]
public void TestHasPublicReadonlyArray ()
{
TypeDefinition type = GetTest ("Test.Rules.Security.HasPublicReadonlyArray");
- Assert.IsNotNull (rule.CheckType (type, new MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Failure, runner.CheckType (type));
}
[Test]
public void TestHasProtectedReadonlyArray ()
{
TypeDefinition type = GetTest ("Test.Rules.Security.HasProtectedReadonlyArray");
- Assert.IsNotNull (rule.CheckType (type, new MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Failure, runner.CheckType (type));
}
[Test]
public void TestHasInternalReadonlyArray ()
{
TypeDefinition type = GetTest ("Test.Rules.Security.HasInternalReadonlyArray");
- Assert.IsNull (rule.CheckType (type, new MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Success, runner.CheckType (type));
}
[Test]
public void TestHasPrivateReadonlyArray ()
{
TypeDefinition type = GetTest ("Test.Rules.Security.HasPrivateReadonlyArray");
- Assert.IsNull (rule.CheckType (type, new MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Success, runner.CheckType (type));
}
[Test]
public void TestHasNoReadonlyArray ()
{
TypeDefinition type = GetTest ("Test.Rules.Security.HasNoReadonlyArray");
- Assert.IsNull (rule.CheckType (type, new MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Success, runner.CheckType (type));
}
[Test]
public void TestHasPublicArray ()
{
TypeDefinition type = GetTest ("Test.Rules.Security.HasPublicArray");
- Assert.IsNull (rule.CheckType (type, new MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Success, runner.CheckType (type));
}
}
}
diff --git a/gendarme/rules/Gendarme.Rules.Security/Test/ChangeLog b/gendarme/rules/Gendarme.Rules.Security/Test/ChangeLog
index 63089035..700f495d 100644
--- a/gendarme/rules/Gendarme.Rules.Security/Test/ChangeLog
+++ b/gendarme/rules/Gendarme.Rules.Security/Test/ChangeLog
@@ -1,3 +1,17 @@
+2008-02-15 Sebastien Pouliot <sebastien@ximian.com>
+
+ * ArrayFieldsShouldNotBeReadOnlyTest.cs
+ * MethodCallWithSubsetLinkDemandTest.cs
+ * NativeFieldsShouldNotBeVisibleTest.cs
+ * NonVirtualMethodWithInheritanceDemandTest.cs
+ * SealedTypeWithInheritanceDemandTest.cs
+ * SecureGetObjectDataOverridesTest.cs
+ * StaticConstructorsShouldBePrivateTest.cs
+ * TypeExposeFieldsTest.cs
+ * TypeIsNotSubsetOfMethodSecurityTest.cs
+ * TypeLinkDemandTest.cs:
+ Updated unit tests wrt framework changes.
+
2008-01-21 Sebastien Pouliot <sebastien@ximian.com>
* NativeFieldsShouldNotBeVisibleTest.cs: New. Unit tests by
diff --git a/gendarme/rules/Gendarme.Rules.Security/Test/MethodCallWithSubsetLinkDemandTest.cs b/gendarme/rules/Gendarme.Rules.Security/Test/MethodCallWithSubsetLinkDemandTest.cs
index b49ea778..8f2f2c6d 100644
--- a/gendarme/rules/Gendarme.Rules.Security/Test/MethodCallWithSubsetLinkDemandTest.cs
+++ b/gendarme/rules/Gendarme.Rules.Security/Test/MethodCallWithSubsetLinkDemandTest.cs
@@ -105,16 +105,16 @@ namespace Test.Rules.Security {
}
private IMethodRule rule;
+ private TestRunner runner;
private AssemblyDefinition assembly;
- private ModuleDefinition module;
[TestFixtureSetUp]
public void FixtureSetUp ()
{
string unit = Assembly.GetExecutingAssembly ().Location;
assembly = AssemblyFactory.GetAssembly (unit);
- module = assembly.MainModule;
rule = new MethodCallWithSubsetLinkDemandRule ();
+ runner = new TestRunner (rule);
}
private TypeDefinition GetTest (string name)
@@ -128,7 +128,7 @@ namespace Test.Rules.Security {
{
TypeDefinition type = GetTest ("SubsetInheritClass");
foreach (MethodDefinition method in type.Methods) {
- Assert.IsNull (rule.CheckMethod (method, new MinimalRunner ()), method.ToString ());
+ Assert.AreEqual (RuleResult.Success, runner.CheckMethod (method), method.ToString ());
}
}
@@ -137,8 +137,7 @@ namespace Test.Rules.Security {
{
TypeDefinition type = GetTest ("NotASubsetInheritClass");
foreach (MethodDefinition method in type.Methods) {
- int n = rule.CheckMethod (method, new MinimalRunner ()).Count;
- Assert.AreEqual (0, n, method.ToString ());
+ Assert.AreEqual (RuleResult.Failure, runner.CheckMethod (method), method.ToString ());
}
}
@@ -147,7 +146,7 @@ namespace Test.Rules.Security {
{
TypeDefinition type = GetTest ("SubsetCallClass");
foreach (MethodDefinition method in type.Methods) {
- Assert.IsNull (rule.CheckMethod (method, new MinimalRunner ()), method.ToString ());
+ Assert.AreEqual (RuleResult.Success, runner.CheckMethod (method), method.ToString ());
}
}
@@ -156,8 +155,7 @@ namespace Test.Rules.Security {
{
TypeDefinition type = GetTest ("NotASubsetCallClass");
foreach (MethodDefinition method in type.Methods) {
- int n = rule.CheckMethod (method, new MinimalRunner ()).Count;
- Assert.AreEqual (0, n, method.ToString ());
+ Assert.AreEqual (RuleResult.Failure, runner.CheckMethod (method), method.ToString ());
}
}
}
diff --git a/gendarme/rules/Gendarme.Rules.Security/Test/NativeFieldsShouldNotBeVisibleTest.cs b/gendarme/rules/Gendarme.Rules.Security/Test/NativeFieldsShouldNotBeVisibleTest.cs
index d7bb26fe..8043392a 100644
--- a/gendarme/rules/Gendarme.Rules.Security/Test/NativeFieldsShouldNotBeVisibleTest.cs
+++ b/gendarme/rules/Gendarme.Rules.Security/Test/NativeFieldsShouldNotBeVisibleTest.cs
@@ -76,6 +76,7 @@ namespace Test.Rules.Security {
public class NativeFieldsShouldNotBeVisibleTest {
private NativeFieldsShouldNotBeVisibleRule rule;
+ private TestRunner runner;
private AssemblyDefinition assembly;
@@ -85,6 +86,7 @@ namespace Test.Rules.Security {
string unit = Assembly.GetExecutingAssembly ().Location;
assembly = AssemblyFactory.GetAssembly (unit);
rule = new NativeFieldsShouldNotBeVisibleRule ();
+ runner = new TestRunner (rule);
}
public TypeDefinition GetTest (string name)
@@ -96,64 +98,63 @@ namespace Test.Rules.Security {
public void TestHasPublicNativeField ()
{
TypeDefinition type = GetTest ("Test.Rules.Security.HasPublicNativeField");
- Assert.IsNotNull (rule.CheckType (type, new MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Failure, runner.CheckType (type));
}
[Test]
public void TestHasProtectedNativeField ()
{
TypeDefinition type = GetTest ("Test.Rules.Security.HasProtectedNativeField");
- Assert.IsNotNull (rule.CheckType (type, new MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Failure, runner.CheckType (type));
}
[Test]
public void TestHasInternalNativeField ()
{
TypeDefinition type = GetTest ("Test.Rules.Security.HasInternalNativeField");
- Assert.IsNull (rule.CheckType (type, new MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Success, runner.CheckType (type));
}
[Test]
public void TestHasPublicReadonlyNativeField ()
{
TypeDefinition type = GetTest ("Test.Rules.Security.HasPublicReadonlyNativeField");
- Assert.IsNull (rule.CheckType (type, new MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Success, runner.CheckType (type));
}
[Test]
public void TestHasPublicNativeFieldArray ()
{
TypeDefinition type = GetTest ("Test.Rules.Security.HasPublicNativeFieldArray");
- Assert.IsNotNull (rule.CheckType (type, new MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Failure, runner.CheckType (type));
}
[Test]
public void TestHasPublicReadonlyNativeFieldArray ()
{
TypeDefinition type = GetTest ("Test.Rules.Security.HasPublicReadonlyNativeFieldArray");
- Assert.IsNotNull (rule.CheckType (type, new MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Failure, runner.CheckType (type));
}
[Test]
public void TestHasPublicNativeFieldArrayArray ()
{
TypeDefinition type = GetTest ("Test.Rules.Security.HasPublicNativeFieldArrayArray");
- Assert.IsNotNull (rule.CheckType (type, new MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Failure, runner.CheckType (type));
}
-
[Test]
public void TestHasPublicNonNativeField ()
{
TypeDefinition type = GetTest ("Test.Rules.Security.HasPublicNonNativeField");
- Assert.IsNull (rule.CheckType (type, new MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Success, runner.CheckType (type));
}
[Test]
public void TestHasPrivateNativeField ()
{
TypeDefinition type = GetTest ("Test.Rules.Security.HasPrivateNativeField");
- Assert.IsNull (rule.CheckType (type, new MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Success, runner.CheckType (type));
}
}
}
diff --git a/gendarme/rules/Gendarme.Rules.Security/Test/NonVirtualMethodWithInheritanceDemandTest.cs b/gendarme/rules/Gendarme.Rules.Security/Test/NonVirtualMethodWithInheritanceDemandTest.cs
index 6333e24f..76f9d0d2 100644
--- a/gendarme/rules/Gendarme.Rules.Security/Test/NonVirtualMethodWithInheritanceDemandTest.cs
+++ b/gendarme/rules/Gendarme.Rules.Security/Test/NonVirtualMethodWithInheritanceDemandTest.cs
@@ -4,7 +4,7 @@
// Authors:
// Sebastien Pouliot <sebastien@ximian.com>
//
-// Copyright (C) 2005-2006 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2005-2006,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
@@ -46,12 +46,12 @@ namespace Test.Rules.Security {
public abstract class AbstractMethodsClass {
[SecurityPermission (SSP.SecurityAction.InheritanceDemand, ControlAppDomain = true)]
- public abstract void Asbtract ();
+ public abstract void Abstract ();
}
public class VirtualMethodsClass: AbstractMethodsClass {
- public override void Asbtract ()
+ public override void Abstract ()
{
}
@@ -96,16 +96,16 @@ namespace Test.Rules.Security {
}
private IMethodRule rule;
+ private TestRunner runner;
private AssemblyDefinition assembly;
- private ModuleDefinition module;
[TestFixtureSetUp]
public void FixtureSetUp ()
{
string unit = Assembly.GetExecutingAssembly ().Location;
assembly = AssemblyFactory.GetAssembly (unit);
- module = assembly.MainModule;
rule = new NonVirtualMethodWithInheritanceDemandRule ();
+ runner = new TestRunner (rule);
}
private TypeDefinition GetTest (string name)
@@ -119,7 +119,7 @@ namespace Test.Rules.Security {
{
TypeDefinition type = GetTest ("AbstractMethodsClass");
foreach (MethodDefinition method in type.Methods) {
- Assert.IsNull (rule.CheckMethod (method, new MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Success, runner.CheckMethod (method), method.ToString ());
}
}
@@ -128,7 +128,14 @@ namespace Test.Rules.Security {
{
TypeDefinition type = GetTest ("VirtualMethodsClass");
foreach (MethodDefinition method in type.Methods) {
- Assert.IsNull (rule.CheckMethod (method, new MinimalRunner ()));
+ switch (method.Name) {
+ case "Abstract":
+ Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckMethod (method), method.Name);
+ break;
+ case "Virtual":
+ Assert.AreEqual (RuleResult.Success, runner.CheckMethod (method), method.Name);
+ break;
+ }
}
}
@@ -137,8 +144,7 @@ namespace Test.Rules.Security {
{
TypeDefinition type = GetTest ("NoVirtualMethodsClass");
foreach (MethodDefinition method in type.Methods) {
- int n = rule.CheckMethod (method, new MinimalRunner ()).Count;
- Assert.AreEqual (0, n, method.ToString ());
+ Assert.AreEqual (RuleResult.Failure, runner.CheckMethod (method), method.ToString ());
}
}
@@ -147,7 +153,7 @@ namespace Test.Rules.Security {
{
TypeDefinition type = GetTest ("NotInheritanceDemandClass");
foreach (MethodDefinition method in type.Methods) {
- Assert.IsNull (rule.CheckMethod (method, new MinimalRunner ()));
+ Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckMethod (method), method.ToString ());
}
}
}
diff --git a/gendarme/rules/Gendarme.Rules.Security/Test/SealedTypeWithInheritanceDemandTest.cs b/gendarme/rules/Gendarme.Rules.Security/Test/SealedTypeWithInheritanceDemandTest.cs
index 202dab8b..5b45ac2c 100644
--- a/gendarme/rules/Gendarme.Rules.Security/Test/SealedTypeWithInheritanceDemandTest.cs
+++ b/gendarme/rules/Gendarme.Rules.Security/Test/SealedTypeWithInheritanceDemandTest.cs
@@ -4,7 +4,7 @@
// Authors:
// Sebastien Pouliot <sebastien@ximian.com>
//
-// Copyright (C) 2005-2006 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2005-2006,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
@@ -72,16 +72,16 @@ namespace Test.Rules.Security {
}
private ITypeRule rule;
+ private TestRunner runner;
private AssemblyDefinition assembly;
- private ModuleDefinition module;
[TestFixtureSetUp]
public void FixtureSetUp ()
{
string unit = Assembly.GetExecutingAssembly ().Location;
assembly = AssemblyFactory.GetAssembly (unit);
- module = assembly.MainModule;
rule = new SealedTypeWithInheritanceDemandRule ();
+ runner = new TestRunner (rule);
}
private TypeDefinition GetTest (string name)
@@ -94,29 +94,28 @@ namespace Test.Rules.Security {
public void NonSealed ()
{
TypeDefinition type = GetTest ("NonSealedClass");
- Assert.IsNull (rule.CheckType (type, new MinimalRunner ()));
+ Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type));
}
[Test]
public void SealedWithoutSecurity ()
{
TypeDefinition type = GetTest ("SealedClassWithoutSecurity");
- Assert.IsNull (rule.CheckType (type, new MinimalRunner ()));
+ Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type));
}
[Test]
public void SealedWithoutInheritanceDemand ()
{
TypeDefinition type = GetTest ("SealedClassWithoutInheritanceDemand");
- Assert.IsNull (rule.CheckType (type, new MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Success, runner.CheckType (type));
}
[Test]
public void SealedWithInheritanceDemand ()
{
TypeDefinition type = GetTest ("SealedClassWithInheritanceDemand");
- int n = rule.CheckType (type, new MinimalRunner ()).Count;
- Assert.AreEqual (0, n, type.ToString ());
+ Assert.AreEqual (RuleResult.Failure, runner.CheckType (type));
}
}
}
diff --git a/gendarme/rules/Gendarme.Rules.Security/Test/SecureGetObjectDataOverridesTest.cs b/gendarme/rules/Gendarme.Rules.Security/Test/SecureGetObjectDataOverridesTest.cs
index 10926b4d..cecbc905 100644
--- a/gendarme/rules/Gendarme.Rules.Security/Test/SecureGetObjectDataOverridesTest.cs
+++ b/gendarme/rules/Gendarme.Rules.Security/Test/SecureGetObjectDataOverridesTest.cs
@@ -4,7 +4,7 @@
// Authors:
// Sebastien Pouliot <sebastien@ximian.com>
//
-// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2005,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
@@ -57,12 +57,12 @@ namespace Test.Rules.Security {
{
}
- public void GetObjectData(SerializationInfo info, StreamingContext context)
+ public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
{
}
}
- public class InheritISerializableClass : NameValueCollection {
+ public class InheritISerializableClass : ISerializableClass {
public InheritISerializableClass ()
{
@@ -121,17 +121,17 @@ namespace Test.Rules.Security {
}
}
- private IMethodRule rule;
+ private ITypeRule rule;
+ private TestRunner runner;
private AssemblyDefinition assembly;
- private ModuleDefinition module;
[TestFixtureSetUp]
public void FixtureSetUp ()
{
string unit = Assembly.GetExecutingAssembly ().Location;
assembly = AssemblyFactory.GetAssembly (unit);
- module = assembly.MainModule;
rule = new SecureGetObjectDataOverridesRule ();
+ runner = new TestRunner (rule);
}
private TypeDefinition GetTest (string name)
@@ -140,71 +140,54 @@ namespace Test.Rules.Security {
return assembly.MainModule.Types[fullname];
}
- private MethodDefinition GetObjectData (TypeDefinition type)
- {
- foreach (MethodDefinition method in type.Methods) {
- if (method.Name == "GetObjectData")
- return method;
- }
- return null;
- }
-
[Test]
public void Serializable ()
{
TypeDefinition type = GetTest ("SerializableClass");
// there's no GetObjectData method here so the test should never fail
- foreach (MethodDefinition method in type.Methods) {
- Assert.IsNull (rule.CheckMethod (method, new MinimalRunner ()));
- }
+ Assert.AreEqual (RuleResult.DoesNotApply, rule.CheckType (type));
}
[Test]
public void ISerializable ()
{
TypeDefinition type = GetTest ("ISerializableClass");
- MethodDefinition method = GetObjectData (type);
- Assert.IsNotNull (rule.CheckMethod (method, new MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Failure, runner.CheckType (type));
}
[Test]
public void InheritISerializable ()
{
TypeDefinition type = GetTest ("InheritISerializableClass");
- MethodDefinition method = GetObjectData (type);
- Assert.IsNotNull (rule.CheckMethod (method, new MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Failure, runner.CheckType (type));
}
[Test]
public void LinkDemand ()
{
TypeDefinition type = GetTest ("LinkDemandClass");
- MethodDefinition method = GetObjectData (type);
- Assert.IsNull (rule.CheckMethod (method, new MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Success, runner.CheckType (type));
}
[Test]
public void InheritanceDemand ()
{
TypeDefinition type = GetTest ("InheritanceDemandClass");
- MethodDefinition method = GetObjectData (type);
- Assert.IsNotNull (rule.CheckMethod (method, new MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Failure, runner.CheckType (type));
}
[Test]
public void Demand ()
{
TypeDefinition type = GetTest ("DemandClass");
- MethodDefinition method = GetObjectData (type);
- Assert.IsNull (rule.CheckMethod (method, new MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Success, runner.CheckType (type));
}
[Test]
public void DemandWrongPermission ()
{
TypeDefinition type = GetTest ("DemandWrongPermissionClass");
- MethodDefinition method = GetObjectData (type);
- Assert.IsNotNull (rule.CheckMethod (method, new MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Failure, runner.CheckType (type));
}
}
}
diff --git a/gendarme/rules/Gendarme.Rules.Security/Test/StaticConstructorsShouldBePrivateTest.cs b/gendarme/rules/Gendarme.Rules.Security/Test/StaticConstructorsShouldBePrivateTest.cs
index 5ed9ccbc..4723bb83 100644
--- a/gendarme/rules/Gendarme.Rules.Security/Test/StaticConstructorsShouldBePrivateTest.cs
+++ b/gendarme/rules/Gendarme.Rules.Security/Test/StaticConstructorsShouldBePrivateTest.cs
@@ -48,8 +48,8 @@ namespace Test.Rules.Security {
public class StaticConstructorsShouldBePrivateTest {
private ITypeRule rule;
+ private TestRunner runner;
private AssemblyDefinition assembly;
- private Runner runner;
[TestFixtureSetUp]
@@ -58,7 +58,7 @@ namespace Test.Rules.Security {
string unit = System.Reflection.Assembly.GetExecutingAssembly ().Location;
assembly = AssemblyFactory.GetAssembly (unit);
rule = new StaticConstructorsShouldBePrivateRule ();
- runner = new MinimalRunner ();
+ runner = new TestRunner (rule);
}
private TypeDefinition GetTest<T> ()
@@ -69,15 +69,13 @@ namespace Test.Rules.Security {
[Test]
public void TestNoStaticCtorDefinedClass ()
{
- MessageCollection messages = rule.CheckType (GetTest<NoStaticCtorDefinedClass> (), runner);
- Assert.IsNull (messages);
+ Assert.AreEqual (RuleResult.Success, runner.CheckType (GetTest<NoStaticCtorDefinedClass> ()));
}
[Test]
public void TestPrivateStaticCtorDefinedClass ()
{
- MessageCollection messages = rule.CheckType (GetTest<PrivateStaticCtorDefinedClass> (), runner);
- Assert.IsNull (messages);
+ Assert.AreEqual (RuleResult.Success, runner.CheckType (GetTest<PrivateStaticCtorDefinedClass> ()));
}
[Test]
@@ -88,9 +86,8 @@ namespace Test.Rules.Security {
if (ctor.IsStatic)
ctor.IsPublic = true; // change it from private to public
- MessageCollection messages = rule.CheckType (inspectedType, runner);
- Assert.IsNotNull (messages);
- Assert.AreEqual (1, messages.Count);
+ Assert.AreEqual (RuleResult.Failure, runner.CheckType (inspectedType), inspectedType.FullName);
+ Assert.AreEqual (1, runner.Defects.Count, "Count");
}
}
}
diff --git a/gendarme/rules/Gendarme.Rules.Security/Test/TypeExposeFieldsTest.cs b/gendarme/rules/Gendarme.Rules.Security/Test/TypeExposeFieldsTest.cs
index 6a7bf8fe..079eac85 100644
--- a/gendarme/rules/Gendarme.Rules.Security/Test/TypeExposeFieldsTest.cs
+++ b/gendarme/rules/Gendarme.Rules.Security/Test/TypeExposeFieldsTest.cs
@@ -4,7 +4,7 @@
// Authors:
// Sebastien Pouliot <sebastien@ximian.com>
//
-// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2005,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
@@ -101,16 +101,16 @@ namespace Test.Rules.Security {
}
private ITypeRule rule;
+ private TestRunner runner;
private AssemblyDefinition assembly;
- private ModuleDefinition module;
[TestFixtureSetUp]
public void FixtureSetUp ()
{
string unit = Assembly.GetExecutingAssembly ().Location;
assembly = AssemblyFactory.GetAssembly (unit);
- module = assembly.MainModule;
rule = new TypeExposeFieldsRule ();
+ runner = new TestRunner (rule);
}
private TypeDefinition GetTest (string name)
@@ -123,42 +123,42 @@ namespace Test.Rules.Security {
public void NonPublic ()
{
TypeDefinition type = GetTest ("NonPublicClass");
- Assert.IsNull (rule.CheckType (type, new MinimalRunner ()));
+ Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type));
}
[Test]
public void NoSecurity ()
{
TypeDefinition type = GetTest ("NoSecurityClass");
- Assert.IsNull (rule.CheckType (type, new MinimalRunner ()));
+ Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type));
}
[Test]
public void NoDemand ()
{
TypeDefinition type = GetTest ("NoDemandClass");
- Assert.IsNull (rule.CheckType (type, new MinimalRunner ()));
+ Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type));
}
[Test]
public void NoPublicField ()
{
TypeDefinition type = GetTest ("NoPublicFieldClass");
- Assert.IsNull (rule.CheckType (type, new MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Success, runner.CheckType (type));
}
[Test]
public void LinkDemandWithField ()
{
TypeDefinition type = GetTest ("LinkDemandWithFieldClass");
- Assert.IsNotNull (rule.CheckType (type, new MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Failure, runner.CheckType (type));
}
[Test]
public void DemandWithField ()
{
TypeDefinition type = GetTest ("DemandWithFieldClass");
- Assert.IsNotNull (rule.CheckType (type, new MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Failure, runner.CheckType (type));
}
}
}
diff --git a/gendarme/rules/Gendarme.Rules.Security/Test/TypeIsNotSubsetOfMethodSecurityTest.cs b/gendarme/rules/Gendarme.Rules.Security/Test/TypeIsNotSubsetOfMethodSecurityTest.cs
index 9b413b9a..00730823 100644
--- a/gendarme/rules/Gendarme.Rules.Security/Test/TypeIsNotSubsetOfMethodSecurityTest.cs
+++ b/gendarme/rules/Gendarme.Rules.Security/Test/TypeIsNotSubsetOfMethodSecurityTest.cs
@@ -4,7 +4,7 @@
// Authors:
// Sebastien Pouliot <sebastien@ximian.com>
//
-// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2005,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
@@ -127,16 +127,16 @@ namespace Test.Rules.Security {
}
private ITypeRule rule;
+ private TestRunner runner;
private AssemblyDefinition assembly;
- private ModuleDefinition module;
[TestFixtureSetUp]
public void FixtureSetUp ()
{
string unit = Assembly.GetExecutingAssembly ().Location;
assembly = AssemblyFactory.GetAssembly (unit);
- module = assembly.MainModule;
rule = new TypeIsNotSubsetOfMethodSecurityRule ();
+ runner = new TestRunner (rule);
}
private TypeDefinition GetTest (string name)
@@ -149,49 +149,49 @@ namespace Test.Rules.Security {
public void NoSecurity ()
{
TypeDefinition type = GetTest ("NoSecurityClass");
- Assert.IsNull (rule.CheckType (type, new MinimalRunner ()));
+ Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type));
}
[Test]
public void LinkDemand ()
{
TypeDefinition type = GetTest ("LinkDemandClass");
- Assert.IsNull (rule.CheckType (type, new MinimalRunner ()));
+ Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type));
}
[Test]
public void InheritanceDemand ()
{
TypeDefinition type = GetTest ("InheritanceDemandClass");
- Assert.IsNull (rule.CheckType (type, new MinimalRunner ()));
+ Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type));
}
[Test]
public void AssertNotSubset ()
{
TypeDefinition type = GetTest ("AssertNotSubsetClass");
- Assert.IsNotNull (rule.CheckType (type, new MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Failure, runner.CheckType (type));
}
[Test]
public void DemandSubset ()
{
TypeDefinition type = GetTest ("DemandSubsetClass");
- Assert.IsNull (rule.CheckType (type, new MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Success, runner.CheckType (type));
}
[Test]
public void DenyNotSubset ()
{
TypeDefinition type = GetTest ("DenyNotSubsetClass");
- Assert.IsNotNull (rule.CheckType (type, new MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Failure, runner.CheckType (type));
}
[Test]
public void PermitOnlySubset ()
{
TypeDefinition type = GetTest ("PermitOnlySubsetClass");
- Assert.IsNull (rule.CheckType (type, new MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Success, runner.CheckType (type));
}
}
}
diff --git a/gendarme/rules/Gendarme.Rules.Security/Test/TypeLinkDemandTest.cs b/gendarme/rules/Gendarme.Rules.Security/Test/TypeLinkDemandTest.cs
index 1ab3ce26..de11438b 100644
--- a/gendarme/rules/Gendarme.Rules.Security/Test/TypeLinkDemandTest.cs
+++ b/gendarme/rules/Gendarme.Rules.Security/Test/TypeLinkDemandTest.cs
@@ -4,7 +4,7 @@
// Authors:
// Sebastien Pouliot <sebastien@ximian.com>
//
-// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2005,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
@@ -125,16 +125,16 @@ namespace Test.Rules.Security {
}
private ITypeRule rule;
+ private TestRunner runner;
private AssemblyDefinition assembly;
- private ModuleDefinition module;
[TestFixtureSetUp]
public void FixtureSetUp ()
{
string unit = Assembly.GetExecutingAssembly ().Location;
assembly = AssemblyFactory.GetAssembly (unit);
- module = assembly.MainModule;
rule = new TypeLinkDemandRule ();
+ runner = new TestRunner (rule);
}
private TypeDefinition GetTest (string name)
@@ -147,56 +147,56 @@ namespace Test.Rules.Security {
public void NonPublic ()
{
TypeDefinition type = GetTest ("NonPublicClass");
- Assert.IsNull (rule.CheckType (type, new MinimalRunner ()));
+ Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type));
}
[Test]
public void Sealed ()
{
TypeDefinition type = GetTest ("SealedClass");
- Assert.IsNull (rule.CheckType (type, new MinimalRunner ()));
+ Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type));
}
[Test]
public void LinkDemand ()
{
TypeDefinition type = GetTest ("LinkDemandClass");
- Assert.IsNull (rule.CheckType (type, new MinimalRunner ()));
+ Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type));
}
[Test]
public void LinkDemandVirtualMethod ()
{
TypeDefinition type = GetTest ("LinkDemandVirtualMethodClass");
- Assert.IsNotNull (rule.CheckType (type, new MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Failure, runner.CheckType (type));
}
[Test]
public void InheritanceDemand ()
{
TypeDefinition type = GetTest ("InheritanceDemandClass");
- Assert.IsNull (rule.CheckType (type, new MinimalRunner ()));
+ Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type));
}
[Test]
public void NoIntersection ()
{
TypeDefinition type = GetTest ("NoIntersectionClass");
- Assert.IsNull (rule.CheckType (type, new MinimalRunner ()));
+ Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type));
}
[Test]
public void NoIntersectionVirtualMethod ()
{
TypeDefinition type = GetTest ("NoIntersectionVirtualMethodClass");
- Assert.IsNotNull (rule.CheckType (type, new MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Failure, runner.CheckType (type));
}
[Test]
public void Intersection ()
{
TypeDefinition type = GetTest ("IntersectionClass");
- Assert.IsNull (rule.CheckType (type, new MinimalRunner ()));
+ Assert.AreEqual (RuleResult.Success, runner.CheckType (type));
}
}
}