Browse Source

Improved xml completion when a document uses multiple xml schemas.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5295 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Matt Ward 17 years ago
parent
commit
4869fa32f3
  1. 5
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/QualifiedName.cs
  2. 16
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlElementPath.cs
  3. 85
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlElementPathsByNamespace.cs
  4. 14
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlNamespace.cs
  5. 36
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlNamespaceCollection.cs
  6. 107
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlParser.cs
  7. 26
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlSchemaCompletion.cs
  8. 75
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlSchemaCompletionCollection.cs
  9. 17
      src/AddIns/DisplayBindings/XmlEditor/Project/XmlEditor.addin
  10. 2
      src/AddIns/DisplayBindings/XmlEditor/Project/XmlEditor.csproj
  11. 2
      src/AddIns/DisplayBindings/XmlEditor/Test/Completion/CtrlSpaceAttributeValueCompletionTestFixture.cs
  12. 33
      src/AddIns/DisplayBindings/XmlEditor/Test/Parser/ActiveElementStartPathTestFixture.cs
  13. 50
      src/AddIns/DisplayBindings/XmlEditor/Test/Parser/ActiveElementUnderCursorTests.cs
  14. 48
      src/AddIns/DisplayBindings/XmlEditor/Test/Parser/NamespacesInScopeForPathTests.cs
  15. 17
      src/AddIns/DisplayBindings/XmlEditor/Test/Parser/ParentElementPathTestFixture.cs
  16. 24
      src/AddIns/DisplayBindings/XmlEditor/Test/Parser/XamlMixedNamespaceTestFixture.cs
  17. 16
      src/AddIns/DisplayBindings/XmlEditor/Test/Paths/ChangeElementPathDefaultNamespaceTests.cs
  18. 32
      src/AddIns/DisplayBindings/XmlEditor/Test/Paths/EmptyElementPathsByNamespaceTestFixture.cs
  19. 42
      src/AddIns/DisplayBindings/XmlEditor/Test/Paths/NamespacesWithoutPathsTests.cs
  20. 2
      src/AddIns/DisplayBindings/XmlEditor/Test/Paths/NoElementPathTestFixture.cs
  21. 54
      src/AddIns/DisplayBindings/XmlEditor/Test/Paths/OneAndTwoElementPathsTestFixture.cs
  22. 8
      src/AddIns/DisplayBindings/XmlEditor/Test/Paths/QualifiedNameToStringTests.cs
  23. 42
      src/AddIns/DisplayBindings/XmlEditor/Test/Paths/SingleElementPathByNamespaceTestFixture.cs
  24. 8
      src/AddIns/DisplayBindings/XmlEditor/Test/Paths/SingleElementPathTestFixture.cs
  25. 47
      src/AddIns/DisplayBindings/XmlEditor/Test/Paths/TwoElementPathTestFixture.cs
  26. 52
      src/AddIns/DisplayBindings/XmlEditor/Test/Paths/TwoElementPathsByNamespaceTestFixture.cs
  27. 87
      src/AddIns/DisplayBindings/XmlEditor/Test/Paths/XmlNamespaceCollectionTests.cs
  28. 75
      src/AddIns/DisplayBindings/XmlEditor/Test/Paths/XmlNamespaceEqualsTests.cs
  29. 225
      src/AddIns/DisplayBindings/XmlEditor/Test/Schema.Multiple/TwoSchemaChildElementCompletionTestFixture.cs
  30. 6
      src/AddIns/DisplayBindings/XmlEditor/Test/Schema/AbstractElementTestFixture.cs
  31. 4
      src/AddIns/DisplayBindings/XmlEditor/Test/Schema/AllElementTestFixture.cs
  32. 4
      src/AddIns/DisplayBindings/XmlEditor/Test/Schema/AttributeAnnotationTestFixture.cs
  33. 2
      src/AddIns/DisplayBindings/XmlEditor/Test/Schema/AttributeGroupRefTestFixture.cs
  34. 2
      src/AddIns/DisplayBindings/XmlEditor/Test/Schema/AttributeRefTestFixture.cs
  35. 2
      src/AddIns/DisplayBindings/XmlEditor/Test/Schema/AttributeValueAnnotationTestFixture.cs
  36. 4
      src/AddIns/DisplayBindings/XmlEditor/Test/Schema/ChildElementAttributesTestFixture.cs
  37. 10
      src/AddIns/DisplayBindings/XmlEditor/Test/Schema/ChoiceTestFixture.cs
  38. 10
      src/AddIns/DisplayBindings/XmlEditor/Test/Schema/ComplexContentExtensionTestFixture.cs
  39. 2
      src/AddIns/DisplayBindings/XmlEditor/Test/Schema/DuplicateElementTestFixture.cs
  40. 2
      src/AddIns/DisplayBindings/XmlEditor/Test/Schema/ElementAnnotationTestFixture.cs
  41. 2
      src/AddIns/DisplayBindings/XmlEditor/Test/Schema/ElementRefAnnotationTestFixture.cs
  42. 4
      src/AddIns/DisplayBindings/XmlEditor/Test/Schema/ElementWithAttributeSchemaTestFixture.cs
  43. 2
      src/AddIns/DisplayBindings/XmlEditor/Test/Schema/EnumAttributeValueTestFixture.cs
  44. 10
      src/AddIns/DisplayBindings/XmlEditor/Test/Schema/ExtensionElementTestFixture.cs
  45. 2
      src/AddIns/DisplayBindings/XmlEditor/Test/Schema/FindAttributeFromComplexTypeTestFixture.cs
  46. 4
      src/AddIns/DisplayBindings/XmlEditor/Test/Schema/GroupRefCompositorTestFixture.cs
  47. 6
      src/AddIns/DisplayBindings/XmlEditor/Test/Schema/GroupRefTestFixture.cs
  48. 4
      src/AddIns/DisplayBindings/XmlEditor/Test/Schema/MissingSchemaElementTestFixture.cs
  49. 2
      src/AddIns/DisplayBindings/XmlEditor/Test/Schema/NestedAttributeGroupRefTestFixture.cs
  50. 8
      src/AddIns/DisplayBindings/XmlEditor/Test/Schema/NestedChoiceTestFixture.cs
  51. 2
      src/AddIns/DisplayBindings/XmlEditor/Test/Schema/NestedElementSchemaTestFixture.cs
  52. 10
      src/AddIns/DisplayBindings/XmlEditor/Test/Schema/NestedSequenceTestFixture.cs
  53. 6
      src/AddIns/DisplayBindings/XmlEditor/Test/Schema/ReferencedElementsTestFixture.cs
  54. 6
      src/AddIns/DisplayBindings/XmlEditor/Test/Schema/RestrictionElementTestFixture.cs
  55. 10
      src/AddIns/DisplayBindings/XmlEditor/Test/Schema/SequencedChoiceTestFixture.cs
  56. 2
      src/AddIns/DisplayBindings/XmlEditor/Test/Schema/SimpleContentWithAttributeTestFixture.cs
  57. 2
      src/AddIns/DisplayBindings/XmlEditor/Test/Schema/SingleElementSchemaTestFixture.cs
  58. 6
      src/AddIns/DisplayBindings/XmlEditor/Test/Schema/TwoElementSchemaTestFixture.cs
  59. 6
      src/AddIns/DisplayBindings/XmlEditor/Test/Schema/XhtmlStrictSchemaTestFixture.cs
  60. 44
      src/AddIns/DisplayBindings/XmlEditor/Test/Schema/XsdSchemaTestFixture.cs
  61. 10
      src/AddIns/DisplayBindings/XmlEditor/Test/XmlEditor.Tests.csproj

5
src/AddIns/DisplayBindings/XmlEditor/Project/Src/QualifiedName.cs

@ -33,6 +33,11 @@ namespace ICSharpCode.XmlEditor
{ {
} }
public QualifiedName(string name, XmlNamespace ns)
: this(name, ns.Name, ns.Prefix)
{
}
public QualifiedName(string name, string namespaceUri, string prefix) public QualifiedName(string name, string namespaceUri, string prefix)
{ {
xmlQualifiedName = new XmlQualifiedName(name, namespaceUri); xmlQualifiedName = new XmlQualifiedName(name, namespaceUri);

16
src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlElementPath.cs

@ -6,6 +6,7 @@
// </file> // </file>
using System; using System;
using System.Collections.Generic;
using System.Text; using System.Text;
namespace ICSharpCode.XmlEditor namespace ICSharpCode.XmlEditor
@ -17,6 +18,7 @@ namespace ICSharpCode.XmlEditor
public class XmlElementPath public class XmlElementPath
{ {
QualifiedNameCollection elements = new QualifiedNameCollection(); QualifiedNameCollection elements = new QualifiedNameCollection();
XmlNamespaceCollection namespacesInScope = new XmlNamespaceCollection();
public XmlElementPath() public XmlElementPath()
{ {
@ -30,6 +32,11 @@ namespace ICSharpCode.XmlEditor
get { return elements; } get { return elements; }
} }
public void AddElement(QualifiedName elementName)
{
elements.Add(elementName);
}
public bool IsEmpty { public bool IsEmpty {
get { return elements.IsEmpty; } get { return elements.IsEmpty; }
} }
@ -52,6 +59,15 @@ namespace ICSharpCode.XmlEditor
} }
} }
public XmlNamespaceCollection NamespacesInScope {
get { return namespacesInScope; }
}
public string GetNamespaceForPrefix(string prefix)
{
return namespacesInScope.GetNamespaceForPrefix(prefix);
}
/// <summary> /// <summary>
/// An xml element path is considered to be equal if /// An xml element path is considered to be equal if
/// each path item has the same name and namespace. /// each path item has the same name and namespace.

85
src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlElementPathsByNamespace.cs

@ -0,0 +1,85 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
namespace ICSharpCode.XmlEditor
{
public class XmlElementPathsByNamespace : Collection<XmlElementPath>
{
Dictionary<string, XmlElementPath> pathsByNamespace = new Dictionary<string, XmlElementPath>();
XmlNamespaceCollection namespacesWithoutPaths = new XmlNamespaceCollection();
public XmlElementPathsByNamespace(XmlElementPath path)
{
SeparateIntoPathsByNamespace(path);
AddSeparatedPathsToCollection();
FindNamespacesWithoutAssociatedPaths(path.NamespacesInScope);
pathsByNamespace.Clear();
}
void SeparateIntoPathsByNamespace(XmlElementPath path)
{
foreach (QualifiedName elementName in path.Elements) {
XmlElementPath matchedPath = FindOrCreatePath(elementName.Namespace);
matchedPath.AddElement(elementName);
}
}
XmlElementPath FindOrCreatePath(string elementNamespace)
{
XmlElementPath path = FindPath(elementNamespace);
if (path != null) {
return path;
}
return CreatePath(elementNamespace);
}
XmlElementPath FindPath(string elementNamespace)
{
XmlElementPath path;
if (pathsByNamespace.TryGetValue(elementNamespace, out path)) {
return path;
}
return null;
}
XmlElementPath CreatePath(string elementNamespace)
{
XmlElementPath path = new XmlElementPath();
pathsByNamespace.Add(elementNamespace, path);
return path;
}
void AddSeparatedPathsToCollection()
{
foreach (KeyValuePair<string, XmlElementPath> dictionaryEntry in pathsByNamespace) {
Add(dictionaryEntry.Value);
}
}
void FindNamespacesWithoutAssociatedPaths(XmlNamespaceCollection namespacesInScope)
{
foreach (XmlNamespace ns in namespacesInScope) {
if (!HavePathForNamespace(ns)) {
namespacesWithoutPaths.Add(ns);
}
}
}
bool HavePathForNamespace(XmlNamespace ns)
{
return pathsByNamespace.ContainsKey(ns.Name);
}
public XmlNamespaceCollection NamespacesWithoutPaths {
get { return namespacesWithoutPaths; }
}
}
}

14
src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlNamespace.cs

@ -78,5 +78,19 @@ namespace ICSharpCode.XmlEditor
} }
return new XmlNamespace(); return new XmlNamespace();
} }
public override bool Equals(object obj)
{
XmlNamespace rhs = obj as XmlNamespace;
if (rhs != null) {
return (Name == rhs.Name) && (Prefix == rhs.Prefix);
}
return false;
}
public override int GetHashCode()
{
return Name.GetHashCode() ^ Prefix.GetHashCode();
}
} }
} }

36
src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlNamespaceCollection.cs

@ -0,0 +1,36 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
namespace ICSharpCode.XmlEditor
{
public class XmlNamespaceCollection : Collection<XmlNamespace>
{
public XmlNamespaceCollection()
{
}
public XmlNamespace[] ToArray()
{
List<XmlNamespace> namespaces = new List<XmlNamespace>(this);
return namespaces.ToArray();
}
public string GetNamespaceForPrefix(string prefix)
{
foreach (XmlNamespace ns in this) {
if (ns.Prefix == prefix) {
return ns.Name;
}
}
return String.Empty;
}
}
}

107
src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlParser.cs

@ -39,8 +39,11 @@ namespace ICSharpCode.XmlEditor
/// is returned.</remarks> /// is returned.</remarks>
public static XmlElementPath GetActiveElementStartPath(string xml, int index) public static XmlElementPath GetActiveElementStartPath(string xml, int index)
{ {
QualifiedNameCollection namespaces = new QualifiedNameCollection(); string elementText = GetActiveElementStartText(xml, index);
return GetActiveElementStartPath(xml, index, namespaces); if (elementText != null) {
return GetActiveElementStartPath(xml, index, elementText);
}
return new XmlElementPath();
} }
/// <summary> /// <summary>
@ -53,8 +56,25 @@ namespace ICSharpCode.XmlEditor
/// is returned.</remarks> /// is returned.</remarks>
public static XmlElementPath GetActiveElementStartPathAtIndex(string xml, int index) public static XmlElementPath GetActiveElementStartPathAtIndex(string xml, int index)
{ {
QualifiedNameCollection namespaces = new QualifiedNameCollection(); // Find first non xml element name character to the right of the index.
return GetActiveElementStartPathAtIndex(xml, index, namespaces); index = GetCorrectedIndex(xml.Length, index);
if (index < 0) { // can happen when xml.Length==0
return new XmlElementPath();
}
int currentIndex = index;
for (; currentIndex < xml.Length; ++currentIndex) {
char ch = xml[currentIndex];
if (!IsXmlNameChar(ch)) {
break;
}
}
string elementText = GetElementNameAtIndex(xml, currentIndex);
if (elementText != null) {
return GetActiveElementStartPath(xml, currentIndex, elementText);
}
return new XmlElementPath();
} }
/// <summary> /// <summary>
@ -62,10 +82,7 @@ namespace ICSharpCode.XmlEditor
/// </summary> /// </summary>
public static XmlElementPath GetParentElementPath(string xml) public static XmlElementPath GetParentElementPath(string xml)
{ {
QualifiedNameCollection namespaces = new QualifiedNameCollection(); return GetFullParentElementPath(xml);
XmlElementPath path = GetFullParentElementPath(xml, namespaces);
path.Compact();
return path;
} }
/// <summary> /// <summary>
@ -158,9 +175,8 @@ namespace ICSharpCode.XmlEditor
string name = GetAttributeNameAtIndex(xml, index); string name = GetAttributeNameAtIndex(xml, index);
QualifiedName qualifiedName = QualifiedName.FromString(name); QualifiedName qualifiedName = QualifiedName.FromString(name);
if (!qualifiedName.IsEmpty && !qualifiedName.HasNamespace && includeNamespace) { if (!qualifiedName.IsEmpty && !qualifiedName.HasNamespace && includeNamespace) {
QualifiedNameCollection namespaces = new QualifiedNameCollection(); XmlElementPath path = GetActiveElementStartPathAtIndex(xml, index);
XmlElementPath path = GetActiveElementStartPathAtIndex(xml, index, namespaces); qualifiedName.Namespace = path.GetNamespaceForPrefix(path.Elements.GetLastPrefix());
qualifiedName.Namespace = namespaces.GetNamespaceForPrefix(path.Elements.GetLastPrefix());
} }
return qualifiedName; return qualifiedName;
} }
@ -409,7 +425,6 @@ namespace ICSharpCode.XmlEditor
public static int GetActiveElementStartIndex(string xml, int index) public static int GetActiveElementStartIndex(string xml, int index)
{ {
int elementStartIndex = -1; int elementStartIndex = -1;
int currentIndex = index - 1; int currentIndex = index - 1;
while (currentIndex > -1) { while (currentIndex > -1) {
@ -531,7 +546,7 @@ namespace ICSharpCode.XmlEditor
/// <summary> /// <summary>
/// Gets the active element path given the element text. /// Gets the active element path given the element text.
/// </summary> /// </summary>
static XmlElementPath GetActiveElementStartPath(string xml, int index, string elementText, QualifiedNameCollection namespaces) static XmlElementPath GetActiveElementStartPath(string xml, int index, string elementText)
{ {
QualifiedName elementName = GetElementName(elementText); QualifiedName elementName = GetElementName(elementText);
if (elementName.IsEmpty) { if (elementName.IsEmpty) {
@ -540,24 +555,23 @@ namespace ICSharpCode.XmlEditor
XmlNamespace elementNamespace = GetElementNamespace(elementText); XmlNamespace elementNamespace = GetElementNamespace(elementText);
XmlElementPath path = GetFullParentElementPath(xml.Substring(0, index), namespaces); XmlElementPath path = GetFullParentElementPath(xml.Substring(0, index));
// Try to get a namespace for the active element's prefix. // Try to get a namespace for the active element's prefix.
if (elementName.HasPrefix && elementNamespace.Name.Length == 0) { if (elementName.HasPrefix && !elementNamespace.HasName) {
elementName.Namespace = namespaces.GetNamespaceForPrefix(elementName.Prefix); elementName.Namespace = path.GetNamespaceForPrefix(elementName.Prefix);
elementNamespace.Name = elementName.Namespace; elementNamespace.Name = elementName.Namespace;
elementNamespace.Prefix = elementName.Prefix; elementNamespace.Prefix = elementName.Prefix;
} }
if (elementNamespace.Name.Length == 0) { if (!elementNamespace.HasName) {
if (path.Elements.Count > 0) { if (path.Elements.Count > 0) {
QualifiedName parentName = path.Elements[path.Elements.Count - 1]; QualifiedName parentName = path.Elements[path.Elements.Count - 1];
elementNamespace.Name = parentName.Namespace; elementNamespace.Name = parentName.Namespace;
elementNamespace.Prefix = parentName.Prefix; elementNamespace.Prefix = parentName.Prefix;
} }
} }
path.Elements.Add(new QualifiedName(elementName.Name, elementNamespace.Name, elementNamespace.Prefix)); path.AddElement(new QualifiedName(elementName.Name, elementNamespace));
path.Compact();
return path; return path;
} }
@ -640,10 +654,10 @@ namespace ICSharpCode.XmlEditor
/// method does not compact the path so it will include all elements /// method does not compact the path so it will include all elements
/// including those in another namespace in the path. /// including those in another namespace in the path.
/// </summary> /// </summary>
static XmlElementPath GetFullParentElementPath(string xml, QualifiedNameCollection namespaces) static XmlElementPath GetFullParentElementPath(string xml)
{ {
XmlElementPath path = new XmlElementPath(); XmlElementPath path = new XmlElementPath();
IDictionary<string,string> namespacesInScope = null; IDictionary<string, string> namespacesInScope = null;
using (StringReader reader = new StringReader(xml)) { using (StringReader reader = new StringReader(xml)) {
using (XmlTextReader xmlReader = new XmlTextReader(reader)) { using (XmlTextReader xmlReader = new XmlTextReader(reader)) {
try { try {
@ -653,7 +667,7 @@ namespace ICSharpCode.XmlEditor
case XmlNodeType.Element: case XmlNodeType.Element:
if (!xmlReader.IsEmptyElement) { if (!xmlReader.IsEmptyElement) {
QualifiedName elementName = new QualifiedName(xmlReader.LocalName, xmlReader.NamespaceURI, xmlReader.Prefix); QualifiedName elementName = new QualifiedName(xmlReader.LocalName, xmlReader.NamespaceURI, xmlReader.Prefix);
path.Elements.Add(elementName); path.AddElement(elementName);
} }
break; break;
case XmlNodeType.EndElement: case XmlNodeType.EndElement:
@ -670,60 +684,13 @@ namespace ICSharpCode.XmlEditor
// Add namespaces in scope for the last element read. // Add namespaces in scope for the last element read.
if (namespacesInScope != null) { if (namespacesInScope != null) {
foreach (KeyValuePair<string, string> ns in namespacesInScope) { foreach (KeyValuePair<string, string> ns in namespacesInScope) {
namespaces.Add(new QualifiedName(String.Empty, ns.Value, ns.Key)); path.NamespacesInScope.Add(new XmlNamespace(ns.Key, ns.Value));
} }
} }
return path; return path;
} }
/// <summary>
/// Gets path of the xml element start tag that the specified
/// <paramref name="index"/> is currently inside.
/// </summary>
/// <remarks>If the index outside the start tag then an empty path
/// is returned.</remarks>
/// <param name="namespaces">Returns the namespaces that are
/// exist in the xml.</param>
static XmlElementPath GetActiveElementStartPath(string xml, int index, QualifiedNameCollection namespaces)
{
XmlElementPath path = new XmlElementPath();
string elementText = GetActiveElementStartText(xml, index);
if (elementText != null) {
path = GetActiveElementStartPath(xml, index, elementText, namespaces);
}
return path;
}
/// <summary>
/// Gets path of the xml element start tag that the specified
/// <paramref name="index"/> is currently located. This is different to the
/// GetActiveElementStartPath method since the index can be inside the element
/// name.
/// </summary>
/// <remarks>If the index outside the start tag then an empty path
/// is returned.</remarks>
static XmlElementPath GetActiveElementStartPathAtIndex(string xml, int index, QualifiedNameCollection namespaces)
{
// Find first non xml element name character to the right of the index.
index = GetCorrectedIndex(xml.Length, index);
if (index < 0) // can happen when xml.Length==0
return new XmlElementPath();
int currentIndex = index;
for (; currentIndex < xml.Length; ++currentIndex) {
char ch = xml[currentIndex];
if (!IsXmlNameChar(ch)) {
break;
}
}
string elementText = GetElementNameAtIndex(xml, currentIndex);
if (elementText != null) {
return GetActiveElementStartPath(xml, currentIndex, elementText, namespaces);
}
return new XmlElementPath();
}
static bool IsQuoteChar(char ch) static bool IsQuoteChar(char ch)
{ {
return (ch == '\"') || (ch == '\''); return (ch == '\"') || (ch == '\'');

26
src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlSchemaCompletion.cs

@ -28,10 +28,9 @@ namespace ICSharpCode.XmlEditor
public class XmlSchemaCompletion public class XmlSchemaCompletion
{ {
XmlSchema schema; XmlSchema schema;
string namespaceUri = String.Empty;
string fileName = String.Empty; string fileName = String.Empty;
bool readOnly; bool readOnly;
string namespacePrefix = String.Empty; XmlNamespace xmlNamespace = new XmlNamespace();
/// <summary> /// <summary>
/// Stores attributes that have been prohibited whilst the code /// Stores attributes that have been prohibited whilst the code
@ -44,8 +43,8 @@ namespace ICSharpCode.XmlEditor
} }
public string DefaultNamespacePrefix { public string DefaultNamespacePrefix {
get { return namespacePrefix; } get { return xmlNamespace.Prefix; }
set { namespacePrefix = value; } set { xmlNamespace.Prefix = value; }
} }
/// <summary> /// <summary>
@ -103,11 +102,15 @@ namespace ICSharpCode.XmlEditor
/// Gets the namespace URI for the schema. /// Gets the namespace URI for the schema.
/// </summary> /// </summary>
public string NamespaceUri { public string NamespaceUri {
get { return namespaceUri; } get { return xmlNamespace.Name; }
} }
public bool HasNamespaceUri { public bool HasNamespaceUri {
get { return !String.IsNullOrWhiteSpace(namespaceUri); } get { return !String.IsNullOrWhiteSpace(NamespaceUri); }
}
public XmlNamespace Namespace {
get { return xmlNamespace; }
} }
/// <summary> /// <summary>
@ -124,6 +127,11 @@ namespace ICSharpCode.XmlEditor
} }
public XmlCompletionItemCollection GetRootElementCompletion() public XmlCompletionItemCollection GetRootElementCompletion()
{
return GetRootElementCompletion(DefaultNamespacePrefix);
}
public XmlCompletionItemCollection GetRootElementCompletion(string namespacePrefix)
{ {
XmlCompletionItemCollection items = new XmlCompletionItemCollection(); XmlCompletionItemCollection items = new XmlCompletionItemCollection();
@ -264,7 +272,7 @@ namespace ICSharpCode.XmlEditor
/// </summary> /// </summary>
public XmlSchemaSimpleType FindSimpleType(string name) public XmlSchemaSimpleType FindSimpleType(string name)
{ {
XmlQualifiedName qualifiedName = new XmlQualifiedName(name, namespaceUri); XmlQualifiedName qualifiedName = new XmlQualifiedName(name, xmlNamespace.Name);
return FindSimpleType(qualifiedName); return FindSimpleType(qualifiedName);
} }
@ -320,7 +328,7 @@ namespace ICSharpCode.XmlEditor
} }
// Default behaviour just return the name with the namespace uri. // Default behaviour just return the name with the namespace uri.
qualifiedName.Namespace = namespaceUri; qualifiedName.Namespace = xmlNamespace.Name;
return qualifiedName; return qualifiedName;
} }
@ -357,7 +365,7 @@ namespace ICSharpCode.XmlEditor
schemaSet.Add(schema); schemaSet.Add(schema);
schemaSet.Compile(); schemaSet.Compile();
namespaceUri = schema.TargetNamespace; xmlNamespace.Name = schema.TargetNamespace;
} }
} finally { } finally {
reader.Close(); reader.Close();

75
src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlSchemaCompletionCollection.cs

@ -7,10 +7,7 @@
using System; using System;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Linq;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Editor.CodeCompletion;
namespace ICSharpCode.XmlEditor namespace ICSharpCode.XmlEditor
{ {
@ -103,9 +100,6 @@ namespace ICSharpCode.XmlEditor
return null; return null;
} }
/// <summary>
/// Finds the schema given the xml element path.
/// </summary>
public XmlSchemaCompletion FindSchema(XmlElementPath path, XmlSchemaCompletion defaultSchema) public XmlSchemaCompletion FindSchema(XmlElementPath path, XmlSchemaCompletion defaultSchema)
{ {
if (path.Elements.HasItems) { if (path.Elements.HasItems) {
@ -120,6 +114,11 @@ namespace ICSharpCode.XmlEditor
return null; return null;
} }
public XmlCompletionItemCollection GetChildElementCompletion(XmlElementPath path)
{
return GetChildElementCompletion(path, null);
}
public XmlCompletionItemCollection GetChildElementCompletion(XmlElementPath path, XmlSchemaCompletion defaultSchema) public XmlCompletionItemCollection GetChildElementCompletion(XmlElementPath path, XmlSchemaCompletion defaultSchema)
{ {
XmlSchemaCompletion schema = FindSchema(path, defaultSchema); XmlSchemaCompletion schema = FindSchema(path, defaultSchema);
@ -129,20 +128,52 @@ namespace ICSharpCode.XmlEditor
return new XmlCompletionItemCollection(); return new XmlCompletionItemCollection();
} }
public XmlCompletionItemCollection GetAttributeCompletion(XmlElementPath path, XmlSchemaCompletion defaultSchema) public XmlCompletionItemCollection GetElementCompletionForAllNamespaces(XmlElementPath path, XmlSchemaCompletion defaultSchema)
{ {
XmlSchemaCompletion schema = FindSchema(path, defaultSchema); XmlElementPathsByNamespace pathsByNamespace = new XmlElementPathsByNamespace(path);
return GetElementCompletion(pathsByNamespace, defaultSchema);
}
public XmlCompletionItemCollection GetElementCompletion(XmlElementPathsByNamespace pathsByNamespace, XmlSchemaCompletion defaultSchema)
{
XmlCompletionItemCollection items = new XmlCompletionItemCollection();
foreach (XmlElementPath path in pathsByNamespace) {
items.AddRange(GetChildElementCompletion(path));
}
XmlNamespaceCollection namespaceWithoutPaths = pathsByNamespace.NamespacesWithoutPaths;
if (!IsDefaultSchemaNamespaceDefinedInPathsByNamespace(namespaceWithoutPaths, defaultSchema)) {
namespaceWithoutPaths.Add(defaultSchema.Namespace);
}
items.AddRange(GetRootElementCompletion(namespaceWithoutPaths));
return items;
}
bool IsDefaultSchemaNamespaceDefinedInPathsByNamespace(XmlNamespaceCollection namespaces, XmlSchemaCompletion defaultSchema)
{
if (defaultSchema != null) {
return namespaces.Contains(defaultSchema.Namespace);
}
return true;
}
public XmlCompletionItemCollection GetRootElementCompletion(XmlNamespaceCollection namespaces)
{
XmlCompletionItemCollection items = new XmlCompletionItemCollection();
foreach (XmlNamespace ns in namespaces) {
XmlSchemaCompletion schema = this[ns.Name];
if (schema != null) { if (schema != null) {
return schema.GetAttributeCompletion(path); items.AddRange(schema.GetRootElementCompletion(ns.Prefix));
} }
return new XmlCompletionItemCollection(); }
return items;
} }
public XmlCompletionItemCollection GetAttributeValueCompletion(XmlElementPath path, string attributeName, XmlSchemaCompletion defaultSchema) public XmlCompletionItemCollection GetAttributeCompletion(XmlElementPath path, XmlSchemaCompletion defaultSchema)
{ {
XmlSchemaCompletion schema = FindSchema(path, defaultSchema); XmlSchemaCompletion schema = FindSchema(path, defaultSchema);
if (schema != null) { if (schema != null) {
return schema.GetAttributeValueCompletion(path, attributeName); return schema.GetAttributeCompletion(path);
} }
return new XmlCompletionItemCollection(); return new XmlCompletionItemCollection();
} }
@ -150,18 +181,14 @@ namespace ICSharpCode.XmlEditor
public XmlCompletionItemCollection GetElementCompletion(string textUpToCursor, XmlSchemaCompletion defaultSchema) public XmlCompletionItemCollection GetElementCompletion(string textUpToCursor, XmlSchemaCompletion defaultSchema)
{ {
XmlElementPath parentPath = XmlParser.GetParentElementPath(textUpToCursor); XmlElementPath parentPath = XmlParser.GetParentElementPath(textUpToCursor);
if (parentPath.Elements.HasItems) { return GetElementCompletionForAllNamespaces(parentPath, defaultSchema);
return GetChildElementCompletion(parentPath, defaultSchema);
} else if (defaultSchema != null) {
return defaultSchema.GetRootElementCompletion();
}
return new XmlCompletionItemCollection();
} }
public XmlCompletionItemCollection GetAttributeCompletion(string textUpToCursor, XmlSchemaCompletion defaultSchema) public XmlCompletionItemCollection GetAttributeCompletion(string textUpToCursor, XmlSchemaCompletion defaultSchema)
{ {
if (!XmlParser.IsInsideAttributeValue(textUpToCursor, textUpToCursor.Length)) { if (!XmlParser.IsInsideAttributeValue(textUpToCursor, textUpToCursor.Length)) {
XmlElementPath path = XmlParser.GetActiveElementStartPath(textUpToCursor, textUpToCursor.Length); XmlElementPath path = XmlParser.GetActiveElementStartPath(textUpToCursor, textUpToCursor.Length);
path.Compact();
if (path.Elements.HasItems) { if (path.Elements.HasItems) {
return GetAttributeCompletion(path, defaultSchema); return GetAttributeCompletion(path, defaultSchema);
} }
@ -175,11 +202,9 @@ namespace ICSharpCode.XmlEditor
string attributeName = XmlParser.GetAttributeName(textUpToCursor, textUpToCursor.Length); string attributeName = XmlParser.GetAttributeName(textUpToCursor, textUpToCursor.Length);
if (attributeName.Length > 0) { if (attributeName.Length > 0) {
XmlElementPath elementPath = XmlParser.GetActiveElementStartPath(textUpToCursor, textUpToCursor.Length); XmlElementPath elementPath = XmlParser.GetActiveElementStartPath(textUpToCursor, textUpToCursor.Length);
if (elementPath.Elements.HasItems) {
return GetAttributeValueCompletion(elementPath, attributeName, defaultSchema); return GetAttributeValueCompletion(elementPath, attributeName, defaultSchema);
} }
} }
}
return new XmlCompletionItemCollection(); return new XmlCompletionItemCollection();
} }
@ -192,5 +217,15 @@ namespace ICSharpCode.XmlEditor
} }
return new XmlCompletionItemCollection(); return new XmlCompletionItemCollection();
} }
public XmlCompletionItemCollection GetAttributeValueCompletion(XmlElementPath path, string attributeName, XmlSchemaCompletion defaultSchema)
{
path.Compact();
XmlSchemaCompletion schema = FindSchema(path, defaultSchema);
if (schema != null) {
return schema.GetAttributeValueCompletion(path, attributeName);
}
return new XmlCompletionItemCollection();
}
} }
} }

17
src/AddIns/DisplayBindings/XmlEditor/Project/XmlEditor.addin

@ -1,4 +1,5 @@
<AddIn name="XML Editor" <AddIn
name="XML Editor"
author="Matt Ward" author="Matt Ward"
copyright="prj:///doc/copyright.txt" copyright="prj:///doc/copyright.txt"
description="Adds XML completion and formatting support" description="Adds XML completion and formatting support"
@ -33,13 +34,19 @@
</Path> </Path>
<Path name="/AddIns/XmlEditor/DefaultSchemaFileAssociations"> <Path name="/AddIns/XmlEditor/DefaultSchemaFileAssociations">
<SchemaFileAssociation id=".wxs" namespaceUri="http://schemas.microsoft.com/wix/2003/01/wi"/> <SchemaFileAssociation id=".addin" namespaceUri="http://www.icsharpcode.net/2005/addin"/>
<SchemaFileAssociation id=".config" namespaceUri="urn:app-config" />
<SchemaFileAssociation id=".build" namespaceUri="http://nant.sf.net/release/0.85/nant.xsd"/> <SchemaFileAssociation id=".build" namespaceUri="http://nant.sf.net/release/0.85/nant.xsd"/>
<SchemaFileAssociation id=".xsl" namespaceUri="http://www.w3.org/1999/XSL/Transform"/> <SchemaFileAssociation id=".config" namespaceUri="urn:app-config" />
<SchemaFileAssociation id=".xs" namespacePrefix="xs" namespaceUri="http://www.w3.org/2001/XMLSchema"/>
<SchemaFileAssociation id=".manifest" namespaceUri="urn:schemas-microsoft-com:asm.v1"/> <SchemaFileAssociation id=".manifest" namespaceUri="urn:schemas-microsoft-com:asm.v1"/>
<SchemaFileAssociation id=".proj" namespaceUri="http://schemas.microsoft.com/developer/msbuild/2003"/>
<SchemaFileAssociation id=".csproj" namespaceUri="http://schemas.microsoft.com/developer/msbuild/2003"/>
<SchemaFileAssociation id=".vbproj" namespaceUri="http://schemas.microsoft.com/developer/msbuild/2003"/>
<SchemaFileAssociation id=".wxi" namespaceUri="http://schemas.microsoft.com/wix/2003/01/wi"/>
<SchemaFileAssociation id=".wxl" namespaceUri="http://schemas.microsoft.com/wix/2006/localization"/>
<SchemaFileAssociation id=".wxs" namespaceUri="http://schemas.microsoft.com/wix/2003/01/wi"/>
<SchemaFileAssociation id=".xaml" namespaceUri="http://schemas.microsoft.com/winfx/avalon/2005"/> <SchemaFileAssociation id=".xaml" namespaceUri="http://schemas.microsoft.com/winfx/avalon/2005"/>
<SchemaFileAssociation id=".xsd" namespacePrefix="xs" namespaceUri="http://www.w3.org/2001/XMLSchema"/>
<SchemaFileAssociation id=".xsl" namespaceUri="http://www.w3.org/1999/XSL/Transform"/>
</Path> </Path>
<Path name="/SharpDevelop/Workbench/LanguageBindings"> <Path name="/SharpDevelop/Workbench/LanguageBindings">

2
src/AddIns/DisplayBindings/XmlEditor/Project/XmlEditor.csproj

@ -132,6 +132,7 @@
</Compile> </Compile>
<Compile Include="Src\XmlEditorService.cs" /> <Compile Include="Src\XmlEditorService.cs" />
<Compile Include="Src\XmlElementPath.cs" /> <Compile Include="Src\XmlElementPath.cs" />
<Compile Include="Src\XmlElementPathsByNamespace.cs" />
<Compile Include="Src\XmlElementTreeNode.cs" /> <Compile Include="Src\XmlElementTreeNode.cs" />
<Compile Include="Src\XmlEncoder.cs" /> <Compile Include="Src\XmlEncoder.cs" />
<Compile Include="Src\XmlFoldParser.cs" /> <Compile Include="Src\XmlFoldParser.cs" />
@ -141,6 +142,7 @@
<Compile Include="Src\StylesheetAssignedCondition.cs" /> <Compile Include="Src\StylesheetAssignedCondition.cs" />
<Compile Include="Src\XmlLanguageBinding.cs" /> <Compile Include="Src\XmlLanguageBinding.cs" />
<Compile Include="Src\XmlNamespace.cs" /> <Compile Include="Src\XmlNamespace.cs" />
<Compile Include="Src\XmlNamespaceCollection.cs" />
<Compile Include="Src\XmlParser.cs" /> <Compile Include="Src\XmlParser.cs" />
<Compile Include="Src\XmlSchemaFileAssociation.cs" /> <Compile Include="Src\XmlSchemaFileAssociation.cs" />
<Compile Include="Src\XmlSchemaFileAssociationListItem.cs" /> <Compile Include="Src\XmlSchemaFileAssociationListItem.cs" />

2
src/AddIns/DisplayBindings/XmlEditor/Test/Completion/CtrlSpaceAttributeValueCompletionTestFixture.cs

@ -69,7 +69,7 @@ namespace XmlEditor.Tests.Completion
ICompletionItem[] GetXsdSchemaElementFormDefaultAttributeValues() ICompletionItem[] GetXsdSchemaElementFormDefaultAttributeValues()
{ {
XmlElementPath path = new XmlElementPath(); XmlElementPath path = new XmlElementPath();
path.Elements.Add(new QualifiedName("schema", "http://www.w3.org/2001/XMLSchema", "xs")); path.AddElement(new QualifiedName("schema", "http://www.w3.org/2001/XMLSchema", "xs"));
return xsdSchema.GetAttributeValueCompletion(path, "elementFormDefault").ToArray(); return xsdSchema.GetAttributeValueCompletion(path, "elementFormDefault").ToArray();
} }

33
src/AddIns/DisplayBindings/XmlEditor/Test/Parser/ActiveElementStartPathTestFixture.cs

@ -20,57 +20,57 @@ namespace XmlEditor.Tests.Parser
string namespaceURI = "http://foo.com/foo.xsd"; string namespaceURI = "http://foo.com/foo.xsd";
[Test] [Test]
public void PathTest1() public void GetActiveElementStartPathForRootElement()
{ {
string text = "<foo xmlns='" + namespaceURI + "' "; string text = "<foo xmlns='" + namespaceURI + "' ";
elementPath = XmlParser.GetActiveElementStartPath(text, text.Length); elementPath = XmlParser.GetActiveElementStartPath(text, text.Length);
expectedElementPath = new XmlElementPath(); expectedElementPath = new XmlElementPath();
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI)); expectedElementPath.AddElement(new QualifiedName("foo", namespaceURI));
Assert.IsTrue(elementPath.Equals(expectedElementPath), Assert.IsTrue(elementPath.Equals(expectedElementPath),
"Incorrect active element path."); "Incorrect active element path.");
} }
[Test] [Test]
public void PathTest2() public void GetActiveElementStartPathForChildElement()
{ {
string text = "<foo xmlns='" + namespaceURI + "' ><bar "; string text = "<foo xmlns='" + namespaceURI + "' ><bar ";
elementPath = XmlParser.GetActiveElementStartPath(text, text.Length); elementPath = XmlParser.GetActiveElementStartPath(text, text.Length);
expectedElementPath = new XmlElementPath(); expectedElementPath = new XmlElementPath();
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI)); expectedElementPath.AddElement(new QualifiedName("foo", namespaceURI));
expectedElementPath.Elements.Add(new QualifiedName("bar", namespaceURI)); expectedElementPath.AddElement(new QualifiedName("bar", namespaceURI));
Assert.IsTrue(expectedElementPath.Equals(elementPath), Assert.IsTrue(expectedElementPath.Equals(elementPath),
"Incorrect active element path."); "Incorrect active element path.");
} }
[Test] [Test]
public void PathTest3() public void GetActiveElementStartPathForChildElementWithNamespacePrefix()
{ {
string text = "<f:foo xmlns:f='" + namespaceURI + "' ><f:bar "; string text = "<f:foo xmlns:f='" + namespaceURI + "' ><f:bar ";
elementPath = XmlParser.GetActiveElementStartPath(text, text.Length); elementPath = XmlParser.GetActiveElementStartPath(text, text.Length);
expectedElementPath = new XmlElementPath(); expectedElementPath = new XmlElementPath();
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI, "f")); expectedElementPath.AddElement(new QualifiedName("foo", namespaceURI, "f"));
expectedElementPath.Elements.Add(new QualifiedName("bar", namespaceURI, "f")); expectedElementPath.AddElement(new QualifiedName("bar", namespaceURI, "f"));
Assert.IsTrue(expectedElementPath.Equals(elementPath), Assert.IsTrue(expectedElementPath.Equals(elementPath),
"Incorrect active element path."); "Incorrect active element path.");
} }
[Test] [Test]
public void PathTest4() public void GetActiveElementStartPathForRootElementWithNamespacePrefix()
{ {
string text = "<x:foo xmlns:x='" + namespaceURI + "' "; string text = "<x:foo xmlns:x='" + namespaceURI + "' ";
elementPath = XmlParser.GetActiveElementStartPath(text, text.Length); elementPath = XmlParser.GetActiveElementStartPath(text, text.Length);
expectedElementPath = new XmlElementPath(); expectedElementPath = new XmlElementPath();
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI, "x")); expectedElementPath.AddElement(new QualifiedName("foo", namespaceURI, "x"));
Assert.IsTrue(expectedElementPath.Equals(elementPath), Assert.IsTrue(expectedElementPath.Equals(elementPath),
"Incorrect active element path."); "Incorrect active element path.");
} }
[Test] [Test]
public void PathTest5() public void GetActiveElementStartPathWithTextIncludingChildElementAttributesOnDifferentLine()
{ {
string text = "<foo xmlns='" + namespaceURI + "'>\r\n"+ string text = "<foo xmlns='" + namespaceURI + "'>\r\n"+
"<y\r\n" + "<y\r\n" +
@ -79,14 +79,14 @@ namespace XmlEditor.Tests.Parser
elementPath = XmlParser.GetActiveElementStartPath(text, text.Length); elementPath = XmlParser.GetActiveElementStartPath(text, text.Length);
expectedElementPath = new XmlElementPath(); expectedElementPath = new XmlElementPath();
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI)); expectedElementPath.AddElement(new QualifiedName("foo", namespaceURI));
expectedElementPath.Elements.Add(new QualifiedName("y", namespaceURI)); expectedElementPath.AddElement(new QualifiedName("y", namespaceURI));
Assert.IsTrue(expectedElementPath.Equals(elementPath), Assert.IsTrue(expectedElementPath.Equals(elementPath),
"Incorrect active element path."); "Incorrect active element path.");
} }
[Test] [Test]
public void PathTest6() public void GetActiveElementStartPathWithTwoElementsInDifferentNamespaces()
{ {
string text = "<bar xmlns='http://bar'>\r\n" + string text = "<bar xmlns='http://bar'>\r\n" +
"<foo xmlns='" + namespaceURI + "' "; "<foo xmlns='" + namespaceURI + "' ";
@ -94,7 +94,8 @@ namespace XmlEditor.Tests.Parser
elementPath = XmlParser.GetActiveElementStartPath(text, text.Length); elementPath = XmlParser.GetActiveElementStartPath(text, text.Length);
expectedElementPath = new XmlElementPath(); expectedElementPath = new XmlElementPath();
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI)); expectedElementPath.AddElement(new QualifiedName("bar", "http://bar"));
expectedElementPath.AddElement(new QualifiedName("foo", namespaceURI));
Assert.IsTrue(expectedElementPath.Equals(elementPath), Assert.IsTrue(expectedElementPath.Equals(elementPath),
"Incorrect active element path."); "Incorrect active element path.");
} }
@ -104,7 +105,7 @@ namespace XmlEditor.Tests.Parser
/// tag. /// tag.
/// </summary> /// </summary>
[Test] [Test]
public void OutOfStartTagPathTest1() public void GetActiveElementStartPathWhenOutOfStartTagPath()
{ {
string text = "<foo xmlns='" + namespaceURI + "'> "; string text = "<foo xmlns='" + namespaceURI + "'> ";

50
src/AddIns/DisplayBindings/XmlEditor/Test/Parser/ActiveElementUnderCursorTests.cs

@ -40,8 +40,8 @@ namespace XmlEditor.Tests.Parser
elementPath = XmlParser.GetActiveElementStartPathAtIndex(text, text.IndexOf("bar ")); elementPath = XmlParser.GetActiveElementStartPathAtIndex(text, text.IndexOf("bar "));
expectedElementPath = new XmlElementPath(); expectedElementPath = new XmlElementPath();
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI)); expectedElementPath.AddElement(new QualifiedName("foo", namespaceURI));
expectedElementPath.Elements.Add(new QualifiedName("bar", namespaceURI)); expectedElementPath.AddElement(new QualifiedName("bar", namespaceURI));
Assert.IsTrue(elementPath.Equals(expectedElementPath), Assert.IsTrue(elementPath.Equals(expectedElementPath),
"Incorrect active element path."); "Incorrect active element path.");
} }
@ -53,8 +53,8 @@ namespace XmlEditor.Tests.Parser
elementPath = XmlParser.GetActiveElementStartPathAtIndex(text, text.IndexOf("bar>")); elementPath = XmlParser.GetActiveElementStartPathAtIndex(text, text.IndexOf("bar>"));
expectedElementPath = new XmlElementPath(); expectedElementPath = new XmlElementPath();
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI)); expectedElementPath.AddElement(new QualifiedName("foo", namespaceURI));
expectedElementPath.Elements.Add(new QualifiedName("bar", namespaceURI)); expectedElementPath.AddElement(new QualifiedName("bar", namespaceURI));
Assert.IsTrue(elementPath.Equals(expectedElementPath), Assert.IsTrue(elementPath.Equals(expectedElementPath),
"Incorrect active element path."); "Incorrect active element path.");
} }
@ -66,8 +66,8 @@ namespace XmlEditor.Tests.Parser
elementPath = XmlParser.GetActiveElementStartPathAtIndex(text, text.IndexOf("ar>")); elementPath = XmlParser.GetActiveElementStartPathAtIndex(text, text.IndexOf("ar>"));
expectedElementPath = new XmlElementPath(); expectedElementPath = new XmlElementPath();
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI)); expectedElementPath.AddElement(new QualifiedName("foo", namespaceURI));
expectedElementPath.Elements.Add(new QualifiedName("bar", namespaceURI)); expectedElementPath.AddElement(new QualifiedName("bar", namespaceURI));
Assert.IsTrue(elementPath.Equals(expectedElementPath), Assert.IsTrue(elementPath.Equals(expectedElementPath),
"Incorrect active element path."); "Incorrect active element path.");
} }
@ -79,8 +79,8 @@ namespace XmlEditor.Tests.Parser
elementPath = XmlParser.GetActiveElementStartPathAtIndex(text, text.Length - 1); elementPath = XmlParser.GetActiveElementStartPathAtIndex(text, text.Length - 1);
expectedElementPath = new XmlElementPath(); expectedElementPath = new XmlElementPath();
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI)); expectedElementPath.AddElement(new QualifiedName("foo", namespaceURI));
expectedElementPath.Elements.Add(new QualifiedName("bar", namespaceURI)); expectedElementPath.AddElement(new QualifiedName("bar", namespaceURI));
Assert.IsTrue(elementPath.Equals(expectedElementPath), Assert.IsTrue(elementPath.Equals(expectedElementPath),
"Incorrect active element path."); "Incorrect active element path.");
} }
@ -92,8 +92,8 @@ namespace XmlEditor.Tests.Parser
elementPath = XmlParser.GetActiveElementStartPathAtIndex(text, text.IndexOf("='a'")); elementPath = XmlParser.GetActiveElementStartPathAtIndex(text, text.IndexOf("='a'"));
expectedElementPath = new XmlElementPath(); expectedElementPath = new XmlElementPath();
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI)); expectedElementPath.AddElement(new QualifiedName("foo", namespaceURI));
expectedElementPath.Elements.Add(new QualifiedName("bar", namespaceURI)); expectedElementPath.AddElement(new QualifiedName("bar", namespaceURI));
Assert.IsTrue(elementPath.Equals(expectedElementPath), Assert.IsTrue(elementPath.Equals(expectedElementPath),
"Incorrect active element path."); "Incorrect active element path.");
} }
@ -105,8 +105,8 @@ namespace XmlEditor.Tests.Parser
elementPath = XmlParser.GetActiveElementStartPathAtIndex(text, text.Length - 1); elementPath = XmlParser.GetActiveElementStartPathAtIndex(text, text.Length - 1);
expectedElementPath = new XmlElementPath(); expectedElementPath = new XmlElementPath();
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI)); expectedElementPath.AddElement(new QualifiedName("foo", namespaceURI));
expectedElementPath.Elements.Add(new QualifiedName("bar", namespaceURI)); expectedElementPath.AddElement(new QualifiedName("bar", namespaceURI));
Assert.IsTrue(elementPath.Equals(expectedElementPath), Assert.IsTrue(elementPath.Equals(expectedElementPath),
"Incorrect active element path."); "Incorrect active element path.");
} }
@ -118,8 +118,8 @@ namespace XmlEditor.Tests.Parser
elementPath = XmlParser.GetActiveElementStartPathAtIndex(text, text.Length); elementPath = XmlParser.GetActiveElementStartPathAtIndex(text, text.Length);
expectedElementPath = new XmlElementPath(); expectedElementPath = new XmlElementPath();
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI)); expectedElementPath.AddElement(new QualifiedName("foo", namespaceURI));
expectedElementPath.Elements.Add(new QualifiedName("bar", namespaceURI)); expectedElementPath.AddElement(new QualifiedName("bar", namespaceURI));
Assert.IsTrue(elementPath.Equals(expectedElementPath), Assert.IsTrue(elementPath.Equals(expectedElementPath),
"Incorrect active element path."); "Incorrect active element path.");
} }
@ -131,8 +131,8 @@ namespace XmlEditor.Tests.Parser
elementPath = XmlParser.GetActiveElementStartPathAtIndex(text, text.Length); elementPath = XmlParser.GetActiveElementStartPathAtIndex(text, text.Length);
expectedElementPath = new XmlElementPath(); expectedElementPath = new XmlElementPath();
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI)); expectedElementPath.AddElement(new QualifiedName("foo", namespaceURI));
expectedElementPath.Elements.Add(new QualifiedName("bar", namespaceURI)); expectedElementPath.AddElement(new QualifiedName("bar", namespaceURI));
Assert.IsTrue(elementPath.Equals(expectedElementPath), Assert.IsTrue(elementPath.Equals(expectedElementPath),
"Incorrect active element path."); "Incorrect active element path.");
} }
@ -144,8 +144,8 @@ namespace XmlEditor.Tests.Parser
elementPath = XmlParser.GetActiveElementStartPathAtIndex(text, text.Length); elementPath = XmlParser.GetActiveElementStartPathAtIndex(text, text.Length);
expectedElementPath = new XmlElementPath(); expectedElementPath = new XmlElementPath();
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI)); expectedElementPath.AddElement(new QualifiedName("foo", namespaceURI));
expectedElementPath.Elements.Add(new QualifiedName("bar", namespaceURI)); expectedElementPath.AddElement(new QualifiedName("bar", namespaceURI));
Assert.IsTrue(elementPath.Equals(expectedElementPath), Assert.IsTrue(elementPath.Equals(expectedElementPath),
"Incorrect active element path."); "Incorrect active element path.");
} }
@ -157,8 +157,8 @@ namespace XmlEditor.Tests.Parser
elementPath = XmlParser.GetActiveElementStartPathAtIndex(text, text.IndexOf("Id=")); elementPath = XmlParser.GetActiveElementStartPathAtIndex(text, text.IndexOf("Id="));
expectedElementPath = new XmlElementPath(); expectedElementPath = new XmlElementPath();
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI)); expectedElementPath.AddElement(new QualifiedName("foo", namespaceURI));
expectedElementPath.Elements.Add(new QualifiedName("bar", namespaceURI)); expectedElementPath.AddElement(new QualifiedName("bar", namespaceURI));
Assert.IsTrue(elementPath.Equals(expectedElementPath), Assert.IsTrue(elementPath.Equals(expectedElementPath),
"Incorrect active element path."); "Incorrect active element path.");
} }
@ -170,7 +170,7 @@ namespace XmlEditor.Tests.Parser
elementPath = XmlParser.GetActiveElementStartPathAtIndex(text, 2); elementPath = XmlParser.GetActiveElementStartPathAtIndex(text, 2);
expectedElementPath = new XmlElementPath(); expectedElementPath = new XmlElementPath();
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI)); expectedElementPath.AddElement(new QualifiedName("foo", namespaceURI));
Assert.IsTrue(elementPath.Equals(expectedElementPath), Assert.IsTrue(elementPath.Equals(expectedElementPath),
"Incorrect active element path."); "Incorrect active element path.");
} }
@ -184,8 +184,8 @@ namespace XmlEditor.Tests.Parser
elementPath = XmlParser.GetActiveElementStartPathAtIndex(text + text2, text.Length); elementPath = XmlParser.GetActiveElementStartPathAtIndex(text + text2, text.Length);
expectedElementPath = new XmlElementPath(); expectedElementPath = new XmlElementPath();
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI)); expectedElementPath.AddElement(new QualifiedName("foo", namespaceURI));
expectedElementPath.Elements.Add(new QualifiedName("bar", namespaceURI)); expectedElementPath.AddElement(new QualifiedName("bar", namespaceURI));
Assert.IsTrue(elementPath.Equals(expectedElementPath), "Incorrect active element path."); Assert.IsTrue(elementPath.Equals(expectedElementPath), "Incorrect active element path.");
} }
@ -198,8 +198,8 @@ namespace XmlEditor.Tests.Parser
elementPath = XmlParser.GetActiveElementStartPathAtIndex(text + text2, text.Length); elementPath = XmlParser.GetActiveElementStartPathAtIndex(text + text2, text.Length);
expectedElementPath = new XmlElementPath(); expectedElementPath = new XmlElementPath();
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI)); expectedElementPath.AddElement(new QualifiedName("foo", namespaceURI));
expectedElementPath.Elements.Add(new QualifiedName("bar", namespaceURI)); expectedElementPath.AddElement(new QualifiedName("bar", namespaceURI));
Assert.IsTrue(elementPath.Equals(expectedElementPath), "Incorrect active element path."); Assert.IsTrue(elementPath.Equals(expectedElementPath), "Incorrect active element path.");
} }
} }

48
src/AddIns/DisplayBindings/XmlEditor/Test/Parser/NamespacesInScopeForPathTests.cs

@ -0,0 +1,48 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.XmlEditor;
using NUnit.Framework;
namespace XmlEditor.Tests.Parser
{
[TestFixture]
public class NamespacesInScopeForPathTests
{
XmlNamespace xmlNamespace;
[SetUp]
public void Init()
{
xmlNamespace = new XmlNamespace("xml", "http://www.w3.org/XML/1998/namespace");
}
[Test]
public void XmlNamespaceInScopeForRootElementWithNoNamespace()
{
string xml = "<root ";
XmlElementPath path = XmlParser.GetActiveElementStartPath(xml, xml.Length);
XmlNamespace[] expectedNamespaces = new XmlNamespace[] {xmlNamespace};
Assert.AreEqual(expectedNamespaces, path.NamespacesInScope.ToArray());
}
[Test]
public void TwoNamespacesInScopeForRootElement()
{
string xml = "<root xmlns='test' ";
XmlElementPath path = XmlParser.GetActiveElementStartPath(xml, xml.Length);
XmlNamespace testNamespace = new XmlNamespace(String.Empty, "test");
XmlNamespace[] expectedNamespaces = new XmlNamespace[] {xmlNamespace, testNamespace};
Assert.AreEqual(expectedNamespaces, path.NamespacesInScope.ToArray());
}
}
}

17
src/AddIns/DisplayBindings/XmlEditor/Test/Parser/ParentElementPathTestFixture.cs

@ -20,49 +20,50 @@ namespace XmlEditor.Tests.Parser
string namespaceURI = "http://foo/foo.xsd"; string namespaceURI = "http://foo/foo.xsd";
[Test] [Test]
public void SuccessTest1() public void GetParentElementPathForRootElement()
{ {
string text = "<foo xmlns='" + namespaceURI + "' ><"; string text = "<foo xmlns='" + namespaceURI + "' ><";
elementPath = XmlParser.GetParentElementPath(text); elementPath = XmlParser.GetParentElementPath(text);
expectedElementPath = new XmlElementPath(); expectedElementPath = new XmlElementPath();
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI)); expectedElementPath.AddElement(new QualifiedName("foo", namespaceURI));
Assert.IsTrue(elementPath.Equals(expectedElementPath), Assert.IsTrue(elementPath.Equals(expectedElementPath),
"Incorrect active element path."); "Incorrect active element path.");
} }
[Test] [Test]
public void SuccessTest2() public void GetParentElementPathForRootElementAfterChildElementEnd()
{ {
string text = "<foo xmlns='" + namespaceURI + "' ><bar></bar><"; string text = "<foo xmlns='" + namespaceURI + "' ><bar></bar><";
elementPath = XmlParser.GetParentElementPath(text); elementPath = XmlParser.GetParentElementPath(text);
expectedElementPath = new XmlElementPath(); expectedElementPath = new XmlElementPath();
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI)); expectedElementPath.AddElement(new QualifiedName("foo", namespaceURI));
Assert.IsTrue(elementPath.Equals(expectedElementPath), Assert.IsTrue(elementPath.Equals(expectedElementPath),
"Incorrect active element path."); "Incorrect active element path.");
} }
[Test] [Test]
public void SuccessTest3() public void GetParentElementPathForRootElementAfterEmptyChildElementEnd()
{ {
string text = "<foo xmlns='" + namespaceURI + "' ><bar/><"; string text = "<foo xmlns='" + namespaceURI + "' ><bar/><";
elementPath = XmlParser.GetParentElementPath(text); elementPath = XmlParser.GetParentElementPath(text);
expectedElementPath = new XmlElementPath(); expectedElementPath = new XmlElementPath();
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI)); expectedElementPath.AddElement(new QualifiedName("foo", namespaceURI));
Assert.IsTrue(elementPath.Equals(expectedElementPath), Assert.IsTrue(elementPath.Equals(expectedElementPath),
"Incorrect active element path."); "Incorrect active element path.");
} }
[Test] [Test]
public void SuccessTest4() public void GetParentElementPathForTwoElementsInDifferentNamespaces()
{ {
string text = "<bar xmlns='http://test.com'><foo xmlns='" + namespaceURI + "' ><"; string text = "<bar xmlns='http://test.com'><foo xmlns='" + namespaceURI + "' ><";
elementPath = XmlParser.GetParentElementPath(text); elementPath = XmlParser.GetParentElementPath(text);
expectedElementPath = new XmlElementPath(); expectedElementPath = new XmlElementPath();
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI)); expectedElementPath.AddElement(new QualifiedName("bar", "http://test.com"));
expectedElementPath.AddElement(new QualifiedName("foo", namespaceURI));
Assert.IsTrue(elementPath.Equals(expectedElementPath), Assert.IsTrue(elementPath.Equals(expectedElementPath),
"Incorrect active element path."); "Incorrect active element path.");
} }

24
src/AddIns/DisplayBindings/XmlEditor/Test/Parser/XamlMixedNamespaceTestFixture.cs

@ -62,7 +62,17 @@ namespace XmlEditor.Tests.Parser
public void DesignSurfacePath() public void DesignSurfacePath()
{ {
XmlElementPath expectedPath = new XmlElementPath(); XmlElementPath expectedPath = new XmlElementPath();
expectedPath.Elements.Add(new QualifiedName("DesignSurface", "clr-namespace:ICSharpCode.WpfDesign.Designer;assembly=ICSharpCode.WpfDesign.Designer", "designer"));
string xamlNamespace = "http://schemas.microsoft.com/winfx/2006/xaml/presentation";
expectedPath.AddElement(new QualifiedName("Window", xamlNamespace));
expectedPath.AddElement(new QualifiedName("Grid", xamlNamespace));
expectedPath.AddElement(new QualifiedName("TabControl", xamlNamespace));
expectedPath.AddElement(new QualifiedName("TabItem", xamlNamespace));
QualifiedName designSurfaceElement = new QualifiedName("DesignSurface",
"clr-namespace:ICSharpCode.WpfDesign.Designer;assembly=ICSharpCode.WpfDesign.Designer",
"designer");
expectedPath.AddElement(designSurfaceElement);
Assert.AreEqual(expectedPath, designSurfacePath); Assert.AreEqual(expectedPath, designSurfacePath);
} }
@ -71,7 +81,17 @@ namespace XmlEditor.Tests.Parser
public void DesignSurfacePath2() public void DesignSurfacePath2()
{ {
XmlElementPath expectedPath = new XmlElementPath(); XmlElementPath expectedPath = new XmlElementPath();
expectedPath.Elements.Add(new QualifiedName("DesignSurface", "clr-namespace:ICSharpCode.WpfDesign.Designer;assembly=ICSharpCode.WpfDesign.Designer", "designer"));
string xamlNamespace = "http://schemas.microsoft.com/winfx/2006/xaml/presentation";
expectedPath.AddElement(new QualifiedName("Window", xamlNamespace));
expectedPath.AddElement(new QualifiedName("Grid", xamlNamespace));
expectedPath.AddElement(new QualifiedName("TabControl", xamlNamespace));
expectedPath.AddElement(new QualifiedName("TabItem", xamlNamespace));
QualifiedName designSurfaceElement = new QualifiedName("DesignSurface",
"clr-namespace:ICSharpCode.WpfDesign.Designer;assembly=ICSharpCode.WpfDesign.Designer",
"designer");
expectedPath.AddElement(designSurfaceElement);
Assert.AreEqual(expectedPath, designSurfacePath2); Assert.AreEqual(expectedPath, designSurfacePath2);
} }

16
src/AddIns/DisplayBindings/XmlEditor/Test/Paths/ChangeElementPathDefaultNamespaceTests.cs

@ -18,13 +18,13 @@ namespace XmlEditor.Tests.Paths
public void ChangeNamespaceForTwoElementsWithoutNamespaceModifiesAllItems() public void ChangeNamespaceForTwoElementsWithoutNamespaceModifiesAllItems()
{ {
XmlElementPath path = new XmlElementPath(); XmlElementPath path = new XmlElementPath();
path.Elements.Add(new QualifiedName("root", String.Empty)); path.AddElement(new QualifiedName("root", String.Empty));
path.Elements.Add(new QualifiedName("child", String.Empty)); path.AddElement(new QualifiedName("child", String.Empty));
path.SetNamespaceForUnqualifiedNames("http://test"); path.SetNamespaceForUnqualifiedNames("http://test");
XmlElementPath expectedPath = new XmlElementPath(); XmlElementPath expectedPath = new XmlElementPath();
expectedPath.Elements.Add(new QualifiedName("root", "http://test")); expectedPath.AddElement(new QualifiedName("root", "http://test"));
expectedPath.Elements.Add(new QualifiedName("child", "http://test")); expectedPath.AddElement(new QualifiedName("child", "http://test"));
Assert.IsTrue(expectedPath.Equals(path)); Assert.IsTrue(expectedPath.Equals(path));
} }
@ -33,13 +33,13 @@ namespace XmlEditor.Tests.Paths
public void ChangeNamespaceForTwoElementsWhereChildElementHasOwnNamespaceOnlyAffectsRootElement() public void ChangeNamespaceForTwoElementsWhereChildElementHasOwnNamespaceOnlyAffectsRootElement()
{ {
XmlElementPath path = new XmlElementPath(); XmlElementPath path = new XmlElementPath();
path.Elements.Add(new QualifiedName("root", String.Empty)); path.AddElement(new QualifiedName("root", String.Empty));
path.Elements.Add(new QualifiedName("child", "has-namespace-already")); path.AddElement(new QualifiedName("child", "has-namespace-already"));
path.SetNamespaceForUnqualifiedNames("http://test"); path.SetNamespaceForUnqualifiedNames("http://test");
XmlElementPath expectedPath = new XmlElementPath(); XmlElementPath expectedPath = new XmlElementPath();
expectedPath.Elements.Add(new QualifiedName("root", "http://test")); expectedPath.AddElement(new QualifiedName("root", "http://test"));
expectedPath.Elements.Add(new QualifiedName("child", "has-namespace-already")); expectedPath.AddElement(new QualifiedName("child", "has-namespace-already"));
Assert.IsTrue(expectedPath.Equals(path)); Assert.IsTrue(expectedPath.Equals(path));
} }

32
src/AddIns/DisplayBindings/XmlEditor/Test/Paths/EmptyElementPathsByNamespaceTestFixture.cs

@ -0,0 +1,32 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.XmlEditor;
using NUnit.Framework;
namespace XmlEditor.Tests.Paths
{
[TestFixture]
public class EmptyElementPathsByNamespaceTestFixture
{
XmlElementPathsByNamespace paths;
[SetUp]
public void Init()
{
XmlElementPath path = new XmlElementPath();
paths = new XmlElementPathsByNamespace(path);
}
[Test]
public void HasNoItemsWhenCreated()
{
Assert.AreEqual(0, paths.Count);
}
}
}

42
src/AddIns/DisplayBindings/XmlEditor/Test/Paths/NamespacesWithoutPathsTests.cs

@ -0,0 +1,42 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.XmlEditor;
using NUnit.Framework;
namespace XmlEditor.Tests.Paths
{
[TestFixture]
public class NamespacesWithoutPathsTests
{
XmlElementPath path;
XmlNamespace fooNamespace;
XmlNamespace barNamespace;
[SetUp]
public void Init()
{
path = new XmlElementPath();
fooNamespace = new XmlNamespace("foo", "http://foo");
barNamespace = new XmlNamespace("bar", "http://bar");
}
[Test]
public void TwoNamespacesInScopeAndOneNamespaceUsedInPathNamespacesWithoutPathsReturnsUnusedNamespace()
{
path.AddElement(new QualifiedName("foo-root", "http://foo"));
path.NamespacesInScope.Add(fooNamespace);
path.NamespacesInScope.Add(barNamespace);
XmlElementPathsByNamespace pathsByNamespaces = new XmlElementPathsByNamespace(path);
XmlNamespace[] expectedNamespaces = new XmlNamespace[] {barNamespace};
Assert.AreEqual(expectedNamespaces, pathsByNamespaces.NamespacesWithoutPaths.ToArray());
}
}
}

2
src/AddIns/DisplayBindings/XmlEditor/Test/Paths/NoElementPathTestFixture.cs

@ -52,7 +52,7 @@ namespace XmlEditor.Tests.Paths
public void NotEqual() public void NotEqual()
{ {
XmlElementPath newPath = new XmlElementPath(); XmlElementPath newPath = new XmlElementPath();
newPath.Elements.Add(new QualifiedName("Foo", "bar")); newPath.AddElement(new QualifiedName("Foo", "bar"));
Assert.IsFalse(newPath.Equals(path), "Should not be equal."); Assert.IsFalse(newPath.Equals(path), "Should not be equal.");
} }

54
src/AddIns/DisplayBindings/XmlEditor/Test/Paths/OneAndTwoElementPathsTestFixture.cs

@ -0,0 +1,54 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.XmlEditor;
using NUnit.Framework;
namespace XmlEditor.Tests.Paths
{
[TestFixture]
public class OneAndTwoElementPathsByNamespaceTestFixture
{
XmlElementPathsByNamespace paths;
[SetUp]
public void Init()
{
XmlElementPath path = new XmlElementPath();
path.AddElement(new QualifiedName("a", "a-namespace"));
path.AddElement(new QualifiedName("b", "b-namespace"));
path.AddElement(new QualifiedName("aa", "a-namespace"));
paths = new XmlElementPathsByNamespace(path);
}
[Test]
public void HasTwoXmlElementPaths()
{
Assert.AreEqual(2, paths.Count);
}
[Test]
public void FirstXmlElementPathHasTwoElements()
{
XmlElementPath expectedPath = new XmlElementPath();
expectedPath.AddElement(new QualifiedName("a", "a-namespace"));
expectedPath.AddElement(new QualifiedName("aa", "a-namespace"));
Assert.AreEqual(expectedPath, paths[0]);
}
[Test]
public void SecondXmlElementPathHasOneElement()
{
XmlElementPath expectedPath = new XmlElementPath();
expectedPath.AddElement(new QualifiedName("b", "b-namespace"));
Assert.AreEqual(expectedPath, paths[1]);
}
}
}

8
src/AddIns/DisplayBindings/XmlEditor/Test/Paths/QualifiedNameToStringTests.cs

@ -69,5 +69,13 @@ namespace XmlEditor.Tests.Paths
QualifiedName name = new QualifiedName("root", "urn:my-uri", null); QualifiedName name = new QualifiedName("root", "urn:my-uri", null);
Assert.AreEqual("root [urn:my-uri]", name.ToString()); Assert.AreEqual("root [urn:my-uri]", name.ToString());
} }
[Test]
public void CreateQualifiedNameWithXmlNamespaceObject()
{
XmlNamespace ns = new XmlNamespace("prefix", "namespace");
QualifiedName name = new QualifiedName("elementName", ns);
Assert.AreEqual("prefix:elementName [namespace]", name.ToString());
}
} }
} }

42
src/AddIns/DisplayBindings/XmlEditor/Test/Paths/SingleElementPathByNamespaceTestFixture.cs

@ -0,0 +1,42 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.XmlEditor;
using NUnit.Framework;
namespace XmlEditor.Tests.Paths
{
[TestFixture]
public class SingleElementPathByNamespaceTestFixture
{
XmlElementPathsByNamespace paths;
[SetUp]
public void Init()
{
XmlElementPath path = new XmlElementPath();
path.AddElement(new QualifiedName("a", "a-namespace"));
paths = new XmlElementPathsByNamespace(path);
}
[Test]
public void HasSingleXmlElementPath()
{
Assert.AreEqual(1, paths.Count);
}
[Test]
public void XmlElementPathHasOneElement()
{
XmlElementPath expectedPath = new XmlElementPath();
expectedPath.AddElement(new QualifiedName("a", "a-namespace"));
Assert.AreEqual(expectedPath, paths[0]);
}
}
}

8
src/AddIns/DisplayBindings/XmlEditor/Test/Paths/SingleElementPathTestFixture.cs

@ -22,7 +22,7 @@ namespace XmlEditor.Tests.Paths
{ {
path = new XmlElementPath(); path = new XmlElementPath();
qualifiedName = new QualifiedName("foo", "http://foo"); qualifiedName = new QualifiedName("foo", "http://foo");
path.Elements.Add(qualifiedName); path.AddElement(qualifiedName);
} }
[Test] [Test]
@ -43,7 +43,7 @@ namespace XmlEditor.Tests.Paths
public void Equality() public void Equality()
{ {
XmlElementPath newPath = new XmlElementPath(); XmlElementPath newPath = new XmlElementPath();
newPath.Elements.Add(new QualifiedName("foo", "http://foo")); newPath.AddElement(new QualifiedName("foo", "http://foo"));
Assert.IsTrue(newPath.Equals(path), "Should be equal."); Assert.IsTrue(newPath.Equals(path), "Should be equal.");
} }
@ -52,7 +52,7 @@ namespace XmlEditor.Tests.Paths
public void NotEqual() public void NotEqual()
{ {
XmlElementPath newPath = new XmlElementPath(); XmlElementPath newPath = new XmlElementPath();
newPath.Elements.Add(new QualifiedName("Foo", "bar")); newPath.AddElement(new QualifiedName("Foo", "bar"));
Assert.IsFalse(newPath.Equals(path), "Should not be equal."); Assert.IsFalse(newPath.Equals(path), "Should not be equal.");
} }
@ -75,7 +75,7 @@ namespace XmlEditor.Tests.Paths
public void TwoElementsPathToString() public void TwoElementsPathToString()
{ {
QualifiedName qualifiedName = new QualifiedName("bar", "http://foo"); QualifiedName qualifiedName = new QualifiedName("bar", "http://foo");
path.Elements.Add(qualifiedName); path.AddElement(qualifiedName);
Assert.AreEqual("foo [http://foo] > bar [http://foo]", path.ToString()); Assert.AreEqual("foo [http://foo] > bar [http://foo]", path.ToString());
} }

47
src/AddIns/DisplayBindings/XmlEditor/Test/Paths/TwoElementPathTestFixture.cs

@ -5,9 +5,9 @@
// <version>$Revision$</version> // <version>$Revision$</version>
// </file> // </file>
using System;
using ICSharpCode.XmlEditor; using ICSharpCode.XmlEditor;
using NUnit.Framework; using NUnit.Framework;
using System;
namespace XmlEditor.Tests.Paths namespace XmlEditor.Tests.Paths
{ {
@ -23,10 +23,10 @@ namespace XmlEditor.Tests.Paths
{ {
path = new XmlElementPath(); path = new XmlElementPath();
firstQualifiedName = new QualifiedName("foo", "http://foo", "f"); firstQualifiedName = new QualifiedName("foo", "http://foo", "f");
path.Elements.Add(firstQualifiedName); path.AddElement(firstQualifiedName);
secondQualifiedName = new QualifiedName("bar", "http://bar", "b"); secondQualifiedName = new QualifiedName("bar", "http://bar", "b");
path.Elements.Add(secondQualifiedName); path.AddElement(secondQualifiedName);
} }
[Test] [Test]
@ -61,8 +61,8 @@ namespace XmlEditor.Tests.Paths
public void Equality() public void Equality()
{ {
XmlElementPath newPath = new XmlElementPath(); XmlElementPath newPath = new XmlElementPath();
newPath.Elements.Add(new QualifiedName("foo", "http://foo", "f")); newPath.AddElement(new QualifiedName("foo", "http://foo", "f"));
newPath.Elements.Add(new QualifiedName("bar", "http://bar", "b")); newPath.AddElement(new QualifiedName("bar", "http://bar", "b"));
Assert.IsTrue(newPath.Equals(path), "Should be equal."); Assert.IsTrue(newPath.Equals(path), "Should be equal.");
} }
@ -71,8 +71,8 @@ namespace XmlEditor.Tests.Paths
public void NotEqual() public void NotEqual()
{ {
XmlElementPath newPath = new XmlElementPath(); XmlElementPath newPath = new XmlElementPath();
newPath.Elements.Add(new QualifiedName("aaa", "a", "a")); newPath.AddElement(new QualifiedName("aaa", "a", "a"));
newPath.Elements.Add(new QualifiedName("bbb", "b", "b")); newPath.AddElement(new QualifiedName("bbb", "b", "b"));
Assert.IsFalse(newPath.Equals(path), "Should not be equal."); Assert.IsFalse(newPath.Equals(path), "Should not be equal.");
} }
@ -88,7 +88,7 @@ namespace XmlEditor.Tests.Paths
public void CompactPathItem() public void CompactPathItem()
{ {
XmlElementPath newPath = new XmlElementPath(); XmlElementPath newPath = new XmlElementPath();
newPath.Elements.Add(new QualifiedName("bar", "http://bar", "b")); newPath.AddElement(new QualifiedName("bar", "http://bar", "b"));
path.Compact(); path.Compact();
Assert.IsTrue(newPath.Equals(path), "Should be equal."); Assert.IsTrue(newPath.Equals(path), "Should be equal.");
@ -100,5 +100,36 @@ namespace XmlEditor.Tests.Paths
string expectedToString = "f:foo [http://foo] > b:bar [http://bar]"; string expectedToString = "f:foo [http://foo] > b:bar [http://bar]";
Assert.AreEqual(expectedToString, path.ToString()); Assert.AreEqual(expectedToString, path.ToString());
} }
[Test]
public void ElementPathsByNamespaceFoo()
{
XmlElementPathsByNamespace paths = new XmlElementPathsByNamespace(path);
XmlElementPath fooPath = paths[0];
XmlElementPath expectedPath = new XmlElementPath();
expectedPath.AddElement(new QualifiedName("foo", "http://foo", "f"));
Assert.IsTrue(expectedPath.Equals(fooPath));
}
[Test]
public void TwoElementPathsByNamespace()
{
XmlElementPathsByNamespace paths = new XmlElementPathsByNamespace(path);
Assert.AreEqual(2, paths.Count);
}
[Test]
public void ElementPathsByNamespaceBar()
{
XmlElementPathsByNamespace paths = new XmlElementPathsByNamespace(path);
XmlElementPath barPath = paths[1];
XmlElementPath expectedPath = new XmlElementPath();
expectedPath.AddElement(new QualifiedName("bar", "http://bar", "b"));
Assert.IsTrue(expectedPath.Equals(barPath));
}
} }
} }

52
src/AddIns/DisplayBindings/XmlEditor/Test/Paths/TwoElementPathsByNamespaceTestFixture.cs

@ -0,0 +1,52 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.XmlEditor;
using NUnit.Framework;
namespace XmlEditor.Tests.Paths
{
[TestFixture]
public class TwoElementPathsByNamespaceTestFixture
{
XmlElementPathsByNamespace paths;
[SetUp]
public void Init()
{
XmlElementPath path = new XmlElementPath();
path.AddElement(new QualifiedName("a", "a-namespace"));
path.AddElement(new QualifiedName("b", "b-namespace"));
paths = new XmlElementPathsByNamespace(path);
}
[Test]
public void HasTwoXmlElementPaths()
{
Assert.AreEqual(2, paths.Count);
}
[Test]
public void FirstXmlElementPathHasOneElement()
{
XmlElementPath expectedPath = new XmlElementPath();
expectedPath.AddElement(new QualifiedName("a", "a-namespace"));
Assert.AreEqual(expectedPath, paths[0]);
}
[Test]
public void SecondXmlElementPathHasOneElement()
{
XmlElementPath expectedPath = new XmlElementPath();
expectedPath.AddElement(new QualifiedName("b", "b-namespace"));
Assert.AreEqual(expectedPath, paths[1]);
}
}
}

87
src/AddIns/DisplayBindings/XmlEditor/Test/Paths/XmlNamespaceCollectionTests.cs

@ -0,0 +1,87 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.XmlEditor;
using NUnit.Framework;
namespace XmlEditor.Tests.Paths
{
[TestFixture]
public class XmlNamespaceCollectionTests
{
XmlNamespaceCollection namespaceCollection;
[SetUp]
public void Init()
{
namespaceCollection = new XmlNamespaceCollection();
}
[Test]
public void ToArrayReturnsXmlNamespaceItemsInCollection()
{
XmlNamespace a = new XmlNamespace("a", "a-ns");
XmlNamespace b = new XmlNamespace("b", "b-ns");
namespaceCollection.Add(a);
namespaceCollection.Add(b);
XmlNamespace[] expectedArray = new XmlNamespace[] { a, b };
Assert.AreEqual(expectedArray, namespaceCollection.ToArray());
}
[Test]
public void GetNamespaceForPrefixReturnsPrefixForKnownNamespaceInCollection()
{
XmlNamespace ns = new XmlNamespace("prefix", "namespace");
namespaceCollection.Add(ns);
Assert.AreEqual("namespace", namespaceCollection.GetNamespaceForPrefix("prefix"));
}
[Test]
public void GetNamespaceForPrefixReturnsEmptyStringForUnknownNamespaceInCollection()
{
XmlNamespace ns = new XmlNamespace("prefix", "namespace");
namespaceCollection.Add(ns);
Assert.AreEqual(String.Empty, namespaceCollection.GetNamespaceForPrefix("unknown-prefix"));
}
[Test]
public void ContainsReturnsFalseForKnownNamespaceWhenPrefixDoesNotMatch()
{
XmlNamespace ns = new XmlNamespace("prefix", "namespace");
namespaceCollection.Add(ns);
XmlNamespace namespaceWithDifferentPrefix = new XmlNamespace(String.Empty, "namespace");
Assert.IsFalse(namespaceCollection.Contains(namespaceWithDifferentPrefix));
}
[Test]
public void ContainsReturnsTrueForKnownNamespaceWhenPrefixIsEmptyString()
{
XmlNamespace ns = new XmlNamespace(String.Empty, "namespace");
namespaceCollection.Add(ns);
Assert.IsTrue(namespaceCollection.Contains(ns));
}
[Test]
public void ContainsReturnsFalseForUnknownNamespace()
{
XmlNamespace ns = new XmlNamespace("prefix", "namespace");
namespaceCollection.Add(ns);
XmlNamespace unknownNamespace = new XmlNamespace("prefix", "unknown-namespace");
Assert.IsFalse(namespaceCollection.Contains(unknownNamespace));
}
}
}

75
src/AddIns/DisplayBindings/XmlEditor/Test/Paths/XmlNamespaceEqualsTests.cs

@ -0,0 +1,75 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.XmlEditor;
using NUnit.Framework;
namespace XmlEditor.Tests.Paths
{
[TestFixture]
public class XmlNamespaceEqualsTests
{
XmlNamespace lhs;
XmlNamespace rhs;
[SetUp]
public void Init()
{
lhs = new XmlNamespace();
rhs = new XmlNamespace();
}
[Test]
public void EmptyNamespacesAreEqual()
{
Assert.IsTrue(lhs.Equals(rhs));
}
[Test]
public void NullNamespaceIsNotEqual()
{
Assert.IsFalse(lhs.Equals(null));
}
[Test]
public void SameNamespaceAndPrefixAreEqual()
{
lhs.Name = "a-ns";
lhs.Prefix = "a";
rhs.Name = "a-ns";
rhs.Prefix = "a";
Assert.IsTrue(lhs.Equals(rhs));
}
[Test]
public void DifferentNamespacesAreNotEqual()
{
lhs.Name = "namespace";
lhs.Prefix = "a";
rhs.Name = "different-namespace";
rhs.Prefix = "a";
Assert.IsFalse(lhs.Equals(rhs));
}
[Test]
public void SameNamespaceButDifferentPrefixAreNotEqual()
{
lhs.Name = "namespace";
lhs.Prefix = "a";
rhs.Name = "namespace";
rhs.Prefix = "b";
Assert.IsFalse(lhs.Equals(rhs));
}
}
}

225
src/AddIns/DisplayBindings/XmlEditor/Test/Schema.Multiple/TwoSchemaChildElementCompletionTestFixture.cs

@ -0,0 +1,225 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.IO;
using ICSharpCode.XmlEditor;
using NUnit.Framework;
namespace XmlEditor.Tests.Schema.Multiple
{
[TestFixture]
public class TwoSchemaChildElementCompletionTestFixture
{
XmlSchemaCompletionCollection schemas;
[SetUp]
public void Init()
{
schemas = new XmlSchemaCompletionCollection();
foreach (string schema in GetSchemas()) {
StringReader reader = new StringReader(schema);
schemas.Add(new XmlSchemaCompletion(reader));
}
}
string[] GetSchemas()
{
return new string[] { GetFooSchema(), GetBarSchema() };
}
string GetFooSchema()
{
return
"<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" targetNamespace=\"foo\" xmlns=\"foo\" elementFormDefault=\"qualified\">\r\n" +
" <xs:element name=\"foo-note\">\r\n" +
" <xs:complexType> \r\n" +
" <xs:sequence>\r\n" +
" <xs:element name=\"foo-text\" type=\"text-type\"/>\r\n" +
" </xs:sequence>\r\n" +
" </xs:complexType>\r\n" +
" </xs:element>\r\n" +
" <xs:complexType name=\"text-type\">\r\n" +
" <xs:attribute name=\"foo-text-attribute\">\r\n" +
" <xs:simpleType>\r\n" +
" <xs:restriction base=\"xs:string\">\r\n" +
" <xs:enumeration value=\"first\"/>\r\n" +
" <xs:enumeration value=\"second\"/>\r\n" +
" <xs:enumeration value=\"third\"/>\r\n" +
" <xs:enumeration value=\"fourth\"/>\r\n" +
" </xs:restriction>\r\n" +
" </xs:simpleType>\r\n" +
" </xs:attribute>\r\n" +
" </xs:complexType>\r\n" +
"</xs:schema>";
}
string GetBarSchema()
{
return
"<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" targetNamespace=\"bar\" xmlns=\"bar\" elementFormDefault=\"qualified\">\r\n" +
" <xs:element name=\"bar-note\">\r\n" +
" <xs:complexType> \r\n" +
" <xs:sequence>\r\n" +
" <xs:element name=\"bar-text\" type=\"text-type\"/>\r\n" +
" </xs:sequence>\r\n" +
" </xs:complexType>\r\n" +
" </xs:element>\r\n" +
" <xs:complexType name=\"text-type\">\r\n" +
" <xs:attribute name=\"bar-text-attribute\">\r\n" +
" <xs:simpleType>\r\n" +
" <xs:restriction base=\"xs:string\">\r\n" +
" <xs:enumeration value=\"bar-first\"/>\r\n" +
" <xs:enumeration value=\"bar-second\"/>\r\n" +
" <xs:enumeration value=\"bar-third\"/>\r\n" +
" <xs:enumeration value=\"bar-fourth\"/>\r\n" +
" </xs:restriction>\r\n" +
" </xs:simpleType>\r\n" +
" </xs:attribute>\r\n" +
" </xs:complexType>\r\n" +
"</xs:schema>";
}
[Test]
public void FooSchemaRootElementAndBarRootElementInPath()
{
XmlElementPath path = new XmlElementPath();
path.AddElement(new QualifiedName("foo-note", "foo"));
path.AddElement(new QualifiedName("bar-note", "bar", "b"));
XmlCompletionItemCollection items = schemas.GetElementCompletionForAllNamespaces(path, null);
items.Sort();
XmlCompletionItemCollection expectedItems = new XmlCompletionItemCollection();
expectedItems.Add(new XmlCompletionItem("b:bar-text", XmlCompletionItemType.XmlElement));
expectedItems.Add(new XmlCompletionItem("foo-text", XmlCompletionItemType.XmlElement));
Assert.AreEqual(expectedItems, items);
}
[Test]
public void FooSchemaElementAndBarElementInXml()
{
string xml =
"<foo-note xmlns='foo' xmlns:b='bar'>\r\n" +
" <b:bar-note>\r\n" +
" <";
XmlCompletionItemCollection expectedItems = new XmlCompletionItemCollection();
expectedItems.Add(new XmlCompletionItem("b:bar-text", XmlCompletionItemType.XmlElement));
expectedItems.Add(new XmlCompletionItem("foo-text", XmlCompletionItemType.XmlElement));
XmlCompletionItemCollection items = schemas.GetElementCompletion(xml, null);
items.Sort();
Assert.AreEqual(expectedItems, items);
}
[Test]
public void FooSchemaRootElementOnlyInPath()
{
XmlElementPath path = new XmlElementPath();
path.NamespacesInScope.Add(new XmlNamespace("b", "bar"));
path.AddElement(new QualifiedName("foo-note", "foo"));
XmlCompletionItemCollection items = schemas.GetElementCompletionForAllNamespaces(path, null);
items.Sort();
XmlCompletionItemCollection expectedItems = new XmlCompletionItemCollection();
expectedItems.Add(new XmlCompletionItem("b:bar-note", XmlCompletionItemType.XmlElement));
expectedItems.Add(new XmlCompletionItem("foo-text", XmlCompletionItemType.XmlElement));
Assert.AreEqual(expectedItems, items);
}
[Test]
public void UnusedNamespaceInScopeCannotBeFoundInSchemaCollection()
{
XmlElementPath path = new XmlElementPath();
path.NamespacesInScope.Add(new XmlNamespace("b", "namespace-which-does-not-exist-in-schema-collection"));
path.AddElement(new QualifiedName("foo-note", "foo"));
XmlCompletionItemCollection items = schemas.GetElementCompletionForAllNamespaces(path, null);
items.Sort();
XmlCompletionItemCollection expectedItems = new XmlCompletionItemCollection();
expectedItems.Add(new XmlCompletionItem("foo-text", XmlCompletionItemType.XmlElement));
Assert.AreEqual(expectedItems, items);
}
[Test]
public void DefaultSchemaRootElementsReturnedWhenNoNamespaceExplicitlyDefinedInXmlAndXmlIsEmpty()
{
XmlSchemaCompletion defaultSchema = schemas["foo"];
string xml = "<";
XmlCompletionItemCollection items = schemas.GetElementCompletion(xml, defaultSchema);
items.Sort();
XmlCompletionItemCollection expectedItems = new XmlCompletionItemCollection();
expectedItems.Add(new XmlCompletionItem("foo-note", XmlCompletionItemType.XmlElement));
Assert.AreEqual(expectedItems, items);
}
[Test]
public void DefaultSchemaRootElementsReturnedOnceWhenNamespaceDefinedButNoElementsExistForthatNamespace()
{
XmlSchemaCompletion defaultSchema = schemas["foo"];
string xml = "<b:bar-note xmlns='foo' xmlns:b='bar'><";
XmlCompletionItemCollection items = schemas.GetElementCompletion(xml, defaultSchema);
items.Sort();
XmlCompletionItemCollection expectedItems = new XmlCompletionItemCollection();
expectedItems.Add(new XmlCompletionItem("b:bar-text", XmlCompletionItemType.XmlElement));
expectedItems.Add(new XmlCompletionItem("foo-note", XmlCompletionItemType.XmlElement));
Assert.AreEqual(expectedItems, items);
}
[Test]
public void CorrectAttributesReturnedForElementWhenTwoNamespacesInXml()
{
string xml =
"<b:bar-note xmlns='foo' xmlns:b='bar'>\r\n" +
" <foo-note>\r\n" +
" <b:bar-text/>\r\n" +
" <foo-text ";
XmlCompletionItemCollection items = schemas.GetAttributeCompletion(xml, null);
XmlCompletionItemCollection expectedItems = new XmlCompletionItemCollection();
expectedItems.Add(new XmlCompletionItem("foo-text-attribute", XmlCompletionItemType.XmlAttribute));
Assert.AreEqual(expectedItems, items);
}
[Test]
public void CorrectAttributeValuesReturnedForElementWhenTwoNamespacesInXml()
{
string xml =
"<b:bar-note xmlns='foo' xmlns:b='bar'>\r\n" +
" <foo-note>\r\n" +
" <b:bar-text/>\r\n" +
" <foo-text foo-text-attribute='f'";
string xmlUpToCursor = xml.Substring(0, xml.Length - 1);
XmlCompletionItemCollection items = schemas.GetAttributeValueCompletion('f', xmlUpToCursor, null);
items.Sort();
XmlCompletionItemCollection expectedItems = new XmlCompletionItemCollection();
expectedItems.Add(new XmlCompletionItem("first", XmlCompletionItemType.XmlAttributeValue));
expectedItems.Add(new XmlCompletionItem("fourth", XmlCompletionItemType.XmlAttributeValue));
expectedItems.Add(new XmlCompletionItem("second", XmlCompletionItemType.XmlAttributeValue));
expectedItems.Add(new XmlCompletionItem("third", XmlCompletionItemType.XmlAttributeValue));
Assert.AreEqual(expectedItems, items);
}
}
}

6
src/AddIns/DisplayBindings/XmlEditor/Test/Schema/AbstractElementTestFixture.cs

@ -26,12 +26,12 @@ namespace XmlEditor.Tests.Schema
{ {
XmlElementPath path = new XmlElementPath(); XmlElementPath path = new XmlElementPath();
path.Elements.Add(new QualifiedName("project", "http://foo")); path.AddElement(new QualifiedName("project", "http://foo"));
path.Elements.Add(new QualifiedName("items", "http://foo")); path.AddElement(new QualifiedName("items", "http://foo"));
itemsElementChildren = SchemaCompletion.GetChildElementCompletion(path); itemsElementChildren = SchemaCompletion.GetChildElementCompletion(path);
path.Elements.Add(new QualifiedName("file", "http://foo")); path.AddElement(new QualifiedName("file", "http://foo"));
fileElementAttributes = SchemaCompletion.GetAttributeCompletion(path); fileElementAttributes = SchemaCompletion.GetAttributeCompletion(path);
fileElementChildren = SchemaCompletion.GetChildElementCompletion(path); fileElementChildren = SchemaCompletion.GetChildElementCompletion(path);

4
src/AddIns/DisplayBindings/XmlEditor/Test/Schema/AllElementTestFixture.cs

@ -26,10 +26,10 @@ namespace XmlEditor.Tests.Schema
public override void FixtureInit() public override void FixtureInit()
{ {
XmlElementPath path = new XmlElementPath(); XmlElementPath path = new XmlElementPath();
path.Elements.Add(new QualifiedName("person", "http://foo")); path.AddElement(new QualifiedName("person", "http://foo"));
personElementChildren = SchemaCompletion.GetChildElementCompletion(path); personElementChildren = SchemaCompletion.GetChildElementCompletion(path);
path.Elements.Add(new QualifiedName("firstname", "http://foo")); path.AddElement(new QualifiedName("firstname", "http://foo"));
firstNameAttributes = SchemaCompletion.GetAttributeCompletion(path); firstNameAttributes = SchemaCompletion.GetAttributeCompletion(path);
firstNameElementChildren = SchemaCompletion.GetChildElementCompletion(path); firstNameElementChildren = SchemaCompletion.GetChildElementCompletion(path);
} }

4
src/AddIns/DisplayBindings/XmlEditor/Test/Schema/AttributeAnnotationTestFixture.cs

@ -25,11 +25,11 @@ namespace XmlEditor.Tests.Schema
public override void FixtureInit() public override void FixtureInit()
{ {
XmlElementPath path = new XmlElementPath(); XmlElementPath path = new XmlElementPath();
path.Elements.Add(new QualifiedName("foo", "http://foo.com")); path.AddElement(new QualifiedName("foo", "http://foo.com"));
fooAttributeCompletionData = SchemaCompletion.GetAttributeCompletion(path); fooAttributeCompletionData = SchemaCompletion.GetAttributeCompletion(path);
path.Elements.Add(new QualifiedName("bar", "http://foo.com")); path.AddElement(new QualifiedName("bar", "http://foo.com"));
barAttributeCompletionData = SchemaCompletion.GetAttributeCompletion(path); barAttributeCompletionData = SchemaCompletion.GetAttributeCompletion(path);
} }

2
src/AddIns/DisplayBindings/XmlEditor/Test/Schema/AttributeGroupRefTestFixture.cs

@ -23,7 +23,7 @@ namespace XmlEditor.Tests.Schema
public override void FixtureInit() public override void FixtureInit()
{ {
XmlElementPath path = new XmlElementPath(); XmlElementPath path = new XmlElementPath();
path.Elements.Add(new QualifiedName("note", "http://www.w3schools.com")); path.AddElement(new QualifiedName("note", "http://www.w3schools.com"));
attributeCompletionItems = SchemaCompletion.GetAttributeCompletion(path); attributeCompletionItems = SchemaCompletion.GetAttributeCompletion(path);
} }

2
src/AddIns/DisplayBindings/XmlEditor/Test/Schema/AttributeRefTestFixture.cs

@ -23,7 +23,7 @@ namespace XmlEditor.Tests.Schema
public override void FixtureInit() public override void FixtureInit()
{ {
XmlElementPath path = new XmlElementPath(); XmlElementPath path = new XmlElementPath();
path.Elements.Add(new QualifiedName("html", "http://foo/xhtml")); path.AddElement(new QualifiedName("html", "http://foo/xhtml"));
attributes = SchemaCompletion.GetAttributeCompletion(path); attributes = SchemaCompletion.GetAttributeCompletion(path);
} }

2
src/AddIns/DisplayBindings/XmlEditor/Test/Schema/AttributeValueAnnotationTestFixture.cs

@ -24,7 +24,7 @@ namespace XmlEditor.Tests.Schema
public override void FixtureInit() public override void FixtureInit()
{ {
XmlElementPath path = new XmlElementPath(); XmlElementPath path = new XmlElementPath();
path.Elements.Add(new QualifiedName("foo", "http://foo.com")); path.AddElement(new QualifiedName("foo", "http://foo.com"));
barAttributeValuesCompletionItems = SchemaCompletion.GetAttributeValueCompletion(path, "bar"); barAttributeValuesCompletionItems = SchemaCompletion.GetAttributeValueCompletion(path, "bar");
} }

4
src/AddIns/DisplayBindings/XmlEditor/Test/Schema/ChildElementAttributesTestFixture.cs

@ -23,8 +23,8 @@ namespace XmlEditor.Tests.Schema
public override void FixtureInit() public override void FixtureInit()
{ {
XmlElementPath path = new XmlElementPath(); XmlElementPath path = new XmlElementPath();
path.Elements.Add(new QualifiedName("project", "http://nant.sf.net//nant-0.84.xsd")); path.AddElement(new QualifiedName("project", "http://nant.sf.net//nant-0.84.xsd"));
path.Elements.Add(new QualifiedName("attrib", "http://nant.sf.net//nant-0.84.xsd")); path.AddElement(new QualifiedName("attrib", "http://nant.sf.net//nant-0.84.xsd"));
attributes = SchemaCompletion.GetAttributeCompletion(path); attributes = SchemaCompletion.GetAttributeCompletion(path);
} }

10
src/AddIns/DisplayBindings/XmlEditor/Test/Schema/ChoiceTestFixture.cs

@ -24,7 +24,7 @@ namespace XmlEditor.Tests.Schema
public override void FixtureInit() public override void FixtureInit()
{ {
XmlElementPath path = new XmlElementPath(); XmlElementPath path = new XmlElementPath();
path.Elements.Add(new QualifiedName("note", "http://www.w3schools.com")); path.AddElement(new QualifiedName("note", "http://www.w3schools.com"));
noteChildElements = SchemaCompletion.GetChildElementCompletion(path); noteChildElements = SchemaCompletion.GetChildElementCompletion(path);
} }
@ -33,8 +33,8 @@ namespace XmlEditor.Tests.Schema
public void TitleHasNoChildElements() public void TitleHasNoChildElements()
{ {
XmlElementPath path = new XmlElementPath(); XmlElementPath path = new XmlElementPath();
path.Elements.Add(new QualifiedName("note", "http://www.w3schools.com")); path.AddElement(new QualifiedName("note", "http://www.w3schools.com"));
path.Elements.Add(new QualifiedName("title", "http://www.w3schools.com")); path.AddElement(new QualifiedName("title", "http://www.w3schools.com"));
Assert.AreEqual(0, SchemaCompletion.GetChildElementCompletion(path).Count, Assert.AreEqual(0, SchemaCompletion.GetChildElementCompletion(path).Count,
"Should be no child elements."); "Should be no child elements.");
} }
@ -43,8 +43,8 @@ namespace XmlEditor.Tests.Schema
public void TextHasNoChildElements() public void TextHasNoChildElements()
{ {
XmlElementPath path = new XmlElementPath(); XmlElementPath path = new XmlElementPath();
path.Elements.Add(new QualifiedName("note", "http://www.w3schools.com")); path.AddElement(new QualifiedName("note", "http://www.w3schools.com"));
path.Elements.Add(new QualifiedName("text", "http://www.w3schools.com")); path.AddElement(new QualifiedName("text", "http://www.w3schools.com"));
Assert.AreEqual(0, SchemaCompletion.GetChildElementCompletion(path).Count, Assert.AreEqual(0, SchemaCompletion.GetChildElementCompletion(path).Count,
"Should be no child elements."); "Should be no child elements.");
} }

10
src/AddIns/DisplayBindings/XmlEditor/Test/Schema/ComplexContentExtensionTestFixture.cs

@ -24,7 +24,7 @@ namespace XmlEditor.Tests.Schema
public override void FixtureInit() public override void FixtureInit()
{ {
XmlElementPath path = new XmlElementPath(); XmlElementPath path = new XmlElementPath();
path.Elements.Add(new QualifiedName("body", "http://www.w3schools.com")); path.AddElement(new QualifiedName("body", "http://www.w3schools.com"));
bodyChildElements = SchemaCompletion.GetChildElementCompletion(path); bodyChildElements = SchemaCompletion.GetChildElementCompletion(path);
bodyAttributes = SchemaCompletion.GetAttributeCompletion(path); bodyAttributes = SchemaCompletion.GetAttributeCompletion(path);
@ -34,8 +34,8 @@ namespace XmlEditor.Tests.Schema
public void TitleHasNoChildElements() public void TitleHasNoChildElements()
{ {
XmlElementPath path = new XmlElementPath(); XmlElementPath path = new XmlElementPath();
path.Elements.Add(new QualifiedName("body", "http://www.w3schools.com")); path.AddElement(new QualifiedName("body", "http://www.w3schools.com"));
path.Elements.Add(new QualifiedName("title", "http://www.w3schools.com")); path.AddElement(new QualifiedName("title", "http://www.w3schools.com"));
Assert.AreEqual(0, SchemaCompletion.GetChildElementCompletion(path).Count, Assert.AreEqual(0, SchemaCompletion.GetChildElementCompletion(path).Count,
"Should be no child elements."); "Should be no child elements.");
@ -45,8 +45,8 @@ namespace XmlEditor.Tests.Schema
public void TextHasNoChildElements() public void TextHasNoChildElements()
{ {
XmlElementPath path = new XmlElementPath(); XmlElementPath path = new XmlElementPath();
path.Elements.Add(new QualifiedName("body", "http://www.w3schools.com")); path.AddElement(new QualifiedName("body", "http://www.w3schools.com"));
path.Elements.Add(new QualifiedName("text", "http://www.w3schools.com")); path.AddElement(new QualifiedName("text", "http://www.w3schools.com"));
Assert.AreEqual(0, SchemaCompletion.GetChildElementCompletion(path).Count, Assert.AreEqual(0, SchemaCompletion.GetChildElementCompletion(path).Count,
"Should be no child elements."); "Should be no child elements.");

2
src/AddIns/DisplayBindings/XmlEditor/Test/Schema/DuplicateElementTestFixture.cs

@ -23,7 +23,7 @@ namespace XmlEditor.Tests.Schema
public override void FixtureInit() public override void FixtureInit()
{ {
XmlElementPath path = new XmlElementPath(); XmlElementPath path = new XmlElementPath();
path.Elements.Add(new QualifiedName("html", "http://foo/xhtml")); path.AddElement(new QualifiedName("html", "http://foo/xhtml"));
htmlChildElements = SchemaCompletion.GetChildElementCompletion(path); htmlChildElements = SchemaCompletion.GetChildElementCompletion(path);
} }

2
src/AddIns/DisplayBindings/XmlEditor/Test/Schema/ElementAnnotationTestFixture.cs

@ -28,7 +28,7 @@ namespace XmlEditor.Tests.Schema
rootElementCompletionItems = SchemaCompletion.GetRootElementCompletion(); rootElementCompletionItems = SchemaCompletion.GetRootElementCompletion();
XmlElementPath path = new XmlElementPath(); XmlElementPath path = new XmlElementPath();
path.Elements.Add(new QualifiedName("foo", "http://foo.com")); path.AddElement(new QualifiedName("foo", "http://foo.com"));
fooChildElementCompletionItems = SchemaCompletion.GetChildElementCompletion(path); fooChildElementCompletionItems = SchemaCompletion.GetChildElementCompletion(path);
} }

2
src/AddIns/DisplayBindings/XmlEditor/Test/Schema/ElementRefAnnotationTestFixture.cs

@ -24,7 +24,7 @@ namespace XmlEditor.Tests.Schema
public override void FixtureInit() public override void FixtureInit()
{ {
XmlElementPath path = new XmlElementPath(); XmlElementPath path = new XmlElementPath();
path.Elements.Add(new QualifiedName("foo", "http://foo.com")); path.AddElement(new QualifiedName("foo", "http://foo.com"));
fooChildElementCompletion = SchemaCompletion.GetChildElementCompletion(path); fooChildElementCompletion = SchemaCompletion.GetChildElementCompletion(path);
} }

4
src/AddIns/DisplayBindings/XmlEditor/Test/Schema/ElementWithAttributeSchemaTestFixture.cs

@ -24,7 +24,7 @@ namespace XmlEditor.Tests.Schema
public override void FixtureInit() public override void FixtureInit()
{ {
XmlElementPath path = new XmlElementPath(); XmlElementPath path = new XmlElementPath();
path.Elements.Add(new QualifiedName("note", "http://www.w3schools.com")); path.AddElement(new QualifiedName("note", "http://www.w3schools.com"));
attributeCompletionItems = SchemaCompletion.GetAttributeCompletion(path); attributeCompletionItems = SchemaCompletion.GetAttributeCompletion(path);
attributeName = attributeCompletionItems[0].Text; attributeName = attributeCompletionItems[0].Text;
@ -46,7 +46,7 @@ namespace XmlEditor.Tests.Schema
public void NoAttributesForUnknownElement() public void NoAttributesForUnknownElement()
{ {
XmlElementPath path = new XmlElementPath(); XmlElementPath path = new XmlElementPath();
path.Elements.Add(new QualifiedName("foobar", "http://www.w3schools.com")); path.AddElement(new QualifiedName("foobar", "http://www.w3schools.com"));
XmlCompletionItemCollection attributes = SchemaCompletion.GetAttributeCompletion(path); XmlCompletionItemCollection attributes = SchemaCompletion.GetAttributeCompletion(path);
Assert.AreEqual(0, attributes.Count, "Should not find attributes for unknown element."); Assert.AreEqual(0, attributes.Count, "Should not find attributes for unknown element.");

2
src/AddIns/DisplayBindings/XmlEditor/Test/Schema/EnumAttributeValueTestFixture.cs

@ -23,7 +23,7 @@ namespace XmlEditor.Tests.Schema
public override void FixtureInit() public override void FixtureInit()
{ {
XmlElementPath path = new XmlElementPath(); XmlElementPath path = new XmlElementPath();
path.Elements.Add(new QualifiedName("foo", "http://foo.com")); path.AddElement(new QualifiedName("foo", "http://foo.com"));
attributeValues = SchemaCompletion.GetAttributeValueCompletion(path, "id"); attributeValues = SchemaCompletion.GetAttributeValueCompletion(path, "id");
} }

10
src/AddIns/DisplayBindings/XmlEditor/Test/Schema/ExtensionElementTestFixture.cs

@ -29,29 +29,29 @@ namespace XmlEditor.Tests.Schema
public override void FixtureInit() public override void FixtureInit()
{ {
XmlElementPath path = new XmlElementPath(); XmlElementPath path = new XmlElementPath();
path.Elements.Add(new QualifiedName("schema", "http://www.w3.org/2001/XMLSchema")); path.AddElement(new QualifiedName("schema", "http://www.w3.org/2001/XMLSchema"));
schemaChildElements = SchemaCompletion.GetChildElementCompletion(path); schemaChildElements = SchemaCompletion.GetChildElementCompletion(path);
schemaAttributes = SchemaCompletion.GetAttributeCompletion(path); schemaAttributes = SchemaCompletion.GetAttributeCompletion(path);
// Get include elements attributes. // Get include elements attributes.
path.Elements.Add(new QualifiedName("include", "http://www.w3.org/2001/XMLSchema")); path.AddElement(new QualifiedName("include", "http://www.w3.org/2001/XMLSchema"));
includeAttributes = SchemaCompletion.GetAttributeCompletion(path); includeAttributes = SchemaCompletion.GetAttributeCompletion(path);
// Get annotation element info. // Get annotation element info.
path.Elements.RemoveLast(); path.Elements.RemoveLast();
path.Elements.Add(new QualifiedName("annotation", "http://www.w3.org/2001/XMLSchema")); path.AddElement(new QualifiedName("annotation", "http://www.w3.org/2001/XMLSchema"));
annotationChildElements = SchemaCompletion.GetChildElementCompletion(path); annotationChildElements = SchemaCompletion.GetChildElementCompletion(path);
annotationAttributes = SchemaCompletion.GetAttributeCompletion(path); annotationAttributes = SchemaCompletion.GetAttributeCompletion(path);
// Get app info attributes. // Get app info attributes.
path.Elements.Add(new QualifiedName("appinfo", "http://www.w3.org/2001/XMLSchema")); path.AddElement(new QualifiedName("appinfo", "http://www.w3.org/2001/XMLSchema"));
appInfoAttributes = SchemaCompletion.GetAttributeCompletion(path); appInfoAttributes = SchemaCompletion.GetAttributeCompletion(path);
// Get foo attributes. // Get foo attributes.
path = new XmlElementPath(); path = new XmlElementPath();
path.Elements.Add(new QualifiedName("foo", "http://www.w3.org/2001/XMLSchema")); path.AddElement(new QualifiedName("foo", "http://www.w3.org/2001/XMLSchema"));
fooAttributes = SchemaCompletion.GetAttributeCompletion(path); fooAttributes = SchemaCompletion.GetAttributeCompletion(path);
} }

2
src/AddIns/DisplayBindings/XmlEditor/Test/Schema/FindAttributeFromComplexTypeTestFixture.cs

@ -26,7 +26,7 @@ namespace XmlEditor.Tests.Schema
public override void FixtureInit() public override void FixtureInit()
{ {
XmlElementPath path = new XmlElementPath(); XmlElementPath path = new XmlElementPath();
path.Elements.Add(new QualifiedName("note", "http://www.w3schools.com")); path.AddElement(new QualifiedName("note", "http://www.w3schools.com"));
XmlSchemaElement element = SchemaCompletion.FindElement(path); XmlSchemaElement element = SchemaCompletion.FindElement(path);
attribute = SchemaCompletion.FindAttribute(element, "name"); attribute = SchemaCompletion.FindAttribute(element, "name");

4
src/AddIns/DisplayBindings/XmlEditor/Test/Schema/GroupRefCompositorTestFixture.cs

@ -28,11 +28,11 @@ namespace XmlEditor.Tests.Schema
public override void FixtureInit() public override void FixtureInit()
{ {
XmlElementPath path = new XmlElementPath(); XmlElementPath path = new XmlElementPath();
path.Elements.Add(new QualifiedName("root", "http://foo")); path.AddElement(new QualifiedName("root", "http://foo"));
rootChildElements = SchemaCompletion.GetChildElementCompletion(path); rootChildElements = SchemaCompletion.GetChildElementCompletion(path);
path.Elements.Add(new QualifiedName("foo", "http://foo")); path.AddElement(new QualifiedName("foo", "http://foo"));
fooAttributes = SchemaCompletion.GetAttributeCompletion(path); fooAttributes = SchemaCompletion.GetAttributeCompletion(path);
} }

6
src/AddIns/DisplayBindings/XmlEditor/Test/Schema/GroupRefTestFixture.cs

@ -25,12 +25,12 @@ namespace XmlEditor.Tests.Schema
{ {
XmlElementPath path = new XmlElementPath(); XmlElementPath path = new XmlElementPath();
path.Elements.Add(new QualifiedName("html", "http://foo/xhtml")); path.AddElement(new QualifiedName("html", "http://foo/xhtml"));
path.Elements.Add(new QualifiedName("body", "http://foo/xhtml")); path.AddElement(new QualifiedName("body", "http://foo/xhtml"));
childElements = SchemaCompletion.GetChildElementCompletion(path); childElements = SchemaCompletion.GetChildElementCompletion(path);
path.Elements.Add(new QualifiedName("p", "http://foo/xhtml")); path.AddElement(new QualifiedName("p", "http://foo/xhtml"));
paraAttributes = SchemaCompletion.GetAttributeCompletion(path); paraAttributes = SchemaCompletion.GetAttributeCompletion(path);
} }

4
src/AddIns/DisplayBindings/XmlEditor/Test/Schema/MissingSchemaElementTestFixture.cs

@ -20,8 +20,8 @@ namespace XmlEditor.Tests.Schema
public override void FixtureInit() public override void FixtureInit()
{ {
XmlElementPath path = new XmlElementPath(); XmlElementPath path = new XmlElementPath();
path.Elements.Add(new QualifiedName("root", "http://foo")); path.AddElement(new QualifiedName("root", "http://foo"));
path.Elements.Add(new QualifiedName("bar", "http://foo")); path.AddElement(new QualifiedName("bar", "http://foo"));
barElementAttributes = SchemaCompletion.GetAttributeCompletion(path); barElementAttributes = SchemaCompletion.GetAttributeCompletion(path);
} }

2
src/AddIns/DisplayBindings/XmlEditor/Test/Schema/NestedAttributeGroupRefTestFixture.cs

@ -23,7 +23,7 @@ namespace XmlEditor.Tests.Schema
public override void FixtureInit() public override void FixtureInit()
{ {
XmlElementPath path = new XmlElementPath(); XmlElementPath path = new XmlElementPath();
path.Elements.Add(new QualifiedName("note", "http://www.w3schools.com")); path.AddElement(new QualifiedName("note", "http://www.w3schools.com"));
attributeCompletionItems = SchemaCompletion.GetAttributeCompletion(path); attributeCompletionItems = SchemaCompletion.GetAttributeCompletion(path);
} }

8
src/AddIns/DisplayBindings/XmlEditor/Test/Schema/NestedChoiceTestFixture.cs

@ -26,12 +26,12 @@ namespace XmlEditor.Tests.Schema
{ {
// Get note child elements. // Get note child elements.
XmlElementPath path = new XmlElementPath(); XmlElementPath path = new XmlElementPath();
path.Elements.Add(new QualifiedName("note", "http://www.w3schools.com")); path.AddElement(new QualifiedName("note", "http://www.w3schools.com"));
noteChildElements = SchemaCompletion.GetChildElementCompletion(path); noteChildElements = SchemaCompletion.GetChildElementCompletion(path);
// Get title child elements. // Get title child elements.
path.Elements.Add(new QualifiedName("title", "http://www.w3schools.com")); path.AddElement(new QualifiedName("title", "http://www.w3schools.com"));
titleChildElements = SchemaCompletion.GetChildElementCompletion(path); titleChildElements = SchemaCompletion.GetChildElementCompletion(path);
} }
@ -46,8 +46,8 @@ namespace XmlEditor.Tests.Schema
public void TextHasNoChildElements() public void TextHasNoChildElements()
{ {
XmlElementPath path = new XmlElementPath(); XmlElementPath path = new XmlElementPath();
path.Elements.Add(new QualifiedName("note", "http://www.w3schools.com")); path.AddElement(new QualifiedName("note", "http://www.w3schools.com"));
path.Elements.Add(new QualifiedName("text", "http://www.w3schools.com")); path.AddElement(new QualifiedName("text", "http://www.w3schools.com"));
Assert.AreEqual(0, SchemaCompletion.GetChildElementCompletion(path).Count, Assert.AreEqual(0, SchemaCompletion.GetChildElementCompletion(path).Count,
"Should be no child elements."); "Should be no child elements.");
} }

2
src/AddIns/DisplayBindings/XmlEditor/Test/Schema/NestedElementSchemaTestFixture.cs

@ -21,7 +21,7 @@ namespace XmlEditor.Tests.Schema
public override void FixtureInit() public override void FixtureInit()
{ {
noteElementPath = new XmlElementPath(); noteElementPath = new XmlElementPath();
noteElementPath.Elements.Add(new QualifiedName("note", "http://www.w3schools.com")); noteElementPath.AddElement(new QualifiedName("note", "http://www.w3schools.com"));
elementCompletionItems = SchemaCompletion.GetChildElementCompletion(noteElementPath); elementCompletionItems = SchemaCompletion.GetChildElementCompletion(noteElementPath);
} }

10
src/AddIns/DisplayBindings/XmlEditor/Test/Schema/NestedSequenceTestFixture.cs

@ -24,7 +24,7 @@ namespace XmlEditor.Tests.Schema
public override void FixtureInit() public override void FixtureInit()
{ {
XmlElementPath path = new XmlElementPath(); XmlElementPath path = new XmlElementPath();
path.Elements.Add(new QualifiedName("note", "http://www.w3schools.com")); path.AddElement(new QualifiedName("note", "http://www.w3schools.com"));
noteChildElements = SchemaCompletion.GetChildElementCompletion(path); noteChildElements = SchemaCompletion.GetChildElementCompletion(path);
} }
@ -32,8 +32,8 @@ namespace XmlEditor.Tests.Schema
public void TitleHasNoChildElements() public void TitleHasNoChildElements()
{ {
XmlElementPath path = new XmlElementPath(); XmlElementPath path = new XmlElementPath();
path.Elements.Add(new QualifiedName("note", "http://www.w3schools.com")); path.AddElement(new QualifiedName("note", "http://www.w3schools.com"));
path.Elements.Add(new QualifiedName("title", "http://www.w3schools.com")); path.AddElement(new QualifiedName("title", "http://www.w3schools.com"));
Assert.AreEqual(0, SchemaCompletion.GetChildElementCompletion(path).Count, Assert.AreEqual(0, SchemaCompletion.GetChildElementCompletion(path).Count,
"Should be no child elements."); "Should be no child elements.");
} }
@ -42,8 +42,8 @@ namespace XmlEditor.Tests.Schema
public void TextHasNoChildElements() public void TextHasNoChildElements()
{ {
XmlElementPath path = new XmlElementPath(); XmlElementPath path = new XmlElementPath();
path.Elements.Add(new QualifiedName("note", "http://www.w3schools.com")); path.AddElement(new QualifiedName("note", "http://www.w3schools.com"));
path.Elements.Add(new QualifiedName("text", "http://www.w3schools.com")); path.AddElement(new QualifiedName("text", "http://www.w3schools.com"));
Assert.AreEqual(0, SchemaCompletion.GetChildElementCompletion(path).Count, Assert.AreEqual(0, SchemaCompletion.GetChildElementCompletion(path).Count,
"Should be no child elements."); "Should be no child elements.");
} }

6
src/AddIns/DisplayBindings/XmlEditor/Test/Schema/ReferencedElementsTestFixture.cs

@ -25,14 +25,14 @@ namespace XmlEditor.Tests.Schema
// Get shipto attributes. // Get shipto attributes.
shipToPath = new XmlElementPath(); shipToPath = new XmlElementPath();
QualifiedName shipOrderName = new QualifiedName("shiporder", "http://www.w3schools.com"); QualifiedName shipOrderName = new QualifiedName("shiporder", "http://www.w3schools.com");
shipToPath.Elements.Add(shipOrderName); shipToPath.AddElement(shipOrderName);
shipToPath.Elements.Add(new QualifiedName("shipto", "http://www.w3schools.com")); shipToPath.AddElement(new QualifiedName("shipto", "http://www.w3schools.com"));
shipToAttributes = SchemaCompletion.GetAttributeCompletion(shipToPath); shipToAttributes = SchemaCompletion.GetAttributeCompletion(shipToPath);
// Get shiporder attributes. // Get shiporder attributes.
shipOrderPath = new XmlElementPath(); shipOrderPath = new XmlElementPath();
shipOrderPath.Elements.Add(shipOrderName); shipOrderPath.AddElement(shipOrderName);
shipOrderAttributes = SchemaCompletion.GetAttributeCompletion(shipOrderPath); shipOrderAttributes = SchemaCompletion.GetAttributeCompletion(shipOrderPath);

6
src/AddIns/DisplayBindings/XmlEditor/Test/Schema/RestrictionElementTestFixture.cs

@ -26,17 +26,17 @@ namespace XmlEditor.Tests.Schema
public override void FixtureInit() public override void FixtureInit()
{ {
XmlElementPath path = new XmlElementPath(); XmlElementPath path = new XmlElementPath();
path.Elements.Add(new QualifiedName("group", "http://www.w3.org/2001/XMLSchema")); path.AddElement(new QualifiedName("group", "http://www.w3.org/2001/XMLSchema"));
childElements = SchemaCompletion.GetChildElementCompletion(path); childElements = SchemaCompletion.GetChildElementCompletion(path);
attributes = SchemaCompletion.GetAttributeCompletion(path); attributes = SchemaCompletion.GetAttributeCompletion(path);
// Get annotation child elements. // Get annotation child elements.
path.Elements.Add(new QualifiedName("annotation", "http://www.w3.org/2001/XMLSchema")); path.AddElement(new QualifiedName("annotation", "http://www.w3.org/2001/XMLSchema"));
annotationChildElements = SchemaCompletion.GetChildElementCompletion(path); annotationChildElements = SchemaCompletion.GetChildElementCompletion(path);
// Get choice child elements. // Get choice child elements.
path.Elements.RemoveLast(); path.Elements.RemoveLast();
path.Elements.Add(new QualifiedName("choice", "http://www.w3.org/2001/XMLSchema")); path.AddElement(new QualifiedName("choice", "http://www.w3.org/2001/XMLSchema"));
choiceChildElements = SchemaCompletion.GetChildElementCompletion(path); choiceChildElements = SchemaCompletion.GetChildElementCompletion(path);
} }

10
src/AddIns/DisplayBindings/XmlEditor/Test/Schema/SequencedChoiceTestFixture.cs

@ -24,7 +24,7 @@ namespace XmlEditor.Tests.Schema
public override void FixtureInit() public override void FixtureInit()
{ {
XmlElementPath path = new XmlElementPath(); XmlElementPath path = new XmlElementPath();
path.Elements.Add(new QualifiedName("note", "http://www.w3schools.com")); path.AddElement(new QualifiedName("note", "http://www.w3schools.com"));
noteChildElements = SchemaCompletion.GetChildElementCompletion(path); noteChildElements = SchemaCompletion.GetChildElementCompletion(path);
} }
@ -33,8 +33,8 @@ namespace XmlEditor.Tests.Schema
public void TitleHasNoChildElements() public void TitleHasNoChildElements()
{ {
XmlElementPath path = new XmlElementPath(); XmlElementPath path = new XmlElementPath();
path.Elements.Add(new QualifiedName("note", "http://www.w3schools.com")); path.AddElement(new QualifiedName("note", "http://www.w3schools.com"));
path.Elements.Add(new QualifiedName("title", "http://www.w3schools.com")); path.AddElement(new QualifiedName("title", "http://www.w3schools.com"));
Assert.AreEqual(0, SchemaCompletion.GetChildElementCompletion(path).Count, Assert.AreEqual(0, SchemaCompletion.GetChildElementCompletion(path).Count,
"Should be no child elements."); "Should be no child elements.");
@ -44,8 +44,8 @@ namespace XmlEditor.Tests.Schema
public void TextHasNoChildElements() public void TextHasNoChildElements()
{ {
XmlElementPath path = new XmlElementPath(); XmlElementPath path = new XmlElementPath();
path.Elements.Add(new QualifiedName("note", "http://www.w3schools.com")); path.AddElement(new QualifiedName("note", "http://www.w3schools.com"));
path.Elements.Add(new QualifiedName("title", "http://www.w3schools.com")); path.AddElement(new QualifiedName("title", "http://www.w3schools.com"));
Assert.AreEqual(0, SchemaCompletion.GetChildElementCompletion(path).Count, Assert.AreEqual(0, SchemaCompletion.GetChildElementCompletion(path).Count,
"Should be no child elements."); "Should be no child elements.");

2
src/AddIns/DisplayBindings/XmlEditor/Test/Schema/SimpleContentWithAttributeTestFixture.cs

@ -23,7 +23,7 @@ namespace XmlEditor.Tests.Schema
public override void FixtureInit() public override void FixtureInit()
{ {
XmlElementPath path = new XmlElementPath(); XmlElementPath path = new XmlElementPath();
path.Elements.Add(new QualifiedName("foo", "http://foo.com")); path.AddElement(new QualifiedName("foo", "http://foo.com"));
attributeCompletionItems = SchemaCompletion.GetAttributeCompletion(path); attributeCompletionItems = SchemaCompletion.GetAttributeCompletion(path);
} }

2
src/AddIns/DisplayBindings/XmlEditor/Test/Schema/SingleElementSchemaTestFixture.cs

@ -25,7 +25,7 @@ namespace XmlEditor.Tests.Schema
public override void FixtureInit() public override void FixtureInit()
{ {
XmlElementPath path = new XmlElementPath(); XmlElementPath path = new XmlElementPath();
path.Elements.Add(new QualifiedName("note", "http://www.w3schools.com")); path.AddElement(new QualifiedName("note", "http://www.w3schools.com"));
attributeCompletionItems = SchemaCompletion.GetAttributeCompletion(path); attributeCompletionItems = SchemaCompletion.GetAttributeCompletion(path);
childElementCompletionItems = SchemaCompletion.GetChildElementCompletion(path); childElementCompletionItems = SchemaCompletion.GetChildElementCompletion(path);

6
src/AddIns/DisplayBindings/XmlEditor/Test/Schema/TwoElementSchemaTestFixture.cs

@ -28,12 +28,12 @@ namespace XmlEditor.Tests.Schema
// Note element path. // Note element path.
noteElementPath = new XmlElementPath(); noteElementPath = new XmlElementPath();
QualifiedName noteQualifiedName = new QualifiedName("note", "http://www.w3schools.com"); QualifiedName noteQualifiedName = new QualifiedName("note", "http://www.w3schools.com");
noteElementPath.Elements.Add(noteQualifiedName); noteElementPath.AddElement(noteQualifiedName);
// Text element path. // Text element path.
textElementPath = new XmlElementPath(); textElementPath = new XmlElementPath();
textElementPath.Elements.Add(noteQualifiedName); textElementPath.AddElement(noteQualifiedName);
textElementPath.Elements.Add(new QualifiedName("text", "http://www.w3schools.com")); textElementPath.AddElement(new QualifiedName("text", "http://www.w3schools.com"));
} }
[Test] [Test]

6
src/AddIns/DisplayBindings/XmlEditor/Test/Schema/XhtmlStrictSchemaTestFixture.cs

@ -32,9 +32,9 @@ namespace XmlEditor.Tests.Schema
// Set up h1 element's path. // Set up h1 element's path.
h1Path = new XmlElementPath(); h1Path = new XmlElementPath();
h1Path.Elements.Add(new QualifiedName("html", namespaceURI)); h1Path.AddElement(new QualifiedName("html", namespaceURI));
h1Path.Elements.Add(new QualifiedName("body", namespaceURI)); h1Path.AddElement(new QualifiedName("body", namespaceURI));
h1Path.Elements.Add(new QualifiedName("h1", namespaceURI)); h1Path.AddElement(new QualifiedName("h1", namespaceURI));
// Get h1 element info. // Get h1 element info.
h1Attributes = schemaCompletion.GetAttributeCompletion(h1Path); h1Attributes = schemaCompletion.GetAttributeCompletion(h1Path);

44
src/AddIns/DisplayBindings/XmlEditor/Test/Schema/XsdSchemaTestFixture.cs

@ -49,13 +49,13 @@ namespace XmlEditor.Tests.Schema
// Set up choice element's path. // Set up choice element's path.
choicePath = new XmlElementPath(); choicePath = new XmlElementPath();
choicePath.Elements.Add(new QualifiedName("schema", namespaceURI, prefix)); choicePath.AddElement(new QualifiedName("schema", namespaceURI, prefix));
choicePath.Elements.Add(new QualifiedName("element", namespaceURI, prefix)); choicePath.AddElement(new QualifiedName("element", namespaceURI, prefix));
choicePath.Elements.Add(new QualifiedName("complexType", namespaceURI, prefix)); choicePath.AddElement(new QualifiedName("complexType", namespaceURI, prefix));
mixedAttributeValues = schemaCompletion.GetAttributeValueCompletion(choicePath, "mixed"); mixedAttributeValues = schemaCompletion.GetAttributeValueCompletion(choicePath, "mixed");
choicePath.Elements.Add(new QualifiedName("choice", namespaceURI, prefix)); choicePath.AddElement(new QualifiedName("choice", namespaceURI, prefix));
// Get choice element info. // Get choice element info.
choiceAttributes = schemaCompletion.GetAttributeCompletion(choicePath); choiceAttributes = schemaCompletion.GetAttributeCompletion(choicePath);
@ -63,53 +63,53 @@ namespace XmlEditor.Tests.Schema
// Set up element path. // Set up element path.
elementPath = new XmlElementPath(); elementPath = new XmlElementPath();
elementPath.Elements.Add(new QualifiedName("schema", namespaceURI, prefix)); elementPath.AddElement(new QualifiedName("schema", namespaceURI, prefix));
elementFormDefaultAttributeValues = schemaCompletion.GetAttributeValueCompletion(elementPath, "elementFormDefault"); elementFormDefaultAttributeValues = schemaCompletion.GetAttributeValueCompletion(elementPath, "elementFormDefault");
blockDefaultAttributeValues = schemaCompletion.GetAttributeValueCompletion(elementPath, "blockDefault"); blockDefaultAttributeValues = schemaCompletion.GetAttributeValueCompletion(elementPath, "blockDefault");
finalDefaultAttributeValues = schemaCompletion.GetAttributeValueCompletion(elementPath, "finalDefault"); finalDefaultAttributeValues = schemaCompletion.GetAttributeValueCompletion(elementPath, "finalDefault");
elementPath.Elements.Add(new QualifiedName("element", namespaceURI, prefix)); elementPath.AddElement(new QualifiedName("element", namespaceURI, prefix));
// Get element attribute info. // Get element attribute info.
elementAttributes = schemaCompletion.GetAttributeCompletion(elementPath); elementAttributes = schemaCompletion.GetAttributeCompletion(elementPath);
// Set up simple enum type path. // Set up simple enum type path.
simpleEnumPath = new XmlElementPath(); simpleEnumPath = new XmlElementPath();
simpleEnumPath.Elements.Add(new QualifiedName("schema", namespaceURI, prefix)); simpleEnumPath.AddElement(new QualifiedName("schema", namespaceURI, prefix));
simpleEnumPath.Elements.Add(new QualifiedName("simpleType", namespaceURI, prefix)); simpleEnumPath.AddElement(new QualifiedName("simpleType", namespaceURI, prefix));
simpleEnumPath.Elements.Add(new QualifiedName("restriction", namespaceURI, prefix)); simpleEnumPath.AddElement(new QualifiedName("restriction", namespaceURI, prefix));
// Get child elements. // Get child elements.
simpleEnumElements = schemaCompletion.GetChildElementCompletion(simpleEnumPath); simpleEnumElements = schemaCompletion.GetChildElementCompletion(simpleEnumPath);
// Set up enum path. // Set up enum path.
enumPath = new XmlElementPath(); enumPath = new XmlElementPath();
enumPath.Elements.Add(new QualifiedName("schema", namespaceURI, prefix)); enumPath.AddElement(new QualifiedName("schema", namespaceURI, prefix));
enumPath.Elements.Add(new QualifiedName("simpleType", namespaceURI, prefix)); enumPath.AddElement(new QualifiedName("simpleType", namespaceURI, prefix));
enumPath.Elements.Add(new QualifiedName("restriction", namespaceURI, prefix)); enumPath.AddElement(new QualifiedName("restriction", namespaceURI, prefix));
enumPath.Elements.Add(new QualifiedName("enumeration", namespaceURI, prefix)); enumPath.AddElement(new QualifiedName("enumeration", namespaceURI, prefix));
// Get attributes. // Get attributes.
enumAttributes = schemaCompletion.GetAttributeCompletion(enumPath); enumAttributes = schemaCompletion.GetAttributeCompletion(enumPath);
// Set up xs:all path. // Set up xs:all path.
allElementPath = new XmlElementPath(); allElementPath = new XmlElementPath();
allElementPath.Elements.Add(new QualifiedName("schema", namespaceURI, prefix)); allElementPath.AddElement(new QualifiedName("schema", namespaceURI, prefix));
allElementPath.Elements.Add(new QualifiedName("element", namespaceURI, prefix)); allElementPath.AddElement(new QualifiedName("element", namespaceURI, prefix));
allElementPath.Elements.Add(new QualifiedName("complexType", namespaceURI, prefix)); allElementPath.AddElement(new QualifiedName("complexType", namespaceURI, prefix));
allElementPath.Elements.Add(new QualifiedName("all", namespaceURI, prefix)); allElementPath.AddElement(new QualifiedName("all", namespaceURI, prefix));
// Get child elements of the xs:all element. // Get child elements of the xs:all element.
allElementChildElements = schemaCompletion.GetChildElementCompletion(allElementPath); allElementChildElements = schemaCompletion.GetChildElementCompletion(allElementPath);
// Set up the path to the annotation element that is a child of xs:all. // Set up the path to the annotation element that is a child of xs:all.
allElementAnnotationPath = new XmlElementPath(); allElementAnnotationPath = new XmlElementPath();
allElementAnnotationPath.Elements.Add(new QualifiedName("schema", namespaceURI, prefix)); allElementAnnotationPath.AddElement(new QualifiedName("schema", namespaceURI, prefix));
allElementAnnotationPath.Elements.Add(new QualifiedName("element", namespaceURI, prefix)); allElementAnnotationPath.AddElement(new QualifiedName("element", namespaceURI, prefix));
allElementAnnotationPath.Elements.Add(new QualifiedName("complexType", namespaceURI, prefix)); allElementAnnotationPath.AddElement(new QualifiedName("complexType", namespaceURI, prefix));
allElementAnnotationPath.Elements.Add(new QualifiedName("all", namespaceURI, prefix)); allElementAnnotationPath.AddElement(new QualifiedName("all", namespaceURI, prefix));
allElementAnnotationPath.Elements.Add(new QualifiedName("annotation", namespaceURI, prefix)); allElementAnnotationPath.AddElement(new QualifiedName("annotation", namespaceURI, prefix));
// Get the xs:all annotation child element. // Get the xs:all annotation child element.
allElementAnnotationChildElements = schemaCompletion.GetChildElementCompletion(allElementAnnotationPath); allElementAnnotationChildElements = schemaCompletion.GetChildElementCompletion(allElementAnnotationPath);

10
src/AddIns/DisplayBindings/XmlEditor/Test/XmlEditor.Tests.csproj

@ -139,13 +139,22 @@
<Compile Include="Folding\SingleLineElementDoesNotCreateFoldTestFixture.cs" /> <Compile Include="Folding\SingleLineElementDoesNotCreateFoldTestFixture.cs" />
<Compile Include="Folding\SingleRootElementFoldTestFixture.cs" /> <Compile Include="Folding\SingleRootElementFoldTestFixture.cs" />
<Compile Include="Folding\TwoElementFoldsTestFixture.cs" /> <Compile Include="Folding\TwoElementFoldsTestFixture.cs" />
<Compile Include="Parser\NamespacesInScopeForPathTests.cs" />
<Compile Include="Parser\XamlMixedNamespaceTestFixture.cs" /> <Compile Include="Parser\XamlMixedNamespaceTestFixture.cs" />
<Compile Include="Paths\ChangeElementPathDefaultNamespaceTests.cs" /> <Compile Include="Paths\ChangeElementPathDefaultNamespaceTests.cs" />
<Compile Include="Paths\EmptyElementPathsByNamespaceTestFixture.cs" />
<Compile Include="Paths\NamespacesWithoutPathsTests.cs" />
<Compile Include="Paths\XmlNamespaceCollectionTests.cs" />
<Compile Include="Paths\XmlNamespaceEqualsTests.cs" />
<Compile Include="Paths\OneAndTwoElementPathsTestFixture.cs" />
<Compile Include="Paths\QualifiedNameCollectionEqualsTests.cs" /> <Compile Include="Paths\QualifiedNameCollectionEqualsTests.cs" />
<Compile Include="Paths\QualifiedNameCollectionTests.cs" /> <Compile Include="Paths\QualifiedNameCollectionTests.cs" />
<Compile Include="Paths\QualifiedNameCollectionToStringTests.cs" /> <Compile Include="Paths\QualifiedNameCollectionToStringTests.cs" />
<Compile Include="Paths\QualifiedNameTests.cs" /> <Compile Include="Paths\QualifiedNameTests.cs" />
<Compile Include="Paths\QualifiedNameToStringTests.cs" /> <Compile Include="Paths\QualifiedNameToStringTests.cs" />
<Compile Include="Paths\SingleElementPathByNamespaceTestFixture.cs" />
<Compile Include="Paths\TwoElementPathsByNamespaceTestFixture.cs" />
<Compile Include="Schema.Multiple\TwoSchemaChildElementCompletionTestFixture.cs" />
<Compile Include="Schema\SchemaHasNamespaceTests.cs" /> <Compile Include="Schema\SchemaHasNamespaceTests.cs" />
<Compile Include="Schema\SingleElementSchemaTestFixture.cs" /> <Compile Include="Schema\SingleElementSchemaTestFixture.cs" />
<Compile Include="Schema\ElementWithAttributeSchemaTestFixture.cs" /> <Compile Include="Schema\ElementWithAttributeSchemaTestFixture.cs" />
@ -305,6 +314,7 @@
<Folder Include="Completion" /> <Folder Include="Completion" />
<Folder Include="Editor" /> <Folder Include="Editor" />
<Folder Include="Folding" /> <Folder Include="Folding" />
<Folder Include="Schema.Multiple" />
<Folder Include="Schema\" /> <Folder Include="Schema\" />
<Folder Include="Parser\" /> <Folder Include="Parser\" />
<Folder Include="Paths\" /> <Folder Include="Paths\" />

Loading…
Cancel
Save