PageRenderTime 41ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/src/NUnit/core/TestFixtureBuilder.cs

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