Esempio n. 1
0
        private CoberturaClass GetCoberturaClassFromDotCoverType(DotCoverType dotCoverType, string namespaceName)
        {
            // TODO Partial classes spread over multiple files are not currently handled

            var coberturaClass = new CoberturaClass();

            coberturaClass.BranchRate = 0;
            coberturaClass.Complexity = 0;

            coberturaClass.FileName = GetRelativeFilenameForDotCoverType(dotCoverType);

            coberturaClass.LineRate = dotCoverType.CoveragePercent * 0.01m;
            coberturaClass.Name     = namespaceName + "." + dotCoverType.Name;

            coberturaClass.Methods = dotCoverType.Methods
                                     .Select(GetCoberturaMethodForDotCoverType)
                                     .ToList();

            coberturaClass.Lines = coberturaClass.Methods
                                   .SelectMany(m => m.Lines)
                                   .OrderBy(l => l.Number)
                                   .ToList();

            return(coberturaClass);
        }
Esempio n. 2
0
        private string GetRelativeFilenameForDotCoverType(DotCoverType dotCoverType)
        {
            var fileIndex = dotCoverType.Methods
                            .SelectMany(m => m.Statements)
                            .Select(s => s.FileIndex)
                            .FirstOrDefault();

            if (fileIndex == default) // Luckily, default int (0) is not used as file index by dotCover
            {
                if (dotCoverType.NestedTypes != null)
                {
                    foreach (var nestedType in dotCoverType.NestedTypes)
                    {
                        var nestedTypeFileName = GetRelativeFilenameForDotCoverType(nestedType);
                        if (nestedTypeFileName != null)
                        {
                            return(nestedTypeFileName);
                        }
                    }
                }

                return(null);
            }

            var file         = _report.Files.First(f => f.Index == fileIndex);
            var fullFilePath = file.Name;

            var relativePart = fullFilePath
                               .Substring(_baseDirectory.Length)
                               .TrimStart('/')
                               .TrimStart('\\');

            return(relativePart);
        }
Esempio n. 3
0
        private DotCoverType GetTypeFromElement(XElement typeElement)
        {
            var dotCoverType = new DotCoverType
            {
                CoveragePercent   = typeElement.GetAttributeDecimalValue("CoveragePercent"),
                CoveredStatements = typeElement.GetAttributeIntValue("CoveredStatements"),
                TotalStatements   = typeElement.GetAttributeIntValue("TotalStatements"),
                Name    = typeElement.GetAttributeStringValue("Name"),
                Methods = typeElement.Elements()
                          .Where(e => e.Name.LocalName == "Method")
                          .Select(GetMethodFromElement)
                          .ToList(),
                NestedTypes = typeElement.Elements()
                              .Where(e => e.Name.LocalName == "Type")
                              .Select(GetTypeFromElement)
                              .ToList()
            };

            return(dotCoverType);
        }