public void ShouldReturnResultOfExecutorRunTest()
        {
            var testCase = new TestCase("Blagh||Test", new Uri("http://executor"), "adsfdsdaf");

            var poshResult = new PowerShellTestResult(TestOutcome.Failed, "Error!!", "Blagh!");

            _executorMock.Setup(m => m.TestFramework).Returns("Blagh");
            _executorMock.Setup(m => m.RunTest(It.IsAny<PowerShell>(), testCase, _runContext.Object))
                .Returns(poshResult);

            TestResult result = null;
            _frameworkHandle.Setup(m => m.RecordResult(It.IsAny<TestResult>())).Callback<TestResult>(x => result = x);

            _test.RunTests(new[] { testCase }, _runContext.Object, _frameworkHandle.Object);

            Assert.AreEqual(TestOutcome.Failed, result.Outcome);
            Assert.AreEqual("Error!!", result.ErrorMessage);
            Assert.AreEqual("Blagh!", result.ErrorStackTrace);
        }
        public void RunTests(IEnumerable<TestCase> tests, IRunContext runContext,
            IFrameworkHandle frameworkHandle)
        {
            _mCancelled = false;
            SetupExecutionPolicy();
            foreach (var test in tests)
            {
                if (_mCancelled) break;

                var testFramework = test.FullyQualifiedName.Split(new[] { "||" }, StringSplitOptions.None)[0];

                var executor = _testExecutors.FirstOrDefault(
                    m => m.TestFramework.Equals(testFramework, StringComparison.OrdinalIgnoreCase));

                if (executor == null)
                {
                    frameworkHandle.SendMessage(TestMessageLevel.Error, String.Format("Unknown test executor: {0}", testFramework));
                    return;
                }

                var testResult = new TestResult(test);
                testResult.Outcome = TestOutcome.Failed;
                testResult.ErrorMessage = "Unexpected error! Failed to run tests!";

                PowerShellTestResult testResultData = null;
                var testOutput = new StringBuilder();

                try
                {
                    var testAdapter = new TestAdapterHost();
                    testAdapter.HostUi.OutputString = s => testOutput.Append(s);

                    var runpsace = RunspaceFactory.CreateRunspace(testAdapter);
                    runpsace.Open();

                    using (var ps = PowerShell.Create())
                    {
                        ps.Runspace = runpsace;

                        testResultData = executor.RunTest(ps, test, runContext);
                    }
                }
                catch (Exception ex)
                {
                    testResult.Outcome = TestOutcome.Failed;
                    testResult.ErrorMessage = ex.Message;
                    testResult.ErrorStackTrace = ex.StackTrace;
                }

                if (testResultData != null)
                {
                    testResult.Outcome = testResultData.Outcome;
                    testResult.ErrorMessage = testResultData.ErrorMessage;
                    testResult.ErrorStackTrace = testResultData.ErrorStacktrace;
                }

                if (testOutput.Length > 0)
                {
                    frameworkHandle.SendMessage(TestMessageLevel.Informational, testOutput.ToString());
                }

                frameworkHandle.RecordResult(testResult);
            }
        }