public string CreateFile(RemoteTestExecutionResults results)
        {
            this.memoryStream = new MemoryStream();
            this.xmlWriter = new XmlTextWriter(new StreamWriter(memoryStream, System.Text.Encoding.UTF8));
            InitializeXmlFile(results);

            var outcome = results.UnitTestOutcome;

            var groupedByAssembly = outcome.TestResults.GroupBy(r => r.TestClass.Assembly.Name);

            foreach (var assembly in groupedByAssembly)
            {
                WriteAssemblyTestSuiteElement(new ComposedUnitTestOutcome() { TestResults = assembly.ToList() });
            }

            return TerminateXmlFile();
        }
        private void InitializeXmlFile(RemoteTestExecutionResults executionResults)
        {
            xmlWriter.Formatting = Formatting.Indented;
            xmlWriter.WriteStartDocument(false);
            xmlWriter.WriteComment("This file represents the results of running a test suite");

            xmlWriter.WriteStartElement("test-results");
            var outcome = executionResults.UnitTestOutcome;

            var errors = outcome.TestResults.Where(p => p.Result == UnitTestOutcome.Error);

            string name;
            if (executionResults.XapBuildResult is XapSourcedXapBuildResult)
            {
                name = (executionResults.XapBuildResult as XapSourcedXapBuildResult).SourceXapFullPath;
            }
            else
            {
                name = executionResults.XapBuildResult.ResultingXapFullPath;
            }

            xmlWriter.WriteAttributeString("name", name);

            xmlWriter.WriteAttributeString("total", outcome.TotalNumberOfTestsExecuted().ToString());
            xmlWriter.WriteAttributeString("errors", outcome.NumberOfErrors().ToString());
            xmlWriter.WriteAttributeString("failures", outcome.NumberOfFailures().ToString());
            xmlWriter.WriteAttributeString("not-run", outcome.NumberOfNotExecuted().ToString());
            xmlWriter.WriteAttributeString("inconclusive", outcome.NumberOfInconclusive().ToString());
            xmlWriter.WriteAttributeString("ignored", "0");
            xmlWriter.WriteAttributeString("skipped", "0");
            xmlWriter.WriteAttributeString("invalid", "0");

            DateTime now = DateTime.Now;
            xmlWriter.WriteAttributeString("date", XmlConvert.ToString(now, "yyyy-MM-dd"));
            xmlWriter.WriteAttributeString("time", XmlConvert.ToString(now, "HH:mm:ss"));
            WriteEnvironment();
            WriteCultureInfo();
        }
        private void OnFinished(RemoteTestExecutionResults executionResults)
        {
            var thereWereAnyTests = executionResults.UnitTestOutcome.TestResults.Any();
            var totalPassed = executionResults.UnitTestOutcome.TestResults.Count(p => p.Result == UnitTestOutcome.Passed);
            var totalFailed = executionResults.UnitTestOutcome.TestResults.Count(p => p.Result != UnitTestOutcome.Passed);

            _logger.Log(string.Format("Total Tests: {0} | Tests Passed: {1}. | Tests Failed: {2}",TestRunInformation.TotalNumberOfMethods,  totalPassed, totalFailed));

            if (executionResults.ExecutionErrors.Any())
            {
                _logger.Log("Errors occured during Remote Silverlight unit test execution:");
                foreach (var executionError in executionResults.ExecutionErrors)
                {
                    _logger.Log(string.Format("\t {0}", executionError));
                }
                _logger.Log("");
            }

            if (!thereWereAnyTests)
            {
                _logger.Log("Exiting (-1) because no Unit Tests were executed - this can't be right, right?");
                Environment.Exit(-1);
            }
            else if (executionResults.Aborted)
            {
                OnAborted(executionResults);
            }
            else if (executionResults.IsTimedOut)
            {
                OnTimedout(executionResults);
            }
            else if (totalFailed > 0)
            {
                _logger.Log("Exiting (-1) because some of the tests failed.");
                Environment.Exit(-1);
            }
            else
            {
                _logger.Log("Lighthouse Test Run completed successfully.");
                Environment.Exit(0);
            }
        }
 private void OnTimedout(RemoteTestExecutionResults executionResults)
 {
     _logger.Log(string.Format("Exiting (-1) because execution Timed Out while waiting for test result."));
     _logger.Log(string.Format("Methods that did not had execution results when timeout occured:"));
     foreach (var methodInfo in executionResults.MethodsStartedButNotFinished)
     {
         _logger.Log(string.Format("{0}.{1}", methodInfo.Class.Name, methodInfo.Method.MethodName));
     }
     Environment.Exit(-1);
 }
 private void OnAborted(RemoteTestExecutionResults executionResults)
 {
     _logger.Log(string.Format("Exiting (-1) because execution was Aborted."));
     Environment.Exit(-1);
 }