ServiceDescriptionTest.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. //
  2. // ServiceDescriptionTest.cs
  3. //
  4. // Author:
  5. // Atsushi Enomoto <[email protected]>
  6. // Ankit Jain <[email protected]>
  7. //
  8. // Copyright (C) 2005 Novell, Inc.
  9. // Copyright (C) 2006 Novell, Inc.
  10. //
  11. using NUnit.Framework;
  12. using System;
  13. using System.IO;
  14. using System.Web.Services.Description;
  15. using System.Xml;
  16. using System.Xml.Serialization;
  17. using System.Collections;
  18. namespace MonoTests.System.Web.Services.Description
  19. {
  20. [TestFixture]
  21. public class ServiceDescriptionTest
  22. {
  23. [Test]
  24. public void SimpleWrite ()
  25. {
  26. ServiceDescription sd = new ServiceDescription ();
  27. Assert.IsNull (sd.Name);
  28. sd.Write (TextWriter.Null);
  29. }
  30. #if NET_2_0
  31. [Test]
  32. public void Namespaces ()
  33. {
  34. FileStream fs = new FileStream ("Test/System.Web.Services.Description/test.wsdl", FileMode.Open);
  35. XmlTextReader xtr = new XmlTextReader (fs);
  36. ServiceDescription sd = ServiceDescription.Read (xtr);
  37. fs.Close ();
  38. Assert.IsNotNull (sd.Namespaces);
  39. Assert.AreEqual (8, sd.Namespaces.Count, "#n0");
  40. ArrayList list = new ArrayList (sd.Namespaces.ToArray ());
  41. list.Sort (new qname_comparer ());
  42. Assert.AreEqual (new XmlQualifiedName ("", "http://schemas.xmlsoap.org/wsdl/"), list [0]);
  43. Assert.AreEqual (new XmlQualifiedName ("http", "http://schemas.xmlsoap.org/wsdl/http/"), list [1]);
  44. Assert.AreEqual (new XmlQualifiedName ("mime", "http://schemas.xmlsoap.org/wsdl/mime/"), list [2]);
  45. Assert.AreEqual (new XmlQualifiedName ("s", "http://www.w3.org/2001/XMLSchema"), list [3]);
  46. Assert.AreEqual (new XmlQualifiedName ("s0", "http://tempuri.org/"), list [4]);
  47. Assert.AreEqual (new XmlQualifiedName ("soap", "http://schemas.xmlsoap.org/wsdl/soap/"), list [5]);
  48. Assert.AreEqual (new XmlQualifiedName ("soapenc", "http://schemas.xmlsoap.org/soap/encoding/"), list [6]);
  49. Assert.AreEqual (new XmlQualifiedName ("tm", "http://microsoft.com/wsdl/mime/textMatching/"), list [7]);
  50. }
  51. [Test]
  52. public void ExtensibleAttributes ()
  53. {
  54. FileStream fs = new FileStream("Test/System.Web.Services.Description/test.wsdl", FileMode.Open);
  55. XmlTextReader xtr = new XmlTextReader(fs);
  56. ServiceDescription sd = ServiceDescription.Read(xtr);
  57. CheckEA (sd, "sdAtt", "sdVal");
  58. CheckEA (sd.Messages [0], "msgAtt", "msgVal");
  59. CheckEA (sd.Messages [0].Parts [0], "partAtt", "partVal");
  60. CheckEA (sd.PortTypes [0], "ptAtt", "ptVal");
  61. CheckEA (sd.PortTypes [0].Operations [0], "opAtt", "opVal");
  62. CheckEA (sd.PortTypes [0].Operations [0].Messages[0], "opmsgAtt", "opmsgVal");
  63. CheckEA (sd.Services [0], "svcAtt", "svcVal");
  64. CheckEA (sd.Services [0].Ports [0], "portAtt", "portVal");
  65. fs.Close ();
  66. }
  67. [Test]
  68. public void Extensions ()
  69. {
  70. FileStream fs = new FileStream("Test/System.Web.Services.Description/test.wsdl", FileMode.Open);
  71. XmlTextReader xtr = new XmlTextReader(fs);
  72. ServiceDescription sd = ServiceDescription.Read(xtr);
  73. fs.Close ();
  74. Assert.IsNotNull (sd.Extensions);
  75. Assert.AreEqual (1, sd.Extensions.Count);
  76. CheckExtensions (sd, "sdElem", "sdVal");
  77. CheckExtensions (sd.Messages [0], "msgElem", "msgVal");
  78. CheckExtensions (sd.Messages [0].Parts [0], "partElem", "partVal");
  79. CheckExtensions (sd.PortTypes [0], "ptElem", "ptVal");
  80. CheckExtensions (sd.PortTypes [0].Operations [0], "opElem", "opVal");
  81. //Binding [0]
  82. Assert.IsNotNull (sd.Bindings [0].Extensions);
  83. Assert.AreEqual (2, sd.Bindings [0].Extensions.Count);
  84. CheckXmlElement (sd.Bindings [0].Extensions [0], "binElem");
  85. Assert.AreEqual (typeof (SoapBinding), sd.Bindings [0].Extensions [1].GetType ());
  86. //Binding [0].Operations [0]
  87. Assert.IsNotNull (sd.Bindings [0].Operations [0].Extensions);
  88. Assert.AreEqual (1, sd.Bindings [0].Operations [0].Extensions.Count);
  89. Assert.AreEqual (typeof (SoapOperationBinding), sd.Bindings [0].Operations [0].Extensions [0].GetType ());
  90. //Service
  91. CheckExtensions (sd.Services [0], "svcElem", "svcVal");
  92. //Service.Port
  93. Assert.IsNotNull (sd.Services [0].Ports [0].Extensions);
  94. Assert.AreEqual (2, sd.Services [0].Ports [0].Extensions.Count);
  95. Assert.AreEqual (typeof (SoapAddressBinding), sd.Services [0].Ports [0].Extensions [0].GetType ());
  96. CheckXmlElement (sd.Services [0].Ports [0].Extensions [1], "portElem");
  97. }
  98. void CheckExtensions (DocumentableItem di, string elemName, string val)
  99. {
  100. Assert.IsNotNull (di.Extensions);
  101. Assert.AreEqual (1, di.Extensions.Count);
  102. Assert.AreEqual (typeof (XmlElement), di.Extensions [0].GetType ());
  103. Assert.AreEqual (elemName, ((XmlElement) di.Extensions [0]).Name);
  104. Assert.AreEqual (val, ((XmlElement) di.Extensions [0]).InnerText);
  105. }
  106. void CheckXmlElement (object o, string name)
  107. {
  108. Assert.AreEqual (typeof (XmlElement), o.GetType ());
  109. Assert.AreEqual (name, ((XmlElement) o).Name);
  110. }
  111. void CheckEA (DocumentableItem di, string att, string val)
  112. {
  113. Assert.IsNotNull (di.ExtensibleAttributes);
  114. Assert.AreEqual (1, di.ExtensibleAttributes.Length);
  115. Assert.AreEqual (att, di.ExtensibleAttributes [0].Name);
  116. Assert.AreEqual (val, di.ExtensibleAttributes [0].Value);
  117. }
  118. #endif
  119. }
  120. class qname_comparer : IComparer
  121. {
  122. public int Compare (object x, object y)
  123. {
  124. XmlQualifiedName a = (XmlQualifiedName) x;
  125. XmlQualifiedName b = (XmlQualifiedName) y;
  126. return String.Compare (a.Name, b.Name);
  127. }
  128. }
  129. }