public void Coverage_NoLinesCovered_StillHasCorrectLength()
        {
            var sourceText = "Line1\nLine2\nLine3";
            var coverageFile = new CoverageFile();

            coverageFile.Source = sourceText;

            coverageFile.Coverage.Count().Should().Be(3);
        }
        public void Source_SetToGet_MaintainsToUnixLineBreaks()
        {
            var sourceText = "Line1\nLine2\nLine3";
            var coverageFile = new CoverageFile();

            coverageFile.Source = sourceText;

            coverageFile.Source.Should().Be("Line1\nLine2\nLine3");
        }
        public void Coverage_NoLinesCovered_AllValuesNull()
        {
            var sourceText = "Line1\nLine2\nLine3";
            var coverageFile = new CoverageFile();

            coverageFile.Source = sourceText;

            coverageFile.Coverage.ToArray()[0].Should().Be(null);
            coverageFile.Coverage.ToArray()[1].Should().Be(null);
            coverageFile.Coverage.ToArray()[2].Should().Be(null);
        }
예제 #4
0
        public override IEnumerable <CoverageFile> Generate()
        {
            var files = new List <CoverageFile>();

            if (Report == null || Report.Root == null)
            {
                return(files);
            }

            foreach (var module in Report.Root.XPathSelectElements("//Modules/Module"))
            {
                var skippedAttr = module.Attribute("skippedDueTo");
                if (skippedAttr != null && skippedAttr.Value.IsNotBlank())
                {
                    continue;
                }

                foreach (var file in module.XPathSelectElements("./Files/File"))
                {
                    var fileid   = file.Attribute("uid").Value;
                    var fullPath = file.Attribute("fullPath").Value;

                    var coverageFile = new CoverageFile
                    {
                        Path   = fullPath.ToUnixPath(),
                        Source = FileSystem.ReadFileText(fullPath)
                    };

                    foreach (var @class in module.XPathSelectElements("./Classes/Class"))
                    {
                        foreach (var method in @class.XPathSelectElements("./Methods/Method"))
                        {
                            foreach (var sequencePoint in method.XPathSelectElements("./SequencePoints/SequencePoint"))
                            {
                                var sequenceFileId = sequencePoint.Attribute("fileid").Value;
                                if (fileid == sequenceFileId)
                                {
                                    var line   = int.Parse(sequencePoint.Attribute("sl").Value, CultureInfo.CurrentCulture);
                                    var visits = int.Parse(sequencePoint.Attribute("vc").Value, CultureInfo.CurrentCulture);

                                    coverageFile.Record(line, visits);
                                }
                            }
                        }
                    }

                    files.Add(coverageFile);
                }
            }

            return(files);
        }
        public void Coverage_OneLineCovered_AllValuesCorrect()
        {
            var sourceText = "Line1\nLine2\nLine3";
            var coverageFile = new CoverageFile();

            coverageFile.Source = sourceText;

            coverageFile.Record(1, 1);

            coverageFile.Coverage.ToArray()[0].Should().Be(1);
            coverageFile.Coverage.ToArray()[1].Should().Be(null);
            coverageFile.Coverage.ToArray()[2].Should().Be(null);
        }
예제 #6
0
        public override IEnumerable<CoverageFile> Generate()
        {
            var files = new List<CoverageFile>();

            if (Report == null || Report.Root == null) return files;

            foreach (var module in Report.Root.XPathSelectElements("//Modules/Module"))
            {
                var skippedAttr = module.Attribute("skippedDueTo");
                if (skippedAttr != null && skippedAttr.Value.IsNotBlank()) continue;

                foreach (var file in module.XPathSelectElements("./Files/File"))
                {
                    var fileid = file.Attribute("uid").Value;
                    var fullPath = file.Attribute("fullPath").Value;

                    var coverageFile = new CoverageFile
                    {
                        Path = fullPath.ToUnixPath()
                    };

                    foreach (var @class in module.XPathSelectElements("./Classes/Class"))
                    {
                        foreach (var method in @class.XPathSelectElements("./Methods/Method"))
                        {
                            foreach(var sequencePoint in method.XPathSelectElements("./SequencePoints/SequencePoint"))
                            {
                                var sequenceFileId = sequencePoint.Attribute("fileid").Value;
                                if (fileid == sequenceFileId)
                                {
                                    var line = int.Parse(sequencePoint.Attribute("sl").Value, CultureInfo.CurrentCulture);
                                    var visits = int.Parse(sequencePoint.Attribute("vc").Value, CultureInfo.CurrentCulture);

                                    coverageFile.Record(line, visits);
                                }
                            }
                        }
                    }

                    files.Add(coverageFile);
                }
            }

            return files;
        }
        public override IEnumerable <CoverageFile> Generate()
        {
            var files = new List <CoverageFile>();

            if (Report == null || Report.Root == null)
            {
                return(files);
            }

            var basePathEl = Report.Root.XPathSelectElement("//sources/source");
            var basePath   = string.Empty;

            if (basePathEl != null && basePathEl.Value.IsNotBlank())
            {
                basePath = basePathEl.Value;
            }

            foreach (var package in Report.Root.XPathSelectElements("//packages/package"))
            {
                foreach (var cl in package.XPathSelectElements("./classes/class"))
                {
                    var filenameAttrib = cl.Attribute("filename");
                    var fileName       = filenameAttrib.Value;
                    var path           = Path.Combine(basePath, fileName);

                    var coverageFile = new CoverageFile()
                    {
                        Path = path.ToUnixPath()
                    };

                    foreach (var line in cl.XPathSelectElements("./lines/line"))
                    {
                        var lineNumber = int.Parse(line.Attribute("number").Value);
                        var hits       = int.Parse(line.Attribute("hits").Value);

                        coverageFile.Record(lineNumber, hits);
                    }

                    files.Add(coverageFile);
                }
            }

            return(files);
        }
        public void Coverage_NoSource_LengthIsLargestLineRecorded()
        {
            var coverageFile = new CoverageFile();

            coverageFile.Record(20, 3);

            coverageFile.Coverage.Count().Should().Be(20);
        }