/// <summary>
        /// Overridden to run the teardown methods specified on the test.
        /// </summary>
        /// <param name="context">The TestExecutionContext to be used.</param>
        /// <returns>A TestResult</returns>
        public override TestResult Execute(TestExecutionContext context)
        {
            TestResult suiteResult = context.CurrentResult;

            if (fixtureType != null)
            {
                try
                {
                    int index = suite.oneTimeTearDownMethods.Length;
                    while (--index >= 0)
                    {
                        // TODO: Pass methods to constructor?
                        MethodInfo fixtureTearDown = suite.oneTimeTearDownMethods[index];
                        if (!fixtureTearDown.IsStatic && context.TestObject == null)
                            Console.WriteLine("Null TestObject in fixture teardown for " + Test.FullName);
                        Reflect.InvokeMethod(fixtureTearDown, fixtureTearDown.IsStatic ? null : context.TestObject);
                    }

                    IDisposable disposable = context.TestObject as IDisposable;
                    if (disposable != null)
                        disposable.Dispose();
                }
                catch (Exception ex)
                {
                    suiteResult.RecordTearDownException(ex);
                }
            }

            return suiteResult;
        }
Exemple #2
0
        /// <summary>
        /// Run SetUp on this level.
        /// </summary>
        /// <param name="context">The execution context to use for running.</param>
        public void RunSetUp(TestExecutionContext context)
        {
            _setUpWasRun = true;

            foreach (MethodInfo setUpMethod in _setUpMethods)
                RunSetUpOrTearDownMethod(context, setUpMethod);
        }
        /// <summary>
        /// Overridden to run the one-time setup for a suite.
        /// </summary>
        /// <param name="context">The TestExecutionContext to be used.</param>
        /// <returns>A TestResult</returns>
        public override TestResult Execute(TestExecutionContext context)
        {
            if (_fixtureType != null)
            {
                // Use pre-constructed fixture if available, otherwise construct it
                if (!IsStaticClass(_fixtureType))
                {
                    context.TestObject = _suite.Fixture ?? Reflect.Construct(_fixtureType, _arguments);
                    if (_suite.Fixture == null)
                    {
                        _suite.Fixture = context.TestObject;
                    }
                    Test.Fixture = _suite.Fixture;
                }

                for (int i = _setUpTearDown.Count; i > 0; )
                    _setUpTearDown[--i].RunSetUp(context);
            }


            for (int i = 0; i < _actions.Count; i++)
                _actions[i].BeforeTest(Test);

            return context.CurrentResult;
        }
        /// <summary>
        /// Runs the test, saving a TestResult in the supplied TestExecutionContext.
        /// </summary>
        /// <param name="context">The context in which the test should run.</param>
        /// <returns>A TestResult</returns>
        public override TestResult Execute(TestExecutionContext context)
        {
            try
            {
                for (int i = _setUpTearDownItems.Count; i > 0;)
                    _setUpTearDownItems[--i].RunSetUp(context);

                context.CurrentResult = innerCommand.Execute(context);
            }
            catch (Exception ex)
            {
#if !PORTABLE
                if (ex is ThreadAbortException)
                    Thread.ResetAbort();
#endif
                context.CurrentResult.RecordException(ex);
            }
            finally
            {
                if (context.ExecutionStatus != TestExecutionStatus.AbortRequested)
                {
                    for(int i = 0; i < _setUpTearDownItems.Count; i++)
                        _setUpTearDownItems[i].RunTearDown(context);
                }
            }

            return context.CurrentResult;
        }
        /// <summary>
        /// Overridden to call the inner command and adjust the result
        /// in case all chlid results were inconclusive.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public async override Task<TestResult> Execute(TestExecutionContext context)
        {
            TestResult theoryResult = await innerCommand.Execute(context);

            if (theoryResult.ResultState == ResultState.Success)
            {
                if (!theoryResult.HasChildren)
                    theoryResult.SetResult(ResultState.Failure, "No test cases were provided", null);
                else
                {
                    bool wasInconclusive = true;
                    foreach (TestResult childResult in theoryResult.Children)
                        if (childResult.ResultState == ResultState.Success)
                        {
                            wasInconclusive = false;
                            break;
                        }

                    if (wasInconclusive)
                        theoryResult.SetResult(ResultState.Failure, "All test cases were inconclusive", null);
                }
            }

            return theoryResult;
        }
Exemple #6
0
        /// <summary>
        /// Runs the test, saving a TestResult in the supplied TestExecutionContext
        /// </summary>
        /// <param name="context">The context in which the test should run.</param>
        /// <returns>A TestResult</returns>
        public override TestResult Execute(TestExecutionContext context)
        {
            // TODO: This command duplicates the calculation of the
            // duration of the test because that calculation is 
            // normally performed at a higher level. Most likely,
            // we should move the maxtime calculation to the
            // higher level eventually.
            long startTicks = Stopwatch.GetTimestamp();

            TestResult testResult = innerCommand.Execute(context);

            long tickCount = Stopwatch.GetTimestamp() - startTicks;
            double seconds = (double)tickCount / Stopwatch.Frequency;
            testResult.Duration = seconds;

            if (testResult.ResultState == ResultState.Success)
            {
                double elapsedTime = testResult.Duration * 1000d;

                if (elapsedTime > maxTime)
                    testResult.SetResult(ResultState.Failure,
                        string.Format("Elapsed time of {0}ms exceeds maximum of {1}ms",
                            elapsedTime, maxTime));
            }

            return testResult;
        }
Exemple #7
0
        /// <summary>
        /// Runs the test, saving a TestResult in the supplied TestExecutionContext
        /// </summary>
        /// <param name="context">The context in which the test should run.</param>
        /// <returns>A TestResult</returns>
        public override TestResult Execute(TestExecutionContext context)
        {
            // TODO: This command duplicates the calculation of the
            // duration of the test because that calculation is 
            // normally performed at a higher level. Most likely,
            // we should move the maxtime calculation to the
            // higher level eventually.
#if (CLR_2_0 || CLR_4_0) && !SILVERLIGHT && !NETCF_2_0
            long startTicks = Stopwatch.GetTimestamp();
#endif

            TestResult testResult = innerCommand.Execute(context);

#if (CLR_2_0 || CLR_4_0) && !SILVERLIGHT && !NETCF_2_0
            long tickCount = Stopwatch.GetTimestamp() - startTicks;
            double seconds = (double)tickCount / Stopwatch.Frequency;
            testResult.Duration = TimeSpan.FromSeconds(seconds);
#else
            testResult.Duration = DateTime.Now - context.StartTime;
#endif

            if (testResult.ResultState == ResultState.Success)
            {
                //int elapsedTime = (int)Math.Round(testResult.Time * 1000.0);
                double elapsedTime = testResult.Duration.TotalMilliseconds;

                if (elapsedTime > maxTime)
                    testResult.SetResult(ResultState.Failure,
                        string.Format("Elapsed time of {0}ms exceeds maximum of {1}ms",
                            elapsedTime, maxTime));
            }

            return testResult;
        }
        /// <summary>
        /// Overridden to run the teardown methods specified on the test.
        /// </summary>
        /// <param name="context">The TestExecutionContext to be used.</param>
        /// <returns>A TestResult</returns>
        public override TestResult Execute(TestExecutionContext context)
        {
            TestResult suiteResult = context.CurrentResult;

            try
            {
                for (int i = _actions.Count; i > 0; )
                    _actions[--i].AfterTest(Test);

                if (_setUpTearDownItems != null)
                    foreach(var item in _setUpTearDownItems)
                        item.RunTearDown(context);

                IDisposable disposable = context.TestObject as IDisposable;
                if (disposable != null && Test is IDisposableFixture)
                    disposable.Dispose();

                //Clear references to test objects to reduce memory usage
                context.TestObject = null;
                Test.Fixture = null;
            }
            catch (Exception ex)
            {
                suiteResult.RecordTearDownException(ex);
            }

            return suiteResult;
        }
Exemple #9
0
 /// <summary>
 /// Construct a WorkItem for a particular test.
 /// </summary>
 /// <param name="test">The test that the WorkItem will run</param>
 /// <param name="context">The TestExecutionContext in which it will run</param>
 public WorkItem(Test test, TestExecutionContext context)
 {
     _test = test;
     _testResult = test.MakeTestResult();
     _state = WorkItemState.Ready;
     _context = context;
 }
Exemple #10
0
 /// <summary>
 /// Construct a WorkItem for a particular test.
 /// </summary>
 /// <param name="test">The test that the WorkItem will run</param>
 /// <param name="context">The context to be used for running this test</param>
 public WorkItem(Test test, TestExecutionContext context)
 {
     _test = test;
     _context = context.Save();
     testResult = test.MakeTestResult();
     _command = test.GetTestCommand();
     _state = WorkItemState.Ready;
 }
Exemple #11
0
 public static WorkItem CreateWorkItem(Test test, TestExecutionContext context, ITestFilter filter)
 {
     TestSuite suite = test as TestSuite;
     if (suite != null && (suite.RunState == RunState.Runnable || suite.RunState == RunState.Explicit))
         return new CompositeWorkItem(suite, context, filter);
     else
         return new SimpleWorkItem(test, context);
 }
 /// <summary>
 /// Construct a CompositeWorkItem for executing a test suite
 /// using a filter to select child tests.
 /// </summary>
 /// <param name="suite">The TestSuite to be executed</param>
 /// <param name="context">The execution context to be used</param>
 /// <param name="childFilter">A filter used to select child tests</param>
 public CompositeWorkItem(TestSuite suite, TestExecutionContext context, ITestFilter childFilter)
     : base(suite, context)
 {
     _suite = suite;
     _setupCommand = suite.GetOneTimeSetUpCommand();
     _teardownCommand = suite.GetOneTimeTearDownCommand();
     _childFilter = childFilter;
 }
Exemple #13
0
 static public WorkItem CreateWorkItem(Test test, TestExecutionContext context, ITestFilter filter)
 {
     TestSuite suite = test as TestSuite;
     if (suite != null)
         return new CompositeWorkItem(suite, context, filter);
     else
         return new SimpleWorkItem((TestMethod)test, context);
 }
        private object RunTestMethod(TestExecutionContext context)
        {
#if NET_4_0 || NET_4_5
            if (AsyncInvocationRegion.IsAsyncOperation(testMethod.Method))
                return RunAsyncTestMethod(context);
            else
#endif
                return RunNonAsyncTestMethod(context);
        }
		public void SaveContext()
		{
            setupContext = TestExecutionContext.CurrentContext;

			currentDirectory = Environment.CurrentDirectory;
			currentCulture = CultureInfo.CurrentCulture;
            currentUICulture = CultureInfo.CurrentUICulture;
            currentPrincipal = Thread.CurrentPrincipal;
		}
Exemple #16
0
        public void CreateWorkItems()
        {
            IMethodInfo method = new MethodWrapper(typeof(DummyFixture), "DummyTest");
            ITest test = new TestMethod(method);
            _workItem = WorkItem.CreateWorkItem(test, TestFilter.Empty);

            _context = new TestExecutionContext();
            _workItem.InitializeContext(_context);
        }
Exemple #17
0
        private async Task<object> RunTestMethod(TestExecutionContext context)
        {
#if NET_4_5
            if (MethodHelper.IsAsyncMethod(testMethod.Method))
                return await RunAsyncTestMethod(context);
            else
#endif
                return RunNonAsyncTestMethod(context);
        }
        /// <summary>
        /// Runs the test, saving a TestResult in
        /// TestExecutionContext.CurrentContext.CurrentResult
        /// </summary>
        /// <param name="testObject"></param>
        public override TestResult Execute(TestExecutionContext context)
        {
            object result = Reflect.InvokeMethod(testMethod.Method, context.TestObject, arguments);

            if (testMethod.hasExpectedResult)
                NUnit.Framework.Assert.AreEqual(testMethod.expectedResult, result);

            context.CurrentResult.SetResult(ResultState.Success);
            return context.CurrentResult;
        }
Exemple #19
0
        /// <summary>
        /// Create a WorkItem appropriate for the test to be run
        /// </summary>
        /// <param name="test">The test to be executed</param>
        /// <param name="context">The execution context in which the test will be run</param>
        /// <param name="filter">A filter for selecting chind tests</param>
        /// <returns></returns>
        public static WorkItem CreateWorkItem(Test test, TestExecutionContext context, ITestFilter filter)
        {
            if (test.RunState != RunState.Runnable && test.RunState != RunState.Explicit)
                return new SimpleWorkItem(new SkipCommand(test), context);

            TestSuite suite = test as TestSuite;
            if (suite != null)
                return new CompositeWorkItem(suite, context, filter);

            return new SimpleWorkItem((TestMethod)test, context);
        }
        /// <summary>
        /// Runs the test, saving a TestResult in the execution context, as
        /// well as returning it. If the test has an expected result, it
        /// is asserts on that value. Since failed tests and errors throw
        /// an exception, this command must be wrapped in an outer command,
        /// will handle that exception and records the failure. This role
        /// is usually played by the SetUpTearDown command.
        /// </summary>
        /// <param name="context">The execution context</param>
        public override TestResult Execute(TestExecutionContext context)
        {
            // TODO: Decide if we should handle exceptions here
            object result = Reflect.InvokeMethod(testMethod.Method, context.TestObject, arguments);

            if (testMethod.HasExpectedResult)
                NUnit.Framework.Assert.AreEqual(testMethod.ExpectedResult, result);

            context.CurrentResult.SetResult(ResultState.Success);
            return context.CurrentResult;
        }
Exemple #21
0
        /// <summary>
        /// Does the one time set up for a suite command.
        /// </summary>
        /// <param name="context">The execution context to use in running the test.</param>
        public virtual void DoOneTimeSetUp(TestExecutionContext context)
        {
            if (fixtureType != null)
            {
                if (context.TestObject == null && !IsStaticClass(fixtureType))
                    context.TestObject = Reflect.Construct(fixtureType, arguments);

                if (suite.OneTimeSetUpMethods != null)
                    foreach (MethodInfo method in suite.OneTimeSetUpMethods)
                        Reflect.InvokeMethod(method, method.IsStatic ? null : context.TestObject);
            }
        }
        /// <summary>
        /// Overridden to run the one-time setup for a suite.
        /// </summary>
        /// <param name="context">The TestExecutionContext to be used.</param>
        /// <returns>A TestResult</returns>
        public override TestResult Execute(TestExecutionContext context)
        {
            if (_fixtureType != null)
            {
                // Use pre-constructed fixture if available, otherwise construct it
                if (!IsStaticClass(_fixtureType))
                    context.TestObject = _suite.Fixture ?? Reflect.Construct(_fixtureType, _arguments);

                _setUpTearDown.RunSetUp(context);
            }

            return context.CurrentResult;
        }
Exemple #23
0
        /// <summary>
        /// Runs the test, saving a TestResult in the execution context, as
        /// well as returning it. If the test has an expected result, it
        /// is asserts on that value. Since failed tests and errors throw
        /// an exception, this command must be wrapped in an outer command,
        /// will handle that exception and records the failure. This role
        /// is usually played by the SetUpTearDown command.
        /// </summary>
        /// <param name="context">The execution context</param>
        public override TestResult Execute(TestExecutionContext context)
        {
            // TODO: Decide if we should handle exceptions here
            object result = RunTestMethod(context);

            if (testMethod.HasExpectedResult)
                NUnit.Framework.Assert.AreEqual(testMethod.ExpectedResult, result);

            context.CurrentResult.SetResult(ResultState.Success);
            // TODO: Set assert count here?
            //context.CurrentResult.AssertCount = context.AssertCount;
            return context.CurrentResult;
        }
        /// <summary>
        /// Overridden to run the one-time setup for a suite.
        /// </summary>
        /// <param name="context">The TestExecutionContext to be used.</param>
        /// <returns>A TestResult</returns>
        public override TestResult Execute(TestExecutionContext context)
        {
            if (fixtureType != null)
            {
                if (context.TestObject == null && !IsStaticClass(fixtureType))
                    context.TestObject = Reflect.Construct(fixtureType, arguments);

                foreach (MethodInfo method in  Reflect.GetMethodsWithAttribute(fixtureType, typeof(TestFixtureSetUpAttribute), true))
                    Reflect.InvokeMethod(method, method.IsStatic ? null : context.TestObject);
            }

            return context.CurrentResult;
        }
        /// <summary>
        /// Construct a CompositeWorkItem for executing a test suite
        /// using a filter to select child tests.
        /// </summary>
        /// <param name="suite">The TestSuite to be executed</param>
        /// <param name="context">The execution context to be used</param>
        /// <param name="childFilter">A filter used to select child tests</param>
        public CompositeWorkItem(TestSuite suite, TestExecutionContext context, ITestFilter childFilter)
            : base(suite, context)
        {
            _suite = suite;
            SetUpTearDownList setUpTearDown = null;
            if (suite.FixtureType != null)
                setUpTearDown =  new SetUpTearDownList(
                    suite.FixtureType, typeof(OneTimeSetUpAttribute), typeof(OneTimeTearDownAttribute));

            _setupCommand = MakeSetUpCommand(suite, setUpTearDown);
            _teardownCommand = MakeTearDownCommand(suite, setUpTearDown);
            _childFilter = childFilter;
        }
Exemple #26
0
        static private void TestCondition()
        {
            var bt = BT.BTBuilder<TestExecutionContext>.Instance;
            TestExecutionContext testData = new TestExecutionContext();

            var root = bt.Condition("Test condition", x => x.SomeData[0] == 1);
            var context = bt.CreateContext(root, testData);
            Status status = context.Update();
            Debug.Assert(status == Status.Fail);
            testData.SomeData[0] = 1;
            status = context.Update();
            Debug.Assert(status == Status.Ok);
        }
        /// <summary>
        /// Overridden to run the teardown methods specified on the test.
        /// </summary>
        /// <param name="context">The TestExecutionContext to be used.</param>
        /// <returns>A TestResult</returns>
        public override TestResult Execute(TestExecutionContext context)
        {
            TestResult suiteResult = context.CurrentResult;

            if (fixtureType != null)
            {
                MethodInfo[] teardownMethods =
                    Reflect.GetMethodsWithAttribute(fixtureType, typeof(TestFixtureTearDownAttribute), true);

                try
                {
                    int index = teardownMethods.Length;
                    while (--index >= 0)
                    {
                        MethodInfo fixtureTearDown = teardownMethods[index];
#if !PORTABLE
                        if (!fixtureTearDown.IsStatic && context.TestObject == null)
                            Console.WriteLine("TestObject should not be null!!!");
#endif
						Reflect.InvokeMethod(fixtureTearDown, fixtureTearDown.IsStatic ? null : context.TestObject);
                    }

                    IDisposable disposable = context.TestObject as IDisposable;
                    if (disposable != null)
                        disposable.Dispose();
                }
                catch (Exception ex)
                {
                    // Error in TestFixtureTearDown or Dispose causes the
                    // suite to be marked as a error, even if
                    // all the contained tests passed.
                    NUnitException nex = ex as NUnitException;
                    if (nex != null)
                        ex = nex.InnerException;

                    // TODO: Can we move this logic into TestResult itself?
                    string message = "TearDown : " + ExceptionHelper.BuildMessage(ex);
                    if (suiteResult.Message != null)
                        message = suiteResult.Message + NUnit.Env.NewLine + message;

                    string stackTrace = "--TearDown" + NUnit.Env.NewLine + ExceptionHelper.BuildStackTrace(ex);
                    if (suiteResult.StackTrace != null)
                        stackTrace = suiteResult.StackTrace + NUnit.Env.NewLine + stackTrace;

                    // TODO: What about ignore exceptions in teardown?
                    suiteResult.SetResult(ResultState.Error, message, stackTrace);
                }
            }

            return suiteResult;
        }
        /// <summary>
        /// Run SetUp on this level after running that for the next lower level.
        /// </summary>
        /// <param name="context">The execution context to use for running.</param>
        public void RunSetUp(TestExecutionContext context)
        {
            // We have not yet run this level
            this._setUpWasRun = false;

            if (Next != null)
                Next.RunSetUp(context);

            // No exception, proceed with this level
            this._setUpWasRun = true;

            foreach (MethodInfo setUpMethod in _setUpMethods)
                Reflect.InvokeMethod(setUpMethod, setUpMethod.IsStatic ? null : context.TestObject);
        }
Exemple #29
0
        /// <summary>
        /// Does the one time tear down for a suite command.
        /// </summary>
        /// <param name="context">The execution context to use in running the test.</param>
        public virtual void DoOneTimeTearDown(TestExecutionContext context)
        {
            if (fixtureType != null)
            {
                TestSuiteResult suiteResult = context.CurrentResult as TestSuiteResult;

                try
                {
                    if (suite.OneTimeTearDownMethods != null)
                    {
                        int index = suite.OneTimeTearDownMethods.Length;
                        while (--index >= 0)
                        {
                            MethodInfo fixtureTearDown = suite.OneTimeTearDownMethods[index];
                            Reflect.InvokeMethod(fixtureTearDown, fixtureTearDown.IsStatic ? null : context.TestObject);
                        }
                    }

                    IDisposable disposable = context.TestObject as IDisposable;
                    if (disposable != null)
                        disposable.Dispose();
                }
                catch (Exception ex)
                {
                    // Error in TestFixtureTearDown or Dispose causes the
                    // suite to be marked as a error, even if
                    // all the contained tests passed.
                    NUnitException nex = ex as NUnitException;
                    if (nex != null)
                        ex = nex.InnerException;

                    // TODO: Can we move this logic into TestResult itself?
                    string message = "TearDown : " + ExceptionHelper.BuildMessage(ex);
                    if (suiteResult.Message != null)
                        message = suiteResult.Message + NUnit.Env.NewLine + message;

#if !NETCF_1_0
                    string stackTrace = "--TearDown" + NUnit.Env.NewLine + ExceptionHelper.BuildStackTrace(ex);
                    if (suiteResult.StackTrace != null)
                        stackTrace = suiteResult.StackTrace + NUnit.Env.NewLine + stackTrace;

                    // TODO: What about ignore exceptions in teardown?
                    suiteResult.SetResult(ResultState.Error, message, stackTrace);
#else
                    Result.SetResult(ResultState.Error, message);
#endif
                }
            }
        }
Exemple #30
0
        private object RunTestMethod(TestExecutionContext context)
        {
#if NET_4_5
            if (MethodHelper.IsAsyncMethod(testMethod.Method))
                return RunAsyncTestMethod(context);
            //{
            //    if (testMethod.Method.ReturnType == typeof(void))
            //        return RunAsyncVoidTestMethod(context);
            //    else
            //        return RunAsyncTaskTestMethod(context);
            //}
            else
#endif
                return RunNonAsyncTestMethod(context);
        }
Exemple #31
0
 public static FakeWorkItem GetWorkItem(Test test, TestExecutionContext context)
 {
     return(new FakeWorkItem(test, context));
 }
Exemple #32
0
 public TestRunCriteriaWithSources(Dictionary <string, IEnumerable <string> > adapterSourceMap, string package, string runSettings, TestExecutionContext testExecutionContext)
 {
     this.AdapterSourceMap     = adapterSourceMap;
     this.Package              = package;
     this.RunSettings          = runSettings;
     this.TestExecutionContext = testExecutionContext;
 }
Exemple #33
0
            public void EscapeWith()
            {
                // Given
                string input  = @"<html>
                        <head>
                            <title>Foobar</title>
                        </head>
                        <body>
                            <h1>Die Sache mit dem Umlaut</h1>
                            <p>Lerchen-Lärchen-Ähnlichkeiten<br/>
                            fehlen.Dieses abzustreiten<br/>
                            mag im Klang der Worte liegen.<br/>
                            Merke, eine Lerch‘ kann fliegen,<br/>
                            Lärchen nicht, was kaum verwundert,<br/>
                            denn nicht eine unter hundert<br/>
                            ist geflügelt.Auch im Singen<br/>
                            sind die Bäume zu bezwingen.<br/>
                            <br/>
                            Die Bätrachtung sollte reichen,<br/>
                            Rächtschreibfählern auszuweichen.<br/>
                            Leicht gälingt’s, zu unterscheiden,<br/>
                            wär ist wär nun von dän beiden.</p>
                            <p>©Ingo Baumgartner, <u>2013</u><br/>
                            Aus der Sammlung<u>Humor, Satire und Nonsens</u>
                            </a>
                            </p>
                        </body>
                    </html>";
                string output = @"<html>
                        <head>
                            <title>Foobar</title>
                        </head>
                        <body>
                            <h1>Die Sache mit dem Umlaut</h1>
                            <p>Lerchen-L&auml;rchen-&Auml;hnlichkeiten<br/>
                            fehlen.Dieses abzustreiten<br/>
                            mag im Klang der Worte liegen.<br/>
                            Merke, eine Lerch‘ kann fliegen,<br/>
                            L&auml;rchen nicht, was kaum verwundert,<br/>
                            denn nicht eine unter hundert<br/>
                            ist gefl&uuml;gelt.Auch im Singen<br/>
                            sind die B&auml;ume zu bezwingen.<br/>
                            <br/>
                            Die B&auml;trachtung sollte reichen,<br/>
                            R&auml;chtschreibf&auml;hlern auszuweichen.<br/>
                            Leicht g&auml;lingt’s, zu unterscheiden,<br/>
                            w&auml;r ist w&auml;r nun von d&auml;n beiden.</p>
                            <p>&copy;Ingo Baumgartner, <u>2013</u><br/>
                            Aus der Sammlung<u>Humor, Satire und Nonsens</u>
                            </a>
                            </p>
                        </body>
                    </html>";
                TestExecutionContext context    = new TestExecutionContext();
                TestDocument         document   = new TestDocument(input);
                HtmlEscape           htmlEscape = new HtmlEscape().WithEscapedChar('ä', 'ö', 'ü', 'Ä', 'Ö', 'Ü', 'ß', '©');

                // When
                IList <IDocument> results = htmlEscape.Execute(new[] { document }, context).ToList();  // Make sure to materialize the result list

                // Then
                Assert.That(results.Select(x => x.Content), Is.EquivalentTo(new[] { output }));
            }
 public RunTestsWithSources(IRequestData requestData, Dictionary <string, IEnumerable <string> > adapterSourceMap, string package, string runSettings, TestExecutionContext testExecutionContext, ITestCaseEventsHandler testCaseEventsHandler, ITestRunEventsHandler testRunEventsHandler)
     : this(requestData, adapterSourceMap, package, runSettings, testExecutionContext, testCaseEventsHandler, testRunEventsHandler, null)
 {
 }
Exemple #35
0
 public TestableRunTestsWithSources(Dictionary <string, IEnumerable <string> > adapterSourceMap, string runSettings,
                                    TestExecutionContext testExecutionContext, ITestCaseEventsHandler testCaseEventsHandler, ITestRunEventsHandler testRunEventsHandler, IRequestData requestData)
     : base(requestData, adapterSourceMap, null, runSettings, testExecutionContext, testCaseEventsHandler, testRunEventsHandler)
 {
 }
Exemple #36
0
 private static void ClearTestResult(TestExecutionContext context)
 {
     context.CurrentResult = context.CurrentTest.MakeTestResult();
 }
Exemple #37
0
        /// <summary>
        /// Runs a TestCommand, sending notifications to a listener.
        /// </summary>
        /// <param name="command">A TestCommand to be executed.</param>
        /// <param name="context">The context in which to execute the command.</param>
        /// <returns>A TestResult.</returns>
        public static TestResult Execute(TestCommand command)
        {
            TestResult testResult;

            TestExecutionContext.Save();
            TestExecutionContext context = TestExecutionContext.CurrentContext;

            //context = new TestExecutionContext(context);

            context.CurrentTest   = command.Test;
            context.CurrentResult = command.Test.MakeTestResult();

            context.Listener.TestStarted(command.Test);
            long startTime = DateTime.Now.Ticks;

            try
            {
                TestSuiteCommand suiteCommand = command as TestSuiteCommand;
                if (suiteCommand != null)
                {
                    testResult = ExecuteSuiteCommand(suiteCommand, context);
                }
                //{
                //    suiteCommand.DoOneTimeSetup();
                //    foreach (TestCommand childCommand in suiteCommand.Children)
                //        Execute(childCommand, context);
                //    suiteCommand.DoOneTimeTearDown();
                //}
                else
                {
                    testResult = command.Execute(context);
                }

                testResult.AssertCount = context.AssertCount;

                long   stopTime = DateTime.Now.Ticks;
                double time     = ((double)(stopTime - startTime)) / (double)TimeSpan.TicksPerSecond;
                testResult.Time = time;

                context.Listener.TestFinished(testResult);
            }
            catch (Exception ex)
            {
#if !NETCF
                if (ex is ThreadAbortException)
                {
                    Thread.ResetAbort();
                }
#endif
                context.CurrentResult.RecordException(ex);
                return(context.CurrentResult);
            }
            finally
            {
                TestExecutionContext.Restore();
                //context.ReverseChanges();
                //context = context.prior;
            }

            return(testResult);
        }
Exemple #38
0
 public TaskHelper(TestExecutionContext execContext)
 {
     _execContext = execContext;
 }
Exemple #39
0
        /// <summary>
        /// Initialize the TestExecutionContext. This must be done
        /// before executing the WorkItem.
        /// </summary>
        /// <remarks>
        /// Originally, the context was provided in the constructor
        /// but delaying initialization of the context until the item
        /// is about to be dispatched allows changes in the parent
        /// context during OneTimeSetUp to be reflected in the child.
        /// </remarks>
        /// <param name="context">The TestExecutionContext to use</param>
        public void InitializeContext(TestExecutionContext context)
        {
            Guard.OperationValid(Context == null, "The context has already been initialized");

            Context = context;
        }
Exemple #40
0
 void IApplyToContext.ApplyToContext(TestExecutionContext context)
 {
     context.CurrentUICulture = new System.Globalization.CultureInfo(_culture, false);
 }
 private object RunNonAsyncTestMethod(TestExecutionContext context)
 {
     return(Reflect.InvokeMethod(testMethod.Method, context.TestObject, arguments));
 }
 void IApplyToContext.ApplyToContext(TestExecutionContext context)
 {
     throw new NotSupportedException();
 }
Exemple #43
0
 public FakeWorkItem(Test test, TestExecutionContext context)
     : base(test, TestFilter.Empty)
 {
     InitializeContext(context);
 }
Exemple #44
0
 /// <summary>
 /// Execute the command
 /// </summary>
 public override Task <TestResult> Execute(TestExecutionContext context)
 {
     return(Task.FromResult(context.CurrentResult));
 }
Exemple #45
0
 private static object InvokeMethod(MethodInfo method, TestExecutionContext context)
 {
     return(Reflect.InvokeMethod(method, method.IsStatic ? null : context.TestObject));
 }
Exemple #46
0
 /// <summary>
 /// Runs the test, returning a TestResult.
 /// </summary>
 /// <param name="context">The TestExecutionContext to be used for running the test.</param>
 /// <returns>A TestResult</returns>
 public abstract TestResult Execute(TestExecutionContext context);
Exemple #47
0
 private static bool TestFailed(TestExecutionContext context)
 {
     return(UnsuccessfulResultStates.Contains(context.CurrentResult.ResultState));
 }
 public void ApplyToContext(TestExecutionContext context)
 {
     context.DefaultFloatingPointTolerance = _tolerance;
 }
Exemple #49
0
 internal TestableRunTestsWithSources(Dictionary <string, IEnumerable <string> > adapterSourceMap, string runSettings,
                                      TestExecutionContext testExecutionContext,
                                      ITestCaseEventsHandler testCaseEventsHandler, ITestRunEventsHandler testRunEventsHandler, Dictionary <Tuple <Uri, string>, IEnumerable <string> > executorUriVsSourceList, IRequestData requestData)
     : base(requestData, adapterSourceMap, null, runSettings, testExecutionContext, testCaseEventsHandler, testRunEventsHandler, executorUriVsSourceList)
 {
 }
 void IApplyToContext.ApplyToContext(TestExecutionContext context)
 {
     context.TestCaseTimeout = _timeout;
 }
 /// <summary>
 /// Used for unit testing only.
 /// </summary>
 /// <param name="requestData"></param>
 /// <param name="adapterSourceMap"></param>
 /// <param name="package">The user input test source(package) if it differ from actual test source otherwise null.</param>
 /// <param name="runSettings"></param>
 /// <param name="testExecutionContext"></param>
 /// <param name="testCaseEventsHandler"></param>
 /// <param name="testRunEventsHandler"></param>
 /// <param name="executorUriVsSourceList"></param>
 /// <param name="testRunCache"></param>
 internal RunTestsWithSources(IRequestData requestData, Dictionary <string, IEnumerable <string> > adapterSourceMap, string package, string runSettings, TestExecutionContext testExecutionContext, ITestCaseEventsHandler testCaseEventsHandler, ITestRunEventsHandler testRunEventsHandler, Dictionary <Tuple <Uri, string>, IEnumerable <string> > executorUriVsSourceList)
     : base(requestData, package, runSettings, testExecutionContext, testCaseEventsHandler, testRunEventsHandler, TestPlatformEventSource.Instance)
 {
     this.adapterSourceMap        = adapterSourceMap;
     this.executorUriVsSourceList = executorUriVsSourceList;
     this.testCaseEventsHandler   = testCaseEventsHandler;
 }
Exemple #52
0
 public static FakeWorkItem GetWorkItem(object obj, string name, TestExecutionContext context)
 {
     return(GetWorkItem(obj.GetType(), name, context));
 }
Exemple #53
0
            public async Task RendersTableWithSettings()
            {
                // Given
                TestExecutionContext context  = new TestExecutionContext();
                TestDocument         document = new TestDocument();
                string content = @"
1 2 ""3 4""
a ""b c"" d
e f g
5 678
""h i""  j ""k""
l=m nop
";

                KeyValuePair <string, string>[] args = new KeyValuePair <string, string>[]
                {
                    new KeyValuePair <string, string>("Class", "tclass"),
                    new KeyValuePair <string, string>("HeaderRows", "1"),
                    new KeyValuePair <string, string>("FooterRows", "2"),
                    new KeyValuePair <string, string>("HeaderCols", "1"),
                    new KeyValuePair <string, string>("HeaderClass", "hclass"),
                    new KeyValuePair <string, string>("BodyClass", "bclass"),
                    new KeyValuePair <string, string>("FooterClass", "fclass")
                };
                TableShortcode shortcode = new TableShortcode();

                // When
                TestDocument result = (TestDocument)await shortcode.ExecuteAsync(args, content, document, context);

                // Then
                result.Content.ShouldBe(
                    @"<table class=""tclass"">
  <thead class=""hclass"">
    <tr>
      <th>1</th>
      <th>2</th>
      <th>3 4</th>
    </tr>
  </thead>
  <tbody class=""bclass"">
    <tr>
      <th>a</th>
      <td>b c</td>
      <td>d</td>
    </tr>
    <tr>
      <th>e</th>
      <td>f</td>
      <td>g</td>
    </tr>
    <tr>
      <th>5</th>
      <td>678</td>
    </tr>
  </tbody>
  <tfoot class=""fclass"">
    <tr>
      <th>h i</th>
      <td>j</td>
      <td>k</td>
    </tr>
    <tr>
      <th>l=m</th>
      <td>nop</td>
    </tr>
  </tfoot>
</table>",
                    StringCompareShould.IgnoreLineEndings);
            }
Exemple #54
0
 public static FakeWorkItem GetWorkItem(Type type, string name, TestExecutionContext context)
 {
     return(GetWorkItem(GetTestMethod(type, name), context));
 }
Exemple #55
0
 protected virtual void AfterExecuting(TestExecutionContext testContext)
 {
 }
Exemple #56
0
 private void RestoreExecutionContext(TestExecutionContext savedContext)
 {
     TestExecutionContext.CurrentContext = savedContext;
 }
Exemple #57
0
 internal void AfterExecutingSafe(TestExecutionContext context)
 {
     using (context.ApplyingContext()) {
         AfterExecuting(context);
     }
 }
Exemple #58
0
 /// <summary>
 /// Construct a TestContext for an ExecutionContext
 /// </summary>
 /// <param name="testExecutionContext">The ExecutionContext to adapt</param>
 public TestContext(TestExecutionContext testExecutionContext)
 {
     _testExecutionContext = testExecutionContext;
 }
Exemple #59
0
 private void RestoreExecutionContext(TestExecutionContext savedContext)
 {
     CallContext.SetData(NUnitCallContext.TestExecutionContextKey, savedContext);
 }
 public TestSuiteAction(TestSuite test, TestExecutionContext initialCtx, IncrementalTestRunner runner) : base(test, initialCtx, runner)
 {
     this.testSuite = test;
 }