diff options
author | Sebastien Pouliot <sebastien@ximian.com> | 2008-09-11 02:42:56 +0400 |
---|---|---|
committer | Sebastien Pouliot <sebastien@ximian.com> | 2008-09-11 02:42:56 +0400 |
commit | 4414a8db8fcb66fc1d571104eac08e7edf62d2f2 (patch) | |
tree | 38a1968c387e8e4f223bf7eb706f5fea633538ab /gendarme/rules/Gendarme.Rules.Smells/Test | |
parent | 832ef64f02dfe5d412ecfa83c6b424800c21c8fe (diff) |
2008-09-10 Sebastien Pouliot <sebastien@ximian.com>
* AvoidMessageChainsTest.cs: Re-enable some tests and add new ones
for better coverage.
* Tests.Rules.Smells.csproj: Add tests to MD project file.
svn path=/trunk/mono-tools/; revision=112717
Diffstat (limited to 'gendarme/rules/Gendarme.Rules.Smells/Test')
3 files changed, 62 insertions, 28 deletions
diff --git a/gendarme/rules/Gendarme.Rules.Smells/Test/AvoidMessageChainsTest.cs b/gendarme/rules/Gendarme.Rules.Smells/Test/AvoidMessageChainsTest.cs index 39e9caff..0e3c581f 100644 --- a/gendarme/rules/Gendarme.Rules.Smells/Test/AvoidMessageChainsTest.cs +++ b/gendarme/rules/Gendarme.Rules.Smells/Test/AvoidMessageChainsTest.cs @@ -63,35 +63,67 @@ namespace Test.Rules.Smells { [TestFixture] public class AvoidMessageChainsTest : MethodRuleTestFixture<AvoidMessageChainsRule> { - - public void MethodWithoutChain () + + [Test] + public void DoesNotApply () + { + AssertRuleDoesNotApply (SimpleMethods.ExternalMethod); + AssertRuleDoesNotApply (SimpleMethods.EmptyMethod); + } + + public void MethodWithSmallChain () { + // 1111111 2222222222222 333333333333333333333333333333333 new One ().ReturnTwo (3).ReturnThree ("Avoid chaining me"); } - public void MethodWithArgumentsWithoutChain (string s) + public void MethodWithArgumentsWithSmallChain (string s) { + // 1111111111 222222222222222 33333333333333333333333333333 Four four = new Two ().ReturnThree (s).ReturnFour (new object (), 3); + } + [Test] + public void MethodWithSmallChainTest () + { + // default is 5 so small chains (like 3) are ok + AssertRuleSuccess<AvoidMessageChainsTest> ("MethodWithSmallChain"); + AssertRuleSuccess<AvoidMessageChainsTest> ("MethodWithArgumentsWithSmallChain"); } [Test] - public void MethodWithoutChainTest () + public void MethodWithSmallChainLowerLimitTest () { - AssertRuleSuccess<AvoidMessageChainsTest> ("MethodWithoutChain"); - AssertRuleSuccess<AvoidMessageChainsTest> ("MethodWithArgumentsWithoutChain"); + int chain = Rule.MaxChainLength; + try { + // unless we lower the limit + Rule.MaxChainLength = 3; + AssertRuleFailure<AvoidMessageChainsTest> ("MethodWithSmallChain", 1); + AssertRuleFailure<AvoidMessageChainsTest> ("MethodWithArgumentsWithSmallChain", 1); + } + finally { + Rule.MaxChainLength = 5; + } } public void MethodWithChain () { object obj = new object (); + // 1111111 2222222222222 333333333333333333333333333333 4444444444444444444 55555555555555 666666666666 777777777777777 new One ().ReturnTwo (3).ReturnThree ("Ha ha! Chained").ReturnFour (obj, 5).ReturnFive (3).ReturnSix ().ReturnOne ('a'); } + public void MethodWithChain_Array () + { + // 11111111111111 222222222222 33333333 44444444444 5555555555555555555 6666666 + Console.WriteLine (new byte [5].Clone ().ToString ().ToUpperInvariant ().Trim ()); + } + [Test] public void MethodWithChainTest () { AssertRuleFailure<AvoidMessageChainsTest> ("MethodWithChain", 1); + AssertRuleFailure<AvoidMessageChainsTest> ("MethodWithChain_Array", 1); } public void MethodWithVariousChains () @@ -110,6 +142,7 @@ namespace Test.Rules.Smells { public void MethodWithArgumentsChained (int x, float f) { + //11111111 2222222222222 333333333333333333333333333333 44444444444444444444444444444 55555555555555 666666666666 777777777777777 new One ().ReturnTwo (x).ReturnThree ("Ha ha! Chained").ReturnFour (new object (), x).ReturnFive (f).ReturnSix ().ReturnOne ('a'); } @@ -119,31 +152,13 @@ namespace Test.Rules.Smells { AssertRuleFailure<AvoidMessageChainsTest> ("MethodWithArgumentsChained", 1); } - [Test] - [Ignore ("Still not working.")] - public void CanonicalScenariosTest () - { - AssertRuleDoesNotApply (SimpleMethods.ExternalMethod); - - //When a method is empty, it returns a ret instruction - //I wonder if this means some compiler optimization or - //anything else - AssertRuleDoesNotApply (SimpleMethods.EmptyMethod); - } - - public void ChainWithTemporaryVariables () + public void SmallChainWithTemporaryVariables () { + // 11111111111111111111111111111111 2222222222 3333333 Version version = Assembly.GetExecutingAssembly ().GetName ().Version; int major = version.Major; } - [Test] - [Ignore ("Uncaught")] - public void ChainWithTemporaryVariablesTest () - { - AssertRuleFailure<AvoidMessageChainsTest> ("ChainWithTemporaryVariables", 1); - } - public void NoChainWithTemporaryVariables () { int x; @@ -152,10 +167,22 @@ namespace Test.Rules.Smells { } [Test] - [Ignore ("Uncaught")] - public void NoChainWithTemporaryVariablesTEst () + public void NoChainWithTemporaryVariablesTest () { + AssertRuleSuccess<AvoidMessageChainsTest> ("SmallChainWithTemporaryVariables"); AssertRuleSuccess<AvoidMessageChainsTest> ("NoChainWithTemporaryVariables"); } + + public bool Compare (int x, long y) + { + // 11111111111 2222222222222222222 3333333 11111111111 2222222 3333333333333333333 + return (x.ToString ().ToUpperInvariant ().Trim () == y.ToString ().Trim ().ToLowerInvariant ()); + } + + [Test] + public void CompareTest () + { + AssertRuleSuccess<AvoidMessageChainsTest> ("Compare"); + } } } diff --git a/gendarme/rules/Gendarme.Rules.Smells/Test/ChangeLog b/gendarme/rules/Gendarme.Rules.Smells/Test/ChangeLog index 312a1b1a..d9dd7a6a 100644 --- a/gendarme/rules/Gendarme.Rules.Smells/Test/ChangeLog +++ b/gendarme/rules/Gendarme.Rules.Smells/Test/ChangeLog @@ -1,3 +1,9 @@ +2008-09-10 Sebastien Pouliot <sebastien@ximian.com> + + * AvoidMessageChainsTest.cs: Re-enable some tests and add new ones + for better coverage. + * Tests.Rules.Smells.csproj: Add tests to MD project file. + 2008-08-14 Sebastien Pouliot <sebastien@ximian.com> * AvoidSpeculativeGeneralityTest.cs: Update unit tests to the new diff --git a/gendarme/rules/Gendarme.Rules.Smells/Test/Test.Rules.Smells.mdp b/gendarme/rules/Gendarme.Rules.Smells/Test/Test.Rules.Smells.mdp index e5ec4299..266d32c6 100644 --- a/gendarme/rules/Gendarme.Rules.Smells/Test/Test.Rules.Smells.mdp +++ b/gendarme/rules/Gendarme.Rules.Smells/Test/Test.Rules.Smells.mdp @@ -21,6 +21,7 @@ <File name="AvoidLongParameterListsTest.cs" subtype="Code" buildaction="Compile" /> <File name="AvoidSpeculativeGeneralityTest.cs" subtype="Code" buildaction="Compile" /> <File name="ChangeLog" subtype="Code" buildaction="Nothing" /> + <File name="AvoidMessageChainsTest.cs" subtype="Code" buildaction="Compile" /> </Contents> <References> <ProjectReference type="Project" localcopy="True" refto="framework" /> |