Browse Source

Added extra unit tests for the Xml Editor's QualifedName classes.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5222 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 16 years ago
parent
commit
972c1e1361
  1. 54
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/QualifiedName.cs
  2. 144
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/QualifiedNameCollection.cs
  3. 2
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XPathQueryControl.cs
  4. 84
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlElementPath.cs
  5. 36
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlNamespace.cs
  6. 114
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlParser.cs
  7. 16
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlSchemaCompletionData.cs
  8. 2
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlView.cs
  9. 14
      src/AddIns/DisplayBindings/XmlEditor/Test/Parser/AttributeNameTestFixture.cs
  10. 70
      src/AddIns/DisplayBindings/XmlEditor/Test/Paths/QualifiedNameCollectionEqualsTests.cs
  11. 147
      src/AddIns/DisplayBindings/XmlEditor/Test/Paths/QualifiedNameCollectionTests.cs
  12. 47
      src/AddIns/DisplayBindings/XmlEditor/Test/Paths/QualifiedNameCollectionToStringTests.cs
  13. 177
      src/AddIns/DisplayBindings/XmlEditor/Test/Paths/QualifiedNameTests.cs
  14. 13
      src/AddIns/DisplayBindings/XmlEditor/Test/Paths/QualifiedNameToStringTests.cs
  15. 4
      src/AddIns/DisplayBindings/XmlEditor/Test/Paths/SingleElementPathTestFixture.cs
  16. 6
      src/AddIns/DisplayBindings/XmlEditor/Test/Paths/TwoElementPathTestFixture.cs
  17. 6
      src/AddIns/DisplayBindings/XmlEditor/Test/XPathQuery/GetNamespacesFromListViewTestFixture.cs
  18. 2
      src/AddIns/DisplayBindings/XmlEditor/Test/XPathQuery/NamespacePropertiesLoaded.cs
  19. 2
      src/AddIns/DisplayBindings/XmlEditor/Test/XPathQuery/NamespacePropertiesSaved.cs
  20. 56
      src/AddIns/DisplayBindings/XmlEditor/Test/XPathQuery/XmlNamespaceTests.cs
  21. 8
      src/AddIns/DisplayBindings/XmlEditor/Test/XPathQuery/XmlNamespaceToStringTests.cs
  22. 4
      src/AddIns/DisplayBindings/XmlEditor/Test/XmlEditor.Tests.csproj

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

@ -29,7 +29,7 @@ namespace ICSharpCode.XmlEditor @@ -29,7 +29,7 @@ namespace ICSharpCode.XmlEditor
}
public QualifiedName(string name, string namespaceUri)
: this(name, namespaceUri, string.Empty)
: this(name, namespaceUri, String.Empty)
{
}
@ -79,6 +79,10 @@ namespace ICSharpCode.XmlEditor @@ -79,6 +79,10 @@ namespace ICSharpCode.XmlEditor
return xmlQualifiedName.GetHashCode();
}
public bool IsEmpty {
get { return xmlQualifiedName.IsEmpty && String.IsNullOrEmpty(prefix); }
}
/// <summary>
/// Gets the namespace of the qualified name.
/// </summary>
@ -87,6 +91,10 @@ namespace ICSharpCode.XmlEditor @@ -87,6 +91,10 @@ namespace ICSharpCode.XmlEditor
set { xmlQualifiedName = new XmlQualifiedName(xmlQualifiedName.Name, value); }
}
public bool HasNamespace {
get { return xmlQualifiedName.Namespace.Length > 0; }
}
/// <summary>
/// Gets the name of the element.
/// </summary>
@ -103,21 +111,45 @@ namespace ICSharpCode.XmlEditor @@ -103,21 +111,45 @@ namespace ICSharpCode.XmlEditor
set { prefix = value; }
}
/// <summary>
/// Returns a string that represents the QualifiedName.
/// </summary>
public bool HasPrefix {
get { return !String.IsNullOrEmpty(prefix); }
}
public override string ToString()
{
if (xmlQualifiedName.Namespace.Length > 0) {
string prefixToString = String.Empty;
if (!String.IsNullOrEmpty(prefix)) {
prefixToString = prefix + ":";
string qualifiedName = GetPrefixedName();
if (HasNamespace) {
return String.Concat(qualifiedName, " [", xmlQualifiedName.Namespace, "]");
}
return String.Concat(prefixToString, xmlQualifiedName.Name, " [", xmlQualifiedName.Namespace, "]");
} else if (!String.IsNullOrEmpty(prefix)) {
return prefix + ":" + xmlQualifiedName.Name;
return qualifiedName;
}
public string GetPrefixedName()
{
if (String.IsNullOrEmpty(prefix)) {
return xmlQualifiedName.Name;
}
return prefix + ":" + xmlQualifiedName.Name;
}
public static QualifiedName FromString(string name)
{
if (name == null) {
return new QualifiedName();
}
int index = name.IndexOf(':');
if (index >= 0) {
return CreateFromNameWithPrefix(name, index);
}
return new QualifiedName(name, String.Empty);
}
static QualifiedName CreateFromNameWithPrefix(string name, int index)
{
string prefix = name.Substring(0, index);
name = name.Substring(index + 1);
return new QualifiedName(name, String.Empty, prefix);
}
}
}

144
src/AddIns/DisplayBindings/XmlEditor/Project/Src/QualifiedNameCollection.cs

@ -9,113 +9,131 @@ using System; @@ -9,113 +9,131 @@ using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
namespace ICSharpCode.XmlEditor
{
/// <summary>
/// A collection that stores <see cref='QualifiedName'/> objects.
/// </summary>
[Serializable()]
public class QualifiedNameCollection : Collection<QualifiedName> {
/// <summary>
/// Initializes a new instance of <see cref='QualifiedNameCollection'/>.
/// </summary>
public class QualifiedNameCollection : Collection<QualifiedName>
{
public QualifiedNameCollection()
{
}
/// <summary>
/// Initializes a new instance of <see cref='QualifiedNameCollection'/> based on another <see cref='QualifiedNameCollection'/>.
/// </summary>
/// <param name='val'>
/// A <see cref='QualifiedNameCollection'/> from which the contents are copied
/// </param>
public QualifiedNameCollection(QualifiedNameCollection val)
public QualifiedNameCollection(QualifiedNameCollection names)
{
this.AddRange(val);
AddRange(names);
}
/// <summary>
/// Initializes a new instance of <see cref='QualifiedNameCollection'/> containing any array of <see cref='QualifiedName'/> objects.
/// </summary>
/// <param name='val'>
/// A array of <see cref='QualifiedName'/> objects with which to intialize the collection
/// </param>
public QualifiedNameCollection(QualifiedName[] val)
public QualifiedNameCollection(QualifiedName[] names)
{
this.AddRange(val);
AddRange(names);
}
public bool HasItems {
get { return Count > 0; }
}
public override string ToString()
{
string text = String.Empty;
for (int i = 0; i < this.Count; i++) {
text += (i == 0) ? this[i] + "" : " > " + this[i];
StringBuilder text = new StringBuilder();
for (int i = 0; i < Count; i++) {
if (i > 0) {
text.Append(" > ");
}
return text;
text.Append(this[i].ToString());
}
return text.ToString();
}
/// <summary>
/// Copies the elements of an array to the end of the <see cref='QualifiedNameCollection'/>.
/// </summary>
/// <param name='val'>
/// An array of type <see cref='QualifiedName'/> containing the objects to add to the collection.
/// </param>
/// <seealso cref='QualifiedNameCollection.Add'/>
public void AddRange(QualifiedName[] val)
public void AddRange(QualifiedName[] names)
{
for (int i = 0; i < val.Length; i++) {
this.Add(val[i]);
for (int i = 0; i < names.Length; i++) {
Add(names[i]);
}
}
/// <summary>
/// Adds the contents of another <see cref='QualifiedNameCollection'/> to the end of the collection.
/// </summary>
/// <param name='val'>
/// A <see cref='QualifiedNameCollection'/> containing the objects to add to the collection.
/// </param>
/// <seealso cref='QualifiedNameCollection.Add'/>
public void AddRange(QualifiedNameCollection val)
public void AddRange(QualifiedNameCollection names)
{
for (int i = 0; i < val.Count; i++) {
this.Add(val[i]);
for (int i = 0; i < names.Count; i++) {
Add(names[i]);
}
}
/// <summary>
/// Removes the last item in this collection.
/// </summary>
public void RemoveLast()
{
if (Count > 0) {
if (HasItems) {
RemoveAt(Count - 1);
}
}
/// <summary>
/// Removes the first item in the collection.
/// </summary>
public void RemoveFirst()
{
if (Count > 0) {
if (HasItems) {
RemoveFirst(1);
}
}
public void RemoveFirst(int howMany)
{
if (howMany > Count) {
howMany = Count;
}
while (howMany > 0) {
RemoveAt(0);
--howMany;
}
}
/// <summary>
/// Gets the namespace prefix of the last item.
/// </summary>
public string LastPrefix {
get {
if (Count > 0) {
public string GetLastPrefix()
{
if (HasItems) {
QualifiedName name = this[Count - 1];
return name.Prefix;
}
return String.Empty;
}
public string GetNamespaceForPrefix(string prefix)
{
foreach (QualifiedName name in this) {
if (name.Prefix == prefix) {
return name.Namespace;
}
}
return String.Empty;
}
public QualifiedName GetLast()
{
if (HasItems) {
return this[Count - 1];
}
return null;
}
public override int GetHashCode()
{
return base.GetHashCode();
}
public override bool Equals(object obj)
{
QualifiedNameCollection rhs = obj as QualifiedNameCollection;
if (rhs != null) {
if (Count == rhs.Count) {
for (int i = 0; i < Count; ++i) {
QualifiedName lhsName = this[i];
QualifiedName rhsName = rhs[i];
if (!lhsName.Equals(rhsName)) {
return false;
}
}
return true;
}
}
return false;
}
}
}

2
src/AddIns/DisplayBindings/XmlEditor/Project/Src/XPathQueryControl.cs

@ -140,7 +140,7 @@ namespace ICSharpCode.XmlEditor @@ -140,7 +140,7 @@ namespace ICSharpCode.XmlEditor
string[] namespaces = memento.Get(NamespacesProperty, new string[0]);
foreach (string ns in namespaces) {
XmlNamespace xmlNamespace = XmlNamespace.FromString(ns);
AddNamespace(xmlNamespace.Prefix, xmlNamespace.Uri);
AddNamespace(xmlNamespace.Prefix, xmlNamespace.Name);
}
// Set namespace data grid column widths.

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

@ -39,13 +39,11 @@ namespace ICSharpCode.XmlEditor @@ -39,13 +39,11 @@ namespace ICSharpCode.XmlEditor
/// </remarks>
public void Compact()
{
if (elements.Count > 0) {
QualifiedName lastName = Elements[Elements.Count - 1];
if (lastName != null) {
int index = FindNonMatchingParentElement(lastName.Namespace);
if (elements.HasItems) {
QualifiedName lastName = Elements.GetLast();
int index = LastIndexNotMatchingNamespace(lastName.Namespace);
if (index != -1) {
RemoveParentElements(index);
}
elements.RemoveFirst(index + 1);
}
}
}
@ -56,22 +54,12 @@ namespace ICSharpCode.XmlEditor @@ -56,22 +54,12 @@ namespace ICSharpCode.XmlEditor
/// </summary>
public override bool Equals(object obj)
{
XmlElementPath path = obj as XmlElementPath;
if (path == null) return false;
if (this == obj) return true;
if (elements.Count == path.elements.Count) {
for (int i = 0; i < elements.Count; ++i) {
if (!elements[i].Equals(path.elements[i])) {
XmlElementPath rhsPath = obj as XmlElementPath;
if (rhsPath == null) {
return false;
}
}
return true;
}
return false;
return elements.Equals(rhsPath.elements);
}
public override int GetHashCode()
@ -79,71 +67,23 @@ namespace ICSharpCode.XmlEditor @@ -79,71 +67,23 @@ namespace ICSharpCode.XmlEditor
return elements.GetHashCode();
}
/// <summary>
/// Gets a string that represents the XmlElementPath.
/// </summary>
public override string ToString()
{
if (elements.Count > 0) {
StringBuilder toString = new StringBuilder();
int lastIndex = elements.Count - 1;
for (int i = 0; i < elements.Count; ++i) {
string elementToString = GetElementToString(elements[i]);
if (i == lastIndex) {
toString.Append(elementToString);
} else {
toString.Append(elementToString);
toString.Append(" > ");
}
}
return toString.ToString();
}
return string.Empty;
return elements.ToString();
}
/// <summary>
/// Removes elements up to and including the specified index.
/// </summary>
void RemoveParentElements(int index)
int LastIndexNotMatchingNamespace(string namespaceUri)
{
while (index >= 0) {
--index;
elements.RemoveFirst();
}
}
/// <summary>
/// Finds the first parent that does belong in the specified
/// namespace.
/// </summary>
int FindNonMatchingParentElement(string namespaceUri)
{
int index = -1;
if (elements.Count > 1) {
// Start the check from the the last but one item.
// Start the check from the last but one item.
for (int i = elements.Count - 2; i >= 0; --i) {
QualifiedName name = elements[i];
if (name.Namespace != namespaceUri) {
index = i;
break;
return i;
}
}
}
return index;
}
/// <summary>
/// Returns the qualified name as a string. If the name has a
/// prefix then it returns "prefix:element" otherwise it returns
/// just the element name.
/// </summary>
static string GetElementToString(QualifiedName name)
{
if (name.Prefix.Length > 0) {
return name.Prefix + ":" + name.Name;
}
return name.Name;
return -1;
}
}
}

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

@ -15,28 +15,48 @@ namespace ICSharpCode.XmlEditor @@ -15,28 +15,48 @@ namespace ICSharpCode.XmlEditor
public class XmlNamespace
{
string prefix = String.Empty;
string uri = String.Empty;
string name = String.Empty;
const string prefixToStringStart = "Prefix [";
const string uriToStringMiddle = "] Uri [";
public XmlNamespace(string prefix, string uri)
public XmlNamespace()
{
this.prefix = prefix;
this.uri = uri;
}
public XmlNamespace(string prefix, string name)
{
Prefix = prefix;
Name = name;
}
public string Prefix {
get { return prefix; }
set {
prefix = value;
if (prefix == null) {
prefix = String.Empty;
}
}
}
public string Name {
get { return name; }
set {
name = value;
if (name == null) {
name = String.Empty;
}
}
}
public string Uri {
get { return uri; }
public bool HasName {
get { return !String.IsNullOrEmpty(name); }
}
public override string ToString()
{
return String.Concat(prefixToStringStart, prefix, uriToStringMiddle, uri, "]");
return String.Concat(prefixToStringStart, prefix, uriToStringMiddle, name, "]");
}
/// <summary>
@ -56,7 +76,7 @@ namespace ICSharpCode.XmlEditor @@ -56,7 +76,7 @@ namespace ICSharpCode.XmlEditor
return new XmlNamespace(prefix, uri);
}
}
return new XmlNamespace(String.Empty, String.Empty);
return new XmlNamespace();
}
}
}

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

@ -25,49 +25,6 @@ namespace ICSharpCode.XmlEditor @@ -25,49 +25,6 @@ namespace ICSharpCode.XmlEditor
/// </remarks>
public sealed class XmlParser
{
/// <summary>
/// Helper class. Holds the namespace URI and the prefix currently
/// in use for this namespace.
/// </summary>
class NamespaceURI
{
string namespaceURI = String.Empty;
string prefix = String.Empty;
public NamespaceURI()
{
}
public NamespaceURI(string namespaceURI, string prefix)
{
this.namespaceURI = namespaceURI;
this.prefix = prefix;
}
public string Namespace {
get { return namespaceURI; }
set { namespaceURI = value; }
}
public string Prefix {
get { return prefix; }
set {
prefix = value;
if (prefix == null) {
prefix = String.Empty;
}
}
}
public override string ToString()
{
if (!String.IsNullOrEmpty(prefix)) {
return prefix + ":" + namespaceURI;
}
return namespaceURI;
}
}
static readonly char[] whitespaceCharacters = new char[] {' ', '\n', '\t', '\r'};
XmlParser()
@ -170,12 +127,10 @@ namespace ICSharpCode.XmlEditor @@ -170,12 +127,10 @@ namespace ICSharpCode.XmlEditor
/// Gets the attribute name and any prefix. The namespace
/// is not determined.
/// </summary>
/// <returns><see langword="null"/> if no attribute name can
/// be found.</returns>
public static QualifiedName GetQualifiedAttributeName(string xml, int index)
{
string name = GetAttributeName(xml, index);
return GetQualifiedName(name);
return QualifiedName.FromString(name);
}
/// <summary>
@ -201,11 +156,11 @@ namespace ICSharpCode.XmlEditor @@ -201,11 +156,11 @@ namespace ICSharpCode.XmlEditor
public static QualifiedName GetQualifiedAttributeNameAtIndex(string xml, int index, bool includeNamespace)
{
string name = GetAttributeNameAtIndex(xml, index);
QualifiedName qualifiedName = GetQualifiedName(name);
if (qualifiedName != null && String.IsNullOrEmpty(qualifiedName.Namespace) && includeNamespace) {
QualifiedName qualifiedName = QualifiedName.FromString(name);
if (!qualifiedName.IsEmpty && !qualifiedName.HasNamespace && includeNamespace) {
QualifiedNameCollection namespaces = new QualifiedNameCollection();
XmlElementPath path = GetActiveElementStartPathAtIndex(xml, index, namespaces);
qualifiedName.Namespace = GetNamespaceForPrefix(namespaces, path.Elements.LastPrefix);
qualifiedName.Namespace = namespaces.GetNamespaceForPrefix(path.Elements.GetLastPrefix());
}
return qualifiedName;
}
@ -517,7 +472,7 @@ namespace ICSharpCode.XmlEditor @@ -517,7 +472,7 @@ namespace ICSharpCode.XmlEditor
name = xml.Substring(1);
}
return GetQualifiedName(name);
return QualifiedName.FromString(name);
}
/// <summary>
@ -526,22 +481,22 @@ namespace ICSharpCode.XmlEditor @@ -526,22 +481,22 @@ namespace ICSharpCode.XmlEditor
/// </summary>
/// <param name="xml">This string must start at the
/// element we are interested in.</param>
static NamespaceURI GetElementNamespace(string xml)
static XmlNamespace GetElementNamespace(string xml)
{
NamespaceURI namespaceURI = new NamespaceURI();
XmlNamespace namespaceUri = new XmlNamespace();
Match match = Regex.Match(xml, ".*?(xmlns\\s*?|xmlns:.*?)=\\s*?['\\\"](.*?)['\\\"]");
if (match.Success) {
namespaceURI.Namespace = match.Groups[2].Value;
namespaceUri.Name = match.Groups[2].Value;
string xmlns = match.Groups[1].Value.Trim();
int prefixIndex = xmlns.IndexOf(':');
if (prefixIndex > 0) {
namespaceURI.Prefix = xmlns.Substring(prefixIndex + 1);
namespaceUri.Prefix = xmlns.Substring(prefixIndex + 1);
}
}
return namespaceURI;
return namespaceUri;
}
static string ReverseString(string text)
@ -579,29 +534,29 @@ namespace ICSharpCode.XmlEditor @@ -579,29 +534,29 @@ namespace ICSharpCode.XmlEditor
static XmlElementPath GetActiveElementStartPath(string xml, int index, string elementText, QualifiedNameCollection namespaces)
{
QualifiedName elementName = GetElementName(elementText);
if (elementName == null) {
if (elementName.IsEmpty) {
return new XmlElementPath();
}
NamespaceURI elementNamespace = GetElementNamespace(elementText);
XmlNamespace elementNamespace = GetElementNamespace(elementText);
XmlElementPath path = GetFullParentElementPath(xml.Substring(0, index), namespaces);
// Try to get a namespace for the active element's prefix.
if (elementName.Prefix.Length > 0 && elementNamespace.Namespace.Length == 0) {
elementName.Namespace = GetNamespaceForPrefix(namespaces, elementName.Prefix);
elementNamespace.Namespace = elementName.Namespace;
if (elementName.HasPrefix && elementNamespace.Name.Length == 0) {
elementName.Namespace = namespaces.GetNamespaceForPrefix(elementName.Prefix);
elementNamespace.Name = elementName.Namespace;
elementNamespace.Prefix = elementName.Prefix;
}
if (elementNamespace.Namespace.Length == 0) {
if (elementNamespace.Name.Length == 0) {
if (path.Elements.Count > 0) {
QualifiedName parentName = path.Elements[path.Elements.Count - 1];
elementNamespace.Namespace = parentName.Namespace;
elementNamespace.Name = parentName.Namespace;
elementNamespace.Prefix = parentName.Prefix;
}
}
path.Elements.Add(new QualifiedName(elementName.Name, elementNamespace.Namespace, elementNamespace.Prefix));
path.Elements.Add(new QualifiedName(elementName.Name, elementNamespace.Name, elementNamespace.Prefix));
path.Compact();
return path;
}
@ -680,26 +635,6 @@ namespace ICSharpCode.XmlEditor @@ -680,26 +635,6 @@ namespace ICSharpCode.XmlEditor
return null;
}
/// <summary>
/// Returns a name and its prefix.
/// </summary>
static QualifiedName GetQualifiedName(string name)
{
if (name.Length == 0) {
return null;
}
QualifiedName qualifiedName = new QualifiedName();
int prefixIndex = name.IndexOf(':');
if (prefixIndex > 0) {
qualifiedName.Prefix = name.Substring(0, prefixIndex);
qualifiedName.Name = name.Substring(prefixIndex + 1);
} else {
qualifiedName.Name = name;
}
return qualifiedName;
}
/// <summary>
/// Gets the parent element path based on the index position. This
/// method does not compact the path so it will include all elements
@ -742,19 +677,6 @@ namespace ICSharpCode.XmlEditor @@ -742,19 +677,6 @@ namespace ICSharpCode.XmlEditor
return path;
}
/// <summary>
/// Finds the namespace for the specified prefix.
/// </summary>
static string GetNamespaceForPrefix(QualifiedNameCollection namespaces, string prefix)
{
foreach (QualifiedName name in namespaces) {
if (name.Prefix == prefix) {
return name.Namespace;
}
}
return String.Empty;
}
/// <summary>
/// Gets path of the xml element start tag that the specified
/// <paramref name="index"/> is currently inside.

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

@ -186,7 +186,7 @@ namespace ICSharpCode.XmlEditor @@ -186,7 +186,7 @@ namespace ICSharpCode.XmlEditor
// Get completion data.
if (element != null) {
return GetChildElementCompletionData(element, path.Elements.LastPrefix).ToArray();
return GetChildElementCompletionData(element, path.Elements.GetLastPrefix()).ToArray();
}
return new ICompletionItem[0];
@ -337,19 +337,19 @@ namespace ICSharpCode.XmlEditor @@ -337,19 +337,19 @@ namespace ICSharpCode.XmlEditor
/// form then no prefix is added.</remarks>
public QualifiedName CreateQualifiedName(string name)
{
int index = name.IndexOf(":");
if (index >= 0) {
string prefix = name.Substring(0, index);
name = name.Substring(index + 1);
QualifiedName qualifiedName = QualifiedName.FromString(name);
if (qualifiedName.HasPrefix) {
foreach (XmlQualifiedName xmlQualifiedName in schema.Namespaces.ToArray()) {
if (xmlQualifiedName.Name == prefix) {
return new QualifiedName(name, xmlQualifiedName.Namespace, prefix);
if (xmlQualifiedName.Name == qualifiedName.Prefix) {
qualifiedName.Namespace = xmlQualifiedName.Namespace;
return qualifiedName;
}
}
}
// Default behaviour just return the name with the namespace uri.
return new QualifiedName(name, namespaceUri);
qualifiedName.Namespace = namespaceUri;
return qualifiedName;
}
/// <summary>

2
src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlView.cs

@ -127,7 +127,7 @@ namespace ICSharpCode.XmlEditor @@ -127,7 +127,7 @@ namespace ICSharpCode.XmlEditor
// Add namespaces.
XmlNamespaceManager namespaceManager = new XmlNamespaceManager(navigator.NameTable);
foreach (XmlNamespace xmlNamespace in namespaces) {
namespaceManager.AddNamespace(xmlNamespace.Prefix, xmlNamespace.Uri);
namespaceManager.AddNamespace(xmlNamespace.Prefix, xmlNamespace.Name);
}
// Run the xpath query.

14
src/AddIns/DisplayBindings/XmlEditor/Test/Parser/AttributeNameTestFixture.cs

@ -76,34 +76,34 @@ namespace XmlEditor.Tests.Parser @@ -76,34 +76,34 @@ namespace XmlEditor.Tests.Parser
public void FailureTest1()
{
string text = "foo=";
Assert.IsNull(XmlParser.GetQualifiedAttributeName(text, text.Length));
Assert.IsTrue(XmlParser.GetQualifiedAttributeName(text, text.Length).IsEmpty);
}
[Test]
public void FailureTest2()
{
string text = "foo=<";
Assert.IsNull(XmlParser.GetQualifiedAttributeName(text, text.Length));
Assert.IsTrue(XmlParser.GetQualifiedAttributeName(text, text.Length).IsEmpty);
}
[Test]
public void FailureTest3()
{
string text = "a";
Assert.IsNull(XmlParser.GetQualifiedAttributeName(text, text.Length));
Assert.IsTrue(XmlParser.GetQualifiedAttributeName(text, text.Length).IsEmpty);
}
[Test]
public void FailureTest4()
{
string text = " a";
Assert.IsNull(XmlParser.GetQualifiedAttributeName(text, text.Length));
Assert.IsTrue(XmlParser.GetQualifiedAttributeName(text, text.Length).IsEmpty);
}
[Test]
public void EmptyString()
{
Assert.IsNull(XmlParser.GetQualifiedAttributeName(String.Empty, 10));
Assert.IsTrue(XmlParser.GetQualifiedAttributeName(String.Empty, 10).IsEmpty);
}
[Test]
@ -118,7 +118,7 @@ namespace XmlEditor.Tests.Parser @@ -118,7 +118,7 @@ namespace XmlEditor.Tests.Parser
[Test]
public void GetQualifiedAttributeNameWithEmptyString()
{
Assert.IsNull(XmlParser.GetQualifiedAttributeNameAtIndex(String.Empty, 0, true));
Assert.IsTrue(XmlParser.GetQualifiedAttributeNameAtIndex(String.Empty, 0, true).IsEmpty);
}
[Test]
@ -136,7 +136,7 @@ namespace XmlEditor.Tests.Parser @@ -136,7 +136,7 @@ namespace XmlEditor.Tests.Parser
[Test]
public void GetQualifiedAttributeNameWithSingleXmlCharacter()
{
Assert.IsNull(XmlParser.GetQualifiedAttributeNameAtIndex("<", 0, true));
Assert.IsTrue(XmlParser.GetQualifiedAttributeNameAtIndex("<", 0, true).IsEmpty);
}
}
}

70
src/AddIns/DisplayBindings/XmlEditor/Test/Paths/QualifiedNameCollectionEqualsTests.cs

@ -0,0 +1,70 @@ @@ -0,0 +1,70 @@
// <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 QualifiedNameCollectionEqualsTests
{
QualifiedNameCollection lhs;
QualifiedNameCollection rhs;
[SetUp]
public void Init()
{
lhs = new QualifiedNameCollection();
rhs = new QualifiedNameCollection();
}
[Test]
public void EmptyCollectionsAreEqual()
{
Assert.IsTrue(lhs.Equals(rhs));
}
[Test]
public void NullIsNotEqualToCollection()
{
Assert.IsFalse(lhs.Equals(null));
}
[Test]
public void EqualReturnsFalseWhenOneCollectionHasAnItemAndTheOtherDoesNot()
{
lhs.Add(new QualifiedName("root", "ns", "a"));
Assert.IsFalse(lhs.Equals(rhs));
}
[Test]
public void EqualsReturnsFalseWhenQualifiedNamesAreDifferent()
{
lhs.Add(new QualifiedName("name1", "ns1", "prefix1"));
rhs.Add(new QualifiedName("name2", "ns2", "prefix2"));
Assert.IsFalse(lhs.Equals(rhs));
}
[Test]
public void EqualsReturnsTrueWhenQualifiedNamesHaveSameNameAndNamespaceButDifferentPrefix()
{
lhs.Add(new QualifiedName("name", "ns", "prefix1"));
rhs.Add(new QualifiedName("name", "ns", "prefix2"));
Assert.IsTrue(lhs.Equals(rhs));
}
[Test]
public void EqualsReturnsFalseWhenQualifiedNamesHaveSameNameButDifferentNamespace()
{
lhs.Add(new QualifiedName("name", "ns1", "prefix"));
rhs.Add(new QualifiedName("name", "ns2", "prefix"));
Assert.IsFalse(lhs.Equals(rhs));
}
}
}

147
src/AddIns/DisplayBindings/XmlEditor/Test/Paths/QualifiedNameCollectionTests.cs

@ -0,0 +1,147 @@ @@ -0,0 +1,147 @@
// <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 QualifiedNameCollectionTests
{
QualifiedName firstName;
QualifiedName secondName;
QualifiedNameCollection qualifiedNameCollection;
[SetUp]
public void Init()
{
firstName = new QualifiedName("first", "first-ns", "first-prefix");
secondName = new QualifiedName("second", "second-ns", "second-prefix");
QualifiedName[] array = new QualifiedName[] { firstName, secondName };
qualifiedNameCollection = new QualifiedNameCollection(array);
}
[Test]
public void CreateQualifiedNameCollectionInstanceUsingQualifiedNameArray()
{
Assert.AreSame(secondName, qualifiedNameCollection[1]);
}
[Test]
public void CreateQualifiedNameCollectionInstanceUsingQualifiedNameCollection()
{
QualifiedName[] array = new QualifiedName[] { firstName, secondName };
QualifiedNameCollection oldCollection = new QualifiedNameCollection(array);
QualifiedNameCollection newCollection = new QualifiedNameCollection(oldCollection);
Assert.AreSame(firstName, newCollection[0]);
}
[Test]
public void RemoveFirstItemFromCollectionRemovesFirstName()
{
qualifiedNameCollection.RemoveFirst();
Assert.AreSame(secondName, qualifiedNameCollection[0]);
}
[Test]
public void RemoveFirstItemFromEmptyCollectionDoesNotThrowArgumentOutOfRangeException()
{
qualifiedNameCollection = new QualifiedNameCollection();
qualifiedNameCollection.RemoveFirst();
}
[Test]
public void RemoveLastItemFromCollectionRemovesLastName()
{
qualifiedNameCollection.RemoveLast();
Assert.AreEqual(1, qualifiedNameCollection.Count);
}
[Test]
public void RemoveLastItemFromCollectionLeavesFirstName()
{
RemoveLastItemFromCollectionRemovesLastName();
Assert.AreSame(firstName, qualifiedNameCollection[0]);
}
[Test]
public void RemoveLastItemFromEmptyCollectionDoesNotThrowArgumentOutOfRangeException()
{
qualifiedNameCollection = new QualifiedNameCollection();
qualifiedNameCollection.RemoveLast();
}
[Test]
public void GetLastPrefixReturnsPrefixFromLastQualifiedNameInCollection()
{
Assert.AreEqual("second-prefix", qualifiedNameCollection.GetLastPrefix());
}
[Test]
public void GetLastPrefixFromEmptyCollectionDoesNotThrowArgumentOutOfRangeException()
{
qualifiedNameCollection = new QualifiedNameCollection();
Assert.AreEqual(String.Empty, qualifiedNameCollection.GetLastPrefix());
}
[Test]
public void GetNamespaceForPrefixFindsCorrectNamespaceForFirstName()
{
Assert.AreEqual("first-ns", qualifiedNameCollection.GetNamespaceForPrefix("first-prefix"));
}
[Test]
public void GetNamespaceForPrefixForUnknownPrefixReturnsEmptyString()
{
Assert.AreEqual(String.Empty, qualifiedNameCollection.GetNamespaceForPrefix("a"));
}
[Test]
public void GetLastReturnsLastQualifiedNameInCollection()
{
Assert.AreSame(secondName, qualifiedNameCollection.GetLast());
}
[Test]
public void GetLastReturnsNullWhenCollectionIsEmpty()
{
qualifiedNameCollection = new QualifiedNameCollection();
Assert.IsNull(qualifiedNameCollection.GetLast());
}
[Test]
public void QualifiedNameCollectionHasItems()
{
Assert.IsTrue(qualifiedNameCollection.HasItems);
}
[Test]
public void EmptyQualifiedNameCollectionHasNoItems()
{
qualifiedNameCollection = new QualifiedNameCollection();
Assert.IsFalse(qualifiedNameCollection.HasItems);
}
[Test]
public void RemoveFirstTwoItemsClearsEntireCollection()
{
qualifiedNameCollection.RemoveFirst(2);
Assert.AreEqual(0, qualifiedNameCollection.Count);
}
[Test]
public void RemovingMoreItemsThanInCollectionDoesNotThrowArgumentOutOfRangeException()
{
qualifiedNameCollection.RemoveFirst(5);
Assert.AreEqual(0, qualifiedNameCollection.Count);
}
}
}

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

@ -0,0 +1,47 @@ @@ -0,0 +1,47 @@
// <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 QualifiedNameCollectionToStringTests
{
QualifiedNameCollection qualifiedNames;
[SetUp]
public void Init()
{
qualifiedNames = new QualifiedNameCollection();
}
[Test]
public void EmptyCollectionToStringReturnsEmptyString()
{
Assert.AreEqual(String.Empty, qualifiedNames.ToString());
}
[Test]
public void OneItemInCollectionReturnsQualifiedNameInToString()
{
qualifiedNames.Add(new QualifiedName("root", "ns", "a"));
Assert.AreEqual("a:root [ns]", qualifiedNames.ToString());
}
[Test]
public void TwoItemsInCollectionReturnsTwoQualifiedNamesInToString()
{
qualifiedNames.Add(new QualifiedName("root1", "ns1", "a1"));
qualifiedNames.Add(new QualifiedName("root2", "ns2", "a2"));
Assert.AreEqual("a1:root1 [ns1] > a2:root2 [ns2]", qualifiedNames.ToString());
}
}
}

177
src/AddIns/DisplayBindings/XmlEditor/Test/Paths/QualifiedNameTests.cs

@ -0,0 +1,177 @@ @@ -0,0 +1,177 @@
// <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 QualifiedNameTests
{
[Test]
public void GetPrefixedNameWithNoPrefixReturnsName()
{
QualifiedName name = new QualifiedName("root", "namespace");
Assert.AreEqual("root", name.GetPrefixedName());
}
[Test]
public void GetPrefixedNameWithPrefixReturnsPrefixAndName()
{
QualifiedName name = new QualifiedName("root", "namespace", "a");
Assert.AreEqual("a:root", name.GetPrefixedName());
}
[Test]
public void EmptyQualifiedNameGetPrefixedNameReturnsEmptyString()
{
QualifiedName name = new QualifiedName();
Assert.AreEqual(String.Empty, name.GetPrefixedName());
}
[Test]
public void HasNamespaceReturnsTrueForNonEmptyNamespace()
{
QualifiedName name = new QualifiedName("root", "namespace");
Assert.IsTrue(name.HasNamespace);
}
[Test]
public void IsEmptyReturnsTrueForEmptyNameAndNamespaceAndPrefix()
{
QualifiedName name = new QualifiedName();
Assert.IsTrue(name.IsEmpty);
}
[Test]
public void IsEmptyReturnsFalseForNonEmptyName()
{
QualifiedName name = new QualifiedName("root", String.Empty);
Assert.IsFalse(name.IsEmpty);
}
[Test]
public void IsEmptyReturnsFalseForNonEmptyNamespace()
{
QualifiedName name = new QualifiedName(String.Empty, "ns");
Assert.IsFalse(name.IsEmpty);
}
[Test]
public void IsEmptyReturnsFalseForNonEmptyNamespacePrefix()
{
QualifiedName name = new QualifiedName(String.Empty, String.Empty, "a");
Assert.IsFalse(name.IsEmpty);
}
[Test]
public void EmptyQualifiedNameReturnsEmptyStringForName()
{
QualifiedName name = new QualifiedName();
Assert.AreEqual(String.Empty, name.Name);
}
[Test]
public void EmptyQualifiedNameReturnsEmptyStringForNamespace()
{
QualifiedName name = new QualifiedName();
Assert.AreEqual(String.Empty, name.Namespace);
}
[Test]
public void EmptyQualifiedNameReturnsEmptyStringForNamespacePrefix()
{
QualifiedName name = new QualifiedName();
Assert.AreEqual(String.Empty, name.Prefix);
}
[Test]
public void NamePropertyReturnsCorrectName()
{
QualifiedName name = new QualifiedName("a", "ns");
Assert.AreEqual("a", name.Name);
}
[Test]
public void NamespacePropertyReturnsCorrectNamespace()
{
QualifiedName name = new QualifiedName("a", "ns");
Assert.AreEqual("ns", name.Namespace);
}
[Test]
public void PrefixPropertyReturnsCorrectNamespace()
{
QualifiedName name = new QualifiedName("a", "ns", "prefix");
Assert.AreEqual("prefix", name.Prefix);
}
[Test]
public void HasPrefixReturnsTrueForNonEmptyPrefix()
{
QualifiedName name = new QualifiedName("a", "ns", "prefix");
Assert.IsTrue(name.HasPrefix);
}
[Test]
public void HasPrefixReturnsFalseForEmptyPrefix()
{
QualifiedName name = new QualifiedName("a", "ns", String.Empty);
Assert.IsFalse(name.HasPrefix);
}
[Test]
public void QualifiedNameChanged()
{
QualifiedName name = new QualifiedName("root", "ns", "a");
name.Name = "element";
Assert.AreEqual("a:element [ns]", name.ToString());
}
[Test]
public void QualifiedNameNamespaceChanged()
{
QualifiedName name = new QualifiedName("root", "ns", "a");
name.Namespace = "new-ns";
Assert.AreEqual("a:root [new-ns]", name.ToString());
}
[Test]
public void QualifiedNamePrefixChanged()
{
QualifiedName name = new QualifiedName("root", "ns", "a");
name.Prefix = "newprefix";
Assert.AreEqual("newprefix:root [ns]", name.ToString());
}
[Test]
public void CreateQualifiedNameFromString()
{
QualifiedName name = QualifiedName.FromString("root");
QualifiedName expectedQualifiedName = new QualifiedName("root", String.Empty);
Assert.AreEqual(expectedQualifiedName, name);
}
[Test]
public void CreateQualifiedNameFromStringContainingPrefix()
{
QualifiedName name = QualifiedName.FromString("a:root");
QualifiedName expectedQualifiedName = new QualifiedName("root", String.Empty, "a");
Assert.AreEqual(expectedQualifiedName, name);
}
[Test]
public void CreateQualifiedNameFromNullString()
{
QualifiedName name = QualifiedName.FromString(null);
Assert.IsTrue(name.IsEmpty);
}
}
}

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

@ -11,9 +11,6 @@ using NUnit.Framework; @@ -11,9 +11,6 @@ using NUnit.Framework;
namespace XmlEditor.Tests.Paths
{
/// <summary>
/// Tests the QualifiedName.ToString method.
/// </summary>
[TestFixture]
public class QualifiedNameToStringTests
{
@ -39,7 +36,7 @@ namespace XmlEditor.Tests.Paths @@ -39,7 +36,7 @@ namespace XmlEditor.Tests.Paths
}
[Test]
public void NameNamespaceAndPrefix()
public void NameAndNamespaceAndPrefixS()
{
QualifiedName name = new QualifiedName("root", "urn:my-uri", "a");
Assert.AreEqual("a:root [urn:my-uri]", name.ToString());
@ -59,12 +56,18 @@ namespace XmlEditor.Tests.Paths @@ -59,12 +56,18 @@ namespace XmlEditor.Tests.Paths
Assert.AreEqual("root", name.ToString());
}
[Test]
public void NullPrefixAndNullNamespace()
{
QualifiedName name = new QualifiedName("root", null, null);
Assert.AreEqual("root", name.ToString());
}
[Test]
public void NullPrefixAndNonEmptyNamespace()
{
QualifiedName name = new QualifiedName("root", "urn:my-uri", null);
Assert.AreEqual("root [urn:my-uri]", name.ToString());
}
}
}

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

@ -67,7 +67,7 @@ namespace XmlEditor.Tests.Paths @@ -67,7 +67,7 @@ namespace XmlEditor.Tests.Paths
[Test]
public void PathToString()
{
string expectedToString = "foo";
string expectedToString = "foo [http://foo]";
Assert.AreEqual(expectedToString, path.ToString());
}
@ -76,7 +76,7 @@ namespace XmlEditor.Tests.Paths @@ -76,7 +76,7 @@ namespace XmlEditor.Tests.Paths
{
QualifiedName qualifiedName = new QualifiedName("bar", "http://foo");
path.Elements.Add(qualifiedName);
Assert.AreEqual("foo > bar", path.ToString());
Assert.AreEqual("foo [http://foo] > bar [http://foo]", path.ToString());
}
}
}

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

@ -47,14 +47,14 @@ namespace XmlEditor.Tests.Paths @@ -47,14 +47,14 @@ namespace XmlEditor.Tests.Paths
[Test]
public void LastPrefix()
{
Assert.AreEqual("b", path.Elements.LastPrefix, "Incorrect last prefix.");
Assert.AreEqual("b", path.Elements.GetLastPrefix(), "Incorrect last prefix.");
}
[Test]
public void LastPrefixAfterLastItemRemoved()
{
path.Elements.RemoveLast();
Assert.AreEqual("f", path.Elements.LastPrefix, "Incorrect last prefix.");
Assert.AreEqual("f", path.Elements.GetLastPrefix(), "Incorrect last prefix.");
}
[Test]
@ -97,7 +97,7 @@ namespace XmlEditor.Tests.Paths @@ -97,7 +97,7 @@ namespace XmlEditor.Tests.Paths
[Test]
public void PathToString()
{
string expectedToString = "f:foo > b:bar";
string expectedToString = "f:foo [http://foo] > b:bar [http://bar]";
Assert.AreEqual(expectedToString, path.ToString());
}
}

6
src/AddIns/DisplayBindings/XmlEditor/Test/XPathQuery/GetNamespacesFromListViewTestFixture.cs

@ -33,7 +33,7 @@ namespace XmlEditor.Tests.XPathQuery @@ -33,7 +33,7 @@ namespace XmlEditor.Tests.XPathQuery
expectedNamespaces.Add(new XmlNamespace("s", "http://sharpdevelop.com"));
foreach (XmlNamespace ns in expectedNamespaces) {
queryControl.AddNamespace(ns.Prefix, ns.Uri);
queryControl.AddNamespace(ns.Prefix, ns.Name);
}
namespacesAddedToGrid = new List<XmlNamespace>();
@ -54,7 +54,7 @@ namespace XmlEditor.Tests.XPathQuery @@ -54,7 +54,7 @@ namespace XmlEditor.Tests.XPathQuery
XmlNamespace actualNamespace = namespaces[i];
Assert.AreEqual(expectedNamespace.Prefix, actualNamespace.Prefix);
Assert.AreEqual(expectedNamespace.Uri, actualNamespace.Uri);
Assert.AreEqual(expectedNamespace.Name, actualNamespace.Name);
}
}
@ -72,7 +72,7 @@ namespace XmlEditor.Tests.XPathQuery @@ -72,7 +72,7 @@ namespace XmlEditor.Tests.XPathQuery
XmlNamespace actualNamespace = namespacesAddedToGrid[i];
Assert.AreEqual(expectedNamespace.Prefix, actualNamespace.Prefix);
Assert.AreEqual(expectedNamespace.Uri, actualNamespace.Uri);
Assert.AreEqual(expectedNamespace.Name, actualNamespace.Name);
}
}

2
src/AddIns/DisplayBindings/XmlEditor/Test/XPathQuery/NamespacePropertiesLoaded.cs

@ -53,7 +53,7 @@ namespace XmlEditor.Tests.XPathQuery @@ -53,7 +53,7 @@ namespace XmlEditor.Tests.XPathQuery
XmlNamespace expectedNamespace = expectedNamespaces[i];
XmlNamespace actualNamespace = actualNamespaces[i];
Assert.AreEqual(expectedNamespace.Prefix, actualNamespace.Prefix);
Assert.AreEqual(expectedNamespace.Uri, actualNamespace.Uri);
Assert.AreEqual(expectedNamespace.Name, actualNamespace.Name);
}
}
}

2
src/AddIns/DisplayBindings/XmlEditor/Test/XPathQuery/NamespacePropertiesSaved.cs

@ -30,7 +30,7 @@ namespace XmlEditor.Tests.XPathQuery @@ -30,7 +30,7 @@ namespace XmlEditor.Tests.XPathQuery
expectedNamespaces.Add(new XmlNamespace("s", "http://sharpdevelop.com"));
foreach (XmlNamespace xmlNamespace in expectedNamespaces) {
queryControl.AddNamespace(xmlNamespace.Prefix, xmlNamespace.Uri);
queryControl.AddNamespace(xmlNamespace.Prefix, xmlNamespace.Name);
}
// Blank prefix and uris should be ignored.
queryControl.AddNamespace(String.Empty, String.Empty);

56
src/AddIns/DisplayBindings/XmlEditor/Test/XPathQuery/XmlNamespaceTests.cs

@ -19,7 +19,61 @@ namespace XmlEditor.Tests.XPathQuery @@ -19,7 +19,61 @@ namespace XmlEditor.Tests.XPathQuery
{
XmlNamespace ns = new XmlNamespace("s", "http://sharpdevelop.com");
Assert.AreEqual("s", ns.Prefix);
Assert.AreEqual("http://sharpdevelop.com", ns.Uri);
Assert.AreEqual("http://sharpdevelop.com", ns.Name);
}
[Test]
public void SettingPrefixPropertyUpdatesPrefix()
{
XmlNamespace ns = new XmlNamespace("s", "http://sharpdevelop.com");
ns.Prefix = "a";
Assert.AreEqual("a", ns.Prefix);
}
[Test]
public void SettingNamePropertyUpdatesNamespace()
{
XmlNamespace ns = new XmlNamespace("s", "http://sharpdevelop.com");
ns.Name = "new-ns";
Assert.AreEqual("new-ns", ns.Name);
}
[Test]
public void NullNamespaceAndPrefixReplacedByEmptyStringsWhenCreatingXmlNamespaceInstance()
{
XmlNamespace ns = new XmlNamespace(null, null);
Assert.AreEqual(String.Empty, ns.Name);
Assert.AreEqual(String.Empty, ns.Prefix);
}
[Test]
public void SettingNamePropertyToNullUpdatesNamespaceToEmptyString()
{
XmlNamespace ns = new XmlNamespace("s", "http://sharpdevelop.com");
ns.Name = null;
Assert.AreEqual(String.Empty, ns.Name);
}
[Test]
public void SettingPrefixPropertyToNullUpdatesPrefixToEmptyString()
{
XmlNamespace ns = new XmlNamespace("s", "http://sharpdevelop.com");
ns.Prefix = null;
Assert.AreEqual(String.Empty, ns.Prefix);
}
[Test]
public void HasNamePropertyReturnsFalseWhenNamespaceIsEmptyString()
{
XmlNamespace ns = new XmlNamespace("s", String.Empty);
Assert.IsFalse(ns.HasName);
}
[Test]
public void HasNamePropertyReturnsTrueWhenNamespaceIsNotEmptyString()
{
XmlNamespace ns = new XmlNamespace("s", "ns");
Assert.IsTrue(ns.HasName);
}
}
}

8
src/AddIns/DisplayBindings/XmlEditor/Test/XPathQuery/XmlNamespaceToStringTests.cs

@ -26,7 +26,7 @@ namespace XmlEditor.Tests.XPathQuery @@ -26,7 +26,7 @@ namespace XmlEditor.Tests.XPathQuery
{
XmlNamespace ns = XmlNamespace.FromString("Prefix [f] Uri [http://foo.com]");
Assert.AreEqual("f", ns.Prefix);
Assert.AreEqual("http://foo.com", ns.Uri);
Assert.AreEqual("http://foo.com", ns.Name);
}
[Test]
@ -34,7 +34,7 @@ namespace XmlEditor.Tests.XPathQuery @@ -34,7 +34,7 @@ namespace XmlEditor.Tests.XPathQuery
{
XmlNamespace ns = XmlNamespace.FromString("Prefix [] Uri [http://foo.com]");
Assert.AreEqual(String.Empty, ns.Prefix);
Assert.AreEqual("http://foo.com", ns.Uri);
Assert.AreEqual("http://foo.com", ns.Name);
}
[Test]
@ -42,7 +42,7 @@ namespace XmlEditor.Tests.XPathQuery @@ -42,7 +42,7 @@ namespace XmlEditor.Tests.XPathQuery
{
XmlNamespace ns = XmlNamespace.FromString("Prefix [f] Uri []");
Assert.AreEqual("f", ns.Prefix);
Assert.AreEqual(String.Empty, ns.Uri);
Assert.AreEqual(String.Empty, ns.Name);
}
[Test]
@ -50,7 +50,7 @@ namespace XmlEditor.Tests.XPathQuery @@ -50,7 +50,7 @@ namespace XmlEditor.Tests.XPathQuery
{
XmlNamespace ns = XmlNamespace.FromString(String.Empty);
Assert.AreEqual(String.Empty, ns.Prefix);
Assert.AreEqual(String.Empty, ns.Uri);
Assert.AreEqual(String.Empty, ns.Name);
}
}
}

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

@ -102,6 +102,10 @@ @@ -102,6 +102,10 @@
<Compile Include="Editor\XmlSchemaPickerTestFixture.cs" />
<Compile Include="Editor\XmlSchemasPanelTestFixture.cs" />
<Compile Include="Parser\XamlMixedNamespaceTestFixture.cs" />
<Compile Include="Paths\QualifiedNameCollectionEqualsTests.cs" />
<Compile Include="Paths\QualifiedNameCollectionTests.cs" />
<Compile Include="Paths\QualifiedNameCollectionToStringTests.cs" />
<Compile Include="Paths\QualifiedNameTests.cs" />
<Compile Include="Paths\QualifiedNameToStringTests.cs" />
<Compile Include="Schema\SchemaHasNamespaceTests.cs" />
<Compile Include="Schema\SingleElementSchemaTestFixture.cs" />

Loading…
Cancel
Save