private static ReportSetUpAndTearDown ExecuteAndMonitor(MethodInfo method) { if (method == null) { throw new ArgumentNullException("method"); } string name = String.Format("{0}.{1}", method.DeclaringType.FullName, method.Name); ReportMonitor monitor = new ReportMonitor(); try { monitor.Start(); method.Invoke(null, null); monitor.Stop(); ReportSetUpAndTearDown setup = new ReportSetUpAndTearDown(name, monitor); return(setup); } catch (Exception ex) { monitor.Stop(); ReportSetUpAndTearDown setup = new ReportSetUpAndTearDown(name, monitor, ex); return(setup); } }
protected virtual object RunFixtureSetUp(Fixture fixture, object fixtureInstance) { if (fixture == null) { throw new ArgumentNullException("fixture"); } ReportMonitor monitor = new ReportMonitor(); try { if (fixture.HasSetUp) { monitor.Start(); fixture.SetUp(fixtureInstance); monitor.Stop(); ReportSetUpAndTearDown setup = new ReportSetUpAndTearDown("TestFixtureSetUp", monitor); if (this.Report != null) { this.Report.TestFixtureSetUp(fixture, setup); } this.OnTestFixtureSetUp(new ReportSetUpAndTearDownEventArgs(setup)); } return(fixtureInstance); } catch (Exception ex) { monitor.Stop(); if (fixture.HasSetUp) { ReportSetUpAndTearDown setup = new ReportSetUpAndTearDown("TestFixtureSetUp", monitor, ex); if (this.Report != null) { this.Report.TestFixtureSetUp(fixture, setup); } this.OnTestFixtureSetUp(new ReportSetUpAndTearDownEventArgs(setup)); } // fail all starters FixtureSetUpFailedException setUpEx = new FixtureSetUpFailedException(ex); FailStarters(fixture, monitor, setUpEx); // add error message return(null); } }
protected virtual ReportRunResult RunFixture(Fixture fixture) { if (this.IsAbortPending) { return(ReportRunResult.Failure); } FixtureRunnerStarter fixtureStarter = new FixtureRunnerStarter(this, fixture); Thread thread = null; try { thread = new Thread(new ThreadStart(fixtureStarter.Start)); if (fixture.ApartmentState != ApartmentState.Unknown) { thread.ApartmentState = fixture.ApartmentState; } thread.Start(); // execute and watch for time outs if (!thread.Join(fixture.TimeOut)) { this.Abort(); Thread.Sleep(1000); if (thread.ThreadState != ThreadState.Stopped) { thread.Abort(); } ReportMonitor monitor = new ReportMonitor(); monitor.Start(); monitor.Stop(); FixtureTimedOutException ex = new FixtureTimedOutException(); foreach (RunPipeStarter starter in fixture.Starters) { starter.Fail(monitor, ex); OnRunResult(new ReportRunEventArgs(starter.Result)); } thread = null; return(ReportRunResult.Failure); } thread = null; // check if something occured duregin execution if (fixtureStarter.ThrowedException != null) { throw new FixtureExecutionException(fixture.Name, fixtureStarter.ThrowedException); } return(fixtureStarter.Result); } finally { if (thread != null) { thread.Abort(); thread = null; } } }
protected virtual void RunFixtureTearDown(Fixture fixture, object fixtureInstance) { if (fixture == null) { throw new ArgumentNullException("fixture"); } ReportMonitor monitor = new ReportMonitor(); try { monitor.Start(); fixture.TearDown(fixtureInstance); monitor.Stop(); if (fixture.HasTearDown) { ReportSetUpAndTearDown tearDown = new ReportSetUpAndTearDown("TestFixtureTearDown", monitor); if (this.Report != null) { this.Report.TestFixtureTearDown(fixture, tearDown); } this.OnTestFixtureTearDown(new ReportSetUpAndTearDownEventArgs(tearDown)); } } catch (Exception ex) { monitor.Stop(); ReportSetUpAndTearDown tearDown = new ReportSetUpAndTearDown( "TestFixtureTearDown", monitor, ex); if (this.Report != null) { this.Report.TestFixtureTearDown(fixture, tearDown); } this.OnTestFixtureTearDown(new ReportSetUpAndTearDownEventArgs(tearDown)); } }
protected virtual Object CreateFixtureInstance(Fixture fixture) { if (fixture == null) { throw new ArgumentNullException("fixture"); } ReportMonitor monitor = new ReportMonitor(); monitor.Start(); try { Object fix = fixture.CreateInstance(); return(fix); } catch (Exception ex) { monitor.Stop(); FixtureConstructorFailedException cex = new FixtureConstructorFailedException(fixture, ex); FailStarters(fixture, monitor, ex); return(null); } }