Beispiel #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);
            }
        }
        protected override void RunFixtures()
        {
            // setup result
            foreach (FixtureVertex v in this.FixtureGraph.Graph.Vertices)
            {
                v.Result = ReportRunResult.NotRun;
            }

            // topological sort
            TopologicalSortAlgorithm topo = new TopologicalSortAlgorithm(this.FixtureGraph.Graph);
            ArrayList list = new ArrayList();

            topo.Compute(list);

            // execute pipes
            foreach (FixtureVertex v in list)
            {
                // result failed
                if (v.Result != ReportRunResult.NotRun)
                {
                    ReportMonitor monitor           = new ReportMonitor();
                    ParentFixtureFailedException ex = new ParentFixtureFailedException();
                    foreach (Fixture fixture in v.Fixtures)
                    {
                        if (!this.FilterFixture(fixture))
                        {
                            continue;
                        }
                        this.SkipStarters(fixture, ex);
                    }
                }
                else
                {
                    // run fixtures
                    v.Result = ReportRunResult.Success;
                    foreach (Fixture fixture in v.Fixtures)
                    {
                        if (!this.FilterFixture(fixture))
                        {
                            continue;
                        }
                        ReportRunResult result = RunFixture(fixture);
                        if (result != ReportRunResult.Success && v.Result != ReportRunResult.Failure)
                        {
                            v.Result = result;
                        }
                    }
                }

                // update children if failed
                if (v.Result != ReportRunResult.Success)
                {
                    foreach (FixtureVertex target in this.FixtureGraph.Graph.AdjacentVertices(v))
                    {
                        target.Result = v.Result;
                    }
                }
            }
        }
Beispiel #3
0
        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;
                }
            }
        }
Beispiel #4
0
 public ReportSetUpAndTearDown(string name, ReportMonitor monitor)
 {
     this.Name         = name;
     this.ConsoleOut   = monitor.Consoler.Out;
     this.ConsoleError = monitor.Consoler.Error;
     this.Duration     = monitor.Timer.Duration;
     this.Memory       = monitor.Memorizer.Usage;
     this.Result       = ReportRunResult.Success;
 }
Beispiel #5
0
        public void Fail(ReportMonitor monitor, Exception ex)
        {
            if (monitor == null)
            {
                throw new ArgumentNullException("monitor");
            }
            if (ex == null)
            {
                throw new ArgumentNullException("ex");
            }

            this.Start();
            this.result = ReportRun.Failure(this.Pipe, monitor, ex);
            this.Failure();
        }
Beispiel #6
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);
            }
        }
Beispiel #7
0
        public static ReportRun Ignore(RunPipe pipe, ReportMonitor monitor)
        {
            ReportRun run = new ReportRun();

            run.ConsoleOut   = monitor.Consoler.Out;
            run.ConsoleError = monitor.Consoler.Error;
            run.Result       = ReportRunResult.Ignore;
            run.Name         = pipe.Name;
            run.AssertCount  = MbUnit.Framework.Assert.AssertCount;
            run.Duration     = monitor.Timer.Duration;
            run.Memory       = monitor.Memorizer.Usage;

            MbUnit.Framework.Assert.FlushWarnings(run);

            return(run);
        }
Beispiel #8
0
        protected virtual void FailStarters(
            Fixture fixture,
            ReportMonitor monitor,
            Exception ex)
        {
            if (monitor == null)
            {
                throw new ArgumentNullException("monitor");
            }
            if (ex == null)
            {
                throw new ArgumentNullException("ex");
            }

            foreach (RunPipeStarter starter in fixture.Starters)
            {
                starter.Fail(monitor, ex);
                OnRunResult(new ReportRunEventArgs(starter.Result));
            }
        }
Beispiel #9
0
        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);
            }
        }
Beispiel #10
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));
            }
        }
Beispiel #11
0
 public ReportSetUpAndTearDown(string name, ReportMonitor monitor, Exception ex)
     : this(name, monitor)
 {
     this.Result    = ReportRunResult.Failure;
     this.Exception = ReportException.FromException(ex);
 }