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 [Category ("MacNotWorking")] // https://bugzilla.xamarin.com/show_bug.cgi?id=51254
28 public void SimpleWrite ()
30 ServiceDescription sd = new ServiceDescription ();
31 Assert.IsNull (sd.Name);
32 sd.Write (TextWriter.Null);
38 ServiceDescription sd = new ServiceDescription ();
39 Assert.IsNotNull (sd.Bindings);
40 Assert.IsNotNull (sd.Extensions);
41 Assert.IsNotNull (sd.Imports);
42 Assert.IsNotNull (sd.Messages);
43 Assert.IsNotNull (sd.PortTypes);
44 Assert.IsNotNull (sd.Services);
45 Assert.IsNotNull (sd.Types);
47 Assert.IsNull (sd.ServiceDescriptions);
48 Assert.IsNull (sd.TargetNamespace);
52 public void ReadAndRetrievalUrl ()
54 Assert.AreEqual (String.Empty, new ServiceDescription ().RetrievalUrl, "#1");
55 ServiceDescription sd = ServiceDescription.Read ("Test/System.Web.Services.Description/test2.wsdl");
56 Assert.AreEqual (String.Empty, sd.RetrievalUrl, "#2");
60 public void Namespaces ()
62 FileStream fs = new FileStream ("Test/System.Web.Services.Description/test.wsdl", FileMode.Open, FileAccess.Read);
63 XmlTextReader xtr = new XmlTextReader (fs);
65 ServiceDescription sd = ServiceDescription.Read (xtr);
68 Assert.IsNotNull (sd.Namespaces);
69 Assert.AreEqual (8, sd.Namespaces.Count, "#n0");
71 ArrayList list = new ArrayList (sd.Namespaces.ToArray ());
72 list.Sort (new qname_comparer ());
74 Assert.AreEqual (new XmlQualifiedName ("", "http://schemas.xmlsoap.org/wsdl/"), list [0]);
75 Assert.AreEqual (new XmlQualifiedName ("http", "http://schemas.xmlsoap.org/wsdl/http/"), list [1]);
76 Assert.AreEqual (new XmlQualifiedName ("mime", "http://schemas.xmlsoap.org/wsdl/mime/"), list [2]);
77 Assert.AreEqual (new XmlQualifiedName ("s", "http://www.w3.org/2001/XMLSchema"), list [3]);
78 Assert.AreEqual (new XmlQualifiedName ("s0", "http://tempuri.org/"), list [4]);
79 Assert.AreEqual (new XmlQualifiedName ("soap", "http://schemas.xmlsoap.org/wsdl/soap/"), list [5]);
80 Assert.AreEqual (new XmlQualifiedName ("soapenc", "http://schemas.xmlsoap.org/soap/encoding/"), list [6]);
81 Assert.AreEqual (new XmlQualifiedName ("tm", "http://microsoft.com/wsdl/mime/textMatching/"), list [7]);
85 public void ExtensibleAttributes ()
87 FileStream fs = new FileStream ("Test/System.Web.Services.Description/test.wsdl", FileMode.Open, FileAccess.Read);
88 XmlTextReader xtr = new XmlTextReader(fs);
90 ServiceDescription sd = ServiceDescription.Read(xtr);
91 CheckEA (sd, "sdAtt", "sdVal");
92 CheckEA (sd.Messages [0], "msgAtt", "msgVal");
93 CheckEA (sd.Messages [0].Parts [0], "partAtt", "partVal");
95 CheckEA (sd.PortTypes [0], "ptAtt", "ptVal");
96 CheckEA (sd.PortTypes [0].Operations [0], "opAtt", "opVal");
97 CheckEA (sd.PortTypes [0].Operations [0].Messages[0], "opmsgAtt", "opmsgVal");
99 CheckEA (sd.Services [0], "svcAtt", "svcVal");
100 CheckEA (sd.Services [0].Ports [0], "portAtt", "portVal");
106 public void Extensions ()
108 FileStream fs = new FileStream("Test/System.Web.Services.Description/test.wsdl", FileMode.Open, FileAccess.Read);
109 XmlTextReader xtr = new XmlTextReader(fs);
111 ServiceDescription sd = ServiceDescription.Read(xtr);
114 Assert.IsNotNull (sd.Extensions);
115 Assert.AreEqual (1, sd.Extensions.Count);
117 CheckExtensions (sd, "sdElem", "sdVal");
118 CheckExtensions (sd.Messages [0], "msgElem", "msgVal");
119 CheckExtensions (sd.Messages [0].Parts [0], "partElem", "partVal");
121 CheckExtensions (sd.PortTypes [0], "ptElem", "ptVal");
122 CheckExtensions (sd.PortTypes [0].Operations [0], "opElem", "opVal");
125 Assert.IsNotNull (sd.Bindings [0].Extensions);
126 Assert.AreEqual (2, sd.Bindings [0].Extensions.Count);
127 CheckXmlElement (sd.Bindings [0].Extensions [0], "binElem");
128 Assert.AreEqual (typeof (SoapBinding), sd.Bindings [0].Extensions [1].GetType ());
130 //Binding [0].Operations [0]
131 Assert.IsNotNull (sd.Bindings [0].Operations [0].Extensions);
132 Assert.AreEqual (1, sd.Bindings [0].Operations [0].Extensions.Count);
133 Assert.AreEqual (typeof (SoapOperationBinding), sd.Bindings [0].Operations [0].Extensions [0].GetType ());
136 CheckExtensions (sd.Services [0], "svcElem", "svcVal");
139 Assert.IsNotNull (sd.Services [0].Ports [0].Extensions);
140 Assert.AreEqual (2, sd.Services [0].Ports [0].Extensions.Count);
141 Assert.AreEqual (typeof (SoapAddressBinding), sd.Services [0].Ports [0].Extensions [0].GetType ());
142 CheckXmlElement (sd.Services [0].Ports [0].Extensions [1], "portElem");
144 string out_file = Path.GetTempFileName ();
146 using (FileStream out_fs = new FileStream(out_file, FileMode.Create))
149 if (!String.IsNullOrEmpty (out_file))
150 File.Delete (out_file);
154 void CheckExtensions (DocumentableItem di, string elemName, string val)
156 Assert.IsNotNull (di.Extensions);
158 Assert.AreEqual (1, di.Extensions.Count);
160 Assert.AreEqual (typeof (XmlElement), di.Extensions [0].GetType ());
161 Assert.AreEqual (elemName, ((XmlElement) di.Extensions [0]).Name);
162 Assert.AreEqual (val, ((XmlElement) di.Extensions [0]).InnerText);
165 void CheckXmlElement (object o, string name)
167 Assert.AreEqual (typeof (XmlElement), o.GetType ());
168 Assert.AreEqual (name, ((XmlElement) o).Name);
171 void CheckEA (DocumentableItem di, string att, string val)
173 Assert.IsNotNull (di.ExtensibleAttributes);
175 Assert.AreEqual (1, di.ExtensibleAttributes.Length);
176 Assert.AreEqual (att, di.ExtensibleAttributes [0].Name);
177 Assert.AreEqual (val, di.ExtensibleAttributes [0].Value);
181 public void ReadInvalid ()
183 ServiceDescription sd = ServiceDescription.Read (XmlReader.Create (new StringReader ("<definitions xmlns='http://schemas.xmlsoap.org/wsdl/'><hoge/></definitions>")));
187 public void ValidatingRead ()
189 ServiceDescription sd = ServiceDescription.Read (XmlReader.Create (new StringReader ("<definitions xmlns='http://schemas.xmlsoap.org/wsdl/'><hoge/></definitions>")), true);
190 Assert.IsTrue (sd.ValidationWarnings.Count > 0);
195 class qname_comparer : IComparer
197 public int Compare (object x, object y)
199 XmlQualifiedName a = (XmlQualifiedName) x;
200 XmlQualifiedName b = (XmlQualifiedName) y;
202 return String.Compare (a.Name, b.Name);