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/?p=license&r=2.4.
5 // ****************************************************************
8 using System
.Reflection
;
13 /// TestFixtureBuilder contains static methods for building
14 /// TestFixtures from types. It uses builtin SuiteBuilders
15 /// and any installed extensions to do it.
17 public class TestFixtureBuilder
19 public static bool CanBuildFrom( Type type
)
21 return CoreExtensions
.Host
.SuiteBuilders
.CanBuildFrom( type
);
25 /// Build a test fixture from a given type.
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
)
31 Test suite
= CoreExtensions
.Host
.SuiteBuilders
.BuildFrom( type
);
34 suite
= CoreExtensions
.Host
.TestDecorators
.Decorate( suite
, type
);
40 /// Build a fixture from an object.
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
)
46 Test suite
= BuildFrom( fixture
.GetType() );
48 suite
.Fixture
= fixture
;
52 public static string GetAssemblyPath( Type fixtureType
)
54 return GetAssemblyPath( fixtureType
.Assembly
);
57 // TODO: This logic should be in shared source
58 public static string GetAssemblyPath( Assembly assembly
)
60 string path
= assembly
.CodeBase
;
61 Uri uri
= new Uri( path
);
63 // If it wasn't loaded locally, use the Location
65 return assembly
.Location
;
68 return path
.Substring( Uri
.UriSchemeFile
.Length
+1 );
71 int start
= Uri
.UriSchemeFile
.Length
+ Uri
.SchemeDelimiter
.Length
;
73 if ( path
[start
] == '/' && path
[start
+2] == ':' )
76 return path
.Substring( start
);
80 /// Private constructor to prevent instantiation
82 private TestFixtureBuilder() { }