/src/NUnit/core/TestFixtureBuilder.cs
C# | 69 lines | 35 code | 10 blank | 24 comment | 7 complexity | 4d597898eddbdc0dbc4f044bc9c6c4a6 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.Reflection; 9 10namespace NUnit.Core 11{ 12 /// <summary> 13 /// TestFixtureBuilder contains static methods for building 14 /// TestFixtures from types. It uses builtin SuiteBuilders 15 /// and any installed extensions to do it. 16 /// </summary> 17 public class TestFixtureBuilder 18 { 19 public static bool CanBuildFrom( Type type ) 20 { 21 return CoreExtensions.Host.SuiteBuilders.CanBuildFrom( type ); 22 } 23 24 /// <summary> 25 /// Build a test fixture from a given type. 26 /// </summary> 27 /// <param name="type">The type to be used for the fixture</param> 28 /// <returns>A TestSuite if the fixture can be built, null if not</returns> 29 public static Test BuildFrom( Type type ) 30 { 31 Test suite = CoreExtensions.Host.SuiteBuilders.BuildFrom( type ); 32 33 if ( suite != null ) 34 suite = CoreExtensions.Host.TestDecorators.Decorate( suite, type ); 35 36 return suite; 37 } 38 39 /// <summary> 40 /// Build a fixture from an object. 41 /// </summary> 42 /// <param name="fixture">The object to be used for the fixture</param> 43 /// <returns>A TestSuite if fixture type can be built, null if not</returns> 44 public static Test BuildFrom( object fixture ) 45 { 46 Test suite = BuildFrom( fixture.GetType() ); 47 48 if( suite != null) 49 { 50 suite.Fixture = fixture; 51 52 // TODO: Integrate building from an object as part of NUnitTestFixtureBuilder 53 if (suite.RunState == RunState.NotRunnable && 54 Reflect.GetConstructor(fixture.GetType()) == null) 55 { 56 suite.RunState = RunState.Runnable; 57 suite.IgnoreReason = null; 58 } 59 } 60 61 return suite; 62 } 63 64 /// <summary> 65 /// Private constructor to prevent instantiation 66 /// </summary> 67 private TestFixtureBuilder() { } 68 } 69}