public void Coverage_MultipleLinesCovered_AllValuesCorrect() { var sourceText = "Line1\nLine2\nLine3"; var coverageFile = new CoverageFile(); coverageFile.Source = sourceText; coverageFile.Record(1, 1); coverageFile.Record(3, 3); coverageFile.Coverage[0].Should().Be(1); coverageFile.Coverage[1].Should().Be(null); coverageFile.Coverage[2].Should().Be(3); }
public void Coverage_NoSource_LengthIsLargestLineRecorded() { var coverageFile = new CoverageFile(); coverageFile.Record(20, 3); coverageFile.Coverage.Length.Should().Be(20); }
public override List <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); var visits = int.Parse(sequencePoint.Attribute("vc").Value); 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); }
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); }