ServiceDescriptionTest.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. [Test]
  31. public void Ctor ()
  32. {
  33. ServiceDescription sd = new ServiceDescription ();
  34. Assert.IsNotNull (sd.Bindings);
  35. Assert.IsNotNull (sd.Extensions);
  36. Assert.IsNotNull (sd.Imports);
  37. Assert.IsNotNull (sd.Messages);
  38. Assert.IsNotNull (sd.PortTypes);
  39. Assert.IsNotNull (sd.Services);
  40. Assert.IsNotNull (sd.Types);
  41. Assert.IsNull (sd.ServiceDescriptions);
  42. Assert.IsNull (sd.TargetNamespace);
  43. }
  44. #if NET_2_0
  45. [Test]
  46. public void Namespaces ()
  47. {
  48. FileStream fs = new FileStream ("Test/System.Web.Services.Description/test.wsdl", FileMode.Open);
  49. XmlTextReader xtr = new XmlTextReader (fs);
  50. ServiceDescription sd = ServiceDescription.Read (xtr);
  51. fs.Close ();
  52. Assert.IsNotNull (sd.Namespaces);
  53. Assert.AreEqual (8, sd.Namespaces.Count, "#n0");
  54. ArrayList list = new ArrayList (sd.Namespaces.ToArray ());
  55. list.Sort (new qname_comparer ());
  56. Assert.AreEqual (new XmlQualifiedName ("", "http://schemas.xmlsoap.org/wsdl/"), list [0]);
  57. Assert.AreEqual (new XmlQualifiedName ("http", "http://schemas.xmlsoap.org/wsdl/http/"), list [1]);
  58. Assert.AreEqual (new XmlQualifiedName ("mime", "http://schemas.xmlsoap.org/wsdl/mime/"), list [2]);
  59. Assert.AreEqual (new XmlQualifiedName ("s", "http://www.w3.org/2001/XMLSchema"), list [3]);
  60. Assert.AreEqual (new XmlQualifiedName ("s0", "http://tempuri.org/"), list [4]);
  61. Assert.AreEqual (new XmlQualifiedName ("soap", "http://schemas.xmlsoap.org/wsdl/soap/"), list [5]);
  62. Assert.AreEqual (new XmlQualifiedName ("soapenc", "http://schemas.xmlsoap.org/soap/encoding/"), list [6]);
  63. Assert.AreEqual (new XmlQualifiedName ("tm", "http://microsoft.com/wsdl/mime/textMatching/"), list [7]);
  64. }
  65. [Test]
  66. public void ExtensibleAttributes ()
  67. {
  68. FileStream fs = new FileStream("Test/System.Web.Services.Description/test.wsdl", FileMode.Open);
  69. XmlTextReader xtr = new XmlTextReader(fs);
  70. ServiceDescription sd = ServiceDescription.Read(xtr);
  71. CheckEA (sd, "sdAtt", "sdVal");
  72. CheckEA (sd.Messages [0], "msgAtt", "msgVal");
  73. CheckEA (sd.Messages [0].Parts [0], "partAtt", "partVal");
  74. CheckEA (sd.PortTypes [0], "ptAtt", "ptVal");
  75. CheckEA (sd.PortTypes [0].Operations [0], "opAtt", "opVal");
  76. CheckEA (sd.PortTypes [0].Operations [0].Messages[0], "opmsgAtt", "opmsgVal");
  77. CheckEA (sd.Services [0], "svcAtt", "svcVal");
  78. CheckEA (sd.Services [0].Ports [0], "portAtt", "portVal");
  79. fs.Close ();
  80. }
  81. [Test]
  82. public void Extensions ()
  83. {
  84. FileStream fs = new FileStream("Test/System.Web.Services.Description/test.wsdl", FileMode.Open);
  85. XmlTextReader xtr = new XmlTextReader(fs);
  86. ServiceDescription sd = ServiceDescription.Read(xtr);
  87. fs.Close ();
  88. Assert.IsNotNull (sd.Extensions);
  89. Assert.AreEqual (1, sd.Extensions.Count);
  90. CheckExtensions (sd, "sdElem", "sdVal");
  91. CheckExtensions (sd.Messages [0], "msgElem", "msgVal");
  92. CheckExtensions (sd.Messages [0].Parts [0], "partElem", "partVal");
  93. CheckExtensions (sd.PortTypes [0], "ptElem", "ptVal");
  94. CheckExtensions (sd.PortTypes [0].Operations [0], "opElem", "opVal");
  95. //Binding [0]
  96. Assert.IsNotNull (sd.Bindings [0].Extensions);
  97. Assert.AreEqual (2, sd.Bindings [0].Extensions.Count);
  98. CheckXmlElement (sd.Bindings [0].Extensions [0], "binElem");
  99. Assert.AreEqual (typeof (SoapBinding), sd.Bindings [0].Extensions [1].GetType ());
  100. //Binding [0].Operations [0]
  101. Assert.IsNotNull (sd.Bindings [0].Operations [0].Extensions);
  102. Assert.AreEqual (1, sd.Bindings [0].Operations [0].Extensions.Count);
  103. Assert.AreEqual (typeof (SoapOperationBinding), sd.Bindings [0].Operations [0].Extensions [0].GetType ());
  104. //Service
  105. CheckExtensions (sd.Services [0], "svcElem", "svcVal");
  106. //Service.Port
  107. Assert.IsNotNull (sd.Services [0].Ports [0].Extensions);
  108. Assert.AreEqual (2, sd.Services [0].Ports [0].Extensions.Count);
  109. Assert.AreEqual (typeof (SoapAddressBinding), sd.Services [0].Ports [0].Extensions [0].GetType ());
  110. CheckXmlElement (sd.Services [0].Ports [0].Extensions [1], "portElem");
  111. }
  112. void CheckExtensions (DocumentableItem di, string elemName, string val)
  113. {
  114. Assert.IsNotNull (di.Extensions);
  115. Assert.AreEqual (1, di.Extensions.Count);
  116. Assert.AreEqual (typeof (XmlElement), di.Extensions [0].GetType ());
  117. Assert.AreEqual (elemName, ((XmlElement) di.Extensions [0]).Name);
  118. Assert.AreEqual (val, ((XmlElement) di.Extensions [0]).InnerText);
  119. }
  120. void CheckXmlElement (object o, string name)
  121. {
  122. Assert.AreEqual (typeof (XmlElement), o.GetType ());
  123. Assert.AreEqual (name, ((XmlElement) o).Name);
  124. }
  125. void CheckEA (DocumentableItem di, string att, string val)
  126. {
  127. Assert.IsNotNull (di.ExtensibleAttributes);
  128. Assert.AreEqual (1, di.ExtensibleAttributes.Length);
  129. Assert.AreEqual (att, di.ExtensibleAttributes [0].Name);
  130. Assert.AreEqual (val, di.ExtensibleAttributes [0].Value);
  131. }
  132. [Test]
  133. public void ReadInvalid ()
  134. {
  135. ServiceDescription sd = ServiceDescription.Read (XmlReader.Create (new StringReader ("<definitions xmlns='http://schemas.xmlsoap.org/wsdl/'><hoge/></definitions>")));
  136. }
  137. [Test]
  138. public void ValidatingRead ()
  139. {
  140. ServiceDescription sd = ServiceDescription.Read (XmlReader.Create (new StringReader ("<definitions xmlns='http://schemas.xmlsoap.org/wsdl/'><hoge/></definitions>")), true);
  141. Assert.IsTrue (sd.ValidationWarnings.Count > 0);
  142. }
  143. #endif
  144. }
  145. class qname_comparer : IComparer
  146. {
  147. public int Compare (object x, object y)
  148. {
  149. XmlQualifiedName a = (XmlQualifiedName) x;
  150. XmlQualifiedName b = (XmlQualifiedName) y;
  151. return String.Compare (a.Name, b.Name);
  152. }
  153. }
  154. }