public override CoveragePoint[] Instrument(string filename) { this.instrumentcalled = true; CoveragePoint[] points = new CoveragePoint[1]; points[0] = new CoveragePoint(); return points; }
public void Setup() { this.points = new CoveragePointCollection(); this.point = new CoveragePoint(); this.point.Hit = true; this.point.LineNumber = 10; this.point1 = new CoveragePoint(); this.point1.Hit = false; this.point1.LineNumber = 20; this.point2 = new CoveragePoint(); this.point2.Hit = false; this.point2.LineNumber = 30; }
private void SaveCoverage(CoveragePoint[] points) { Coverage coverage = new Coverage(this.Settings, points); string fileName = this.Settings.ExpectedFilename; // create directory before writing file if (!Directory.Exists(Path.GetDirectoryName(fileName))) { Directory.CreateDirectory(Path.GetDirectoryName(fileName)); } using (FileStream outputstream = new FileStream(fileName, FileMode.Create)) { Coverage.SaveCoverage(outputstream, coverage); } }
public void TestInstrumentWithPointsReturned() { CoveragePoint[] parserpoints = new CoveragePoint[1]; parserpoints[0] = new CoveragePoint(); this.parser.CoveragePoints = parserpoints; string filename = Path.GetTempFileName(); Assert.IsTrue(File.Exists(filename)); string instrumentedfilename = filename + ".instrumented"; Assert.IsFalse(File.Exists(instrumentedfilename)); CoveragePoint[] points = this.instrumenter.Instrument(filename); Assert.AreEqual(1, points.Length); Assert.IsTrue(File.Exists(filename)); Assert.IsTrue(File.Exists(instrumentedfilename)); using(StreamReader stream = File.OpenText(filename)) { Assert.AreEqual(MockParser.PARSED_TEXT + "\r\n", stream.ReadToEnd()); } using(StreamReader stream = File.OpenText(instrumentedfilename )) { Assert.IsFalse((MockParser.PARSED_TEXT + "\r\n").Equals( stream.ReadToEnd())); } points = this.instrumenter.Instrument(filename); Assert.IsTrue(File.Exists(filename)); Assert.IsTrue(File.Exists(instrumentedfilename)); using(StreamReader stream = File.OpenText(instrumentedfilename )) { Assert.IsFalse((MockParser.PARSED_TEXT + "\r\n").Equals( stream.ReadToEnd())); } this.instrumenter.Deinstrument(filename); Assert.IsFalse(File.Exists(instrumentedfilename)); }
/// <summary> /// Gets the coverage code. /// </summary> /// <param name="settings">The settings.</param> /// <param name="point">The point.</param> /// <returns></returns> public string GetCoverageCode(ReportSettings settings, CoveragePoint point) { string qualifiedCall = "SharpCover.Results.Add("; return String.Format(qualifiedCall + "@\"{0}\", @\"{1}\", {2})", new object[] { settings.ReportName, settings.ActualFilename, point.AbsoluteNumber }); }
private string AddCoveragePoint(int Index) { CoveragePoint point = new CoveragePoint(filename, GetNamespace(Index), coveragepoints.Count + 1, baseCoveragePoint, false); coveragepoints.Add(point); point.LineNumber = IndexToLineNumber(Index); return GetCoverageCode(this.settings, point); }
/// <summary> /// Parses the specified filename. /// </summary> /// <param name="filename">The filename.</param> /// <returns></returns> public string Parse(string filename) { XmlDocument doc = new XmlDocument(); doc.Load(filename); XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable); nsmgr.AddNamespace("def", "http://schemas.microsoft.com/developer/msbuild/2003"); XmlElement assemblyName = (XmlElement)doc.DocumentElement.SelectSingleNode("def:PropertyGroup/def:AssemblyName", nsmgr); if (string.Compare(assemblyName.Value, typeof(Results).Assembly.GetName().Name, StringComparison.InvariantCultureIgnoreCase) == 0) { // don't extend yourself return null; } string assemblyReference = typeof(Results).Assembly.FullName; XmlElement itemGroup = (XmlElement)doc.DocumentElement.SelectSingleNode("def:ItemGroup", nsmgr); XmlElement reference = (XmlElement)itemGroup.SelectSingleNode(string.Format("def:Reference[@Include='{0}']", assemblyReference), nsmgr); string fileContent = null; if (reference == null) { reference = doc.CreateElement("Reference"); XmlAttribute attr = doc.CreateAttribute("Include"); attr.Value = assemblyReference; reference.Attributes.Append(attr); XmlElement specificVersion = doc.CreateElement("SpecificVersion"); XmlText specificVersionValue = doc.CreateTextNode(bool.FalseString); specificVersion.AppendChild(specificVersionValue); reference.AppendChild(specificVersion); XmlElement hintPath = doc.CreateElement("HintPath"); XmlText hintPathValue = doc.CreateTextNode(typeof(Results).Assembly.Location); hintPath.AppendChild(hintPathValue); reference.AppendChild(hintPath); itemGroup.AppendChild(reference); using (MemoryStream ms = new MemoryStream()) { StreamWriter writer = new StreamWriter(ms, Encoding.UTF8); doc.Save(writer); ms.Seek(0, SeekOrigin.Begin); using (StreamReader sr = new StreamReader(ms, Encoding.UTF8, false)) { fileContent = sr.ReadToEnd(); } } // HACK: remove empty xmlns attribute! fileContent = fileContent.Replace(" xmlns=\"\"", string.Empty); } coveragePoint = new CoveragePoint(filename, null, -1, -1, false); return fileContent; }
private void UninstrumentFiles(CoveragePoint[] points) { Hashtable done = new Hashtable(); foreach (CoveragePoint point in points) { // Check if we've already deinstrumented the file associated with this point if (done[point.Filename] != null) continue; else { done[point.Filename] = point.Filename; Trace.WriteLineIf(Logger.OutputType.TraceInfo, "Deinstrumenting " + point.Filename); this.instrumenter.Deinstrument(point.Filename); } } }
/// <summary> /// Adds the specified point. /// </summary> /// <param name="point">The point.</param> /// <returns></returns> public int Add(CoveragePoint point) { return base.InnerList.Add(point); }
/// <summary> /// Removes the specified point. /// </summary> /// <param name="point">The point.</param> public void Remove(CoveragePoint point) { base.InnerList.Remove(point); }
/// <summary> /// Inserts the specified index. /// </summary> /// <param name="index">The index.</param> /// <param name="point">The point.</param> public void Insert(int index, CoveragePoint point) { base.InnerList.Insert(index, point); }