Пример #1
0
        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);
            }
        }
Пример #2
0
        void RenderSetUpOrTearDownFailure(string context, ReportSetUpAndTearDown setup)
        {
            TestResult summary = new TestResult();

            switch (setup.Result)
            {
            case ReportRunResult.Failure:
                summary.State = TDF.TestState.Failed;
                break;

            case ReportRunResult.Success:
                summary.State = TDF.TestState.Passed;
                break;
            }

            summary.TotalTests = this.testCount;
            summary.Name       = String.Format("{0} {1}", context, setup.Name);
            summary.TimeSpan   = new TimeSpan(0, 0, 0, 0, (int)(setup.Duration * 1000));
            if (setup.Exception != null)
            {
                summary.Message = setup.Exception.Message;

                StringWriter    sw = new StringWriter();
                ReportException ex = setup.Exception;
                summary.StackTrace = ex.ToString();
            }

            this.testListener.TestFinished(summary);
        }
Пример #3
0
        protected virtual bool RunAssemblyTearDown()
        {
            if (!this.explorer.HasAssemblyTearDown)
            {
                return(true);
            }

            ReportSetUpAndTearDown tearDown = this.explorer.AssemblyTearDown();

            this.report.AssemblyTearDown(this.Explorer.Assembly, tearDown);
            this.OnAssemblyTearDown(new ReportSetUpAndTearDownEventArgs(tearDown));

            return(tearDown.Result == ReportRunResult.Success);
        }
Пример #4
0
        protected virtual bool RunAssemblySetUp()
        {
            if (!this.Explorer.HasAssemblySetUp)
            {
                return(true);
            }

            ReportSetUpAndTearDown setup = this.Explorer.AssemblySetUp();

            this.report.AssemblySetUp(this.Explorer.Assembly, setup);
            this.OnAssemblySetUp(new ReportSetUpAndTearDownEventArgs(setup));

            return(setup.Result == ReportRunResult.Success);
        }
Пример #5
0
        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);
            }
        }
Пример #6
0
        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));
            }
        }