private string EnsureTestName(TestResult test)
 {
     string name = test.Name;
     if (string.IsNullOrWhiteSpace(name))
     {
         name = "Test" + testCounter;
     }
     return name.EscapeTeamCitySpecialCharacters();
 }
        private bool HandleTestyDroidXmlReportResult(string key, string value)
        {
            // The result kind section can also contain test name.
            if (key.Trim() != "##TestyDroidTestsReport")
            {
                return false;
            }
           
            var reportPath = value;
            var adb = _adbFactory.GetAndroidDebugBridge();
            var fileContents = adb.ReadFileContents(_device, reportPath);

            XmlDocument report = new XmlDocument();
            report.LoadXml(fileContents);

            var testResults = report.GetElementsByTagName("TestResult");
            foreach (XmlElement testResult in testResults)
            {
                var testName = testResult.GetAttribute("Name");
                var testStatus = testResult.GetAttribute("Status");
                var testDuration = testResult.GetAttribute("Duration");
                var testMessage = testResult.GetAttribute("Message");
                var stackTrace = testResult.InnerText;

                TestResultKind resultKind;
                switch (testStatus)
                {
                    case "Failed":
                        resultKind = TestResultKind.Failure;
                        break;
                    case "Skipped":
                        resultKind = TestResultKind.Skipped;
                        break;
                    case "Inconclusive":
                        resultKind = TestResultKind.Inconclusive;
                        break;
                    case "Passed":
                        resultKind = TestResultKind.Passed;
                        break;
                    default:
                        throw new FormatException("Could not parse the result type in the test report: " + testStatus);
                }

                var test = new TestResult(testName, resultKind);
                test.Message = testMessage;
                test.StackTrace = stackTrace;
                test.Duration = TimeSpan.Parse(testDuration);

                this._TestReportTestResults.AddTest(test);

            }

            return true;

        }
 private void AppendTestsFromCount(TestResultKind kind, string resultDetailSection)
 {
     int count;
     if (resultDetailSection.Length == 1)
     {
         if (int.TryParse(resultDetailSection, out count))
         {
             for (int i = 0; i < count; i++)
             {
                 var dummyTestResult = new TestResult(string.Empty, kind);
                 TestResults.AddTest(dummyTestResult);
             }
         }
     }
 }
        private bool HandleXamarinTestSuiteResult(string key, string value)
        {
            // The result kind section can also contain test name.

            string resultTestName = string.Empty;
            string resultKind = string.Empty;

            if (key.Contains(":"))
            {
                var resultKindSectionSplit = key.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
                resultKind = resultKindSectionSplit[0].Trim();
                resultTestName = resultKindSectionSplit[1].Trim();
            }
            else
            {
                resultKind = key.Trim();
            }
          
            switch (resultKind)
            {
                case "failure":
                    var testResult = new TestResult(resultTestName, TestResultKind.Failure);
                    testResult.Message = value;
                    this.TestResults.AddTest(testResult);
                    break;

                case "passed":
                    AppendTestsFromCount(TestResultKind.Passed, value);
                    break;

                case "skipped":
                    AppendTestsFromCount(TestResultKind.Skipped, value);
                    break;

                case "inconclusive":
                    AppendTestsFromCount(TestResultKind.Inconclusive, value);
                    break;

                case "failed":
                    break;

                default:
                    return false;

            }

            return true;
        }
 private void ReportTestStarted(TestResult failedTest)
 {
     var name = EnsureTestName(failedTest);
     string testStartedMessage = string.Format("##teamcity[testStarted name='{0}']", name);
     _Writer(testStartedMessage);
 }
 private void ReportTestFailed(TestResult failedTest)
 {
     var name = EnsureTestName(failedTest);
     string testFailedMessage = string.Format("##teamcity[testFailed name='{0}' message='{1}' details='{2}']", name, failedTest.Message.EscapeTeamCitySpecialCharacters(), failedTest.StackTrace.EscapeTeamCitySpecialCharacters());
     _Writer(testFailedMessage);
 }
 private void ReportTestIgnored(TestResult test)
 {
     var name = EnsureTestName(test);
     string testIgnoredMessage = string.Format("##teamcity[testIgnored name='{0}' message='{1}']", name, "Ignored.");
     _Writer(testIgnoredMessage);
 }