/// <summary> /// Build a fixture from an object. /// </summary> /// <param name="fixture">The object to be used for the fixture</param> /// <returns>A TestSuite if fixture type can be built, null if not</returns> public static Test BuildFrom(object fixture) { Test suite = BuildFrom(fixture.GetType()); if (suite != null) { suite.Fixture = fixture; // TODO: Integrate building from an object as part of NUnitTestFixtureBuilder if (suite.RunState == RunState.NotRunnable && Reflect.GetConstructor(fixture.GetType()) == null) { suite.RunState = RunState.Runnable; suite.IgnoreReason = null; } } return(suite); }
// TODO: Only used in tests public object BuildTestFixture(Type fixtureType) { Reflect.CheckFixtureType(fixtureType); object testFixture; ConstructorInfo ctor = Reflect.GetConstructor(fixtureType); try { testFixture = ctor.Invoke(Type.EmptyTypes); } catch (Exception ex) { throw new InvalidTestFixtureException(ctor.Name + " threw a exception", ex); } if (testFixture == null) { throw new InvalidTestFixtureException(ctor.Name + " cannot be invoked"); } return(testFixture); }