private void RunTearDown()
            {
                TestResult result = null;

                System.Runtime.CompilerServices.RuntimeHelpers.PrepareConstrainedRegions();
                try
                {
                    if (this.Owner.Fixture.TearDown == null)
                    {
                        return;
                    }

                    result = new TestResult(this.Owner.Fixture.Name, this.Owner.Fixture.TearDown);
                    result.Start();
                    this.Owner.Fixture.TearDown.Invoke(this.fixtureInstance, null);
                    result.Success();
                }
                catch (Exception ex)
                {
                    if (result != null)
                    {
                        Exception current = ex;
                        if (current is TargetInvocationException)
                        {
                            current = ex.InnerException;
                        }
                        result.Fail(current);
                        this.Owner.TestListener.TearDown(result);
                    }
                }
            }
            private void RunTest(ITestCase test)
            {
                TestResult result = new TestResult(test);

                System.Runtime.CompilerServices.RuntimeHelpers.PrepareConstrainedRegions();
                try
                {
                    result.Start();
                    test.Run(this.fixtureInstance);
                    result.Success();
                }
                catch (Exception ex)
                {
                    Exception current = ex;
                    if (current is TargetInvocationException)
                    {
                        current = current.InnerException;
                    }
                    if (current is IgnoreException)
                    {
                        result.Ignore();
                    }
                    else if (current is AssumptionFailureException)
                    {
                        result.Success();
                    }
                    else
                    {
                        result.Fail(current);
                    }
                }
                this.Owner.TestListener.Test(result);
            }
            private bool RunTestFixtureSetUp()
            {
                TestResult result = null;;

                System.Runtime.CompilerServices.RuntimeHelpers.PrepareConstrainedRegions();
                try
                {
                    if (this.Owner.Fixture.FixtureSetUp == null)
                    {
                        return(true);
                    }

                    result = new TestResult(this.Owner.Fixture.Name, this.Owner.Fixture.FixtureSetUp);
                    result.Start();
                    this.Owner.Fixture.FixtureSetUp.Invoke(null, null);
                    result.Success();
                    this.Owner.TestListener.FixtureSetUp(result);

                    return(true);
                }
                catch (Exception ex)
                {
                    if (result != null)
                    {
                        Exception current = ex;
                        if (current is TargetInvocationException)
                        {
                            current = ex.InnerException;
                        }
                        result.Fail(current);
                        this.Owner.TestListener.FixtureSetUp(result);
                    }
                    return(false);
                }
            }
            private bool RunSetUp()
            {
                TestResult result = null;

                try
                {
                    if (this.Owner.Fixture.SetUp == null)
                    {
                        return(true);
                    }

                    result = new TestResult(this.Owner.Fixture.Name, this.Owner.Fixture.SetUp);
                    result.Start();
                    this.Owner.Fixture.SetUp.Invoke(this.fixtureInstance, null);
                    result.Success();
                    this.Owner.TestListener.SetUp(result);

                    return(true);
                }
                catch (Exception ex)
                {
                    if (result != null)
                    {
                        Exception current = ex;
                        if (current is TargetInvocationException)
                        {
                            current = ex.InnerException;
                        }
                        result.Fail(current);
                        this.Owner.TestListener.SetUp(result);
                    }
                    return(false);
                }
            }
        public void Run()
        {
            workerThread = null;
            System.Runtime.CompilerServices.RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                using (FixtureWorker worker = new FixtureWorker(this))
                {
                    workerThread = new Thread(new ThreadStart(worker.RunAsync));
                    workerThread.SetApartmentState(this.Fixture.Apartment);
                    workerThread.IsBackground = true;
                    workerThread.Priority     = ThreadPriority.Lowest;

                    int timeOut =
                        (this.Fixture.TimeOut == int.MaxValue)
                            ? int.MaxValue : 60 * 1000 * this.Fixture.TimeOut;
                    // if a debugger is attached, no time out
                    if (System.Diagnostics.Debugger.IsAttached)
                    {
                        timeOut = int.MaxValue;
                    }

                    workerThread.Start();
                    if (!workerThread.Join(timeOut))
                    {
                        // cancel and wait for 10 sec
                        worker.CancelAsync();
                        if (!workerThread.Join(10 * 1000))
                        {
                            this.AbortWorkerThread();
                        }

                        // store result
                        TestResult result = new TestResult(Fixture.Name, "FixtureTimedOut");
                        result.Start();
                        result.Fail(new FixtureTimedOutException(this.Fixture.Name));
                        this.TestListener.FixtureTearDown(result);
                    }
                    else
                    {
                        if (worker.UnhandledException != null)
                        {
                            throw new ApplicationException("Exception is runner", worker.UnhandledException);
                        }
                    }
                }
            }
            finally
            {
                this.AbortWorkerThread();
            }
        }
        public void Run()
        {
            workerThread = null;
            System.Runtime.CompilerServices.RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                using (FixtureWorker worker = new FixtureWorker(this))
                {
                    workerThread = new Thread(new ThreadStart(worker.RunAsync));
                    workerThread.SetApartmentState(this.Fixture.Apartment);
                    workerThread.IsBackground = true;
                    workerThread.Priority = ThreadPriority.Lowest;

                    int timeOut = 
                        (this.Fixture.TimeOut==int.MaxValue) 
                            ? int.MaxValue : 60 * 1000 * this.Fixture.TimeOut;
                    // if a debugger is attached, no time out
                    if (System.Diagnostics.Debugger.IsAttached)
                        timeOut = int.MaxValue;

                    workerThread.Start();
                    if (!workerThread.Join(timeOut))
                    {
                        // cancel and wait for 10 sec
                        worker.CancelAsync();
                        if (!workerThread.Join(10 * 1000))
                            this.AbortWorkerThread();

                        // store result
                        TestResult result = new TestResult(Fixture.Name, "FixtureTimedOut");
                        result.Start();
                        result.Fail(new FixtureTimedOutException(this.Fixture.Name));
                        this.TestListener.FixtureTearDown(result);
                    }
                    else
                    {
                        if (worker.UnhandledException != null)
                            throw new ApplicationException("Exception is runner", worker.UnhandledException);
                    }
                }
            }
            finally
            {
                this.AbortWorkerThread();
            }
        }
            private bool CreateFixtureInstance()
            {
                TestResult result = new TestResult(this.Owner.Fixture.Name, "Create");

                System.Runtime.CompilerServices.RuntimeHelpers.PrepareConstrainedRegions();
                try
                {
                    this.fixtureInstance = this.Owner.Fixture.CreateInstance();
                    return(true);
                }
                catch (Exception ex)
                {
                    Exception current = ex;
                    if (current is TargetInvocationException)
                    {
                        current = ex.InnerException;
                    }
                    result.Fail(current);
                    this.Owner.TestListener.SetUp(result);
                    return(false);
                }
            }
 private void RunTest(ITestCase test)
 {
     TestResult result = new TestResult(test);
     System.Runtime.CompilerServices.RuntimeHelpers.PrepareConstrainedRegions();
     try
     {
         result.Start();
         test.Run(this.fixtureInstance);
         result.Success();
     }
     catch (Exception ex)
     {
         Exception current = ex;
         if (current is TargetInvocationException)
             current = current.InnerException;
         if (current is IgnoreException)
             result.Ignore();
         else if (current is AssumptionFailureException)
             result.Success();
         else
             result.Fail(current);
     }
     this.Owner.TestListener.Test(result);
 }
            private void RunTearDown()
            {
                TestResult result = null;
                System.Runtime.CompilerServices.RuntimeHelpers.PrepareConstrainedRegions();
                try
                {
                    if (this.Owner.Fixture.TearDown == null)
                        return;

                    result = new TestResult(this.Owner.Fixture.Name, this.Owner.Fixture.TearDown);
                    result.Start();
                    this.Owner.Fixture.TearDown.Invoke(this.fixtureInstance,null);
                    result.Success();
                }
                catch (Exception ex)
                {
                    if (result != null)
                    {
                        Exception current = ex;
                        if (current is TargetInvocationException)
                            current = ex.InnerException;
                        result.Fail(current);
                        this.Owner.TestListener.TearDown(result);
                    }
                }
            }
            private bool RunSetUp()
            {
                TestResult result = null;
                try
                {
                    if (this.Owner.Fixture.SetUp == null)
                        return true;

                    result = new TestResult(this.Owner.Fixture.Name, this.Owner.Fixture.SetUp);
                    result.Start();
                    this.Owner.Fixture.SetUp.Invoke(this.fixtureInstance,null);
                    result.Success();
                    this.Owner.TestListener.SetUp(result);

                    return true;
                }
                catch (Exception ex)
                {
                    if (result != null)
                    {
                        Exception current = ex;
                        if (current is TargetInvocationException)
                            current = ex.InnerException;
                        result.Fail(current);
                        this.Owner.TestListener.SetUp(result);
                    }
                    return false;
                }
            }
            private bool RunTestFixtureSetUp()
            {
                TestResult result = null; ;
                System.Runtime.CompilerServices.RuntimeHelpers.PrepareConstrainedRegions();
                try
                {
                    if (this.Owner.Fixture.FixtureSetUp == null)
                        return true;

                    result = new TestResult(this.Owner.Fixture.Name, this.Owner.Fixture.FixtureSetUp);
                    result.Start();
                    this.Owner.Fixture.FixtureSetUp.Invoke(null, null);
                    result.Success();
                    this.Owner.TestListener.FixtureSetUp(result);

                    return true;
                }
                catch (Exception ex)
                {
                    if (result != null)
                    {
                        Exception current = ex;
                        if (current is TargetInvocationException)
                            current = ex.InnerException;
                        result.Fail(current);
                        this.Owner.TestListener.FixtureSetUp(result);
                    }
                    return false;
                }
            }
 private bool CreateFixtureInstance()
 {
     TestResult result = new TestResult(this.Owner.Fixture.Name, "Create");
     System.Runtime.CompilerServices.RuntimeHelpers.PrepareConstrainedRegions();
     try
     {
         this.fixtureInstance = this.Owner.Fixture.CreateInstance();
         return true;
     }
     catch (Exception ex)
     {
         Exception current = ex;
         if (current is TargetInvocationException)
             current = ex.InnerException;
         result.Fail(current);
         this.Owner.TestListener.SetUp(result);
         return false;
     }
 }