1 // 2 // ServiceDescriptionImporterTest.cs 3 // 4 // Author: 5 // Atsushi Enomoto <atsushi@ximian.com> 6 // 7 // Copyright (C) 2007 Novell, Inc. 8 // 9 10 #if !MOBILE && !MONOMAC 11 12 using NUnit.Framework; 13 14 using System; 15 using System.CodeDom; 16 using System.CodeDom.Compiler; 17 using Microsoft.CSharp; 18 using System.Web.Services.Description; 19 20 namespace MonoTests.System.Web.Services.Description 21 { 22 [TestFixture] 23 public class ServiceDescriptionImporterTest 24 { GenerateCodeFromWsdl(ServiceDescription sd)25 CodeNamespace GenerateCodeFromWsdl (ServiceDescription sd) 26 { 27 ServiceDescriptionImporter imp = 28 new ServiceDescriptionImporter (); 29 imp.AddServiceDescription (sd, null, null); 30 CodeNamespace cns = new CodeNamespace (); 31 imp.Import (cns, null); 32 return cns; 33 } 34 FindTypeFrom(CodeNamespace cns, string name)35 CodeTypeDeclaration FindTypeFrom (CodeNamespace cns, string name) 36 { 37 foreach (CodeTypeDeclaration td in cns.Types) 38 if (td.Name == name) 39 return td; 40 return null; 41 } 42 FindMemberFrom(CodeNamespace cns, string name)43 CodeTypeDeclaration FindMemberFrom (CodeNamespace cns, string name) 44 { 45 foreach (CodeTypeDeclaration td in cns.Types) 46 if (td.Name == name) 47 return td; 48 return null; 49 } 50 51 [Test] Constructor()52 public void Constructor () 53 { 54 ServiceDescriptionImporter imp = 55 new ServiceDescriptionImporter (); 56 Assert.IsTrue (imp.CodeGenerator is CSharpCodeProvider); 57 } 58 59 [Test] // wtf? no ArgumentNullException? SetNullCodeGenerator()60 public void SetNullCodeGenerator () 61 { 62 ServiceDescriptionImporter imp = 63 new ServiceDescriptionImporter (); 64 imp.CodeGenerator = null; 65 } 66 67 [Test] GenerateNullableTypes()68 public void GenerateNullableTypes () 69 { 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") 76 continue; 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"); 80 return; 81 } 82 Assert.Fail ("The expected member didn't appear."); 83 } 84 85 [Test] GenerateWebReferencesEmpty()86 public void GenerateWebReferencesEmpty () 87 { 88 // yuck - This causes NRE. 89 //ServiceDescriptionImporter.GenerateWebReferences ( 90 // new WebReferenceCollection (), null, null, null); 91 ServiceDescriptionImporter.GenerateWebReferences ( 92 new WebReferenceCollection (), 93 null, 94 new CodeCompileUnit (), 95 new WebReferenceOptions ()); 96 } 97 98 [Test] 99 [Ignore ("This test requires HttpGet available by configuration.")] ImportHttpOnlyWsdl()100 public void ImportHttpOnlyWsdl () 101 { 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") 116 continue; 117 Assert.AreEqual ("System.Web.Services.Protocols.HttpGetClientProtocol", cd.BaseTypes [0].BaseType); 118 verified = true; 119 } 120 Assert.IsTrue (verified, "verified"); 121 } 122 } 123 } 124 125 #endif 126