2 // ServiceDescriptionTest.cs
5 // Atsushi Enomoto <atsushi@ximian.com>
6 // Ankit Jain <jankit@novell.com>
8 // Copyright (C) 2005 Novell, Inc.
9 // Copyright (C) 2006 Novell, Inc.
12 using NUnit.Framework;
16 using System.Web.Services.Description;
18 using System.Xml.Serialization;
19 using System.Collections;
21 namespace MonoTests.System.Web.Services.Description
24 public class ServiceDescriptionTest
27 public void SimpleWrite ()
29 ServiceDescription sd = new ServiceDescription ();
30 Assert.IsNull (sd.Name);
31 sd.Write (TextWriter.Null);
37 ServiceDescription sd = new ServiceDescription ();
38 Assert.IsNotNull (sd.Bindings);
39 Assert.IsNotNull (sd.Extensions);
40 Assert.IsNotNull (sd.Imports);
41 Assert.IsNotNull (sd.Messages);
42 Assert.IsNotNull (sd.PortTypes);
43 Assert.IsNotNull (sd.Services);
44 Assert.IsNotNull (sd.Types);
46 Assert.IsNull (sd.ServiceDescriptions);
47 Assert.IsNull (sd.TargetNamespace);
52 public void Namespaces ()
54 FileStream fs = new FileStream ("Test/System.Web.Services.Description/test.wsdl", FileMode.Open);
55 XmlTextReader xtr = new XmlTextReader (fs);
57 ServiceDescription sd = ServiceDescription.Read (xtr);
60 Assert.IsNotNull (sd.Namespaces);
61 Assert.AreEqual (8, sd.Namespaces.Count, "#n0");
63 ArrayList list = new ArrayList (sd.Namespaces.ToArray ());
64 list.Sort (new qname_comparer ());
66 Assert.AreEqual (new XmlQualifiedName ("", "http://schemas.xmlsoap.org/wsdl/"), list [0]);
67 Assert.AreEqual (new XmlQualifiedName ("http", "http://schemas.xmlsoap.org/wsdl/http/"), list [1]);
68 Assert.AreEqual (new XmlQualifiedName ("mime", "http://schemas.xmlsoap.org/wsdl/mime/"), list [2]);
69 Assert.AreEqual (new XmlQualifiedName ("s", "http://www.w3.org/2001/XMLSchema"), list [3]);
70 Assert.AreEqual (new XmlQualifiedName ("s0", "http://tempuri.org/"), list [4]);
71 Assert.AreEqual (new XmlQualifiedName ("soap", "http://schemas.xmlsoap.org/wsdl/soap/"), list [5]);
72 Assert.AreEqual (new XmlQualifiedName ("soapenc", "http://schemas.xmlsoap.org/soap/encoding/"), list [6]);
73 Assert.AreEqual (new XmlQualifiedName ("tm", "http://microsoft.com/wsdl/mime/textMatching/"), list [7]);
77 public void ExtensibleAttributes ()
79 FileStream fs = new FileStream("Test/System.Web.Services.Description/test.wsdl", FileMode.Open);
80 XmlTextReader xtr = new XmlTextReader(fs);
82 ServiceDescription sd = ServiceDescription.Read(xtr);
83 CheckEA (sd, "sdAtt", "sdVal");
84 CheckEA (sd.Messages [0], "msgAtt", "msgVal");
85 CheckEA (sd.Messages [0].Parts [0], "partAtt", "partVal");
87 CheckEA (sd.PortTypes [0], "ptAtt", "ptVal");
88 CheckEA (sd.PortTypes [0].Operations [0], "opAtt", "opVal");
89 CheckEA (sd.PortTypes [0].Operations [0].Messages[0], "opmsgAtt", "opmsgVal");
91 CheckEA (sd.Services [0], "svcAtt", "svcVal");
92 CheckEA (sd.Services [0].Ports [0], "portAtt", "portVal");
98 public void Extensions ()
100 FileStream fs = new FileStream("Test/System.Web.Services.Description/test.wsdl", FileMode.Open);
101 XmlTextReader xtr = new XmlTextReader(fs);
103 ServiceDescription sd = ServiceDescription.Read(xtr);
106 Assert.IsNotNull (sd.Extensions);
107 Assert.AreEqual (1, sd.Extensions.Count);
109 CheckExtensions (sd, "sdElem", "sdVal");
110 CheckExtensions (sd.Messages [0], "msgElem", "msgVal");
111 CheckExtensions (sd.Messages [0].Parts [0], "partElem", "partVal");
113 CheckExtensions (sd.PortTypes [0], "ptElem", "ptVal");
114 CheckExtensions (sd.PortTypes [0].Operations [0], "opElem", "opVal");
117 Assert.IsNotNull (sd.Bindings [0].Extensions);
118 Assert.AreEqual (2, sd.Bindings [0].Extensions.Count);
119 CheckXmlElement (sd.Bindings [0].Extensions [0], "binElem");
120 Assert.AreEqual (typeof (SoapBinding), sd.Bindings [0].Extensions [1].GetType ());
122 //Binding [0].Operations [0]
123 Assert.IsNotNull (sd.Bindings [0].Operations [0].Extensions);
124 Assert.AreEqual (1, sd.Bindings [0].Operations [0].Extensions.Count);
125 Assert.AreEqual (typeof (SoapOperationBinding), sd.Bindings [0].Operations [0].Extensions [0].GetType ());
128 CheckExtensions (sd.Services [0], "svcElem", "svcVal");
131 Assert.IsNotNull (sd.Services [0].Ports [0].Extensions);
132 Assert.AreEqual (2, sd.Services [0].Ports [0].Extensions.Count);
133 Assert.AreEqual (typeof (SoapAddressBinding), sd.Services [0].Ports [0].Extensions [0].GetType ());
134 CheckXmlElement (sd.Services [0].Ports [0].Extensions [1], "portElem");
138 void CheckExtensions (DocumentableItem di, string elemName, string val)
140 Assert.IsNotNull (di.Extensions);
142 Assert.AreEqual (1, di.Extensions.Count);
144 Assert.AreEqual (typeof (XmlElement), di.Extensions [0].GetType ());
145 Assert.AreEqual (elemName, ((XmlElement) di.Extensions [0]).Name);
146 Assert.AreEqual (val, ((XmlElement) di.Extensions [0]).InnerText);
149 void CheckXmlElement (object o, string name)
151 Assert.AreEqual (typeof (XmlElement), o.GetType ());
152 Assert.AreEqual (name, ((XmlElement) o).Name);
155 void CheckEA (DocumentableItem di, string att, string val)
157 Assert.IsNotNull (di.ExtensibleAttributes);
159 Assert.AreEqual (1, di.ExtensibleAttributes.Length);
160 Assert.AreEqual (att, di.ExtensibleAttributes [0].Name);
161 Assert.AreEqual (val, di.ExtensibleAttributes [0].Value);
165 public void ReadInvalid ()
167 ServiceDescription sd = ServiceDescription.Read (XmlReader.Create (new StringReader ("<definitions xmlns='http://schemas.xmlsoap.org/wsdl/'><hoge/></definitions>")));
171 public void ValidatingRead ()
173 ServiceDescription sd = ServiceDescription.Read (XmlReader.Create (new StringReader ("<definitions xmlns='http://schemas.xmlsoap.org/wsdl/'><hoge/></definitions>")), true);
174 Assert.IsTrue (sd.ValidationWarnings.Count > 0);
180 class qname_comparer : IComparer
182 public int Compare (object x, object y)
184 XmlQualifiedName a = (XmlQualifiedName) x;
185 XmlQualifiedName b = (XmlQualifiedName) y;
187 return String.Compare (a.Name, b.Name);