예제 #1
0
        private TestResult RunTestInContext()
		{
			TestExecutionContext.Save();

            TestExecutionContext.CurrentContext.CurrentTest = this;

            ContextDictionary context = Context;
            context._ec = TestExecutionContext.CurrentContext;

            CallContext.SetData("NUnit.Framework.TestContext", context);

            if (this.Parent != null)
            {
                this.Fixture = this.Parent.Fixture;
                TestSuite suite = this.Parent as TestSuite;
                if (suite != null)
                {
                    this.setUpMethods = suite.GetSetUpMethods();
                    this.tearDownMethods = suite.GetTearDownMethods();
                }
            }

            try
            {
                // Temporary... to allow for tests that directly execute a test case
                if (Fixture == null && !method.IsStatic)
                    Fixture = Reflect.Construct(this.FixtureType);

                if (this.Properties["_SETCULTURE"] != null)
                    TestExecutionContext.CurrentContext.CurrentCulture =
                        new System.Globalization.CultureInfo((string)Properties["_SETCULTURE"]);

                if (this.Properties["_SETUICULTURE"] != null)
                    TestExecutionContext.CurrentContext.CurrentUICulture =
                        new System.Globalization.CultureInfo((string)Properties["_SETUICULTURE"]);

				return RunRepeatedTest();
            }
            catch (Exception ex)
            {
				log.Debug("TestMethod: Caught " + ex.GetType().Name);
				
                if (ex is ThreadAbortException)
                    Thread.ResetAbort();

				TestResult testResult = new TestResult(this);
                RecordException(ex, testResult, FailureSite.Test);
				
				return testResult;
            }
            finally
            {
                Fixture = null;

                CallContext.FreeNamedDataSlot("NUnit.Framework.TestContext");
                TestExecutionContext.Restore();
            }
		}
예제 #2
0
        private TestResult RunSuiteInContext(EventListener listener, ITestFilter filter)
        {
            TestExecutionContext.Save();

            try
            {
                return(ShouldRunOnOwnThread
                        ? new TestSuiteThread(this).Run(listener, filter)
                        : RunSuite(listener, filter));
            }
            finally
            {
                TestExecutionContext.Restore();
            }
        }
예제 #3
0
        private TestResult RunTestInContext()
		{
			TestExecutionContext.Save();

            TestExecutionContext.CurrentContext.CurrentTest = this;

            if (this.Parent != null)
            {
                this.Fixture = this.Parent.Fixture;
                TestSuite suite = this.Parent as TestSuite;
                if (suite != null)
                {
                    this.setUpMethods = suite.SetUpMethods;
                    this.tearDownMethods = suite.TearDownMethods;
#if CLR_2_0 || CLR_4_0
                    this.suiteActions = suite.GetTestActions();
#endif
                }
            }

            try
            {
#if CLR_2_0 || CLR_4_0
                this.actions = ActionsHelper.GetActionsFromAttributeProvider(method);
#endif

                // Temporary... to allow for tests that directly execute a test case);
                if (Fixture == null && !method.IsStatic)
                    Fixture = Reflect.Construct(this.FixtureType);

                if (this.Properties["_SETCULTURE"] != null)
                    TestExecutionContext.CurrentContext.CurrentCulture =
                        new System.Globalization.CultureInfo((string)Properties["_SETCULTURE"]);
                else if (this.Properties["SetCulture"] != null) // In case we are running NUnitLite tests
                    TestExecutionContext.CurrentContext.CurrentCulture =
                        new System.Globalization.CultureInfo((string)Properties["SetCulture"]);

                if (this.Properties["_SETUICULTURE"] != null)
                    TestExecutionContext.CurrentContext.CurrentUICulture =
                        new System.Globalization.CultureInfo((string)Properties["_SETUICULTURE"]);
                if (this.Properties["SetUICulture"] != null) // In case we are running NUnitLite tests
                    TestExecutionContext.CurrentContext.CurrentUICulture =
                        new System.Globalization.CultureInfo((string)Properties["SetUICulture"]);

				return RunRepeatedTest();
            }
            catch (Exception ex)
            {
				log.Debug("TestMethod: Caught " + ex.GetType().Name);
				
                if (ex is ThreadAbortException)
                    Thread.ResetAbort();

				TestResult testResult = new TestResult(this);
                RecordException(ex, testResult, FailureSite.Test);
				
				return testResult;
            }
            finally
            {
                Fixture = null;

                TestExecutionContext.Restore();
            }
		}