XmlSchemaSetTests.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. //
  2. // System.Xml.XmlSchemaSetTests.cs
  3. //
  4. // Author:
  5. // Atsushi Enomoto <[email protected]>
  6. //
  7. // (C) 2004 Novell Inc.
  8. //
  9. #if NET_2_0
  10. using System;
  11. using System.Collections;
  12. using System.IO;
  13. using System.Xml;
  14. using System.Xml.Schema;
  15. using NUnit.Framework;
  16. namespace MonoTests.System.Xml
  17. {
  18. [TestFixture]
  19. public class XmlSchemaSetTests
  20. {
  21. [Test]
  22. public void Add ()
  23. {
  24. XmlSchemaSet ss = new XmlSchemaSet ();
  25. XmlDocument doc = new XmlDocument ();
  26. doc.LoadXml ("<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' />");
  27. ss.Add (null, new XmlNodeReader (doc)); // null targetNamespace
  28. ss.Compile ();
  29. // same document, different targetNamespace
  30. ss.Add ("ab", new XmlNodeReader (doc));
  31. // Add(null, xmlReader) -> targetNamespace in the schema
  32. doc.LoadXml ("<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' targetNamespace='urn:foo' />");
  33. ss.Add (null, new XmlNodeReader (doc));
  34. Assert.AreEqual (3, ss.Count);
  35. bool chameleon = false;
  36. bool ab = false;
  37. bool urnfoo = false;
  38. foreach (XmlSchema schema in ss.Schemas ()) {
  39. if (schema.TargetNamespace == null)
  40. chameleon = true;
  41. else if (schema.TargetNamespace == "ab")
  42. ab = true;
  43. else if (schema.TargetNamespace == "urn:foo")
  44. urnfoo = true;
  45. }
  46. Assert.IsTrue (chameleon, "chameleon schema missing");
  47. Assert.IsTrue (ab, "target-remapped schema missing");
  48. Assert.IsTrue (urnfoo, "target specified in the schema ignored");
  49. }
  50. [Test]
  51. [Ignore ("This behavior might be changed, since Add(XmlSchema) does not throw any exceptions, while this does.")]
  52. [ExpectedException (typeof (ArgumentException))]
  53. public void AddTwice ()
  54. {
  55. XmlSchemaSet ss = new XmlSchemaSet ();
  56. XmlDocument doc = new XmlDocument ();
  57. doc.LoadXml ("<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' />");
  58. ss.Add ("ab", new XmlNodeReader (doc));
  59. ss.Add ("ab", new XmlNodeReader (doc));
  60. }
  61. [Test]
  62. public void CompilationSettings ()
  63. {
  64. Assert.IsNotNull (new XmlSchemaSet ().CompilationSettings);
  65. new XmlSchemaSet ().CompilationSettings = null;
  66. }
  67. [Test]
  68. public void DisableUpaCheck ()
  69. {
  70. string schema = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>
  71. <xs:complexType name='Foo'>
  72. <xs:sequence>
  73. <xs:choice minOccurs='0'>
  74. <xs:element name='el'/>
  75. </xs:choice>
  76. <xs:element name='el' />
  77. </xs:sequence>
  78. </xs:complexType>
  79. </xs:schema>";
  80. XmlSchema xs = XmlSchema.Read (new XmlTextReader (
  81. schema, XmlNodeType.Document, null), null);
  82. XmlSchemaSet xss = new XmlSchemaSet ();
  83. xss.Add (xs);
  84. xss.CompilationSettings.EnableUpaCheck = false;
  85. xss.Compile ();
  86. }
  87. }
  88. }
  89. #endif