2 // ServiceDescriptionImporterTest.cs
5 // Atsushi Enomoto <atsushi@ximian.com>
7 // Copyright (C) 2007 Novell, Inc.
10 #if !MOBILE && !MONOMAC
12 using NUnit.Framework;
16 using System.CodeDom.Compiler;
17 using Microsoft.CSharp;
18 using System.Web.Services.Description;
20 namespace MonoTests.System.Web.Services.Description
23 public class ServiceDescriptionImporterTest
25 CodeNamespace GenerateCodeFromWsdl (ServiceDescription sd)
27 ServiceDescriptionImporter imp =
28 new ServiceDescriptionImporter ();
29 imp.AddServiceDescription (sd, null, null);
30 CodeNamespace cns = new CodeNamespace ();
31 imp.Import (cns, null);
35 CodeTypeDeclaration FindTypeFrom (CodeNamespace cns, string name)
37 foreach (CodeTypeDeclaration td in cns.Types)
43 CodeTypeDeclaration FindMemberFrom (CodeNamespace cns, string name)
45 foreach (CodeTypeDeclaration td in cns.Types)
52 public void Constructor ()
54 ServiceDescriptionImporter imp =
55 new ServiceDescriptionImporter ();
56 Assert.IsTrue (imp.CodeGenerator is CSharpCodeProvider);
59 [Test] // wtf? no ArgumentNullException?
60 public void SetNullCodeGenerator ()
62 ServiceDescriptionImporter imp =
63 new ServiceDescriptionImporter ();
64 imp.CodeGenerator = null;
68 public void GenerateNullableTypes ()
70 CodeNamespace cns = GenerateCodeFromWsdl (
71 ServiceDescription.Read ("Test/System.Web.Services.Description/test2.wsdl"));
72 CodeTypeDeclaration td = FindTypeFrom (cns, "Service");
73 foreach (CodeTypeMember member in td.Members) {
74 CodeMemberMethod method = member as CodeMemberMethod;
75 if (method == null || method.Name != "Hola")
77 Assert.AreEqual ("System.Nullable`1", method.ReturnType.BaseType, "#1");
78 Assert.AreEqual (1, method.ReturnType.TypeArguments.Count, "#2");
79 Assert.AreEqual ("System.Int32", method.ReturnType.TypeArguments [0].BaseType, "#3");
82 Assert.Fail ("The expected member didn't appear.");
86 public void GenerateWebReferencesEmpty ()
88 // yuck - This causes NRE.
89 //ServiceDescriptionImporter.GenerateWebReferences (
90 // new WebReferenceCollection (), null, null, null);
91 ServiceDescriptionImporter.GenerateWebReferences (
92 new WebReferenceCollection (),
94 new CodeCompileUnit (),
95 new WebReferenceOptions ());
99 [Ignore ("This test requires HttpGet available by configuration.")]
100 public void ImportHttpOnlyWsdl ()
102 ServiceDescriptionImporter imp =
103 new ServiceDescriptionImporter ();
104 imp.AddServiceDescription (ServiceDescription.Read ("Test/System.Web.Services.Description/test3.wsdl"), null, null);
105 CodeNamespace cns = new CodeNamespace ();
106 CodeCompileUnit ccu = new CodeCompileUnit ();
107 ccu.Namespaces.Add (cns);
108 imp.Import (cns, ccu);
109 // FIXME: this test could require more precise result
110 bool verified = false;
111 Assert.AreEqual (1, ccu.Namespaces.Count, "#1");
112 Assert.AreEqual (1, ccu.Namespaces [0].Types.Count, "#2");
113 foreach (CodeTypeDeclaration cd in ccu.Namespaces [0].Types) {
114 Console.WriteLine ("***" + cd.Name);
115 if (cd.Name != "MyService")
117 Assert.AreEqual ("System.Web.Services.Protocols.HttpGetClientProtocol", cd.BaseTypes [0].BaseType);
120 Assert.IsTrue (verified, "verified");