[runtime] Fix corlib out of date error with disabled COM
[mono.git] / mcs / class / System.Web.Services / Test / System.Web.Services.Description / ServiceDescriptionTest.cs
1 //
2 // ServiceDescriptionTest.cs
3 //
4 // Author:
5 //      Atsushi Enomoto  <atsushi@ximian.com>
6 //      Ankit Jain  <jankit@novell.com>
7 //
8 // Copyright (C) 2005 Novell, Inc.
9 // Copyright (C) 2006 Novell, Inc.
10 //
11
12 using NUnit.Framework;
13
14 using System;
15 using System.IO;
16 using System.Web.Services.Description;
17 using System.Xml;
18 using System.Xml.Serialization;
19 using System.Collections;
20
21 namespace MonoTests.System.Web.Services.Description
22 {
23         [TestFixture]
24         public class ServiceDescriptionTest
25         {
26                 [Test]
27                 public void SimpleWrite ()
28                 {
29                         ServiceDescription sd = new ServiceDescription ();
30                         Assert.IsNull (sd.Name);
31                         sd.Write (TextWriter.Null);
32                 }
33
34                 [Test]
35                 public void Ctor ()
36                 {
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);
45
46                         Assert.IsNull (sd.ServiceDescriptions);
47                         Assert.IsNull (sd.TargetNamespace);
48                 }
49
50                 [Test]
51                 public void ReadAndRetrievalUrl ()
52                 {
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");
56                 }
57
58                 [Test]
59                 public void Namespaces ()
60                 {
61                         FileStream fs = new FileStream ("Test/System.Web.Services.Description/test.wsdl", FileMode.Open, FileAccess.Read);
62                         XmlTextReader xtr = new XmlTextReader (fs);
63
64                         ServiceDescription sd = ServiceDescription.Read (xtr);
65                         fs.Close ();
66
67                         Assert.IsNotNull (sd.Namespaces);
68                         Assert.AreEqual (8, sd.Namespaces.Count, "#n0");
69
70                         ArrayList list = new ArrayList (sd.Namespaces.ToArray ());
71                         list.Sort (new qname_comparer ());
72
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]);
81                 }
82
83                 [Test]
84                 public void ExtensibleAttributes ()
85                 {
86                     FileStream fs = new FileStream ("Test/System.Web.Services.Description/test.wsdl", FileMode.Open, FileAccess.Read);
87                     XmlTextReader xtr = new XmlTextReader(fs);
88
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");
93
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");
97
98                     CheckEA (sd.Services [0], "svcAtt", "svcVal");
99                     CheckEA (sd.Services [0].Ports [0], "portAtt", "portVal");
100
101                     fs.Close ();
102                 }
103
104                 [Test]
105                 public void Extensions ()
106                 {
107                         FileStream fs = new FileStream("Test/System.Web.Services.Description/test.wsdl", FileMode.Open, FileAccess.Read);
108                     XmlTextReader xtr = new XmlTextReader(fs);
109
110                     ServiceDescription sd = ServiceDescription.Read(xtr);
111                     fs.Close ();
112
113                     Assert.IsNotNull (sd.Extensions);
114                     Assert.AreEqual (1, sd.Extensions.Count);
115
116                     CheckExtensions (sd, "sdElem", "sdVal");
117                     CheckExtensions (sd.Messages [0], "msgElem", "msgVal");
118                     CheckExtensions (sd.Messages [0].Parts [0], "partElem", "partVal");
119
120                     CheckExtensions (sd.PortTypes [0], "ptElem", "ptVal");
121                     CheckExtensions (sd.PortTypes [0].Operations [0], "opElem", "opVal");
122
123                     //Binding [0]
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 ());
128                 
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 ());
133
134                     //Service
135                     CheckExtensions (sd.Services [0], "svcElem", "svcVal");
136
137                     //Service.Port
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");
142
143                     string out_file = Path.GetTempFileName ();
144                     try {
145                             using (FileStream out_fs = new FileStream(out_file, FileMode.Create))
146                                     sd.Write (out_fs);
147                     } finally {
148                             if (!String.IsNullOrEmpty (out_file))
149                                     File.Delete (out_file);
150                     }
151                 }
152
153                 void CheckExtensions (DocumentableItem di, string elemName, string val)
154                 {
155                         Assert.IsNotNull (di.Extensions);
156
157                         Assert.AreEqual (1, di.Extensions.Count);
158
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);
162                 }
163
164                 void CheckXmlElement (object o, string name)
165                 {
166                         Assert.AreEqual (typeof (XmlElement), o.GetType ());
167                         Assert.AreEqual (name, ((XmlElement) o).Name);
168                 }
169
170                 void CheckEA (DocumentableItem di, string att, string val)
171                 {
172                         Assert.IsNotNull (di.ExtensibleAttributes);
173                         
174                         Assert.AreEqual (1, di.ExtensibleAttributes.Length);
175                         Assert.AreEqual (att, di.ExtensibleAttributes [0].Name);
176                         Assert.AreEqual (val, di.ExtensibleAttributes [0].Value);
177                 }
178
179                 [Test]
180                 public void ReadInvalid ()
181                 {
182                         ServiceDescription sd = ServiceDescription.Read (XmlReader.Create (new StringReader ("<definitions xmlns='http://schemas.xmlsoap.org/wsdl/'><hoge/></definitions>")));
183                 }
184
185                 [Test]
186                 public void ValidatingRead ()
187                 {
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);
190                 }
191
192     }
193
194         class qname_comparer : IComparer
195         {
196                 public int Compare (object x, object y)
197                 {
198                         XmlQualifiedName a = (XmlQualifiedName) x;
199                         XmlQualifiedName b = (XmlQualifiedName) y;
200
201                         return String.Compare (a.Name, b.Name);
202                 }
203         }
204 }
205