New test.
[mono.git] / mcs / class / System.Web.Services / Test / System.Web.Services.Description / ServiceDescriptionReflectorTest.cs
1 //
2 // ServiceDescriptionReflectorTest.cs
3 //
4 // Author:
5 //      Gert Driesen  <drieseng@users.sourceforge.net>
6 //
7 // Copyright (C) 2006 Novell, Inc.
8 //
9
10 using NUnit.Framework;
11
12 using System;
13 using System.Globalization;
14 using System.IO;
15 using System.Web.Services;
16 using System.Web.Services.Description;
17 using System.Xml.Serialization;
18
19 namespace MonoTests.System.Web.Services.Description
20 {
21         [TestFixture]
22         public class ServiceDescriptionReflectorTest
23         {
24                 [Test]
25                 [Category ("NotWorking")]
26                 public void IncludeTest ()
27                 {
28                         ServiceDescriptionReflector reflector = new ServiceDescriptionReflector ();
29                         reflector.Reflect (typeof (IncludeTestServices), "http://localhost/IncludeTestServices.asmx");
30
31                         Assert.AreEqual (0, reflector.Schemas.Count, "#1");
32                         Assert.AreEqual (1, reflector.ServiceDescriptions.Count, "#2");
33
34                         ServiceDescription sd = reflector.ServiceDescriptions[0];
35
36                         Assert.IsNull (sd.Name, "#3");
37                         Assert.AreEqual (1, sd.Types.Schemas.Count, "#4");
38
39                         StringWriter sw = new StringWriter ();
40                         sd.Write (sw);
41
42                         Assert.AreEqual (string.Format(CultureInfo.InvariantCulture,
43                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
44 #if NET_2_0
45                                 "<wsdl:definitions xmlns:soap=\"http://schemas.xmlsoap.org/wsdl/soap/\" xmlns:tm=\"http://microsoft.com/wsdl/mime/textMatching/\""  +
46                                 " xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:mime=\"http://schemas.xmlsoap.org/wsdl/mime/\"" +
47                                 " xmlns:tns=\"http://tempuri.org/\" xmlns:s=\"http://www.w3.org/2001/XMLSchema\"" +
48                                 " xmlns:soap12=\"http://schemas.xmlsoap.org/wsdl/soap12/\"" +
49                                 " xmlns:http=\"http://schemas.xmlsoap.org/wsdl/http/\" targetNamespace=\"http://tempuri.org/\"" +
50                                 " xmlns:wsdl=\"http://schemas.xmlsoap.org/wsdl/\">{0}" +
51 #else
52                                 "<wsdl:definitions xmlns:http=\"http://schemas.xmlsoap.org/wsdl/http/\" xmlns:soap=\"http://schemas.xmlsoap.org/wsdl/soap/\"" +
53                                 " xmlns:s=\"http://www.w3.org/2001/XMLSchema\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\"" +
54                                 " xmlns:tns=\"http://tempuri.org/\" xmlns:tm=\"http://microsoft.com/wsdl/mime/textMatching/\"" +
55                                 " xmlns:mime=\"http://schemas.xmlsoap.org/wsdl/mime/\" targetNamespace=\"http://tempuri.org/\"" +
56                                 " xmlns:wsdl=\"http://schemas.xmlsoap.org/wsdl/\">{0}" +
57 #endif
58                                 "  <wsdl:types>{0}" +
59                                 "    <s:schema elementFormDefault=\"qualified\" targetNamespace=\"http://tempuri.org/\">{0}" +
60                                 "      <s:element name=\"EchoString\">{0}" +
61                                 "        <s:complexType>{0}" +
62                                 "          <s:sequence>{0}" +
63                                 "            <s:element minOccurs=\"0\" maxOccurs=\"1\" name=\"strval\" type=\"s:string\" />{0}" +
64                                 "          </s:sequence>{0}" +
65                                 "        </s:complexType>{0}" +
66                                 "      </s:element>{0}" +
67                                 "      <s:element name=\"EchoStringResponse\">{0}" +
68                                 "        <s:complexType>{0}" +
69                                 "          <s:sequence>{0}" +
70                                 "            <s:element minOccurs=\"1\" maxOccurs=\"1\" name=\"MyTime\" type=\"s:time\" />{0}" +
71                                 "          </s:sequence>{0}" +
72                                 "        </s:complexType>{0}" +
73                                 "      </s:element>{0}" +
74                                 "      <s:element name=\"Vehicle\">{0}" +
75                                 "        <s:complexType>{0}" +
76                                 "          <s:sequence>{0}" +
77                                 "            <s:element minOccurs=\"0\" maxOccurs=\"1\" name=\"licenseNumber\" type=\"s:string\" />{0}" +
78                                 "          </s:sequence>{0}" +
79                                 "        </s:complexType>{0}" +
80                                 "      </s:element>{0}" +
81                                 "      <s:element name=\"VehicleResponse\">{0}" +
82                                 "        <s:complexType>{0}" +
83                                 "          <s:sequence>{0}" +
84                                 "            <s:element minOccurs=\"1\" maxOccurs=\"1\" name=\"NewVehicle\" nillable=\"true\" type=\"tns:Vehicle\" />{0}" +
85                                 "          </s:sequence>{0}" +
86                                 "        </s:complexType>{0}" +
87                                 "      </s:element>{0}" +
88                                 "      <s:complexType name=\"Vehicle\" abstract=\"true\">{0}" +
89                                 "        <s:sequence>{0}" +
90                                 "          <s:element minOccurs=\"0\" maxOccurs=\"1\" name=\"licenseNumber\" type=\"s:string\" />{0}" +
91                                 "          <s:element minOccurs=\"1\" maxOccurs=\"1\" name=\"make\" type=\"s:dateTime\" />{0}" +
92                                 "          <s:element minOccurs=\"1\" maxOccurs=\"1\" name=\"age\" type=\"tns:TimeSpan\" />{0}" +
93                                 "        </s:sequence>{0}" +
94                                 "      </s:complexType>{0}" +
95                                 "      <s:complexType name=\"TimeSpan\" />{0}" +
96                                 "      <s:complexType name=\"Car\">{0}" +
97                                 "        <s:complexContent mixed=\"false\">{0}" +
98                                 "          <s:extension base=\"tns:Vehicle\" />{0}" +
99                                 "        </s:complexContent>{0}" +
100                                 "      </s:complexType>{0}" +
101                                 "    </s:schema>{0}" +
102                                 "  </wsdl:types>{0}" +
103                                 "  <wsdl:message name=\"EchoStringSoapIn\">{0}" +
104                                 "    <wsdl:part name=\"parameters\" element=\"tns:EchoString\" />{0}" +
105                                 "  </wsdl:message>{0}" +
106                                 "  <wsdl:message name=\"EchoStringSoapOut\">{0}" +
107                                 "    <wsdl:part name=\"parameters\" element=\"tns:EchoStringResponse\" />{0}" +
108                                 "  </wsdl:message>{0}" +
109                                 "  <wsdl:message name=\"VehicleSoapIn\">{0}" +
110                                 "    <wsdl:part name=\"parameters\" element=\"tns:Vehicle\" />{0}" +
111                                 "  </wsdl:message>{0}" +
112                                 "  <wsdl:message name=\"VehicleSoapOut\">{0}" +
113                                 "    <wsdl:part name=\"parameters\" element=\"tns:VehicleResponse\" />{0}" +
114                                 "  </wsdl:message>{0}" +
115                                 "  <wsdl:portType name=\"IncludeTestServicesSoap\">{0}" +
116                                 "    <wsdl:operation name=\"EchoString\">{0}" +
117                                 "      <wsdl:input message=\"tns:EchoStringSoapIn\" />{0}" +
118                                 "      <wsdl:output message=\"tns:EchoStringSoapOut\" />{0}" +
119                                 "    </wsdl:operation>{0}" +
120                                 "    <wsdl:operation name=\"Vehicle\">{0}" +
121                                 "      <wsdl:input message=\"tns:VehicleSoapIn\" />{0}" +
122                                 "      <wsdl:output message=\"tns:VehicleSoapOut\" />{0}" +
123                                 "    </wsdl:operation>{0}" +
124                                 "  </wsdl:portType>{0}" +
125                                 "  <wsdl:binding name=\"IncludeTestServicesSoap\" type=\"tns:IncludeTestServicesSoap\">{0}" +
126 #if NET_2_0
127                                 "    <soap:binding transport=\"http://schemas.xmlsoap.org/soap/http\" />{0}" +
128 #else
129                                 "    <soap:binding transport=\"http://schemas.xmlsoap.org/soap/http\" style=\"document\" />{0}" +
130 #endif
131                                 "    <wsdl:operation name=\"EchoString\">{0}" +
132                                 "      <soap:operation soapAction=\"http://tempuri.org/EchoString\" style=\"document\" />{0}" +
133                                 "      <wsdl:input>{0}" +
134                                 "        <soap:body use=\"literal\" />{0}" +
135                                 "      </wsdl:input>{0}" +
136                                 "      <wsdl:output>{0}" +
137                                 "        <soap:body use=\"literal\" />{0}" +
138                                 "      </wsdl:output>{0}" +
139                                 "    </wsdl:operation>{0}" +
140                                 "    <wsdl:operation name=\"Vehicle\">{0}" +
141                                 "      <soap:operation soapAction=\"http://tempuri.org/Vehicle\" style=\"document\" />{0}" +
142                                 "      <wsdl:input>{0}" +
143                                 "        <soap:body use=\"literal\" />{0}" +
144                                 "      </wsdl:input>{0}" +
145                                 "      <wsdl:output>{0}" +
146                                 "        <soap:body use=\"literal\" />{0}" +
147                                 "      </wsdl:output>{0}" +
148                                 "    </wsdl:operation>{0}" +
149                                 "  </wsdl:binding>{0}" +
150 #if NET_2_0
151                                 "  <wsdl:binding name=\"IncludeTestServicesSoap12\" type=\"tns:IncludeTestServicesSoap\">{0}" +
152                                 "    <soap12:binding transport=\"http://schemas.xmlsoap.org/soap/http\" />{0}" +
153                                 "    <wsdl:operation name=\"EchoString\">{0}" +
154                                 "      <soap12:operation soapAction=\"http://tempuri.org/EchoString\" style=\"document\" />{0}" +
155                                 "      <wsdl:input>{0}" +
156                                 "        <soap12:body use=\"literal\" />{0}" +
157                                 "      </wsdl:input>{0}" +
158                                 "      <wsdl:output>{0}" +
159                                 "        <soap12:body use=\"literal\" />{0}" +
160                                 "      </wsdl:output>{0}" +
161                                 "    </wsdl:operation>{0}" +
162                                 "    <wsdl:operation name=\"Vehicle\">{0}" +
163                                 "      <soap12:operation soapAction=\"http://tempuri.org/Vehicle\" style=\"document\" />{0}" +
164                                 "      <wsdl:input>{0}" +
165                                 "        <soap12:body use=\"literal\" />{0}" +
166                                 "      </wsdl:input>{0}" +
167                                 "      <wsdl:output>{0}" +
168                                 "        <soap12:body use=\"literal\" />{0}" +
169                                 "      </wsdl:output>{0}" +
170                                 "    </wsdl:operation>{0}" +
171                                 "  </wsdl:binding>{0}" +
172 #endif
173                                 "  <wsdl:service name=\"IncludeTestServices\">{0}" +
174 #if ONLY_1_1
175                                 "    <documentation xmlns=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
176 #endif
177                                 "    <wsdl:port name=\"IncludeTestServicesSoap\" binding=\"tns:IncludeTestServicesSoap\">{0}" +
178                                 "      <soap:address location=\"http://localhost/IncludeTestServices.asmx\" />{0}" +
179                                 "    </wsdl:port>{0}" +
180 #if NET_2_0
181                                 "    <wsdl:port name=\"IncludeTestServicesSoap12\" binding=\"tns:IncludeTestServicesSoap12\">{0}" +
182                                 "      <soap12:address location=\"http://localhost/IncludeTestServices.asmx\" />{0}" +
183                                 "    </wsdl:port>{0}" +
184 #endif
185                                 "  </wsdl:service>{0}" +
186                                 "</wsdl:definitions>", Environment.NewLine), sw.ToString (), "#5");
187                 }
188
189                 public class IncludeTestServices : WebService
190                 {
191                         [WebMethod ()]
192                         [return: XmlElement ("MyTime", DataType = "time")]
193                         public DateTime EchoString ([XmlElement (DataType = "string")] string strval)
194                         {
195                                 return DateTime.Now;
196                         }
197
198                         [WebMethod ()]
199                         [XmlInclude (typeof (Car))]
200                         public Vehicle Vehicle (string licenseNumber)
201                         {
202                                 if (licenseNumber == "0") {
203                                         Vehicle v = new Car ();
204                                         v.licenseNumber = licenseNumber;
205                                         return v;
206                                 } else {
207                                         return null;
208                                 }
209                         }
210                 }
211                 [XmlRoot ("NewVehicle")]
212                 public abstract class Vehicle
213                 {
214                         public string licenseNumber;
215                         public DateTime make;
216                         public TimeSpan age;
217                 }
218
219                 public class Car : Vehicle
220                 {
221                 }
222         }
223 }