/// <summary>
        /// Creates an aggregate root test result.
        /// </summary>
        /// <param name="runId">The test run id.</param>
        /// <param name="test">The test element.</param>
        /// <returns>The test result.</returns>
        public static GallioTestResult CreateAggregateRootTestResult(Guid runId, ITestElement test)
        {
            var result = new GallioTestResult(runId, test);

            result.Outcome = VSTestOutcome.Pending;
            return(result);
        }
        private static GallioTestResult CreateTestResult(TestStepRun run, Guid runId, ITestElement test, bool includeTestStepRunXml)
        {
            var result = new GallioTestResult(runId, test);
            result.TestName = run.Step.FullName;
            result.Outcome = GetOutcome(run.Result.Outcome);

            foreach (StructuredStream stream in run.TestLog.Streams)
            {
                string contents = stream.ToString();

                if (stream.Name == MarkupStreamNames.DebugTrace)
                    result.DebugTrace += contents;
                else if (stream.Name == MarkupStreamNames.ConsoleOutput)
                    result.StdOut += contents;
                else if (stream.Name == MarkupStreamNames.ConsoleError)
                    result.StdErr += contents;
                else if (stream.Name == MarkupStreamNames.Failures || stream.Name == MarkupStreamNames.Warnings)
                    result.ErrorMessage += contents;
                else
                    result.DebugTrace += contents;
            }

            result.SetTimings(run.StartTime, run.EndTime, run.Result.Duration);

            if (includeTestStepRunXml)
                result.TestStepRunXml = TestStepRunToXml(run);

            foreach (TestStepRun childRun in run.Children)
                result.AddInnerResult(CreateTestResult(childRun, runId, test, false));

            return result;
        }
Beispiel #3
0
        /// <summary>
        /// Adds a test result as an inner result.
        /// </summary>
        /// <param name="testResult">The test result to add.</param>
        public void AddInnerResult(GallioTestResult testResult)
        {
            int oldLength = m_innerResults.Length;

            Array.Resize(ref m_innerResults, oldLength + 1);
            m_innerResults[oldLength] = testResult;
        }
        /// <summary>
        /// Gets the test step runs associated with a test result.
        /// </summary>
        public static IList <TestStepRun> GetTestStepRuns(GallioTestResult result)
        {
            List <TestStepRun> runs = new List <TestStepRun>();

            if (result.IsAggregateRoot)
            {
                foreach (GallioTestResult innerResult in result.InnerResults)
                {
                    TestStepRun run = GetTestStepRun(innerResult);
                    if (run != null)
                    {
                        runs.Add(run);
                    }
                }
            }
            else
            {
                TestStepRun run = GetTestStepRun(result);
                if (run != null)
                {
                    runs.Add(run);
                }
            }

            return(runs);
        }
Beispiel #5
0
 /// <summary>
 /// Sets the list of inner results.
 /// </summary>
 /// <param name="testResults">The test results to set.</param>
 public void SetInnerResults(IList <GallioTestResult> testResults)
 {
     m_innerResults = new GallioTestResult[testResults.Count];
     for (int i = 0; i < testResults.Count; i++)
     {
         m_innerResults[i] = testResults[i];
     }
 }
        /// <summary>
        /// Merges Gallio test results.
        /// </summary>
        /// <param name="inMemory">The currently available test result, or null if none.</param>
        /// <param name="fromTheWire">The test result to add, or null if none.</param>
        /// <returns>The merged test result.</returns>
        public static GallioTestResult Merge(GallioTestResult inMemory, GallioTestResult fromTheWire)
        {
            if (fromTheWire == null)
            {
                return(inMemory);
            }
            if (inMemory == null)
            {
                return(fromTheWire);
            }

            List <GallioTestResult> combinedResults = new List <GallioTestResult>();
            VSTestOutcome           combinedOutcome = VSTestOutcome.Pending;

            CombineResults(combinedResults, ref combinedOutcome, inMemory);
            CombineResults(combinedResults, ref combinedOutcome, fromTheWire);

            GallioTestResult result;

            if (combinedResults.Count == 1)
            {
                result = combinedResults[0];
            }
            else
            {
                result = CreateAggregateRootTestResult(inMemory.Id.RunId, inMemory.Test);

                if (combinedResults.Count != 0)
                {
                    result.SetInnerResults(combinedResults);

                    DateTime startTime = DateTime.MaxValue;
                    DateTime endTime   = DateTime.MinValue;
                    TimeSpan duration  = TimeSpan.Zero;
                    foreach (GallioTestResult innerResult in combinedResults)
                    {
                        if (innerResult.StartTime < startTime)
                        {
                            startTime = innerResult.StartTime;
                        }
                        if (innerResult.EndTime > endTime)
                        {
                            endTime = innerResult.EndTime;
                        }
                        duration += innerResult.Duration;
                    }

                    result.SetTimings(startTime, endTime, duration);
                }
            }

            result.Outcome = combinedOutcome;
            return(result);
        }
Beispiel #7
0
        /// <summary>
        /// Closes the test result viewer for the specified Gallio result.
        /// </summary>
        /// <param name="result">The test result message.</param>
        public void CloseResultViewer(TestResultMessage result)
        {
            if (!TipShellExtension.IsInitialized)
            {
                return;
            }

            GallioTestResult gallioResult = result as GallioTestResult;

            if (gallioResult != null)
            {
                toolWindowManager.CloseToolWindow(GetWindowId(gallioResult));
            }
        }
Beispiel #8
0
        /// <summary>
        /// Invokes the test result viewer for the specified Gallio test.
        /// </summary>
        /// <param name="result">The result of the unit test.</param>
        public void InvokeResultViewer(TestResultMessage result)
        {
            if (!TipShellExtension.IsInitialized)
            {
                return;
            }

            GallioTestResult gallioResult = result as GallioTestResult;

            if (gallioResult != null)
            {
                TestResultWindow window = new TestResultWindow(gallioResult);
                toolWindowManager.OpenToolWindow(GetWindowId(gallioResult), window);
            }
        }
        private static GallioTestResult CreateTestResult(TestStepRun run, Guid runId, ITestElement test, bool includeTestStepRunXml)
        {
            var result = new GallioTestResult(runId, test);

            result.TestName = run.Step.FullName;
            result.Outcome  = GetOutcome(run.Result.Outcome);

            foreach (StructuredStream stream in run.TestLog.Streams)
            {
                string contents = stream.ToString();

                if (stream.Name == MarkupStreamNames.DebugTrace)
                {
                    result.DebugTrace += contents;
                }
                else if (stream.Name == MarkupStreamNames.ConsoleOutput)
                {
                    result.StdOut += contents;
                }
                else if (stream.Name == MarkupStreamNames.ConsoleError)
                {
                    result.StdErr += contents;
                }
                else if (stream.Name == MarkupStreamNames.Failures || stream.Name == MarkupStreamNames.Warnings)
                {
                    result.ErrorMessage += contents;
                }
                else
                {
                    result.DebugTrace += contents;
                }
            }

            result.SetTimings(run.StartTime, run.EndTime, run.Result.Duration);

            if (includeTestStepRunXml)
            {
                result.TestStepRunXml = TestStepRunToXml(run);
            }

            foreach (TestStepRun childRun in run.Children)
            {
                result.AddInnerResult(CreateTestResult(childRun, runId, test, false));
            }

            return(result);
        }
        protected override void Initialize()
        {
            foreach (ITestElement testElement in runContext.RunConfig.TestElements)
            {
                GallioTestElement gallioTestElement = testElement as GallioTestElement;
                if (gallioTestElement != null)
                {
                    testElementsById.Add(gallioTestElement.GallioTestId, gallioTestElement);
                }
            }

            Events.RunStarted += delegate(object sender, RunStartedEventArgs e)
            {
                // Change the status of all tests to Started so that all Gallio tests look "In Progress".
                // If we didn't do this, then there would be one "In Progress" test (the first one started)
                // and a whole bunch of "Pending" tests.  Visual Studio assumes that it controls the order
                // of execution of all tests but it cannot.  Behind the scenes we hijack the order of execution
                // when Visual Studio starts the first test.  Of course that test might not actually run
                // first but it will seem to be "In Progress" just the same.  Instead of misleading the user
                // as to which test is currently running, we just make them all look "In Progress" at once.  Ugh.
                foreach (GallioTestElement gallioTestElement in testElementsById.Values)
                {
                    TestStateEvent ev = new TestStateEvent(runContext.RunConfig.TestRun.Id, gallioTestElement.ExecutionId.Id, TestState.Started);
                    runContext.ResultSink.AddResult(ev);
                }
            };

            Events.TestStepFinished += delegate(object sender, TestStepFinishedEventArgs e)
            {
                // Submit a GallioTestResult for each primary run of a test case.
                // In the case of data-driven tests, we may submit multiple results that will later be merged.
                if (e.TestStepRun.Step.IsPrimary)
                {
                    GallioTestElement gallioTestElement = GetTestElement(e.Test);
                    if (gallioTestElement != null)
                    {
                        GallioTestResult result = GallioTestResultFactory.CreateTestResult(e.TestStepRun, runContext.RunConfig.TestRun.Id, gallioTestElement);
                        runContext.ResultSink.AddResult(result);
                    }
                }
            };
        }
Beispiel #11
0
        public override TestResult MergeResults(TestResult inMemory, TestResultMessage fromTheWire)
        {
            // The only type of message we should receive from the wire is a GallioTestResult.
            // However, we can receive multiple results in the case where the test is data-driven
            // so we need to merge them.
            GallioTestResult gallioInMemory = inMemory as GallioTestResult;

            if (gallioInMemory == null && inMemory != null)
            {
                gallioInMemory = new GallioTestResult(gallioInMemory);
            }

            GallioTestResult gallioFromTheWire = fromTheWire as GallioTestResult;

            if (gallioFromTheWire == null && fromTheWire is TestResult)
            {
                gallioFromTheWire = new GallioTestResult((TestResult)fromTheWire);
            }

            return(GallioTestResultFactory.Merge(gallioInMemory, gallioFromTheWire));
        }
        /// <summary>
        /// Gets a test step run from a given test result.
        /// </summary>
        /// <param name="result">A test result.</param>
        /// <returns>A test step run instance.</returns>
        public static TestStepRun GetTestStepRun(GallioTestResult result)
        {
            TestStepRun run = TestStepRunFromXml(result.TestStepRunXml);

#if VS100_OR_NEWER
            if (run != null)
            {
                foreach (CollectorDataEntry collectorEntry in result.CollectorDataEntries)
                {
                    if (collectorEntry != null)
                    {
                        var attachmentData = CreateAttachmentData(collectorEntry);
                        if (attachmentData != null)
                        {
                            run.TestLog.Attachments.Add(attachmentData.ToAttachmentData());
                        }
                    }
                }
            }
#endif
            return(run);
        }
        private static void CombineResults(List<GallioTestResult> combinedResults, ref VSTestOutcome combinedOutcome, GallioTestResult source)
        {
            CombineOutcome(ref combinedOutcome, source.Outcome);

            if (source.IsAggregateRoot)
            {
                foreach (GallioTestResult innerResult in source.InnerResults)
                {
                    combinedResults.Add(innerResult);
                    CombineOutcome(ref combinedOutcome, innerResult.Outcome);
                }
            }
            else
            {
                combinedResults.Add(source);
            }
        }
Beispiel #14
0
 private GallioTestResult(GallioTestResult result)
     : base(result)
 {
     testStepRunXml = result.testStepRunXml;
 }
 /// <summary>
 /// Creates an aggregate root test result.
 /// </summary>
 /// <param name="runId">The test run id.</param>
 /// <param name="test">The test element.</param>
 /// <returns>The test result.</returns>
 public static GallioTestResult CreateAggregateRootTestResult(Guid runId, ITestElement test)
 {
     var result = new GallioTestResult(runId, test);
     result.Outcome = VSTestOutcome.Pending;
     return result;
 }
        /// <summary>
        /// Gets the test step runs associated with a test result.
        /// </summary>
        public static IList<TestStepRun> GetTestStepRuns(GallioTestResult result)
        {
            List<TestStepRun> runs = new List<TestStepRun>();

            if (result.IsAggregateRoot)
            {
                foreach (GallioTestResult innerResult in result.InnerResults)
                {
                    TestStepRun run = GetTestStepRun(innerResult);
                    if (run != null)
                        runs.Add(run);
                }
            }
            else
            {
                TestStepRun run = GetTestStepRun(result);
                if (run != null)
                    runs.Add(run);
            }

            return runs;
        }
        private static void CombineResults(List <GallioTestResult> combinedResults, ref VSTestOutcome combinedOutcome, GallioTestResult source)
        {
            CombineOutcome(ref combinedOutcome, source.Outcome);

            if (source.IsAggregateRoot)
            {
                foreach (GallioTestResult innerResult in source.InnerResults)
                {
                    combinedResults.Add(innerResult);
                    CombineOutcome(ref combinedOutcome, innerResult.Outcome);
                }
            }
            else
            {
                combinedResults.Add(source);
            }
        }
        /// <summary>
        /// Merges Gallio test results.
        /// </summary>
        /// <param name="inMemory">The currently available test result, or null if none.</param>
        /// <param name="fromTheWire">The test result to add, or null if none.</param>
        /// <returns>The merged test result.</returns>
        public static GallioTestResult Merge(GallioTestResult inMemory, GallioTestResult fromTheWire)
        {
            if (fromTheWire == null)
                return inMemory;
            if (inMemory == null)
                return fromTheWire;

            List<GallioTestResult> combinedResults = new List<GallioTestResult>();
            VSTestOutcome combinedOutcome = VSTestOutcome.Pending;
            CombineResults(combinedResults, ref combinedOutcome, inMemory);
            CombineResults(combinedResults, ref combinedOutcome, fromTheWire);

            GallioTestResult result;
            if (combinedResults.Count == 1)
            {
                result = combinedResults[0];
            }
            else
            {
                result = CreateAggregateRootTestResult(inMemory.Id.RunId, inMemory.Test);

                if (combinedResults.Count != 0)
                {
                    result.SetInnerResults(combinedResults);

                    DateTime startTime = DateTime.MaxValue;
                    DateTime endTime = DateTime.MinValue;
                    TimeSpan duration = TimeSpan.Zero;
                    foreach (GallioTestResult innerResult in combinedResults)
                    {
                        if (innerResult.StartTime < startTime)
                            startTime = innerResult.StartTime;
                        if (innerResult.EndTime > endTime)
                            endTime = innerResult.EndTime;
                        duration += innerResult.Duration;
                    }

                    result.SetTimings(startTime, endTime, duration);
                }
            }

            result.Outcome = combinedOutcome;
            return result;
        }
Beispiel #19
0
 private static string GetWindowId(GallioTestResult result)
 {
     return("Gallio.VisualStudio.Tip.TestResult:" + result.Id.TestId);
 }
        /// <summary>
        /// Adds a test result as an inner result.
        /// </summary>
        /// <param name="testResult">The test result to add.</param>
        public void AddInnerResult(GallioTestResult testResult)
        {
            int oldLength = m_innerResults.Length;

            Array.Resize(ref m_innerResults, oldLength + 1);
            m_innerResults[oldLength] = testResult;
        }
 private GallioTestResult(GallioTestResult result)
     : base(result)
 {
     testStepRunXml = result.testStepRunXml;
 }
 /// <summary>
 /// Sets the list of inner results.
 /// </summary>
 /// <param name="testResults">The test results to set.</param>
 public void SetInnerResults(IList<GallioTestResult> testResults)
 {
     m_innerResults = new GallioTestResult[testResults.Count];
     for (int i = 0; i < testResults.Count; i++)
         m_innerResults[i] = testResults[i];
 }
Beispiel #23
0
 private static string GetWindowId(GallioTestResult result)
 {
     return "Gallio.VisualStudio.Tip.TestResult:" + result.Id.TestId;
 }
Beispiel #24
0
        public override TestResult MergeResults(TestResult inMemory, TestResultMessage fromTheWire)
        {
            // The only type of message we should receive from the wire is a GallioTestResult.
            // However, we can receive multiple results in the case where the test is data-driven
            // so we need to merge them.
            GallioTestResult gallioInMemory = inMemory as GallioTestResult;
            if (gallioInMemory == null && inMemory != null)
                gallioInMemory = new GallioTestResult(gallioInMemory);

            GallioTestResult gallioFromTheWire = fromTheWire as GallioTestResult;
            if (gallioFromTheWire == null && fromTheWire is TestResult)
                gallioFromTheWire = new GallioTestResult((TestResult)fromTheWire);

            return GallioTestResultFactory.Merge(gallioInMemory, gallioFromTheWire);
        }
        /// <summary>
        /// Gets a test step run from a given test result.
        /// </summary>
        /// <param name="result">A test result.</param>
        /// <returns>A test step run instance.</returns>
        public static TestStepRun GetTestStepRun(GallioTestResult result)
        {
            TestStepRun run = TestStepRunFromXml(result.TestStepRunXml);
#if VS100_OR_NEWER
            if (run != null)
            {
                foreach (CollectorDataEntry collectorEntry in result.CollectorDataEntries)
                {
                    if (collectorEntry != null)
                    {
                        var attachmentData = CreateAttachmentData(collectorEntry);
                        if(attachmentData != null)
                        {
                            run.TestLog.Attachments.Add(attachmentData.ToAttachmentData());
                        }
                    }
                }                
            }
#endif
            return run;
        }