PageRenderTime 38ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/mcs/class/System.Xml.Linq/Test/System.Xml.Linq/XNamespaceTest.cs

https://bitbucket.org/steenlund/mono-2.6.7-for-amiga
C# | 140 lines | 96 code | 16 blank | 28 comment | 4 complexity | 42fb7b0b390cf063bc0bcdaae6fb7c29 MD5 | raw file
Possible License(s): LGPL-2.0, MPL-2.0-no-copyleft-exception, CC-BY-SA-3.0, GPL-2.0, LGPL-2.1
  1. //
  2. // Authors:
  3. // Atsushi Enomoto
  4. //
  5. // Copyright 2007 Novell (http://www.novell.com)
  6. //
  7. // Permission is hereby granted, free of charge, to any person obtaining
  8. // a copy of this software and associated documentation files (the
  9. // "Software"), to deal in the Software without restriction, including
  10. // without limitation the rights to use, copy, modify, merge, publish,
  11. // distribute, sublicense, and/or sell copies of the Software, and to
  12. // permit persons to whom the Software is furnished to do so, subject to
  13. // the following conditions:
  14. //
  15. // The above copyright notice and this permission notice shall be
  16. // included in all copies or substantial portions of the Software.
  17. //
  18. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  19. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  21. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  22. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  23. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  24. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  25. //
  26. using System;
  27. using System.IO;
  28. using System.Xml;
  29. using System.Xml.Linq;
  30. using NUnit.Framework;
  31. namespace MonoTests.System.Xml.Linq
  32. {
  33. [TestFixture]
  34. public class XNamespaceTest
  35. {
  36. [Test]
  37. [ExpectedException (typeof (ArgumentNullException))]
  38. public void GetNull ()
  39. {
  40. XNamespace.Get (null);
  41. }
  42. [Test]
  43. public void GetEmpty ()
  44. {
  45. XNamespace n = XNamespace.Get (String.Empty);
  46. Assert.AreEqual (String.Empty, n.NamespaceName);
  47. }
  48. [Test]
  49. //[ExpectedException (typeof (ArgumentException))]
  50. public void GetBrokenFormat ()
  51. {
  52. XNamespace n = XNamespace.Get ("{");
  53. Assert.AreEqual ("{", n.NamespaceName, "#1");
  54. }
  55. [Test]
  56. //[ExpectedException (typeof (XmlException))]
  57. public void GetBrokenFormat2 ()
  58. {
  59. XNamespace n = XNamespace.Get ("}");
  60. Assert.AreEqual ("}", n.NamespaceName, "#1");
  61. }
  62. [Test]
  63. //[ExpectedException (typeof (ArgumentException))]
  64. public void GetBrokenFormat3 ()
  65. {
  66. XNamespace n = XNamespace.Get ("{{}}x");
  67. Assert.AreEqual ("{{}}x", n.NamespaceName, "#1");
  68. }
  69. [Test]
  70. public void GetBrokenFormat4 ()
  71. {
  72. XNamespace n = XNamespace.Get ("{}x}");
  73. Assert.AreEqual ("{}x}", n.NamespaceName, "#1");
  74. }
  75. [Test]
  76. public void Get1 ()
  77. {
  78. XNamespace n = XNamespace.Get ("{x_x}");
  79. Assert.AreEqual ("{x_x}", n.NamespaceName, "#1");
  80. n = XNamespace.Get ("x_x"); // looks like this is the ordinal use.
  81. Assert.AreEqual ("x_x", n.NamespaceName, "#2");
  82. }
  83. [Test]
  84. public void Get2 ()
  85. {
  86. XNamespace n = XNamespace.Get (String.Empty);
  87. Assert.IsTrue (Object.ReferenceEquals (XNamespace.None, n), "#1");
  88. n = XNamespace.Get ("http://www.w3.org/2000/xmlns/");
  89. Assert.IsTrue (Object.ReferenceEquals (XNamespace.Xmlns, n), "#2");
  90. Assert.IsTrue (Object.ReferenceEquals (XNamespace.Get ("urn:foo"), XNamespace.Get ("urn:foo")), "#3");
  91. }
  92. [Test]
  93. public void GetName ()
  94. {
  95. XNamespace n = XNamespace.Get ("urn:foo");
  96. Assert.IsTrue (Object.ReferenceEquals (n.GetName ("foo"), n.GetName ("foo")), "#1");
  97. Assert.IsTrue (n.GetName ("foo") == n.GetName ("foo"), "#2");
  98. Assert.IsFalse (n.GetName ("foo") == n.GetName ("bar"), "#3");
  99. }
  100. [Test]
  101. public void Predefined ()
  102. {
  103. Assert.AreEqual ("http://www.w3.org/XML/1998/namespace", XNamespace.Xml.NamespaceName, "#1");
  104. Assert.AreEqual ("http://www.w3.org/2000/xmlns/", XNamespace.Xmlns.NamespaceName, "#2");
  105. }
  106. [Test]
  107. public void Addition ()
  108. {
  109. XNamespace ns = "http://www.novell.com";
  110. XName d = ns + "hello";
  111. Assert.AreEqual ("hello", d.LocalName, "localname");
  112. Assert.AreEqual (ns, d.Namespace, "namespace");
  113. Assert.AreEqual ("http://www.novell.com", d.NamespaceName, "nsname");
  114. }
  115. [Test]
  116. public void Equals ()
  117. {
  118. Assert.IsTrue (XNamespace.None.Equals (XNamespace.Get ("")), "#1");
  119. Assert.IsTrue (XNamespace.None == XNamespace.Get (""), "#2");
  120. Assert.IsFalse (XNamespace.None.Equals (XNamespace.Get (" ")), "#3");
  121. Assert.IsFalse (XNamespace.None == XNamespace.Get (" "), "#4");
  122. }
  123. }
  124. }