1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
|
//
// MonoTests.System.Runtime.Remoting.SoapServicesTest.cs
//
// Author: Lluis Sanchez Gual (lluis@ximian.com)
//
// 2003 (C) Copyright, Novell, Inc.
//
using System;
using System.Reflection;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Metadata;
using NUnit.Framework;
namespace MonoTests.System.Runtime.Remoting
{
[SoapTypeAttribute (XmlElementName="ename", XmlNamespace="ens", XmlTypeName="tname", XmlTypeNamespace="tns")]
public class SoapTest
{
[SoapField(XmlElementName="atrib",XmlNamespace="ns1",UseAttribute=true)]
public string atribut;
[SoapField(XmlElementName="elem",XmlNamespace="ns1")]
public int element;
[SoapField(XmlElementName="elem2")]
public int element2;
[SoapMethod (SoapAction="myaction")]
public void FesAlgo ()
{
}
public void FesAlgoMes ()
{
}
public void FesAlgoMesEspecial ()
{
}
}
public class SoapTest1
{
}
[SoapTypeAttribute (XmlElementName="ename", XmlTypeName="tname")]
public class SoapTest2
{
}
[SoapTypeAttribute (XmlNamespace="ens", XmlTypeNamespace="tns")]
public class SoapTest3
{
}
[TestFixture]
public class SoapServicesTest
{
public string ThisNamespace
{
get
{
string tn = "http://schemas.microsoft.com/clr/nsassem/";
tn += GetType ().Namespace + "/" + GetType ().Assembly.GetName().Name;
return tn;
}
}
public string GetClassNs (Type t)
{
string tn = "http://schemas.microsoft.com/clr/nsassem/";
tn += t.FullName + "/" + t.Assembly.GetName().Name;
return tn;
}
public string GetSimpleTypeName (Type t)
{
return t.FullName + ", " + t.Assembly.GetName().Name;
}
[Test]
public void TestGetXmlType ()
{
bool res;
string name, ns;
// XmlType
res = SoapServices.GetXmlElementForInteropType (typeof(SoapTest), out name, out ns);
Assert.IsTrue (res, "E1");
Assert.AreEqual ("ename", name, "E2");
Assert.AreEqual ("ens", ns, "E3");
res = SoapServices.GetXmlElementForInteropType (typeof(SoapTest1), out name, out ns);
Assert.IsTrue (!res, "E4");
res = SoapServices.GetXmlElementForInteropType (typeof(SoapTest2), out name, out ns);
Assert.IsTrue (res, "E5");
Assert.AreEqual ("ename", name, "E6");
Assert.AreEqual (ThisNamespace, ns, "E7");
res = SoapServices.GetXmlElementForInteropType (typeof(SoapTest3), out name, out ns);
Assert.IsTrue (res, "E8");
Assert.AreEqual ("SoapTest3", name, "E9");
Assert.AreEqual ("ens", ns, "E10");
// XmlElement
res = SoapServices.GetXmlTypeForInteropType (typeof(SoapTest), out name, out ns);
Assert.IsTrue (res, "T1");
Assert.AreEqual ("tname", name, "T2");
Assert.AreEqual ("tns", ns, "T3");
res = SoapServices.GetXmlTypeForInteropType (typeof(SoapTest1), out name, out ns);
Assert.IsTrue (!res, "T4");
res = SoapServices.GetXmlTypeForInteropType (typeof(SoapTest2), out name, out ns);
Assert.IsTrue (res, "T5");
Assert.AreEqual ("tname", name, "T6");
Assert.AreEqual (ThisNamespace, ns, "T7");
res = SoapServices.GetXmlTypeForInteropType (typeof(SoapTest3), out name, out ns);
Assert.IsTrue (res, "T8");
Assert.AreEqual ("SoapTest3", name, "T9");
Assert.AreEqual ("tns", ns, "T10");
}
[Test]
public void TestGetInteropType ()
{
Type t;
// Manual registration
t = SoapServices.GetInteropTypeFromXmlElement ("aa","bb");
Assert.AreEqual (t, null, "M1");
SoapServices.RegisterInteropXmlElement ("aa","bb",typeof(SoapTest));
t = SoapServices.GetInteropTypeFromXmlElement ("aa","bb");
Assert.AreEqual (typeof (SoapTest), t, "M2");
t = SoapServices.GetInteropTypeFromXmlType ("aa","bb");
Assert.AreEqual (null, t, "M3");
SoapServices.RegisterInteropXmlType ("aa","bb",typeof(SoapTest));
t = SoapServices.GetInteropTypeFromXmlType ("aa","bb");
Assert.AreEqual (typeof (SoapTest), t, "M4");
// Preload type
SoapServices.PreLoad (typeof(SoapTest2));
t = SoapServices.GetInteropTypeFromXmlElement ("ename",ThisNamespace);
Assert.AreEqual (typeof (SoapTest2), t, "T1");
t = SoapServices.GetInteropTypeFromXmlType ("tname",ThisNamespace);
Assert.AreEqual (typeof (SoapTest2), t, "T2");
// Preload assembly
SoapServices.PreLoad (typeof(SoapTest).Assembly);
t = SoapServices.GetInteropTypeFromXmlElement ("SoapTest3","ens");
Assert.AreEqual (typeof (SoapTest3), t, "A1");
t = SoapServices.GetInteropTypeFromXmlType ("SoapTest3","tns");
Assert.AreEqual (typeof (SoapTest3), t, "A2");
}
[Test]
public void TestSoapFields ()
{
string name;
Type t;
SoapServices.GetInteropFieldTypeAndNameFromXmlAttribute (typeof(SoapTest), "atrib", "ns1", out t, out name);
Assert.AreEqual ("atribut", name, "#1");
Assert.AreEqual (typeof(string), t, "#2");
SoapServices.GetInteropFieldTypeAndNameFromXmlElement (typeof(SoapTest), "elem", "ns1", out t, out name);
Assert.AreEqual ("element", name, "#3");
Assert.AreEqual (typeof(int), t, "#4");
SoapServices.GetInteropFieldTypeAndNameFromXmlElement (typeof(SoapTest), "elem2", null, out t, out name);
Assert.AreEqual ("element2", name, "#5");
Assert.AreEqual (typeof(int), t, "#6");
}
[Test]
[Category("NotWorking")]
public void TestSoapActions ()
{
string act;
MethodBase mb;
mb = typeof(SoapTest).GetMethod ("FesAlgo");
act = SoapServices.GetSoapActionFromMethodBase (mb);
Assert.AreEqual ("myaction", act, "S1");
mb = typeof(SoapTest).GetMethod ("FesAlgoMes");
SoapServices.RegisterSoapActionForMethodBase (mb, "anotheraction");
act = SoapServices.GetSoapActionFromMethodBase (mb);
Assert.AreEqual ("anotheraction", act, "S2");
mb = typeof(SoapTest).GetMethod ("FesAlgoMesEspecial");
act = SoapServices.GetSoapActionFromMethodBase (mb);
Assert.AreEqual (GetClassNs (typeof(SoapTest))+ "#FesAlgoMesEspecial", act, "S3");
string typeName, methodName;
bool res;
res = SoapServices.GetTypeAndMethodNameFromSoapAction ("myaction", out typeName, out methodName);
Assert.IsTrue (res, "M1");
Assert.AreEqual (GetSimpleTypeName (typeof(SoapTest)), typeName, "M2");
Assert.AreEqual ("FesAlgo", methodName, "M3");
res = SoapServices.GetTypeAndMethodNameFromSoapAction ("anotheraction", out typeName, out methodName);
Assert.IsTrue (res, "M4");
Assert.AreEqual (GetSimpleTypeName (typeof(SoapTest)), typeName, "M5");
Assert.AreEqual ("FesAlgoMes", methodName, "M6");
res = SoapServices.GetTypeAndMethodNameFromSoapAction (GetClassNs (typeof(SoapTest))+ "#FesAlgoMesEspecial", out typeName, out methodName);
Assert.IsTrue (res, "M7");
Assert.AreEqual (GetSimpleTypeName (typeof(SoapTest)), typeName, "M8");
Assert.AreEqual ("FesAlgoMesEspecial", methodName, "M9");
}
}
}
|