示例#1
0
        private IEnumerable <CodeCoverageStatistics> ReadDataFromNodes(XmlDocument doc, string summaryXmlLocation)
        {
            var listCoverageStats = new List <CodeCoverageStatistics>();

            if (doc == null)
            {
                return(null);
            }

            XmlNode reportNode = doc.SelectSingleNode("coverage");

            if (reportNode != null)
            {
                if (reportNode.Attributes != null)
                {
                    CodeCoverageStatistics coverageStatisticsForLines = GetCCStats(labelTag: _linesCovered, coveredTag: _linesCoveredTag, validTag: _linesValidTag,
                                                                                   priorityTag: "line", summaryXmlLocation: summaryXmlLocation, reportNode: reportNode);

                    if (coverageStatisticsForLines != null)
                    {
                        listCoverageStats.Add(coverageStatisticsForLines);
                    }

                    CodeCoverageStatistics coverageStatisticsForBranches = GetCCStats(labelTag: _branchesCovered, coveredTag: _branchesCoveredTag, validTag: _branchesValidTag,
                                                                                      priorityTag: "branch", summaryXmlLocation: summaryXmlLocation, reportNode: reportNode);

                    if (coverageStatisticsForBranches != null)
                    {
                        listCoverageStats.Add(coverageStatisticsForBranches);
                    }
                }
            }

            return(listCoverageStats.AsEnumerable());
        }
示例#2
0
        private async Task <double?> GetCodeCoverageForBuild(String projectId, int buildId)
        {
            _logger.LogInformation($"[{nameof(GetCodeCoverageForBuild)}] BEGIN {{project:{projectId}, buildId:{buildId}}}");
            try
            {
                const string CoverageStatsLabel = "Lines";

                GitHttpClient            gitClient  = _connection.GetClient <GitHttpClient>();
                TestManagementHttpClient testClient = _connection.GetClient <TestManagementHttpClient>();
                //Получить покрытие кода по id билда
                var codeCoverage = await testClient.GetCodeCoverageSummaryAsync(projectId, buildId);

                _logger.LogInformation($"[{nameof(GetCodeCoverageForBuild)}] GetCodeCoverageSummaryAsync(project:{projectId}, buildId:{buildId}) success!");

                CodeCoverageStatistics CoverageStats = null;
                if (codeCoverage.CoverageData.Count > 0)
                {
                    // TODO: Переделать на случай если будет несколько CoverageData
                    CoverageStats = codeCoverage?.CoverageData[0].CoverageStats
                                    .FirstOrDefault(x => x.Label.Equals(CoverageStatsLabel, StringComparison.OrdinalIgnoreCase));
                }

                return(CoverageStats?.Covered * 100.00 / CoverageStats?.Total);
            }
            catch (Exception e)
            {
                _logger.LogError($"[{nameof(GetCodeCoverageForBuild)}] ERROR: {e.ToString()}");
                return(null);
            }
            finally
            {
                _logger.LogInformation($"[{nameof(GetCodeCoverageForBuild)}] COMPLETED");
            }
        }
示例#3
0
        private async Task WriteBuildDetails(Build build, List <TestRun> testRuns, CodeCoverageSummary coverage, ISink sink)
        {
            CodeCoverageStatistics linesCovered = coverage?.CoverageData?.FirstOrDefault()?.CoverageStats?.FirstOrDefault(s => s.Label == LinesCoverageStatsLabel);

            int totalTests   = testRuns?.Sum(r => r.TotalTests) ?? 0;
            int passedTests  = testRuns?.Sum(r => r.PassedTests) ?? 0;
            int ignoredTests = testRuns?.Sum(r => r.IncompleteTests + r.NotApplicableTests + r.UnanalyzedTests) ?? 0;

            await sink.Write(
                new string[]
            {
                build.Id.ToString(),
                build.BuildNumber,
                build.Definition?.Name,
                build.RequestedBy?.DisplayName,
                build.RequestedFor?.DisplayName,
                build.Repository?.Name,
                build.QueueTime?.ToString("s"),
                build.StartTime?.ToString("s"),
                build.FinishTime?.ToString("s"),
                build.SourceBranch,
                build.SourceVersion,
                build.Result.ToString(),
                totalTests.ToString(),
                passedTests.ToString(),
                ignoredTests.ToString(),
                linesCovered?.Covered.ToString(),
                linesCovered?.Total.ToString()
            });
        }
        private IEnumerable<CodeCoverageStatistics> ReadDataFromNodes(XmlDocument doc, string summaryXmlLocation)
        {
            var listCoverageStats = new List<CodeCoverageStatistics>();

            if (doc == null)
            {
                return null;
            }

            //read data from report nodes
            XmlNode reportNode = doc.SelectSingleNode("report");
            if (reportNode != null)
            {
                XmlNodeList counterNodeList = doc.SelectNodes("/report/counter");
                if (counterNodeList != null)
                {

                    foreach (XmlNode counterNode in counterNodeList)
                    {
                        var coverageStatistics = new CodeCoverageStatistics();

                        if (counterNode.Attributes != null)
                        {
                            if (counterNode.Attributes["type"] != null)
                            {
                                coverageStatistics.Label = ToTitleCase(counterNode.Attributes["type"].Value);
                                coverageStatistics.Position = CodeCoverageUtilities.GetPriorityOrder(coverageStatistics.Label);
                            }

                            if (counterNode.Attributes[_covered] != null)
                            {
                                float covered;
                                if (!float.TryParse(counterNode.Attributes[_covered].Value, out covered))
                                {
                                    throw new InvalidDataException(StringUtil.Loc("InvalidValueInXml", _covered, summaryXmlLocation));
                                }
                                coverageStatistics.Covered = (int)covered;
                                if (counterNode.Attributes[_missed] != null)
                                {
                                    float missed;
                                    if (!float.TryParse(counterNode.Attributes[_missed].Value, out missed))
                                    {
                                        throw new InvalidDataException(StringUtil.Loc("InvalidValueInXml", _missed, summaryXmlLocation));
                                    }
                                    coverageStatistics.Total = (int)missed + (int)covered;
                                }
                            }
                        }

                        listCoverageStats.Add(coverageStatistics);
                    }
                }
            }
            return listCoverageStats.AsEnumerable();
        }
示例#5
0
        private IEnumerable <CodeCoverageStatistics> ReadDataFromNodes(XmlDocument doc, string summaryXmlLocation)
        {
            var listCoverageStats = new List <CodeCoverageStatistics>();

            if (doc == null)
            {
                return(null);
            }

            //read data from report nodes
            XmlNode reportNode = doc.SelectSingleNode("report");

            if (reportNode != null)
            {
                XmlNodeList counterNodeList = doc.SelectNodes("/report/counter");
                if (counterNodeList != null)
                {
                    foreach (XmlNode counterNode in counterNodeList)
                    {
                        var coverageStatistics = new CodeCoverageStatistics();

                        if (counterNode.Attributes != null)
                        {
                            if (counterNode.Attributes["type"] != null)
                            {
                                coverageStatistics.Label    = ToTitleCase(counterNode.Attributes["type"].Value);
                                coverageStatistics.Position = CodeCoverageUtilities.GetPriorityOrder(coverageStatistics.Label);
                            }

                            if (counterNode.Attributes[_covered] != null)
                            {
                                float covered;
                                if (!float.TryParse(counterNode.Attributes[_covered].Value, out covered))
                                {
                                    throw new InvalidDataException(StringUtil.Loc("InvalidValueInXml", _covered, summaryXmlLocation));
                                }
                                coverageStatistics.Covered = (int)covered;
                                if (counterNode.Attributes[_missed] != null)
                                {
                                    float missed;
                                    if (!float.TryParse(counterNode.Attributes[_missed].Value, out missed))
                                    {
                                        throw new InvalidDataException(StringUtil.Loc("InvalidValueInXml", _missed, summaryXmlLocation));
                                    }
                                    coverageStatistics.Total = (int)missed + (int)covered;
                                }
                            }
                        }

                        listCoverageStats.Add(coverageStatistics);
                    }
                }
            }
            return(listCoverageStats.AsEnumerable());
        }
示例#6
0
        /// <summary>
        /// Add coverage statistics for a run to summary.
        /// </summary>
        /// <param name="label">Label for the statistics.</param>
        /// <param name="total">Total entities.</param>
        /// <param name="covered">Number of entities covered.</param>
        /// <param name="priority">Priority order for the statistics.</param>
        public void AddCoverageStatistics(string label, int total, int covered, Priority priority)
        {
            var stats = new CodeCoverageStatistics();

            stats.Covered  = covered;
            stats.Total    = total;
            stats.Position = (int)priority;
            stats.Label    = label;

            this.CodeCoverageData.CoverageStats.Add(stats);
        }
示例#7
0
        private CodeCoverageStatistics GetCCStats(string labelTag, string coveredTag, string validTag, string priorityTag, string summaryXmlLocation, XmlNode reportNode)
        {
            CodeCoverageStatistics coverageStatistics = null;

            if (reportNode.Attributes[coveredTag] != null && reportNode.Attributes[validTag] != null)
            {
                coverageStatistics          = new CodeCoverageStatistics();
                coverageStatistics.Label    = labelTag;
                coverageStatistics.Position = CodeCoverageUtilities.GetPriorityOrder(priorityTag);

                coverageStatistics.Covered = (int)ParseFromXML(coveredTag, summaryXmlLocation, reportNode);

                coverageStatistics.Total = (int)ParseFromXML(validTag, summaryXmlLocation, reportNode);
            }

            return(coverageStatistics);
        }
        private CodeCoverageStatistics GetCCStats(string labelTag, string coveredTag, string validTag, string priorityTag, string summaryXmlLocation, XmlNode reportNode)
        {
            CodeCoverageStatistics coverageStatistics = null;

            if (reportNode.Attributes[coveredTag] != null && reportNode.Attributes[validTag] != null)
            {
                coverageStatistics = new CodeCoverageStatistics();
                coverageStatistics.Label = labelTag;
                coverageStatistics.Position = CodeCoverageUtilities.GetPriorityOrder(priorityTag);

                coverageStatistics.Covered = (int)ParseFromXML(coveredTag, summaryXmlLocation, reportNode);

                coverageStatistics.Total = (int)ParseFromXML(validTag, summaryXmlLocation, reportNode);
            }

            return coverageStatistics;
        }