Merge branch 'master' into config-checks-ipv6
[mono.git] / mcs / nunit24 / NUnitExtensions / core / RepeatedTestDecorator.cs
1 // ****************************************************************\r
2 // Copyright 2007, Charlie Poole\r
3 // This is free software licensed under the NUnit license. You may\r
4 // obtain a copy of the license at http://nunit.org/?p=license&r=2.4\r
5 // ****************************************************************\r
6 using System;\r
7 using System.Reflection;\r
8 using NUnit.Core.Extensibility;\r
9 \r
10 namespace NUnit.Core.Extensions\r
11 {\r
12         /// <summary>\r
13         /// Summary description for RepeatedTestDecorator.\r
14         /// </summary>\r
15         [NUnitAddin(Description="Runs a test case multiple times")]\r
16         public class RepeatedTestDecorator : ITestDecorator, IAddin\r
17         {\r
18                 private static readonly string RepeatAttributeType = "NUnit.Framework.Extensions.RepeatAttribute";\r
19 \r
20                 #region IAddin Members\r
21                 public bool Install(IExtensionHost host)\r
22                 {\r
23                         IExtensionPoint decorators = host.GetExtensionPoint( "TestDecorators" );\r
24                         if ( decorators == null )\r
25                                 return false;\r
26                                 \r
27                         decorators.Install( this );\r
28                         return true;\r
29                 }\r
30                 #endregion\r
31 \r
32                 #region ITestDecorator Members\r
33                 public Test Decorate(Test test, MemberInfo member)\r
34                 {\r
35                         if ( member == null )\r
36                                 return test;\r
37 \r
38                         TestCase testCase = test as TestCase;\r
39                         if ( testCase == null )\r
40                                 return test;\r
41 \r
42                         Attribute repeatAttr = Reflect.GetAttribute( member, RepeatAttributeType, true );\r
43                         if ( repeatAttr == null )\r
44                                 return test;            \r
45 \r
46                         object propVal = Reflect.GetPropertyValue( repeatAttr, "Count", \r
47                                 BindingFlags.Public | BindingFlags.Instance );\r
48 \r
49                         if ( propVal == null )\r
50                                 return test;\r
51 \r
52                         int count = (int)propVal;\r
53 \r
54                         return new RepeatedTestCase( testCase, count );\r
55                 }\r
56 \r
57 //              public Test Decorate( Test test, Type fixtureType )\r
58 //              {\r
59 //                      return test;\r
60 //              }\r
61                 #endregion\r
62         }\r
63 }\r