Manages the list of markers and provides ways to retrieve markers for specific positions.
 /// <summary>
 /// Adds a single marker for the XPathNodeMatch.
 /// </summary>
 public static void AddMarker(MarkerStrategy markerStrategy, XPathNodeMatch node)
 {
     if (node.HasLineInfo() && node.Value.Length > 0) {
         LineSegment lineSegment = markerStrategy.Document.GetLineSegment(node.LineNumber);
         markerStrategy.AddMarker(new XPathNodeTextMarker(lineSegment.Offset + node.LinePosition, node));
     }
 }
		public void SetUpTestFixture()
		{
			try {
				string configFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "NCoverAddIn.Tests");
				PropertyService.InitializeService(configFolder, Path.Combine(configFolder, "data"), "NCoverAddIn.Tests");
			} catch (Exception) {}
			
			IDocument document = MockDocument.Create();
			string code = "\t\t{\r\n" +
				"\t\t\tint count = 0;\r\n" +
				"\t\t}\r\n";
			document.TextContent = code;
			markerStrategy = new MarkerStrategy(document);
			
			string xml = "<PartCoverReport>\r\n" +
				"\t<File id=\"1\" url=\"c:\\Projects\\Foo\\FooTestFixture.cs\"/>\r\n" +
				"\t<Assembly id=\"1\" name=\"Foo.Tests\" module=\"C:\\Projects\\Test\\bin\\Foo.Tests.DLL\" domain=\"test-domain-Foo.Tests.dll\" domainIdx=\"1\" />\r\n" +
				"\t<Type name=\"Foo.Tests.FooTestFixture\" asmref=\"1\">\r\n" +
				"\t\t<Method name=\"SimpleTest\">\r\n" +
				"\t\t\t<pt visit=\"1\" sl=\"1\" sc=\"3\" el=\"1\" ec=\"4\" fid=\"1\" />\r\n" +
				"\t\t\t<pt visit=\"1\" sl=\"2\" sc=\"4\" el=\"2\" ec=\"18\" fid=\"1\" />\r\n" +
				"\t\t\t<pt visit=\"0\" sl=\"3\" sc=\"3\" el=\"3\" ec=\"4\" fid=\"1\" />\r\n" +
				"\t\t</Method>\r\n" +
				"\t</Type>\r\n" +
				"</PartCoverReport>";
			CodeCoverageResults results = new CodeCoverageResults(new StringReader(xml));
			CodeCoverageMethod method = results.Modules[0].Methods[0];
			CodeCoverageHighlighter highlighter = new CodeCoverageHighlighter();
			highlighter.AddMarkers(markerStrategy, method.SequencePoints);	
			
			// Add non-code coverage markers.
			markerStrategy.AddMarker(new TextMarker(0, 2, TextMarkerType.Underlined));
			markerStrategy.AddMarker(new TextMarker(4, 5, TextMarkerType.Underlined));
		}
		public void Init()
		{
			try {
				string configFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "NCoverAddIn.Tests");
				PropertyService.InitializeService(configFolder, Path.Combine(configFolder, "data"), "NCoverAddIn.Tests");
			} catch (Exception) {}
			
			IDocument document = MockDocument.Create();
			document.TextContent = "abcdefg\r\nabc";
			MarkerStrategy markerStrategy = new MarkerStrategy(document);
			
			string xml = "<PartCoverReport>\r\n" +
				"\t<File id=\"1\" url=\"c:\\Projects\\XmlEditor\\Test\\Schema\\SingleElementSchemaTestFixture.cs\" />\r\n" +
				"\t<Assembly id=\"1\" name=\"XmlEditor.Tests\" module=\"C:\\Projects\\Test\\XmlEditor.Tests\\bin\\XmlEditor.Tests.DLL\" domain=\"test-domain-XmlEditor.Tests.dll\" domainIdx=\"1\" />\r\n" +
				"\t<Type name=\"XmlEditor.Tests.Schema.SingleElementSchemaTestFixture\" asmref=\"1\">\r\n" +
				"\t\t<Method name=\"GetSchema\">\r\n" +
				"\t\t<pt visit=\"1\" fid=\"1\" sl=\"1\" sc=\"1\" el=\"1\" ec=\"9\"/>\r\n" +
				"\t\t<pt visit=\"1\" fid=\"1\" sl=\"1\" sc=\"1\" el=\"1\" ec=\"0\" />\r\n" +
				"\t\t<pt visit=\"1\" fid=\"1\" sl=\"1\" sc=\"1\" el=\"1\" ec=\"-1\" />\r\n" +
				"\t\t<pt visit=\"1\" fid=\"1\" sl=\"1\" sc=\"3\" el=\"1\" ec=\"2\" />\r\n" +
				"\t\t</Method>\r\n" +
				"\t</Type>\r\n" +
				"</PartCoverReport>";
			
			CodeCoverageResults results = new CodeCoverageResults(new StringReader(xml));
			CodeCoverageMethod method = results.Modules[0].Methods[0];
			CodeCoverageHighlighter highlighter = new CodeCoverageHighlighter();
			highlighter.AddMarkers(markerStrategy, method.SequencePoints);
			
			markers = new List<CodeCoverageTextMarker>();
			foreach (CodeCoverageTextMarker marker in markerStrategy.TextMarker) {
				markers.Add(marker);
			}
		}
		public void AddMarker(MarkerStrategy markerStrategy, CodeCoverageSequencePoint sequencePoint)
		{
			if (!IsValidSequencePoint(markerStrategy.Document, sequencePoint)) {
				return;
			}
			
			if (sequencePoint.EndLine == sequencePoint.Line) {
				LineSegment lineSegment = markerStrategy.Document.GetLineSegment(sequencePoint.Line - 1);
				markerStrategy.AddMarker(new CodeCoverageTextMarker(lineSegment.Offset + sequencePoint.Column - 1, sequencePoint));
			} else {
				// Sequence point spread across lines.
				for (int line = sequencePoint.Line; line <= sequencePoint.EndLine; ++line) {
					LineSegment lineSegment = markerStrategy.Document.GetLineSegment(line - 1);
					if (line == sequencePoint.Line) {
						// First line.
						markerStrategy.AddMarker(new CodeCoverageTextMarker(lineSegment.Offset + sequencePoint.Column - 1, lineSegment.Length - (sequencePoint.Column - 1), sequencePoint));
					} else if (line == sequencePoint.EndLine) {
						// Last line.
						markerStrategy.AddMarker(new CodeCoverageTextMarker(lineSegment.Offset, sequencePoint.EndColumn - 1, sequencePoint));
					} else {
						markerStrategy.AddMarker(new CodeCoverageTextMarker(lineSegment.Offset, lineSegment.Length, sequencePoint));						
					}
				}
			}
		}
		public void OneNodeMarked()
		{
			string xml = "<root><foo/></root>";
			XPathNodeMatch[] nodes = XmlView.SelectNodes(xml, "//root");
			
			IDocument doc = MockDocument.Create();
			doc.TextContent = xml;
			MarkerStrategy markerStrategy = new MarkerStrategy(doc);
			XPathNodeTextMarker.AddMarkers(markerStrategy, nodes);
			
			List<TextMarker> markers = new List<TextMarker>();
			foreach (TextMarker marker in markerStrategy.TextMarker) {
				markers.Add(marker);
			}
			
			// Remove markers.
			XPathNodeTextMarker.RemoveMarkers(markerStrategy);
			List<TextMarker> markersAfterRemove = new List<TextMarker>();
			foreach (TextMarker markerAfterRemove in markerStrategy.TextMarker) {
				markers.Add(markerAfterRemove);
			}

			XPathNodeTextMarker xpathNodeTextMarker = (XPathNodeTextMarker)markers[0];
			Assert.AreEqual(1, markers.Count);
			Assert.AreEqual(1, xpathNodeTextMarker.Offset);
			Assert.AreEqual(4, xpathNodeTextMarker.Length);
			Assert.AreEqual(TextMarkerType.SolidBlock, xpathNodeTextMarker.TextMarkerType);
			Assert.AreEqual(0, markersAfterRemove.Count);
			Assert.AreEqual(XPathNodeTextMarker.MarkerBackColor, xpathNodeTextMarker.Color);
		}
        //public event EventHandler<DocumentEventArgs> DocumentEventHandler;

        //public event EventHandler<LineLengthChangeEventArgs> LineLengthChanged
        //{
        //    add { LineManager.LineLengthChanged += value; }
        //    remove { LineManager.LineLengthChanged -= value; }
        //}

        //public event EventHandler<LineCountChangeEventArgs> LineCountChanged
        //{
        //    add { LineManager.LineCountChanged += value; }
        //    remove { LineManager.LineCountChanged -= value; }
        //}

        //public event EventHandler<LineEventArgs> LineDeleted
        //{
        //    add { LineManager.LineDeleted += value; }
        //    remove { LineManager.LineDeleted -= value; }
        //}
        #endregion

        #region Lifecycle
        public Document()
        {
            TextBuffer         = new TextBuffer();
            FormattingStrategy = new DefaultFormattingStrategy();
            LineManager        = new LineManager(this, null);
            FoldingManager     = new FoldingManager(this, LineManager);
            MarkerStrategy     = new MarkerStrategy(this);
            BookmarkManager    = new BookmarkManager(this, LineManager);
        }
		static bool ContainsCodeCoverageMarkers(MarkerStrategy markerStrategy)
		{			
			foreach (TextMarker marker in markerStrategy.TextMarker) {
				if (marker is CodeCoverageTextMarker) {
					return true;
				}
			}
			return false;
		}
		static bool ContainsNonCodeCoverageMarkers(MarkerStrategy markerStrategy)
		{			
			int count = 0;
			foreach (TextMarker marker in markerStrategy.TextMarker) {
				if (marker is CodeCoverageTextMarker) {
					return false;
				}
				count++;
			}
			return count > 0;
		}
		public void EmptyCommentNode()
		{
			string xml = "<!----><root/>";
			XPathNodeMatch[] nodes = XmlView.SelectNodes(xml, "//comment()");
			
			IDocument doc = MockDocument.Create();
			doc.TextContent = xml;
			MarkerStrategy markerStrategy = new MarkerStrategy(doc);
			XPathNodeTextMarker.AddMarkers(markerStrategy, nodes);
			
			List<TextMarker> markers = new List<TextMarker>();
			foreach (TextMarker marker in markerStrategy.TextMarker) {
				markers.Add(marker);
			}
			
			Assert.AreEqual(0, markers.Count);
			Assert.AreEqual(1, nodes.Length);
		}
        public void NamespaceQuery()
        {
            string xml = "<?xml version='1.0'?>\r\n" +
                "<Xml1></Xml1>";
            XPathNodeMatch[] nodes = XmlView.SelectNodes(xml, "//namespace::*");

            IDocument doc = MockDocument.Create();
            doc.TextContent = xml;
            MarkerStrategy markerStrategy = new MarkerStrategy(doc);
            XPathNodeTextMarker.AddMarkers(markerStrategy, nodes);

            List<TextMarker> markers = new List<TextMarker>();
            foreach (TextMarker marker in markerStrategy.TextMarker) {
                markers.Add(marker);
            }
            Assert.AreEqual(0, markers.Count);
            Assert.AreEqual(1, nodes.Length);
        }
		public void SetUpFixture()
		{
			try {
				string configFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "NCoverAddIn.Tests");
				PropertyService.InitializeService(configFolder, Path.Combine(configFolder, "data"), "NCoverAddIn.Tests");
			} catch (Exception) {}
			
			IDocument document = MockDocument.Create();
			string code = "\t\t{\r\n" +
				"\t\t\tAssert.AreEqual(0, childElementCompletionData.Length, \"\" +\r\n" +
				"\t\t\t                \"Not expecting any child elements.\");\r\n" +
				"\t\t}\r\n";
			document.TextContent = code;
			MarkerStrategy markerStrategy = new MarkerStrategy(document);

			string xml = "<PartCoverReport>\r\n" +
				"\t<file id=\"1\" url=\"c:\\Projects\\XmlEditor\\Test\\Schema\\SingleElementSchemaTestFixture.cs\" />\r\n" +
				"\t<Assembly id=\"1\" name=\"XmlEditor.Tests\" module=\"C:\\Projects\\Test\\XmlEditor.Tests\\bin\\XmlEditor.Tests.DLL\" domain=\"test-domain-XmlEditor.Tests.dll\" domainIdx=\"1\" />\r\n" +
				"\t<Type asmref=\"1\" name=\"XmlEditor.Tests.Schema.SingleElementSchemaTestFixture\">\r\n" +
				"\t\t<Method name=\"NoteElementHasNoChildElements\">\r\n" +
				"\t\t\t<pt visit=\"1\" fid=\"1\" sl=\"1\" sc=\"3\" el=\"1\" ec=\"4\" />\r\n" +
				"\t\t\t<pt visit=\"1\" fid=\"1\" sl=\"2\" sc=\"4\" el=\"3\" ec=\"57\" />\r\n" +
				"\t\t\t<pt visit=\"1\" fid=\"1\" sl=\"4\" sc=\"3\" el=\"4\" ec=\"4\" />\r\n" +
				"\t\t</Method>\r\n" +
				"\t</Type>\r\n" +
				"</PartCoverReport>";
			
			CodeCoverageResults results = new CodeCoverageResults(new StringReader(xml));
			CodeCoverageMethod method = results.Modules[0].Methods[0];
			CodeCoverageHighlighter highlighter = new CodeCoverageHighlighter();
			highlighter.AddMarkers(markerStrategy, method.SequencePoints);
			
			foreach (CodeCoverageTextMarker marker in markerStrategy.TextMarker) {
				if (markerOne == null) {
					markerOne = marker;
				} else if (markerTwo == null) {
					markerTwo = marker;
				} else if (markerThree == null) {
					markerThree = marker;
				} else if (markerFour == null) {
					markerFour = marker;
				}
			}
		}
		public void SetUpFixture()
		{
			try {
				string configFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "NCoverAddIn.Tests");
				PropertyService.InitializeService(configFolder, Path.Combine(configFolder, "data"), "NCoverAddIn.Tests");
			} catch (Exception) {}
			
			IDocument document = MockDocument.Create();
			string code = "\t\t{\r\n" +
				"\t\t\treturn \"<?xml version=\\\"1.0\\\"?>\\r\\n\" +\r\n" +
				"\t\t\t\t\"<xs:schema xmlns:xs=\\\"http://www.w3.org/2001/XMLSchema\\\"\\r\\n\" +\r\n" +
				"\t\t\t\t\"targetNamespace=\\\"http://www.w3schools.com\\\"\\r\\n\" +\r\n" +
				"\t\t\t\t\"xmlns=\\\"http://www.w3schools.com\\\"\\r\\n\" +\r\n" +
				"\t\t\t\t\"elementFormDefault=\\\"qualified\\\">\\r\\n\" +\r\n" +
				"\t\t\t\t\"<xs:element name=\\\"note\\\">\\r\\n\" +\r\n" +
				"\t\t\t\t\"</xs:element>\\r\\n\" +\r\n" +
				"\t\t\t\t\"</xs:schema>\";\r\n" +
				"\t\t}\r\n";
			document.TextContent = code;
			MarkerStrategy markerStrategy = new MarkerStrategy(document);
			
			string xml = "<PartCoverReport>\r\n" +
				"\t<File id=\"1\" url=\"c:\\Projects\\XmlEditor\\Test\\Schema\\SingleElementSchemaTestFixture.cs\" />\r\n" +
				"\t<Assembly id=\"1\" name=\"XmlEditor.Tests\" module=\"C:\\Projects\\Test\\XmlEditor.Tests\\bin\\XmlEditor.Tests.DLL\" domain=\"test-domain-XmlEditor.Tests.dll\" domainIdx=\"1\" />\r\n" +
				"\t<Type asmref=\"XmlEditor.Tests\" name=\"XmlEditor.Tests.Schema.SingleElementSchemaTestFixture\" flags=\"1232592\">\r\n" +
				"\t\t<Method name=\"GetSchema\">\r\n" +
				"\t\t\t<pt visit=\"1\" fid=\"1\" sl=\"1\" sc=\"3\" el=\"1\" ec=\"4\" />\r\n" +
				"\t\t\t<pt visit=\"1\" fid=\"1\" sl=\"2\" sc=\"4\" el=\"9\" ec=\"20\" />\r\n" +
				"\t\t\t<pt visit=\"1\" fid=\"1\" sl=\"10\" sc=\"3\" el=\"10\" ec=\"4\" />\r\n" +
				"\t\t</Method>\r\n" +
				"\t</Type>\r\n" +
				"</PartCoverReport>";
			
			CodeCoverageResults results = new CodeCoverageResults(new StringReader(xml));
			CodeCoverageMethod method = results.Modules[0].Methods[0];
			CodeCoverageHighlighter highlighter = new CodeCoverageHighlighter();
			highlighter.AddMarkers(markerStrategy, method.SequencePoints);

			markers = new List<CodeCoverageTextMarker>();
			foreach (CodeCoverageTextMarker marker in markerStrategy.TextMarker) {
				markers.Add(marker);
			}
		}
Exemplo n.º 13
0
 /// <summary>
 /// Removes all the XPathNodeMarkers from the marker strategy.
 /// </summary>
 public static void RemoveMarkers(MarkerStrategy markerStrategy)
 {
     markerStrategy.RemoveAll(IsXPathNodeTextMarkerMatch);
 }
Exemplo n.º 14
0
 /// <summary>
 /// Adds markers for each XPathNodeMatch.
 /// </summary>
 public static void AddMarkers(MarkerStrategy markerStrategy, XPathNodeMatch[] nodes)
 {
     foreach (XPathNodeMatch node in nodes) {
         AddMarker(markerStrategy, node);
     }
 }
		/// <summary>
		/// Removes all CodeCoverageMarkers from the marker strategy.
		/// </summary>
		public void RemoveMarkers(MarkerStrategy markerStrategy)
		{
			markerStrategy.RemoveAll(IsCodeCoverageTextMarkerMatch);
		}
		/// <summary>
		/// Adds text markers for the code coverage sequence points.
		/// </summary>
		/// <remarks>The sequence points are added to the marker strategy even 
		/// if they are not all for the same document.</remarks>
		public void AddMarkers(MarkerStrategy markerStrategy, List<CodeCoverageSequencePoint> sequencePoints)
		{
			foreach (CodeCoverageSequencePoint sequencePoint in sequencePoints) {
				AddMarker(markerStrategy, sequencePoint);
			}
		}