XmlSchemaCollectionTests.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. //
  2. // System.Xml.XmlSchemaCollectionTests.cs
  3. //
  4. // Author:
  5. // Atsushi Enomoto <[email protected]>
  6. //
  7. // (C) 2002 Atsushi Enomoto
  8. //
  9. using System;
  10. using System.Globalization;
  11. using System.IO;
  12. using System.Xml;
  13. using System.Xml.Schema;
  14. using NUnit.Framework;
  15. namespace MonoTests.System.Xml
  16. {
  17. [TestFixture]
  18. public class XmlSchemaCollectionTests : Assertion
  19. {
  20. private XmlSchema GetSchema (string path)
  21. {
  22. return XmlSchema.Read (new XmlTextReader (path), null);
  23. }
  24. private XmlQualifiedName QName (string name, string ns)
  25. {
  26. return new XmlQualifiedName (name, ns);
  27. }
  28. [Test]
  29. public void TestAdd ()
  30. {
  31. XmlSchemaCollection col = new XmlSchemaCollection ();
  32. XmlSchema schema = new XmlSchema ();
  33. XmlSchemaElement elem = new XmlSchemaElement ();
  34. elem.Name = "foo";
  35. schema.Items.Add (elem);
  36. schema.TargetNamespace = "urn:foo";
  37. col.Add (schema);
  38. col.Add (schema); // No problem !?
  39. XmlSchema schema2 = new XmlSchema ();
  40. schema2.Items.Add (elem);
  41. schema2.TargetNamespace = "urn:foo";
  42. col.Add (schema2); // No problem !!
  43. schema.Compile (null);
  44. col.Add (schema);
  45. col.Add (schema); // Still no problem !!!
  46. schema2.Compile (null);
  47. col.Add (schema2);
  48. schema = GetSchema ("Test/XmlFiles/xsd/3.xsd");
  49. schema.Compile (null);
  50. col.Add (schema);
  51. schema2 = GetSchema ("Test/XmlFiles/xsd/3.xsd");
  52. schema2.Compile (null);
  53. col.Add (schema2);
  54. }
  55. [Test]
  56. public void TestAddDoesCompilation ()
  57. {
  58. XmlSchema schema = new XmlSchema ();
  59. Assert (!schema.IsCompiled);
  60. XmlSchemaCollection col = new XmlSchemaCollection ();
  61. col.Add (schema);
  62. Assert (schema.IsCompiled);
  63. }
  64. [Test] // bug #75126
  65. public void TestGetEnumerator ()
  66. {
  67. new XmlSchemaCollection().GetEnumerator();
  68. }
  69. [Test] // bug #78220
  70. public void TestCompile ()
  71. {
  72. string schemaFragment1 = string.Format (CultureInfo.InvariantCulture,
  73. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  74. "<xs:schema xmlns:tns=\"NSDate\" elementFormDefault=\"qualified\" targetNamespace=\"NSDate\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  75. " <xs:import namespace=\"NSStatus\" />{0}" +
  76. " <xs:element name=\"trans\" type=\"tns:TranslationStatus\" />{0}" +
  77. " <xs:complexType name=\"TranslationStatus\">{0}" +
  78. " <xs:simpleContent>{0}" +
  79. " <xs:extension xmlns:q1=\"NSStatus\" base=\"q1:StatusType\">{0}" +
  80. " <xs:attribute name=\"Language\" type=\"xs:int\" use=\"required\" />{0}" +
  81. " </xs:extension>{0}" +
  82. " </xs:simpleContent>{0}" +
  83. " </xs:complexType>{0}" +
  84. "</xs:schema>", Environment.NewLine);
  85. string schemaFragment2 = string.Format (CultureInfo.InvariantCulture,
  86. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  87. "<xs:schema xmlns:tns=\"NSStatus\" elementFormDefault=\"qualified\" targetNamespace=\"NSStatus\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  88. " <xs:simpleType name=\"StatusType\">{0}" +
  89. " <xs:restriction base=\"xs:string\">{0}" +
  90. " <xs:enumeration value=\"Untouched\" />{0}" +
  91. " <xs:enumeration value=\"Touched\" />{0}" +
  92. " <xs:enumeration value=\"Complete\" />{0}" +
  93. " <xs:enumeration value=\"None\" />{0}" +
  94. " </xs:restriction>{0}" +
  95. " </xs:simpleType>{0}" +
  96. "</xs:schema>", Environment.NewLine);
  97. XmlSchema schema1 = XmlSchema.Read (new StringReader (schemaFragment1), null);
  98. XmlSchema schema2 = XmlSchema.Read (new StringReader (schemaFragment2), null);
  99. XmlSchemaCollection schemas = new XmlSchemaCollection ();
  100. schemas.Add (schema2);
  101. schemas.Add (schema1);
  102. Assert ("#1", schema1.IsCompiled);
  103. Assert ("#2", schema2.IsCompiled);
  104. }
  105. }
  106. }