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:
authorNéstor Salceda <nestor@mono-cvs.ximian.com>2008-12-22 23:11:17 +0300
committerNéstor Salceda <nestor@mono-cvs.ximian.com>2008-12-22 23:11:17 +0300
commitb0b83a0ccd20969b1eeab9be53bd6e5de78999b7 (patch)
treecba98dbe024a86483597b93e20c02f9900ee4768 /gendarme/rules/Gendarme.Rules.Smells/Test
parent563ddb3ae18e4ae3edc6f9918cfc4a97b3598b5c (diff)
2008-12-22 Néstor Salceda <nestor.salceda@gmail.com>
* AvoidSwitchStatementsTest.cs: New. Unit tests for AvoidSwitchStatementsRule. svn path=/trunk/mono-tools/; revision=122000
Diffstat (limited to 'gendarme/rules/Gendarme.Rules.Smells/Test')
-rw-r--r--gendarme/rules/Gendarme.Rules.Smells/Test/AvoidSwitchStatementsTest.cs98
-rw-r--r--gendarme/rules/Gendarme.Rules.Smells/Test/ChangeLog5
2 files changed, 103 insertions, 0 deletions
diff --git a/gendarme/rules/Gendarme.Rules.Smells/Test/AvoidSwitchStatementsTest.cs b/gendarme/rules/Gendarme.Rules.Smells/Test/AvoidSwitchStatementsTest.cs
new file mode 100644
index 00000000..e8660ac5
--- /dev/null
+++ b/gendarme/rules/Gendarme.Rules.Smells/Test/AvoidSwitchStatementsTest.cs
@@ -0,0 +1,98 @@
+// Unit Test for AvoidSwitchStatements Rule.
+//
+// Authors:
+// Néstor Salceda <nestor.salceda@gmail.com>
+//
+// (C) 2008 Néstor Salceda
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Collections.Generic;
+
+using Test.Rules.Fixtures;
+using Test.Rules.Definitions;
+using Test.Rules.Helpers;
+
+using Gendarme.Framework;
+using Gendarme.Rules.Smells;
+
+using NUnit.Framework;
+
+namespace Test.Rules.Smells {
+ [TestFixture]
+ public class AvoidSwitchStatementsTest : MethodRuleTestFixture<AvoidSwitchStatementsRule> {
+
+ [Test]
+ public void SkipOnBodylessMethodsTest ()
+ {
+ AssertRuleDoesNotApply (SimpleMethods.ExternalMethod);
+ }
+
+ [Test]
+ public void SuccessOnEmptyMethodsTest ()
+ {
+ AssertRuleSuccess (SimpleMethods.EmptyMethod);
+ }
+
+ void MethodWithSwitch (Severity severity)
+ {
+ switch (severity) {
+ case Severity.High:
+ case Severity.Low:
+ default:
+ break;
+ }
+ }
+
+ [Test]
+ public void FailOnMethodWithSwitchTest ()
+ {
+ AssertRuleFailure <AvoidSwitchStatementsTest> ("MethodWithSwitch", 1);
+ }
+
+ void MethodWithoutSwitch (Severity severity)
+ {
+ if (severity == Severity.High || severity == Severity.Low)
+ return;
+ }
+
+ [Test]
+ public void SuccessOnMethodWithoutSwitch ()
+ {
+ AssertRuleSuccess <AvoidSwitchStatementsTest> ("MethodWithoutSwitch");
+ }
+
+ IEnumerable<string> MethodWithoutSwitchAndGenerator (IEnumerable<string> enumerable)
+ {
+ foreach (string value in enumerable)
+ yield return value;
+
+ yield return null;
+ }
+
+ [Test]
+ public void SuccessOnMethodWithoutSwitchAndGeneratorTest ()
+ {
+ AssertRuleDoesNotApply (Type.GetType ("Test.Rules.Smells.AvoidSwitchStatementsTest+<MethodWithoutSwitchAndGenerator>c__Iterator0"), "MoveNext");
+ }
+ }
+}
diff --git a/gendarme/rules/Gendarme.Rules.Smells/Test/ChangeLog b/gendarme/rules/Gendarme.Rules.Smells/Test/ChangeLog
index 88cc314d..8d8c89e6 100644
--- a/gendarme/rules/Gendarme.Rules.Smells/Test/ChangeLog
+++ b/gendarme/rules/Gendarme.Rules.Smells/Test/ChangeLog
@@ -1,3 +1,8 @@
+2008-12-22 Néstor Salceda <nestor.salceda@gmail.com>
+
+ * AvoidSwitchStatementsTest.cs: New. Unit tests for
+ AvoidSwitchStatementsRule.
+
2008-12-17 Sebastien Pouliot <sebastien@ximian.com>
* AvoidCodeDuplicatedInSameClassTest.cs: Fix a test case so it