WebReferenceOptionsTest.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //
  2. // WebReferenceOptionsTest.cs
  3. //
  4. // Author:
  5. // Atsushi Enomoto <[email protected]>
  6. //
  7. // Copyright (C) 2006 Novell, Inc.
  8. //
  9. #if NET_2_0
  10. using NUnit.Framework;
  11. using System;
  12. using System.IO;
  13. using System.Web.Services.Description;
  14. using System.Xml;
  15. using System.Xml.Schema;
  16. using System.Xml.Serialization;
  17. using System.Collections;
  18. namespace MonoTests.System.Web.Services.Description
  19. {
  20. [TestFixture]
  21. public class WebReferenceOptionsTest
  22. {
  23. string xml1 = "<webReferenceOptions xmlns='http://microsoft.com/webReference/' />";
  24. string xml2 = @"
  25. <webReferenceOptions xmlns='http://microsoft.com/webReference/'>
  26. <codeGenerationOptions>properties newAsync</codeGenerationOptions>
  27. <style>client</style>
  28. <verbose>false</verbose>
  29. </webReferenceOptions>
  30. ";
  31. string xml3 = @"
  32. <webReferenceOptions xmlns='http://microsoft.com/webReference/'>
  33. <gyabo/>
  34. <hoge/>
  35. </webReferenceOptions>";
  36. [Test]
  37. [Category ("NotDotNet")] // why on earth does it allow invalid xml?
  38. public void Schema ()
  39. {
  40. Validate (xml1);
  41. Validate (xml2);
  42. try {
  43. Validate (xml3);
  44. Assert.Fail ("xml3 is invalid.");
  45. } catch (XmlSchemaValidationException) {
  46. }
  47. }
  48. void Validate (string xml)
  49. {
  50. XmlReaderSettings s = new XmlReaderSettings ();
  51. s.ValidationType = ValidationType.Schema;
  52. s.Schemas.Add (WebReferenceOptions.Schema);
  53. XmlReader r = XmlReader.Create (new StringReader (xml), s);
  54. while (!r.EOF)
  55. r.Read ();
  56. }
  57. [Test]
  58. public void Read ()
  59. {
  60. Read (xml1);
  61. Read (xml2);
  62. try {
  63. Read (xml3);
  64. Assert.Fail ("xml3 is invalid.");
  65. } catch (InvalidOperationException) {
  66. }
  67. }
  68. void Read (string xml)
  69. {
  70. XmlReader r = XmlReader.Create (new StringReader (xml));
  71. WebReferenceOptions.Read (r, null);
  72. }
  73. }
  74. }
  75. #endif