/src/NUnit/core/SetUpFixture.cs
C# | 54 lines | 35 code | 6 blank | 13 comment | 3 complexity | baa7a901abcaa3ffc95de5aa5e92192b MD5 | raw file
1// **************************************************************** 2// This is free software licensed under the NUnit license. You 3// may obtain a copy of the license as well as information regarding 4// copyright ownership at http://nunit.org. 5// **************************************************************** 6 7using System; 8using System.IO; 9using System.Reflection; 10 11namespace NUnit.Core 12{ 13 /// <summary> 14 /// SetUpFixture extends TestSuite and supports 15 /// Setup and TearDown methods. 16 /// </summary> 17 public class SetUpFixture : TestSuite 18 { 19 #region Constructor 20 public SetUpFixture( Type type ) : base( type ) 21 { 22 this.TestName.Name = type.Namespace; 23 if (this.TestName.Name == null) 24 this.TestName.Name = "[default namespace]"; 25 int index = TestName.Name.LastIndexOf('.'); 26 if (index > 0) 27 this.TestName.Name = this.TestName.Name.Substring(index + 1); 28 29 this.fixtureSetUpMethods = Reflect.GetMethodsWithAttribute( type, NUnitFramework.SetUpAttribute, true ); 30 this.fixtureTearDownMethods = Reflect.GetMethodsWithAttribute( type, NUnitFramework.TearDownAttribute, true ); 31 } 32 #endregion 33 34 #region TestSuite Overrides 35 36 /// <summary> 37 /// Gets a string representing the kind of test 38 /// that this object represents, for use in display. 39 /// </summary> 40 public override string TestType 41 { 42 get { return "SetUpFixture"; } 43 } 44 45 public override TestResult Run(EventListener listener, ITestFilter filter) 46 { 47 using ( new DirectorySwapper( AssemblyHelper.GetDirectoryName( FixtureType.Assembly ) ) ) 48 { 49 return base.Run(listener, filter); 50 } 51 } 52 #endregion 53 } 54}