Esempio n. 1
0
            public WhenAborted(bool abortTwice)
            {
                abortedSandbox = new Sandbox();
                abortedSandbox.Abort(TestOutcome.Canceled, "Abort message.");

                if (abortTwice)
                {
                    abortedSandbox.Abort(TestOutcome.Passed, "A different message.");
                }
            }
        protected internal override TestResult RunImpl(ITestCommand rootTestCommand, Model.Tree.TestStep parentTestStep, TestExecutionOptions options, IProgressMonitor progressMonitor)
        {
            using (progressMonitor.BeginTask("Running tests.", rootTestCommand.TestCount))
            {
                // Note: We do not check options.SkipTestExecution here because we want to build up
                // the tree of data-driven test steps.  So we actually check it later on in the
                // PatternTestExecutor.  This is different from framework adapters
                // at this time (because they do not generally support dynamically generated data-driven tests).
                Sandbox      sandbox         = new Sandbox();
                EventHandler canceledHandler = delegate { sandbox.Abort(TestOutcome.Canceled, "The user canceled the test run."); };
                try
                {
                    progressMonitor.Canceled += canceledHandler;

                    TestAssemblyExecutionParameters.Reset();

                    PatternTestExecutor executor = new PatternTestExecutor(options, progressMonitor, formatter, converter, environmentManager);

                    // Inlined to minimize stack depth.
                    var action = executor.CreateActionToRunTest(rootTestCommand, parentTestStep, sandbox, null);
                    action.Run();
                    return(action.Result);
                }
                finally
                {
                    progressMonitor.Canceled -= canceledHandler;
                    sandbox.Dispose();
                }
            }
        }
Esempio n. 3
0
        public void WhenSandboxEntersProtectedContext_AbortsAreDeferred()
        {
            StructuredDocumentWriter writer = new StructuredDocumentWriter();
            bool completed = false;

            Sandbox          sandbox = new Sandbox();
            ManualResetEvent barrier = new ManualResetEvent(false);

            Tasks.StartThreadTask("Wake", () =>
            {
                barrier.WaitOne();
                sandbox.Abort(TestOutcome.Canceled, "Canceled for testing purposes.");
            });

            TestOutcome outcome = sandbox.Run(writer, () =>
            {
                using (sandbox.Protect())
                {
                    barrier.Set();
                    Thread.Sleep(300);
                    completed = true;
                }
                Thread.Sleep(300);
            }, "Run Description");

            Assert.IsTrue(completed);
            Assert.AreEqual(TestOutcome.Canceled, outcome);
            Assert.Contains(writer.ToString(), "Canceled for testing purposes.");
        }
Esempio n. 4
0
        public void RunCanBeAbortedInProgress()
        {
            StructuredDocumentWriter writer = new StructuredDocumentWriter();
            ManualResetEvent         ready  = new ManualResetEvent(false);
            bool completed = false;

            Sandbox sandbox = new Sandbox();

            Tasks.StartThreadTask("Background abort.", () =>
            {
                ready.WaitOne();
                sandbox.Abort(TestOutcome.Canceled, "Test was canceled.");
            });

            TestOutcome outcome = sandbox.Run(writer, () =>
            {
                ready.Set();
                Thread.Sleep(10000);
                completed = true;
            }, "Run Description");

            Assert.IsFalse(completed, "The action should have been aborted prior to completion.");

            Assert.AreEqual(TestOutcome.Canceled, outcome);
            Assert.AreEqual(TestOutcome.Canceled, sandbox.AbortOutcome);
            Assert.AreEqual("Test was canceled.", sandbox.AbortMessage);
            Assert.IsTrue(sandbox.WasAborted);

            Assert.Contains(writer.ToString(), "Run Description");
            Assert.Contains(writer.ToString(), "Test was canceled.");
        }
        protected internal override TestResult RunImpl(ITestCommand rootTestCommand, Model.Tree.TestStep parentTestStep, TestExecutionOptions options, IProgressMonitor progressMonitor)
        {
            using (progressMonitor.BeginTask("Running tests.", rootTestCommand.TestCount))
            {
                // Note: We do not check options.SkipTestExecution here because we want to build up
                // the tree of data-driven test steps.  So we actually check it later on in the
                // PatternTestExecutor.  This is different from framework adapters
                // at this time (because they do not generally support dynamically generated data-driven tests).
                Sandbox sandbox = new Sandbox();
                EventHandler canceledHandler = delegate { sandbox.Abort(TestOutcome.Canceled, "The user canceled the test run."); };
                try
                {
                    progressMonitor.Canceled += canceledHandler;

                    TestAssemblyExecutionParameters.Reset();

                    PatternTestExecutor executor = new PatternTestExecutor(options, progressMonitor, formatter, converter, environmentManager);

                    // Inlined to minimize stack depth.
                    var action = executor.CreateActionToRunTest(rootTestCommand, parentTestStep, sandbox, null);
                    action.Run();
                    return action.Result;
                }
                finally
                {
                    progressMonitor.Canceled -= canceledHandler;
                    sandbox.Dispose();
                }
            }
        }