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);
51 public void ReadAndRetrievalUrl ()
53 Assert.AreEqual (String.Empty, new ServiceDescription ().RetrievalUrl, "#1");
54 ServiceDescription sd = ServiceDescription.Read ("Test/System.Web.Services.Description/test2.wsdl");
55 Assert.AreEqual (String.Empty, sd.RetrievalUrl, "#2");
59 public void Namespaces ()
61 FileStream fs = new FileStream ("Test/System.Web.Services.Description/test.wsdl", FileMode.Open, FileAccess.Read);
62 XmlTextReader xtr = new XmlTextReader (fs);
64 ServiceDescription sd = ServiceDescription.Read (xtr);
67 Assert.IsNotNull (sd.Namespaces);
68 Assert.AreEqual (8, sd.Namespaces.Count, "#n0");
70 ArrayList list = new ArrayList (sd.Namespaces.ToArray ());
71 list.Sort (new qname_comparer ());
73 Assert.AreEqual (new XmlQualifiedName ("", "http://schemas.xmlsoap.org/wsdl/"), list [0]);
74 Assert.AreEqual (new XmlQualifiedName ("http", "http://schemas.xmlsoap.org/wsdl/http/"), list [1]);
75 Assert.AreEqual (new XmlQualifiedName ("mime", "http://schemas.xmlsoap.org/wsdl/mime/"), list [2]);
76 Assert.AreEqual (new XmlQualifiedName ("s", "http://www.w3.org/2001/XMLSchema"), list [3]);
77 Assert.AreEqual (new XmlQualifiedName ("s0", "http://tempuri.org/"), list [4]);
78 Assert.AreEqual (new XmlQualifiedName ("soap", "http://schemas.xmlsoap.org/wsdl/soap/"), list [5]);
79 Assert.AreEqual (new XmlQualifiedName ("soapenc", "http://schemas.xmlsoap.org/soap/encoding/"), list [6]);
80 Assert.AreEqual (new XmlQualifiedName ("tm", "http://microsoft.com/wsdl/mime/textMatching/"), list [7]);
84 public void ExtensibleAttributes ()
86 FileStream fs = new FileStream ("Test/System.Web.Services.Description/test.wsdl", FileMode.Open, FileAccess.Read);
87 XmlTextReader xtr = new XmlTextReader(fs);
89 ServiceDescription sd = ServiceDescription.Read(xtr);
90 CheckEA (sd, "sdAtt", "sdVal");
91 CheckEA (sd.Messages [0], "msgAtt", "msgVal");
92 CheckEA (sd.Messages [0].Parts [0], "partAtt", "partVal");
94 CheckEA (sd.PortTypes [0], "ptAtt", "ptVal");
95 CheckEA (sd.PortTypes [0].Operations [0], "opAtt", "opVal");
96 CheckEA (sd.PortTypes [0].Operations [0].Messages[0], "opmsgAtt", "opmsgVal");
98 CheckEA (sd.Services [0], "svcAtt", "svcVal");
99 CheckEA (sd.Services [0].Ports [0], "portAtt", "portVal");
105 public void Extensions ()
107 FileStream fs = new FileStream("Test/System.Web.Services.Description/test.wsdl", FileMode.Open, FileAccess.Read);
108 XmlTextReader xtr = new XmlTextReader(fs);
110 ServiceDescription sd = ServiceDescription.Read(xtr);
113 Assert.IsNotNull (sd.Extensions);
114 Assert.AreEqual (1, sd.Extensions.Count);
116 CheckExtensions (sd, "sdElem", "sdVal");
117 CheckExtensions (sd.Messages [0], "msgElem", "msgVal");
118 CheckExtensions (sd.Messages [0].Parts [0], "partElem", "partVal");
120 CheckExtensions (sd.PortTypes [0], "ptElem", "ptVal");
121 CheckExtensions (sd.PortTypes [0].Operations [0], "opElem", "opVal");
124 Assert.IsNotNull (sd.Bindings [0].Extensions);
125 Assert.AreEqual (2, sd.Bindings [0].Extensions.Count);
126 CheckXmlElement (sd.Bindings [0].Extensions [0], "binElem");
127 Assert.AreEqual (typeof (SoapBinding), sd.Bindings [0].Extensions [1].GetType ());
129 //Binding [0].Operations [0]
130 Assert.IsNotNull (sd.Bindings [0].Operations [0].Extensions);
131 Assert.AreEqual (1, sd.Bindings [0].Operations [0].Extensions.Count);
132 Assert.AreEqual (typeof (SoapOperationBinding), sd.Bindings [0].Operations [0].Extensions [0].GetType ());
135 CheckExtensions (sd.Services [0], "svcElem", "svcVal");
138 Assert.IsNotNull (sd.Services [0].Ports [0].Extensions);
139 Assert.AreEqual (2, sd.Services [0].Ports [0].Extensions.Count);
140 Assert.AreEqual (typeof (SoapAddressBinding), sd.Services [0].Ports [0].Extensions [0].GetType ());
141 CheckXmlElement (sd.Services [0].Ports [0].Extensions [1], "portElem");
143 string out_file = Path.GetTempFileName ();
145 using (FileStream out_fs = new FileStream(out_file, FileMode.Create))
148 if (!String.IsNullOrEmpty (out_file))
149 File.Delete (out_file);
153 void CheckExtensions (DocumentableItem di, string elemName, string val)
155 Assert.IsNotNull (di.Extensions);
157 Assert.AreEqual (1, di.Extensions.Count);
159 Assert.AreEqual (typeof (XmlElement), di.Extensions [0].GetType ());
160 Assert.AreEqual (elemName, ((XmlElement) di.Extensions [0]).Name);
161 Assert.AreEqual (val, ((XmlElement) di.Extensions [0]).InnerText);
164 void CheckXmlElement (object o, string name)
166 Assert.AreEqual (typeof (XmlElement), o.GetType ());
167 Assert.AreEqual (name, ((XmlElement) o).Name);
170 void CheckEA (DocumentableItem di, string att, string val)
172 Assert.IsNotNull (di.ExtensibleAttributes);
174 Assert.AreEqual (1, di.ExtensibleAttributes.Length);
175 Assert.AreEqual (att, di.ExtensibleAttributes [0].Name);
176 Assert.AreEqual (val, di.ExtensibleAttributes [0].Value);
180 public void ReadInvalid ()
182 ServiceDescription sd = ServiceDescription.Read (XmlReader.Create (new StringReader ("<definitions xmlns='http://schemas.xmlsoap.org/wsdl/'><hoge/></definitions>")));
186 public void ValidatingRead ()
188 ServiceDescription sd = ServiceDescription.Read (XmlReader.Create (new StringReader ("<definitions xmlns='http://schemas.xmlsoap.org/wsdl/'><hoge/></definitions>")), true);
189 Assert.IsTrue (sd.ValidationWarnings.Count > 0);
194 class qname_comparer : IComparer
196 public int Compare (object x, object y)
198 XmlQualifiedName a = (XmlQualifiedName) x;
199 XmlQualifiedName b = (XmlQualifiedName) y;
201 return String.Compare (a.Name, b.Name);