Merge pull request #5428 from kumpera/wasm-support-p2
[mono.git] / mcs / class / System.Runtime.Remoting / Test / RemotingServicesTest.cs
1 //\r
2 // System.Runtime.Remoting.RemotingServices NUnit V2.0 test class\r
3 //\r
4 // Author Jean-Marc ANDRE (jean-marc.andre@polymtl.ca)\r
5 //\r
6 // ToDo: I didn't write test functions for the method not yep\r
7 // implemented by Mono\r
8 \r
9 using System;\r
10 using System.Collections;\r
11 using NUnit.Framework;\r
12 using System.Reflection;\r
13 using System.Runtime.Remoting;\r
14 using System.Threading;\r
15 using System.Runtime.Remoting.Activation;\r
16 using System.Runtime.Remoting.Messaging;\r
17 using System.Runtime.Remoting.Proxies;\r
18 using System.Runtime.Remoting.Channels;\r
19 using System.Runtime.Remoting.Channels.Tcp;\r
20 \r
21 using MonoTests.Helpers;\r
22 \r
23 namespace MonoTests.System.Runtime.Remoting.RemotingServicesInternal\r
24 {\r
25         // We need our own proxy to intercept messages to remote object\r
26         // and forward them using RemotingServices.ExecuteMessage\r
27         public class MyProxy : RealProxy\r
28         {\r
29                 MarshalByRefObject target;\r
30                 IMessageSink _sink;\r
31                 MethodBase _mthBase;\r
32                 bool methodOverloaded = false;\r
33 \r
34                 public MethodBase MthBase {\r
35                         get { return _mthBase; }\r
36                 }\r
37 \r
38                 public bool IsMethodOverloaded {\r
39                         get { return methodOverloaded; }\r
40                 }\r
41 \r
42                 public MyProxy (Type serverType, MarshalByRefObject target)\r
43                         : base (serverType)\r
44                 {\r
45                         this.target = target;\r
46 \r
47                         IChannel [] registeredChannels = ChannelServices.RegisteredChannels;\r
48                         string ObjectURI;\r
49 \r
50                         // A new IMessageSink chain has to be created\r
51                         // since the RemotingServices.GetEnvoyChainForProxy() is not yet\r
52                         // implemented.\r
53                         foreach (IChannel channel in registeredChannels) {\r
54                                 IChannelSender channelSender = channel as IChannelSender;\r
55                                 if (channelSender != null) {\r
56                                         _sink = (IMessageSink) channelSender.CreateMessageSink (RemotingServices.GetObjectUri (target), null, out ObjectURI);\r
57                                 }\r
58                         }\r
59 \r
60                 }\r
61 \r
62                 // Messages will be intercepted here and redirected\r
63                 // to another object.\r
64                 public override IMessage Invoke (IMessage msg)\r
65                 {\r
66                         try {\r
67                                 if (msg is IConstructionCallMessage) {\r
68                                         IActivator remActivator = (IActivator) RemotingServices.Connect (typeof (IActivator), "tcp://localhost:1234/RemoteActivationService.rem");\r
69                                         IConstructionReturnMessage crm = remActivator.Activate ((IConstructionCallMessage) msg);\r
70                                         return crm;\r
71                                 } else {\r
72                                         methodOverloaded = RemotingServices.IsMethodOverloaded ((IMethodMessage) msg);\r
73 \r
74                                         _mthBase = RemotingServices.GetMethodBaseFromMethodMessage ((IMethodMessage) msg);\r
75                                         MethodCallMessageWrapper mcm = new MethodCallMessageWrapper ((IMethodCallMessage) msg);\r
76                                         mcm.Uri = RemotingServices.GetObjectUri ((MarshalByRefObject) target);\r
77                                         MarshalByRefObject objRem = (MarshalByRefObject) Activator.CreateInstance (GetProxiedType ());\r
78                                         RemotingServices.ExecuteMessage ((MarshalByRefObject) objRem, (IMethodCallMessage) msg);\r
79                                         IMessage rtnMsg = null;\r
80 \r
81                                         try {\r
82                                                 rtnMsg = _sink.SyncProcessMessage (msg);\r
83                                         } catch (Exception e) {\r
84                                                 Console.WriteLine (e.Message);\r
85                                         }\r
86 \r
87                                         Console.WriteLine ("RR:" + rtnMsg);\r
88                                         return rtnMsg;\r
89                                 }\r
90                         } catch (Exception ex) {\r
91                                 Console.WriteLine (ex);\r
92                                 return null;\r
93                         }\r
94                 }\r
95         } // end MyProxy\r
96 \r
97         // This class is used to create "CAO"\r
98         public class MarshalObjectFactory : MarshalByRefObject\r
99         {\r
100                 public MarshalObject GetNewMarshalObject ()\r
101                 {\r
102                         return new MarshalObject ();\r
103                 }\r
104         }\r
105 \r
106         // A class used by the tests\r
107         public class MarshalObject : ContextBoundObject\r
108         {\r
109                 public MarshalObject ()\r
110                 {\r
111 \r
112                 }\r
113 \r
114                 public MarshalObject (int id, string uri)\r
115                 {\r
116                         this.id = id;\r
117                         this.uri = uri;\r
118                 }\r
119 \r
120                 public int Id {\r
121                         get { return id; }\r
122                         set { id = value; }\r
123                 }\r
124 \r
125                 public string Uri {\r
126                         get { return uri; }\r
127                 }\r
128 \r
129                 public void Method1 ()\r
130                 {\r
131                         _called++;\r
132                         methodOneWay = RemotingServices.IsOneWay (MethodBase.GetCurrentMethod ());\r
133                 }\r
134 \r
135                 public void Method2 ()\r
136                 {\r
137                         methodOneWay = RemotingServices.IsOneWay (MethodBase.GetCurrentMethod ());\r
138                 }\r
139 \r
140                 public void Method2 (int i)\r
141                 {\r
142                         methodOneWay = RemotingServices.IsOneWay (MethodBase.GetCurrentMethod ());\r
143                 }\r
144 \r
145                 [OneWay ()]\r
146                 public void Method3 ()\r
147                 {\r
148                         methodOneWay = RemotingServices.IsOneWay (MethodBase.GetCurrentMethod ());\r
149                 }\r
150 \r
151                 public static int Called {\r
152                         get { return _called; }\r
153                 }\r
154 \r
155                 public static bool IsMethodOneWay {\r
156                         get { return methodOneWay; }\r
157                 }\r
158 \r
159                 private static int _called;\r
160                 private int id = 0;\r
161                 private string uri;\r
162                 private static bool methodOneWay = false;\r
163         }\r
164 \r
165         // Another class used by the tests\r
166         public class DerivedMarshalObject : MarshalObject\r
167         {\r
168                 public DerivedMarshalObject () { }\r
169 \r
170                 public DerivedMarshalObject (int id, string uri) : base (id, uri) { }\r
171         }\r
172 \r
173         interface A\r
174         {\r
175         }\r
176 \r
177         interface B : A\r
178         {\r
179         }\r
180 \r
181         public class CC : MarshalByRefObject\r
182         {\r
183         }\r
184 \r
185         public class DD : MarshalByRefObject\r
186         {\r
187         }\r
188 \r
189 \r
190 } // namespace MonoTests.System.Runtime.Remoting.RemotingServicesInternal\r
191 \r
192 namespace MonoTests.Remoting\r
193 {\r
194         using MonoTests.System.Runtime.Remoting.RemotingServicesInternal;\r
195 \r
196         // The main test class\r
197         [TestFixture]\r
198         public class RemotingServicesTest\r
199         {\r
200                 private static int MarshalObjectId = 0;\r
201 \r
202                 public RemotingServicesTest ()\r
203                 {\r
204                         MarshalObjectId = 0;\r
205                 }\r
206 \r
207                 // Helper function that create a new\r
208                 // MarshalObject with an unique ID\r
209                 private static MarshalObject NewMarshalObject ()\r
210                 {\r
211                         string uri = "MonoTests.System.Runtime.Remoting.RemotingServicesTest.MarshalObject" + MarshalObjectId.ToString ();\r
212                         MarshalObject objMarshal = new MarshalObject (MarshalObjectId, uri);\r
213 \r
214                         MarshalObjectId++;\r
215 \r
216                         return objMarshal;\r
217                 }\r
218 \r
219                 // Another helper function\r
220                 private DerivedMarshalObject NewDerivedMarshalObject ()\r
221                 {\r
222                         string uri = "MonoTests.System.Runtime.Remoting.RemotingServicesTest.DerivedMarshalObject" + MarshalObjectId.ToString ();\r
223                         DerivedMarshalObject objMarshal = new DerivedMarshalObject (MarshalObjectId, uri);\r
224 \r
225                         MarshalObjectId++;\r
226 \r
227                         return objMarshal;\r
228                 }\r
229 \r
230                 // The two folling method test RemotingServices.Marshal()\r
231                 [Test]\r
232                 public void Marshal1 ()\r
233                 {\r
234 \r
235                         MarshalObject objMarshal = NewMarshalObject ();\r
236                         ObjRef objRef = RemotingServices.Marshal (objMarshal);\r
237 \r
238                         Assert.IsNotNull (objRef.URI, "#A01");\r
239 \r
240                         MarshalObject objRem = (MarshalObject) RemotingServices.Unmarshal (objRef);\r
241                         Assert.AreEqual (objMarshal.Id, objRem.Id, "#A02");\r
242 \r
243                         objRem.Id = 2;\r
244                         Assert.AreEqual (objMarshal.Id, objRem.Id, "#A03");\r
245 \r
246                         // TODO: uncomment when RemotingServices.Disconnect is implemented\r
247                         //RemotingServices.Disconnect(objMarshal);\r
248 \r
249                         objMarshal = NewMarshalObject ();\r
250 \r
251                         objRef = RemotingServices.Marshal (objMarshal, objMarshal.Uri);\r
252 \r
253                         Assert.IsTrue (objRef.URI.EndsWith (objMarshal.Uri), "#A04");\r
254                         // TODO: uncomment when RemotingServices.Disconnect is implemented\r
255                         //RemotingServices.Disconnect(objMarshal);\r
256                 }\r
257 \r
258                 [Test]\r
259                 public void Marshal2 ()\r
260                 {\r
261                         DerivedMarshalObject derivedObjMarshal = NewDerivedMarshalObject ();\r
262 \r
263                         ObjRef objRef = RemotingServices.Marshal (derivedObjMarshal, derivedObjMarshal.Uri, typeof (MarshalObject));\r
264 \r
265                         // Check that the type of the marshaled object is MarshalObject\r
266                         Assert.IsTrue (objRef.TypeInfo.TypeName.StartsWith ((typeof (MarshalObject)).ToString ()), "#A05");\r
267 \r
268                         // TODO: uncomment when RemotingServices.Disconnect is implemented\r
269                         //RemotingServices.Disconnect(derivedObjMarshal);\r
270                 }\r
271 \r
272                 // Tests RemotingServices.GetObjectUri()\r
273                 [Test]\r
274                 public void GetObjectUri ()\r
275                 {\r
276                         MarshalObject objMarshal = NewMarshalObject ();\r
277 \r
278                         Assert.IsNull (RemotingServices.GetObjectUri (objMarshal), "#A06");\r
279 \r
280                         RemotingServices.Marshal (objMarshal);\r
281 \r
282                         Assert.IsNotNull (RemotingServices.GetObjectUri (objMarshal), "#A07");\r
283                         // TODO: uncomment when RemotingServices.Disconnect is implemented\r
284                         //RemotingServices.Disconnect(objMarshal);\r
285                 }\r
286 \r
287                 // Tests RemotingServices.Connect\r
288                 [Test]\r
289                 public void Connect ()\r
290                 {\r
291                         var port = NetworkHelpers.FindFreePort ();\r
292                         MarshalObject objMarshal = NewMarshalObject ();\r
293 \r
294                         IDictionary props = new Hashtable ();\r
295                         props ["name"] = objMarshal.Uri;\r
296                         props ["port"] = port;\r
297                         TcpChannel chn = new TcpChannel (props, null, null);\r
298                         ChannelServices.RegisterChannel (chn);\r
299 \r
300                         try {\r
301                                 RemotingServices.Marshal (objMarshal, objMarshal.Uri);\r
302                                 MarshalObject objRem = (MarshalObject) RemotingServices.Connect (typeof (MarshalObject), $"tcp://localhost:{port}/" + objMarshal.Uri);\r
303                                 Assert.IsTrue (RemotingServices.IsTransparentProxy (objRem), "#A08");\r
304                         } finally {\r
305                                 ChannelServices.UnregisterChannel (chn);\r
306                                 RemotingServices.Disconnect (objMarshal);\r
307                         }\r
308                 }\r
309 \r
310                 // Tests RemotingServices.Marshal()\r
311                 [Test]\r
312                 public void MarshalThrowException ()\r
313                 {\r
314                         var port = NetworkHelpers.FindFreePort ();\r
315                         MarshalObject objMarshal = NewMarshalObject ();\r
316 \r
317                         IDictionary props = new Hashtable ();\r
318                         props ["name"] = objMarshal.Uri;\r
319                         props ["port"] = port;\r
320                         TcpChannel chn = new TcpChannel (props, null, null);\r
321                         ChannelServices.RegisterChannel (chn);\r
322 \r
323                         try {\r
324                                 RemotingServices.Marshal (objMarshal, objMarshal.Uri);\r
325                                 MarshalObject objRem = (MarshalObject) RemotingServices.Connect (typeof (MarshalObject), $"tcp://localhost:{port}/" + objMarshal.Uri);\r
326                                 // This line should throw a RemotingException\r
327                                 // It is forbidden to export an object which is not\r
328                                 // a real object\r
329                                 try {\r
330                                         RemotingServices.Marshal (objRem, objMarshal.Uri);\r
331                                         Assert.Fail ("#1");\r
332                                 } catch (RemotingException e) {\r
333                                 }\r
334                         } finally {\r
335                                 ChannelServices.UnregisterChannel (chn);\r
336 \r
337                                 // TODO: uncomment when RemotingServices.Disconnect is implemented\r
338                                 //RemotingServices.Disconnect(objMarshal);\r
339                         }\r
340                 }\r
341 \r
342                 // Tests RemotingServices.ExecuteMessage()\r
343                 // also tests GetMethodBaseFromMessage()\r
344                 // IsMethodOverloaded()\r
345                 [Test]\r
346                 public void ExecuteMessage ()\r
347                 {\r
348                         var port = NetworkHelpers.FindFreePort ();\r
349                         TcpChannel chn = new TcpChannel (port);\r
350                         ChannelServices.RegisterChannel (chn);\r
351                         try {\r
352                                 MarshalObject objMarshal = NewMarshalObject ();\r
353                                 RemotingConfiguration.RegisterWellKnownServiceType (typeof (MarshalObject), objMarshal.Uri, WellKnownObjectMode.SingleCall);\r
354 \r
355                                 // use a proxy to catch the Message\r
356                                 MyProxy proxy = new MyProxy (typeof (MarshalObject), (MarshalObject) Activator.GetObject (typeof (MarshalObject), $"tcp://localhost:{port}/" + objMarshal.Uri));\r
357 \r
358                                 MarshalObject objRem = (MarshalObject) proxy.GetTransparentProxy ();\r
359 \r
360                                 objRem.Method1 ();\r
361 \r
362                                 // Tests RemotingServices.GetMethodBaseFromMethodMessage()\r
363                                 Assert.AreEqual ("Method1", proxy.MthBase.Name, "#A09");\r
364                                 Assert.IsFalse (proxy.IsMethodOverloaded, "#A09.1");\r
365 \r
366                                 objRem.Method2 ();\r
367                                 Assert.IsTrue (proxy.IsMethodOverloaded, "#A09.2");\r
368 \r
369                                 // Tests RemotingServices.ExecuteMessage();\r
370                                 // If ExecuteMessage does it job well, Method1 should be called 2 times\r
371                                 Assert.AreEqual (2, MarshalObject.Called, "#A10");\r
372                         } finally {\r
373                                 ChannelServices.UnregisterChannel (chn);\r
374                         }\r
375                 }\r
376 \r
377                 // Tests the IsOneWay method\r
378                 [Test]\r
379                 public void IsOneWay ()\r
380                 {\r
381                         var port = NetworkHelpers.FindFreePort ();\r
382                         TcpChannel chn = new TcpChannel (port);\r
383                         ChannelServices.RegisterChannel (chn);\r
384                         try {\r
385                                 RemotingConfiguration.RegisterWellKnownServiceType (typeof (MarshalObject), "MarshalObject.rem", WellKnownObjectMode.Singleton);\r
386 \r
387                                 MarshalObject objRem = (MarshalObject) Activator.GetObject (typeof (MarshalObject), $"tcp://localhost:{port}/MarshalObject.rem");\r
388 \r
389                                 Assert.IsTrue (RemotingServices.IsTransparentProxy (objRem), "#A10.1");\r
390 \r
391                                 objRem.Method1 ();\r
392                                 Thread.Sleep (20);\r
393                                 Assert.IsFalse (MarshalObject.IsMethodOneWay, "#A10.2");\r
394                                 objRem.Method3 ();\r
395                                 Thread.Sleep (20);\r
396                                 Assert.IsTrue (MarshalObject.IsMethodOneWay, "#A10.3");\r
397                         } finally {\r
398                                 ChannelServices.UnregisterChannel (chn);\r
399                         }\r
400                 }\r
401 \r
402                 [Test]\r
403                 public void GetObjRefForProxy ()\r
404                 {\r
405                         var port = NetworkHelpers.FindFreePort ();\r
406                         TcpChannel chn = new TcpChannel (port);\r
407                         ChannelServices.RegisterChannel (chn);\r
408                         try {\r
409                                 // Register le factory as a SAO\r
410                                 RemotingConfiguration.RegisterWellKnownServiceType (typeof (MarshalObjectFactory), "MonoTests.System.Runtime.Remoting.RemotingServicesTest.Factory.soap", WellKnownObjectMode.Singleton);\r
411 \r
412                                 MarshalObjectFactory objFactory = (MarshalObjectFactory) Activator.GetObject (typeof (MarshalObjectFactory), $"tcp://localhost:{port}/MonoTests.System.Runtime.Remoting.RemotingServicesTest.Factory.soap");\r
413 \r
414                                 // Get a new "CAO"\r
415                                 MarshalObject objRem = objFactory.GetNewMarshalObject ();\r
416 \r
417                                 ObjRef objRefRem = RemotingServices.GetObjRefForProxy ((MarshalByRefObject) objRem);\r
418 \r
419                                 Assert.IsNotNull (objRefRem, "#A11");\r
420                         } finally {\r
421                                 ChannelServices.UnregisterChannel (chn);\r
422                         }\r
423                 }\r
424 \r
425                 // Tests GetRealProxy\r
426                 [Test]\r
427                 public void GetRealProxy ()\r
428                 {\r
429                         var port = NetworkHelpers.FindFreePort ();\r
430                         TcpChannel chn = new TcpChannel (port);\r
431                         ChannelServices.RegisterChannel (chn);\r
432                         try {\r
433                                 RemotingConfiguration.RegisterWellKnownServiceType (typeof (MarshalObject), "MonoTests.System.Runtime.Remoting.RemotingServicesTest.MarshalObject.soap", WellKnownObjectMode.Singleton);\r
434 \r
435                                 MyProxy proxy = new MyProxy (typeof (MarshalObject), (MarshalByRefObject) Activator.GetObject (typeof (MarshalObject), $"tcp://localhost:{port}/MonoTests.System.Runtime.Remoting.RemotingServicesTest.MarshalObject.soap"));\r
436                                 MarshalObject objRem = (MarshalObject) proxy.GetTransparentProxy ();\r
437 \r
438                                 RealProxy rp = RemotingServices.GetRealProxy (objRem);\r
439 \r
440                                 Assert.IsNotNull (rp, "#A12");\r
441                                 Assert.AreEqual ("MonoTests.System.Runtime.Remoting.RemotingServicesInternal.MyProxy", rp.GetType ().ToString (), "#A13");\r
442                         } finally {\r
443                                 ChannelServices.UnregisterChannel (chn);\r
444                         }\r
445                 }\r
446 \r
447                 // Tests SetObjectUriForMarshal()\r
448                 [Test]\r
449                 public void SetObjectUriForMarshal ()\r
450                 {\r
451                         var port = NetworkHelpers.FindFreePort ();\r
452                         TcpChannel chn = new TcpChannel (port);\r
453                         ChannelServices.RegisterChannel (chn);\r
454                         try {\r
455                                 MarshalObject objRem = NewMarshalObject ();\r
456                                 RemotingServices.SetObjectUriForMarshal (objRem, objRem.Uri);\r
457                                 RemotingServices.Marshal (objRem);\r
458 \r
459                                 objRem = (MarshalObject) Activator.GetObject (typeof (MarshalObject), $"tcp://localhost:{port}/" + objRem.Uri);\r
460                                 Assert.IsNotNull (objRem, "#A14");\r
461                         } finally {\r
462                                 ChannelServices.UnregisterChannel (chn);\r
463                         }\r
464 \r
465                 }\r
466 \r
467                 // Tests GetServeurTypeForUri()\r
468                 [Test]\r
469                 public void GetServeurTypeForUri ()\r
470                 {\r
471                         var port = NetworkHelpers.FindFreePort ();\r
472                         TcpChannel chn = new TcpChannel (port);\r
473                         Type type = typeof (MarshalObject);\r
474                         ChannelServices.RegisterChannel (chn);\r
475                         try {\r
476                                 MarshalObject objRem = NewMarshalObject ();\r
477                                 RemotingServices.SetObjectUriForMarshal (objRem, objRem.Uri);\r
478                                 RemotingServices.Marshal (objRem);\r
479 \r
480                                 Type typeRem = RemotingServices.GetServerTypeForUri (RemotingServices.GetObjectUri (objRem));\r
481                                 Assert.AreEqual (type, typeRem, "#A15");\r
482                         } finally {\r
483                                 ChannelServices.UnregisterChannel (chn);\r
484                         }\r
485                 }\r
486 \r
487                 // Tests IsObjectOutOfDomain\r
488                 // Tests IsObjectOutOfContext\r
489                 [Test]\r
490                 [Category ("NotWorking")]\r
491                 public void IsObjectOutOf ()\r
492                 {\r
493                         var port = NetworkHelpers.FindFreePort ();\r
494                         TcpChannel chn = new TcpChannel (port);\r
495                         ChannelServices.RegisterChannel (chn);\r
496                         try {\r
497                                 RemotingConfiguration.RegisterWellKnownServiceType (typeof (MarshalObject), "MarshalObject2.rem", WellKnownObjectMode.Singleton);\r
498 \r
499                                 MarshalObject objRem = (MarshalObject) Activator.GetObject (typeof (MarshalObject), $"tcp://localhost:{port}/MarshalObject2.rem");\r
500 \r
501                                 Assert.IsTrue (RemotingServices.IsObjectOutOfAppDomain (objRem), "#A16");\r
502                                 Assert.IsTrue (RemotingServices.IsObjectOutOfContext (objRem), "#A17");\r
503 \r
504                                 MarshalObject objMarshal = new MarshalObject ();\r
505                                 Assert.IsFalse (RemotingServices.IsObjectOutOfAppDomain (objMarshal), "#A18");\r
506                                 Assert.IsFalse (RemotingServices.IsObjectOutOfContext (objMarshal), "#A19");\r
507                         } finally {\r
508                                 ChannelServices.UnregisterChannel (chn);\r
509                         }\r
510                 }\r
511 \r
512                 [Test]\r
513                 public void ApplicationNameTest ()\r
514                 {\r
515                         var port = NetworkHelpers.FindFreePort ();\r
516                         RemotingConfiguration.ApplicationName = "app";\r
517                         TcpChannel chn = new TcpChannel (port);\r
518                         ChannelServices.RegisterChannel (chn);\r
519                         try {\r
520                                 RemotingConfiguration.RegisterWellKnownServiceType (typeof (MarshalObject), "obj3.rem", WellKnownObjectMode.Singleton);\r
521 \r
522                                 MarshalObject objRem = (MarshalObject) Activator.GetObject (typeof (MarshalObject), $"tcp://localhost:{port}/app/obj3.rem");\r
523                                 MarshalObject objRem2 = (MarshalObject) Activator.GetObject (typeof (MarshalObject), $"tcp://localhost:{port}/obj3.rem");\r
524 \r
525                                 Assert.IsTrue (RemotingServices.IsTransparentProxy (objRem), "#AN1");\r
526                                 Assert.IsTrue (RemotingServices.IsTransparentProxy (objRem2), "#AN2");\r
527 \r
528                                 Assert.IsNotNull (RemotingServices.GetServerTypeForUri ("obj3.rem"), "#AN3");\r
529                                 Assert.IsNotNull (RemotingServices.GetServerTypeForUri ("/app/obj3.rem"), "#AN4");\r
530                                 Assert.IsNull (RemotingServices.GetServerTypeForUri ("//app/obj3.rem"), "#AN5");\r
531                                 Assert.IsNull (RemotingServices.GetServerTypeForUri ("app/obj3.rem"), "#AN6");\r
532                                 Assert.IsNull (RemotingServices.GetServerTypeForUri ("/whatever/obj3.rem"), "#AN7");\r
533                                 Assert.IsNotNull (RemotingServices.GetServerTypeForUri ("/obj3.rem"), "#AN8");\r
534                                 Assert.IsNull (RemotingServices.GetServerTypeForUri ("//obj3.rem"), "#AN9");\r
535                         } finally {\r
536                                 ChannelServices.UnregisterChannel (chn);\r
537                         }\r
538                 }\r
539 \r
540                 [Test]\r
541                 public void GetObjectWithChannelDataTest ()\r
542                 {\r
543                         var port = NetworkHelpers.FindFreePort ();\r
544                         TcpChannel chn = new TcpChannel (port);\r
545                         ChannelServices.RegisterChannel (chn);\r
546                         try {\r
547                                 RemotingConfiguration.RegisterWellKnownServiceType (typeof (MarshalObject), "getobjectwithchanneldata.rem", WellKnownObjectMode.Singleton);\r
548 \r
549                                 string channelData = "test";\r
550                                 Assert.IsNotNull (Activator.GetObject (typeof (MarshalObject), $"tcp://localhost:{port}/getobjectwithchanneldata.rem", channelData), "#01");\r
551                         } finally {\r
552                                 ChannelServices.UnregisterChannel (chn);\r
553                         }\r
554                 }\r
555 \r
556                 [Test]\r
557                 [Ignore ("We cannot test RemotingConfiguration.Configure() because it keeps channels registered. If we really need to test it, do it as a standalone case")]\r
558                 public void ConnectProxyCast ()\r
559                 {\r
560                         var port = NetworkHelpers.FindFreePort ();\r
561                         object o;\r
562                         RemotingConfiguration.Configure (null);\r
563 \r
564                         o = RemotingServices.Connect (typeof (MarshalByRefObject), $"tcp://localhost:{port}/ff1.rem");\r
565                         Assert.IsInstanceOfType (typeof (DD), o, "#m1");\r
566                         Assert.IsInstanceOfType (typeof (A), o, "#m2");\r
567                         Assert.IsInstanceOfType (typeof (B), o, "#m3");\r
568                         AssertHelper.IsNotInstanceOfType (typeof (CC), !(o is CC), "#m4");\r
569 \r
570                         o = RemotingServices.Connect (typeof (A), $"tcp://localhost:{port}/ff3.rem");\r
571                         Assert.IsInstanceOfType (typeof (DD), o, "#a1");\r
572                         Assert.IsInstanceOfType (typeof (A), o, "#a2");\r
573                         Assert.IsInstanceOfType (typeof (B), o, "#a3");\r
574                         AssertHelper.IsNotInstanceOfType (typeof (CC), o, "#a4");\r
575 \r
576                         o = RemotingServices.Connect (typeof (DD), $"tcp://localhost:{port}/ff4.rem");\r
577                         Assert.IsInstanceOfType (typeof (DD), o, "#d1");\r
578                         Assert.IsInstanceOfType (typeof (A), o, "#d2");\r
579                         Assert.IsInstanceOfType (typeof (B), o, "#d3");\r
580                         AssertHelper.IsNotInstanceOfType (typeof (CC), o, "#d4");\r
581 \r
582                         o = RemotingServices.Connect (typeof (CC), $"tcp://localhost:{port}/ff5.rem");\r
583                         AssertHelper.IsNotInstanceOfType (typeof (DD), o, "#c1");\r
584                         Assert.IsInstanceOfType (typeof (A), o, "#c2");\r
585                         Assert.IsInstanceOfType (typeof (B), o, "#c3");\r
586                         Assert.IsInstanceOfType (typeof (CC), o, "#c4");\r
587                 }\r
588                 // Don't add any tests that must create channels\r
589                 // after ConnectProxyCast (), because this test calls\r
590                 // RemotingConfiguration.Configure ().\r
591         } // end class RemotingServicesTest\r
592 } // end of namespace MonoTests.Remoting\r