XmlSchemaSetTests.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. }
  62. }
  63. #endif