~a-schlapsi/nunit-3.0/linux-makefile

« back to all changes in this revision

Viewing changes to src/framework/Internal/SetUpFixture.cs

  • Committer: Andreas Schlapsi
  • Date: 2010-01-23 23:14:05 UTC
  • mfrom: (18.1.137 work)
  • Revision ID: a.schlapsi@gmx.at-20100123231405-17deqoh18nfnbq1j
Merged with trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
using System;
25
25
using System.IO;
26
26
using System.Reflection;
 
27
using NUnit.Framework.Api;
27
28
 
28
 
namespace NUnit.Core
 
29
namespace NUnit.Framework.Internal
29
30
{
30
31
        /// <summary>
31
32
        /// SetUpFixture extends TestSuite and supports
34
35
        public class SetUpFixture : TestSuite
35
36
        {
36
37
                #region Constructor
 
38
 
 
39
        /// <summary>
 
40
        /// Initializes a new instance of the <see cref="SetUpFixture"/> class.
 
41
        /// </summary>
 
42
        /// <param name="type">The type.</param>
37
43
                public SetUpFixture( Type type ) : base( type )
38
44
                {
39
 
            this.TestName.Name = type.Namespace;
40
 
            if (this.TestName.Name == null)
41
 
                this.TestName.Name = "[default namespace]";
42
 
            int index = TestName.Name.LastIndexOf('.');
 
45
            this.Name = type.Namespace;
 
46
            if (this.Name == null)
 
47
                this.Name = "[default namespace]";
 
48
            int index = this.Name.LastIndexOf('.');
43
49
            if (index > 0)
44
 
                this.TestName.Name = this.TestName.Name.Substring(index + 1);
 
50
                this.Name = this.Name.Substring(index + 1);
45
51
            
46
 
                        this.fixtureSetUpMethods = Reflect.GetMethodsWithAttribute( type, typeof(NUnit.Framework.SetUpAttribute), true );
47
 
                        this.fixtureTearDownMethods = Reflect.GetMethodsWithAttribute( type, typeof(NUnit.Framework.TearDownAttribute), true );
 
52
                        this.fixtureSetUpMethods = GetSetUpTearDownMethods( typeof(NUnit.Framework.SetUpAttribute) );
 
53
                        this.fixtureTearDownMethods = GetSetUpTearDownMethods( typeof(NUnit.Framework.TearDownAttribute) );
48
54
                }
49
 
                #endregion
 
55
 
 
56
        private MethodInfo[] GetSetUpTearDownMethods(Type attrType)
 
57
        {
 
58
            MethodInfo[] methods = Reflect.GetMethodsWithAttribute(FixtureType, attrType, true);
 
59
 
 
60
            foreach (MethodInfo method in methods)
 
61
                if (method.IsAbstract ||
 
62
                     !method.IsPublic && !method.IsFamily ||
 
63
                     method.GetParameters().Length > 0 ||
 
64
                     !method.ReturnType.Equals(typeof(void)))
 
65
                {
 
66
                    this.IgnoreReason = string.Format("Invalid signature for SetUp or TearDown method: {0}", method.Name);
 
67
                    this.RunState = RunState.NotRunnable;
 
68
                    break;
 
69
                }
 
70
 
 
71
            return methods;
 
72
        }
 
73
        #endregion
50
74
 
51
75
                #region TestSuite Overrides
52
 
                public override TestResult Run(ITestListener listener, TestFilter filter)
 
76
        /// <summary>
 
77
        /// Runs the suite under a particular filter, sending
 
78
        /// notifications to a listener.
 
79
        /// </summary>
 
80
        /// <param name="listener">An event listener to receive notifications</param>
 
81
        /// <param name="filter">A filter used in running the test</param>
 
82
        /// <returns></returns>
 
83
                public override TestResult Run(ITestListener listener)
53
84
                {
54
85
                        using ( new DirectorySwapper( AssemblyHelper.GetDirectoryName( FixtureType.Assembly ) ) )
55
86
                        {
56
 
                                return base.Run(listener, filter);
 
87
                                return base.Run(listener);
57
88
                        }
58
89
                }
59
90
                #endregion