~adam-rpconnelly/nunit-3.0/bug-483845

« back to all changes in this revision

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

  • Committer: Charlie Poole
  • Date: 2010-01-08 17:21:03 UTC
  • Revision ID: charlie@nunit.com-20100108172103-o065jps8sbft4hhq
Further simplification of API and internals: Removing TestInfo and NUnitFramework classes, eliminating all references to the framework from the test runner and using xml to communicate results back to the runner.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
// ***********************************************************************
23
23
 
24
24
using System;
 
25
using System.Reflection;
25
26
using NUnit.Framework.Api;
26
27
 
27
28
namespace NUnit.Framework.Internal
33
34
        public class TestFixture : TestSuite
34
35
        {
35
36
                #region Constructors
 
37
        /// <summary>
 
38
        /// Initializes a new instance of the <see cref="TestFixture"/> class.
 
39
        /// </summary>
 
40
        /// <param name="fixtureType">Type of the fixture.</param>
36
41
        public TestFixture(Type fixtureType)
37
42
            : this(fixtureType, null) { }
38
43
 
 
44
        /// <summary>
 
45
        /// Initializes a new instance of the <see cref="TestFixture"/> class.
 
46
        /// </summary>
 
47
        /// <param name="fixtureType">Type of the fixture.</param>
 
48
        /// <param name="arguments">The arguments.</param>
39
49
        public TestFixture(Type fixtureType, object[] arguments)
40
50
            : base(fixtureType, arguments) 
41
51
        {
42
 
            this.fixtureSetUpMethods =
43
 
                Reflect.GetMethodsWithAttribute(fixtureType, typeof(TestFixtureSetUpAttribute), true);
44
 
            this.fixtureTearDownMethods =
45
 
                Reflect.GetMethodsWithAttribute(fixtureType, typeof(TestFixtureTearDownAttribute), true);
46
 
            this.setUpMethods =
47
 
                Reflect.GetMethodsWithAttribute(this.FixtureType, typeof(SetUpAttribute), true);
48
 
            this.tearDownMethods =
49
 
                Reflect.GetMethodsWithAttribute(this.FixtureType, typeof(TearDownAttribute), true);
 
52
            this.fixtureSetUpMethods =      GetSetUpTearDownMethods( typeof(TestFixtureSetUpAttribute) );
 
53
            this.fixtureTearDownMethods =   GetSetUpTearDownMethods( typeof( TestFixtureTearDownAttribute) );
 
54
            this.setUpMethods =             GetSetUpTearDownMethods( typeof(SetUpAttribute) );
 
55
            this.tearDownMethods =          GetSetUpTearDownMethods( typeof(TearDownAttribute) );
 
56
        }
 
57
 
 
58
        private MethodInfo[] GetSetUpTearDownMethods(Type attrType)
 
59
        {
 
60
            MethodInfo[] methods = Reflect.GetMethodsWithAttribute(FixtureType, attrType, true);
 
61
 
 
62
            foreach ( MethodInfo method in methods )
 
63
                if ( method.IsAbstract ||
 
64
                     !method.IsPublic && !method.IsFamily ||
 
65
                     method.GetParameters().Length > 0 ||
 
66
                     !method.ReturnType.Equals(typeof(void)))
 
67
                {
 
68
                    this.IgnoreReason = string.Format("Invalid signature for SetUp or TearDown method: {0}", method.Name);
 
69
                    this.RunState = RunState.NotRunnable;
 
70
                    break;
 
71
                }
 
72
 
 
73
            return methods;
50
74
        }
51
75
        #endregion
52
76
 
53
77
                #region TestSuite Overrides
 
78
 
 
79
        /// <summary>
 
80
        /// Runs the suite under a particular filter, sending
 
81
        /// notifications to a listener.
 
82
        /// </summary>
 
83
        /// <param name="listener">An event listener to receive notifications</param>
 
84
        /// <param name="filter">A filter used in running the test</param>
 
85
        /// <returns></returns>
54
86
        public override TestResult Run(ITestListener listener, TestFilter filter)
55
87
        {
56
88
            using ( new DirectorySwapper( AssemblyHelper.GetDirectoryName( FixtureType.Assembly ) ) )
59
91
            }
60
92
        }
61
93
 
 
94
        /// <summary>
 
95
        /// Does the one time set up.
 
96
        /// </summary>
 
97
        /// <param name="suiteResult">The suite result.</param>
62
98
        protected override void DoOneTimeSetUp(TestResult suiteResult)
63
99
        {
64
100
            base.DoOneTimeSetUp(suiteResult);
66
102
            suiteResult.AssertCount = Assert.Counter; ;
67
103
        }
68
104
 
 
105
        /// <summary>
 
106
        /// Does the one time tear down.
 
107
        /// </summary>
 
108
        /// <param name="suiteResult">The suite result.</param>
69
109
        protected override void DoOneTimeTearDown(TestResult suiteResult)
70
110
        {
71
111
            base.DoOneTimeTearDown(suiteResult);