Merge pull request #3913 from omwok/master
[mono.git] / mcs / class / System.Runtime.Remoting / Test / RemotingServicesTest.cs
index 38b0a61c74fd927e90cb97af5fbedd8a129a5802..02c6a532c00ce24d94a757b312892a2df1920c86 100644 (file)
@@ -22,566 +22,557 @@ namespace MonoTests.System.Runtime.Remoting.RemotingServicesInternal
 {\r
        // We need our own proxy to intercept messages to remote object\r
        // and forward them using RemotingServices.ExecuteMessage\r
-       public class MyProxy: RealProxy\r
+       public class MyProxy : RealProxy\r
        {\r
                MarshalByRefObject target;\r
                IMessageSink _sink;\r
                MethodBase _mthBase;\r
                bool methodOverloaded = false;\r
-               \r
-               public MethodBase MthBase\r
-               {\r
-                       get{ return _mthBase;}\r
+\r
+               public MethodBase MthBase {\r
+                       get { return _mthBase; }\r
                }\r
-               \r
-               public bool IsMethodOverloaded\r
-               {\r
-                       get{return methodOverloaded;}\r
+\r
+               public bool IsMethodOverloaded {\r
+                       get { return methodOverloaded; }\r
                }\r
-               \r
-               public MyProxy(Type serverType, MarshalByRefObject target): base(serverType)\r
+\r
+               public MyProxy (Type serverType, MarshalByRefObject target)\r
+                       : base (serverType)\r
                {\r
                        this.target = target;\r
-                       \r
-                       IChannel[] registeredChannels = ChannelServices.RegisteredChannels;\r
+\r
+                       IChannel [] registeredChannels = ChannelServices.RegisteredChannels;\r
                        string ObjectURI;\r
-                       \r
+\r
                        // A new IMessageSink chain has to be created\r
                        // since the RemotingServices.GetEnvoyChainForProxy() is not yet\r
                        // implemented.\r
-                       foreach(IChannel channel in registeredChannels)\r
-                       {\r
+                       foreach (IChannel channel in registeredChannels) {\r
                                IChannelSender channelSender = channel as IChannelSender;\r
-                               if(channelSender != null)\r
-                               {\r
-                                       _sink = (IMessageSink) channelSender.CreateMessageSink(RemotingServices.GetObjectUri(target), null, out ObjectURI);\r
+                               if (channelSender != null) {\r
+                                       _sink = (IMessageSink) channelSender.CreateMessageSink (RemotingServices.GetObjectUri (target), null, out ObjectURI);\r
                                }\r
                        }\r
-                       \r
+\r
                }\r
-               \r
+\r
                // Messages will be intercepted here and redirected\r
                // to another object.\r
-               public override IMessage Invoke(IMessage msg)\r
+               public override IMessage Invoke (IMessage msg)\r
                {\r
-                       try\r
-                       {\r
-                               if(msg is IConstructionCallMessage)\r
-                               {\r
-                                       IActivator remActivator = (IActivator) RemotingServices.Connect(typeof(IActivator), "tcp://localhost:1234/RemoteActivationService.rem");\r
-                                       IConstructionReturnMessage crm = remActivator.Activate((IConstructionCallMessage)msg);\r
+                       try {\r
+                               if (msg is IConstructionCallMessage) {\r
+                                       IActivator remActivator = (IActivator) RemotingServices.Connect (typeof (IActivator), "tcp://localhost:1234/RemoteActivationService.rem");\r
+                                       IConstructionReturnMessage crm = remActivator.Activate ((IConstructionCallMessage) msg);\r
                                        return crm;\r
-                               }\r
-                               else\r
-                               {\r
-                                       methodOverloaded = RemotingServices.IsMethodOverloaded((IMethodMessage)msg);\r
-                                       \r
-                                       _mthBase = RemotingServices.GetMethodBaseFromMethodMessage((IMethodMessage)msg);\r
-                                       MethodCallMessageWrapper mcm = new MethodCallMessageWrapper((IMethodCallMessage) msg);\r
-                                       mcm.Uri = RemotingServices.GetObjectUri((MarshalByRefObject)target);\r
-                                       MarshalByRefObject objRem = (MarshalByRefObject)Activator.CreateInstance(GetProxiedType());\r
-                                       RemotingServices.ExecuteMessage((MarshalByRefObject)objRem, (IMethodCallMessage)msg);\r
+                               } else {\r
+                                       methodOverloaded = RemotingServices.IsMethodOverloaded ((IMethodMessage) msg);\r
+\r
+                                       _mthBase = RemotingServices.GetMethodBaseFromMethodMessage ((IMethodMessage) msg);\r
+                                       MethodCallMessageWrapper mcm = new MethodCallMessageWrapper ((IMethodCallMessage) msg);\r
+                                       mcm.Uri = RemotingServices.GetObjectUri ((MarshalByRefObject) target);\r
+                                       MarshalByRefObject objRem = (MarshalByRefObject) Activator.CreateInstance (GetProxiedType ());\r
+                                       RemotingServices.ExecuteMessage ((MarshalByRefObject) objRem, (IMethodCallMessage) msg);\r
                                        IMessage rtnMsg = null;\r
-                                       \r
-                                       try\r
-                                       {\r
-                                               rtnMsg = _sink.SyncProcessMessage(msg);\r
-                                       }\r
-                                       catch(Exception e)\r
-                                       {\r
-                                               Console.WriteLine(e.Message);\r
+\r
+                                       try {\r
+                                               rtnMsg = _sink.SyncProcessMessage (msg);\r
+                                       } catch (Exception e) {\r
+                                               Console.WriteLine (e.Message);\r
                                        }\r
-                                       \r
+\r
                                        Console.WriteLine ("RR:" + rtnMsg);\r
                                        return rtnMsg;\r
                                }\r
-                       }\r
-                       catch (Exception ex)\r
-                       {\r
+                       } catch (Exception ex) {\r
                                Console.WriteLine (ex);\r
                                return null;\r
                        }\r
                }\r
        } // end MyProxy\r
-       \r
+\r
        // This class is used to create "CAO"\r
-       public class MarshalObjectFactory: MarshalByRefObject\r
+       public class MarshalObjectFactory : MarshalByRefObject\r
        {\r
-               public MarshalObject GetNewMarshalObject()\r
+               public MarshalObject GetNewMarshalObject ()\r
                {\r
-                       return new MarshalObject();\r
+                       return new MarshalObject ();\r
                }\r
        }\r
-       \r
+\r
        // A class used by the tests\r
-       public class MarshalObject: ContextBoundObject\r
+       public class MarshalObject : ContextBoundObject\r
        {\r
-               public MarshalObject()\r
+               public MarshalObject ()\r
                {\r
-                       \r
+\r
                }\r
-               \r
-               public MarshalObject(int id, string uri)\r
+\r
+               public MarshalObject (int id, string uri)\r
                {\r
                        this.id = id;\r
                        this.uri = uri;\r
                }\r
-               public int Id\r
-               {\r
-                       get{return id;}\r
-                       set{id = value;}\r
+\r
+               public int Id {\r
+                       get { return id; }\r
+                       set { id = value; }\r
                }\r
-               public string Uri\r
-               {\r
-                       get{return uri;}\r
+\r
+               public string Uri {\r
+                       get { return uri; }\r
                }\r
-               \r
-               public void Method1()\r
+\r
+               public void Method1 ()\r
                {\r
                        _called++;\r
-                       methodOneWay = RemotingServices.IsOneWay(MethodBase.GetCurrentMethod());                        \r
+                       methodOneWay = RemotingServices.IsOneWay (MethodBase.GetCurrentMethod ());\r
                }\r
-               \r
-               public void Method2()\r
+\r
+               public void Method2 ()\r
                {\r
-                       methodOneWay = RemotingServices.IsOneWay(MethodBase.GetCurrentMethod());                        \r
+                       methodOneWay = RemotingServices.IsOneWay (MethodBase.GetCurrentMethod ());\r
                }\r
-               \r
-               public void Method2(int i)\r
+\r
+               public void Method2 (int i)\r
                {\r
-                       methodOneWay = RemotingServices.IsOneWay(MethodBase.GetCurrentMethod());                        \r
-                       \r
+                       methodOneWay = RemotingServices.IsOneWay (MethodBase.GetCurrentMethod ());\r
                }\r
-               \r
-               [OneWay()]\r
-               public void Method3()\r
+\r
+               [OneWay ()]\r
+               public void Method3 ()\r
                {\r
-                       methodOneWay = RemotingServices.IsOneWay(MethodBase.GetCurrentMethod());                        \r
-                       \r
+                       methodOneWay = RemotingServices.IsOneWay (MethodBase.GetCurrentMethod ());\r
                }\r
-               \r
-               public static int Called\r
-               {\r
-                       get{return _called;}\r
+\r
+               public static int Called {\r
+                       get { return _called; }\r
                }\r
-               \r
-               public static bool IsMethodOneWay\r
-               {\r
-                       get{return methodOneWay;}\r
+\r
+               public static bool IsMethodOneWay {\r
+                       get { return methodOneWay; }\r
                }\r
-               \r
-               \r
+\r
                private static int _called;\r
                private int id = 0;\r
                private string uri;\r
                private static bool methodOneWay = false;\r
        }\r
-       \r
+\r
        // Another class used by the tests\r
-       public class DerivedMarshalObject: MarshalObject\r
+       public class DerivedMarshalObject : MarshalObject\r
        {\r
-               public DerivedMarshalObject(){}\r
-               \r
-               public DerivedMarshalObject(int id, string uri): base(id, uri) {}\r
-       }       \r
-       \r
+               public DerivedMarshalObject () { }\r
+\r
+               public DerivedMarshalObject (int id, string uri) : base (id, uri) { }\r
+       }\r
+\r
        interface A\r
        {\r
        }\r
-       \r
-       interface B: A\r
-       { \r
+\r
+       interface B : A\r
+       {\r
        }\r
-       \r
-       public class CC: MarshalByRefObject\r
-       { \r
+\r
+       public class CC : MarshalByRefObject\r
+       {\r
        }\r
-       \r
-       public class DD: MarshalByRefObject\r
-       { \r
+\r
+       public class DD : MarshalByRefObject\r
+       {\r
        }\r
-       \r
-       \r
+\r
+\r
 } // namespace MonoTests.System.Runtime.Remoting.RemotingServicesInternal\r
 \r
 namespace MonoTests.Remoting\r
 {\r
        using MonoTests.System.Runtime.Remoting.RemotingServicesInternal;\r
-       \r
+\r
        // The main test class\r
        [TestFixture]\r
-       public class RemotingServicesTest : Assertion\r
+       public class RemotingServicesTest\r
        {\r
                private static int MarshalObjectId = 0;\r
-                       \r
-               public RemotingServicesTest()\r
+\r
+               public RemotingServicesTest ()\r
                {\r
                        MarshalObjectId = 0;\r
                }\r
-               \r
+\r
                // Helper function that create a new\r
                // MarshalObject with an unique ID\r
-               private static MarshalObject NewMarshalObject()\r
+               private static MarshalObject NewMarshalObject ()\r
                {\r
-                       string uri = "MonoTests.System.Runtime.Remoting.RemotingServicesTest.MarshalObject" + MarshalObjectId.ToString();\r
-                       MarshalObject objMarshal = new MarshalObject(MarshalObjectId, uri);\r
-                       \r
+                       string uri = "MonoTests.System.Runtime.Remoting.RemotingServicesTest.MarshalObject" + MarshalObjectId.ToString ();\r
+                       MarshalObject objMarshal = new MarshalObject (MarshalObjectId, uri);\r
+\r
                        MarshalObjectId++;\r
-                       \r
+\r
                        return objMarshal;\r
                }\r
-               \r
+\r
                // Another helper function\r
-               private DerivedMarshalObject NewDerivedMarshalObject()\r
+               private DerivedMarshalObject NewDerivedMarshalObject ()\r
                {\r
-                       string uri = "MonoTests.System.Runtime.Remoting.RemotingServicesTest.DerivedMarshalObject" + MarshalObjectId.ToString();\r
-                       DerivedMarshalObject objMarshal = new DerivedMarshalObject(MarshalObjectId, uri);\r
-                       \r
+                       string uri = "MonoTests.System.Runtime.Remoting.RemotingServicesTest.DerivedMarshalObject" + MarshalObjectId.ToString ();\r
+                       DerivedMarshalObject objMarshal = new DerivedMarshalObject (MarshalObjectId, uri);\r
+\r
                        MarshalObjectId++;\r
-                       \r
+\r
                        return objMarshal;\r
                }\r
-               \r
+\r
                // The two folling method test RemotingServices.Marshal()\r
                [Test]\r
-               public void Marshal1()\r
+               public void Marshal1 ()\r
                {\r
-                       \r
-                       MarshalObject objMarshal = NewMarshalObject();\r
-                       ObjRef objRef = RemotingServices.Marshal(objMarshal);\r
-                       \r
-                       Assert("#A01", objRef.URI != null);\r
-                       \r
-                       MarshalObject objRem = (MarshalObject) RemotingServices.Unmarshal(objRef);\r
-                       AssertEquals("#A02", objMarshal.Id, objRem.Id);\r
-                       \r
+\r
+                       MarshalObject objMarshal = NewMarshalObject ();\r
+                       ObjRef objRef = RemotingServices.Marshal (objMarshal);\r
+\r
+                       Assert.IsNotNull (objRef.URI, "#A01");\r
+\r
+                       MarshalObject objRem = (MarshalObject) RemotingServices.Unmarshal (objRef);\r
+                       Assert.AreEqual (objMarshal.Id, objRem.Id, "#A02");\r
+\r
                        objRem.Id = 2;\r
-                       AssertEquals("#A03", objMarshal.Id, objRem.Id);\r
-                       \r
+                       Assert.AreEqual (objMarshal.Id, objRem.Id, "#A03");\r
+\r
                        // TODO: uncomment when RemotingServices.Disconnect is implemented\r
                        //RemotingServices.Disconnect(objMarshal);\r
-                       \r
-                       objMarshal = NewMarshalObject();\r
-                       \r
-                       objRef = RemotingServices.Marshal(objMarshal, objMarshal.Uri);\r
-                       \r
-                       Assert("#A04", objRef.URI.EndsWith(objMarshal.Uri));\r
+\r
+                       objMarshal = NewMarshalObject ();\r
+\r
+                       objRef = RemotingServices.Marshal (objMarshal, objMarshal.Uri);\r
+\r
+                       Assert.IsTrue (objRef.URI.EndsWith (objMarshal.Uri), "#A04");\r
                        // TODO: uncomment when RemotingServices.Disconnect is implemented\r
-                       //RemotingServices.Disconnect(objMarshal);              \r
+                       //RemotingServices.Disconnect(objMarshal);\r
                }\r
-               \r
+\r
                [Test]\r
-               public void Marshal2()\r
+               public void Marshal2 ()\r
                {\r
-                       DerivedMarshalObject derivedObjMarshal = NewDerivedMarshalObject();\r
-                       \r
-                       ObjRef objRef = RemotingServices.Marshal(derivedObjMarshal, derivedObjMarshal.Uri, typeof(MarshalObject));\r
-                       \r
+                       DerivedMarshalObject derivedObjMarshal = NewDerivedMarshalObject ();\r
+\r
+                       ObjRef objRef = RemotingServices.Marshal (derivedObjMarshal, derivedObjMarshal.Uri, typeof (MarshalObject));\r
+\r
                        // Check that the type of the marshaled object is MarshalObject\r
-                       Assert("#A05", objRef.TypeInfo.TypeName.StartsWith((typeof(MarshalObject)).ToString()));\r
-                       \r
+                       Assert.IsTrue (objRef.TypeInfo.TypeName.StartsWith ((typeof (MarshalObject)).ToString ()), "#A05");\r
+\r
                        // TODO: uncomment when RemotingServices.Disconnect is implemented\r
                        //RemotingServices.Disconnect(derivedObjMarshal);\r
                }\r
-               \r
+\r
                // Tests RemotingServices.GetObjectUri()\r
                [Test]\r
-               public void GetObjectUri()\r
+               public void GetObjectUri ()\r
                {\r
-                       MarshalObject objMarshal = NewMarshalObject();\r
-                       \r
-                       Assert("#A06", RemotingServices.GetObjectUri(objMarshal) == null);\r
-                       \r
-                       ObjRef objRef = RemotingServices.Marshal(objMarshal);\r
-                       \r
-                       Assert("#A07", RemotingServices.GetObjectUri(objMarshal) != null);\r
+                       MarshalObject objMarshal = NewMarshalObject ();\r
+\r
+                       Assert.IsNull (RemotingServices.GetObjectUri (objMarshal), "#A06");\r
+\r
+                       RemotingServices.Marshal (objMarshal);\r
+\r
+                       Assert.IsNotNull (RemotingServices.GetObjectUri (objMarshal), "#A07");\r
                        // TODO: uncomment when RemotingServices.Disconnect is implemented\r
                        //RemotingServices.Disconnect(objMarshal);\r
                }\r
-               \r
+\r
                // Tests RemotingServices.Connect\r
                [Test]\r
-               public void Connect()\r
+               public void Connect ()\r
                {\r
-                       MarshalObject objMarshal = NewMarshalObject();\r
-                       \r
-                       IDictionary props = new Hashtable();\r
-                       props["name"] = objMarshal.Uri;\r
-                       props["port"] = 1236;\r
-                       TcpChannel chn = new TcpChannel(props, null, null);\r
-                       ChannelServices.RegisterChannel(chn);\r
-                       \r
-                       RemotingServices.Marshal(objMarshal,objMarshal.Uri);\r
-                       \r
-                       MarshalObject objRem = (MarshalObject) RemotingServices.Connect(typeof(MarshalObject), "tcp://localhost:1236/" + objMarshal.Uri);\r
-                       \r
-                       Assert("#A08", RemotingServices.IsTransparentProxy(objRem));\r
-                       \r
-                       ChannelServices.UnregisterChannel(chn);\r
-                       \r
-                       RemotingServices.Disconnect(objMarshal);\r
-               }\r
-               \r
+                       MarshalObject objMarshal = NewMarshalObject ();\r
+\r
+                       IDictionary props = new Hashtable ();\r
+                       props ["name"] = objMarshal.Uri;\r
+                       props ["port"] = 1236;\r
+                       TcpChannel chn = new TcpChannel (props, null, null);\r
+                       ChannelServices.RegisterChannel (chn);\r
+\r
+                       try {\r
+                               RemotingServices.Marshal (objMarshal, objMarshal.Uri);\r
+                               MarshalObject objRem = (MarshalObject) RemotingServices.Connect (typeof (MarshalObject), "tcp://localhost:1236/" + objMarshal.Uri);\r
+                               Assert.IsTrue (RemotingServices.IsTransparentProxy (objRem), "#A08");\r
+                       } finally {\r
+                               ChannelServices.UnregisterChannel (chn);\r
+                               RemotingServices.Disconnect (objMarshal);\r
+                       }\r
+               }\r
+\r
                // Tests RemotingServices.Marshal()\r
                [Test]\r
-               [ExpectedException(typeof(RemotingException))]  \r
-               public void MarshalThrowException()\r
+               public void MarshalThrowException ()\r
                {\r
-                       MarshalObject objMarshal = NewMarshalObject();\r
-                       \r
-                       IDictionary props = new Hashtable();\r
-                       props["name"] = objMarshal.Uri;\r
-                       props["port"] = 1237;\r
-                       TcpChannel chn = new TcpChannel(props, null, null);\r
-                       ChannelServices.RegisterChannel(chn);\r
-                       \r
-                       RemotingServices.Marshal(objMarshal,objMarshal.Uri);\r
-                       \r
-                       MarshalObject objRem = (MarshalObject) RemotingServices.Connect(typeof(MarshalObject), "tcp://localhost:1237/" + objMarshal.Uri);\r
-                       // This line sould throw a RemotingException\r
-                       // It is forbidden to export an object which is not\r
-                       // a real object\r
-                       try\r
-                       {\r
-                               RemotingServices.Marshal(objRem, objMarshal.Uri);\r
+                       MarshalObject objMarshal = NewMarshalObject ();\r
+\r
+                       IDictionary props = new Hashtable ();\r
+                       props ["name"] = objMarshal.Uri;\r
+                       props ["port"] = 1237;\r
+                       TcpChannel chn = new TcpChannel (props, null, null);\r
+                       ChannelServices.RegisterChannel (chn);\r
+\r
+                       try {\r
+                               RemotingServices.Marshal (objMarshal, objMarshal.Uri);\r
+                               MarshalObject objRem = (MarshalObject) RemotingServices.Connect (typeof (MarshalObject), "tcp://localhost:1237/" + objMarshal.Uri);\r
+                               // This line should throw a RemotingException\r
+                               // It is forbidden to export an object which is not\r
+                               // a real object\r
+                               try {\r
+                                       RemotingServices.Marshal (objRem, objMarshal.Uri);\r
+                                       Assert.Fail ("#1");\r
+                               } catch (RemotingException e) {\r
+                               }\r
+                       } finally {\r
+                               ChannelServices.UnregisterChannel (chn);\r
+\r
+                               // TODO: uncomment when RemotingServices.Disconnect is implemented\r
+                               //RemotingServices.Disconnect(objMarshal);\r
                        }\r
-                       catch(Exception e)\r
-                       {\r
-                               ChannelServices.UnregisterChannel(chn);\r
-                       \r
-                       // TODO: uncomment when RemotingServices.Disconnect is implemented\r
-                       //RemotingServices.Disconnect(objMarshal);\r
-                       \r
-                               throw e;\r
-                       }               \r
                }\r
-               \r
+\r
                // Tests RemotingServices.ExecuteMessage()\r
                // also tests GetMethodBaseFromMessage()\r
                // IsMethodOverloaded()\r
                [Test]\r
-               public void ExecuteMessage()\r
+               public void ExecuteMessage ()\r
                {\r
-                       TcpChannel chn = null;\r
-                       try\r
-                       {\r
-                               chn = new TcpChannel(1235);\r
-                               ChannelServices.RegisterChannel(chn);\r
-                               \r
-                               MarshalObject objMarshal = NewMarshalObject();\r
-                               RemotingConfiguration.RegisterWellKnownServiceType(typeof(MarshalObject), objMarshal.Uri, WellKnownObjectMode.SingleCall);\r
-                               \r
+                       TcpChannel chn = new TcpChannel (1235);\r
+                       ChannelServices.RegisterChannel (chn);\r
+                       try {\r
+                               MarshalObject objMarshal = NewMarshalObject ();\r
+                               RemotingConfiguration.RegisterWellKnownServiceType (typeof (MarshalObject), objMarshal.Uri, WellKnownObjectMode.SingleCall);\r
+\r
                                // use a proxy to catch the Message\r
-                               MyProxy proxy = new MyProxy(typeof(MarshalObject), (MarshalObject) Activator.GetObject(typeof(MarshalObject), "tcp://localhost:1235/" + objMarshal.Uri));\r
-                               \r
-                               MarshalObject objRem = (MarshalObject) proxy.GetTransparentProxy();\r
-                               \r
-                               objRem.Method1();\r
-                               \r
+                               MyProxy proxy = new MyProxy (typeof (MarshalObject), (MarshalObject) Activator.GetObject (typeof (MarshalObject), "tcp://localhost:1235/" + objMarshal.Uri));\r
+\r
+                               MarshalObject objRem = (MarshalObject) proxy.GetTransparentProxy ();\r
+\r
+                               objRem.Method1 ();\r
+\r
                                // Tests RemotingServices.GetMethodBaseFromMethodMessage()\r
-                               AssertEquals("#A09","Method1",proxy.MthBase.Name);\r
-                               Assert("#A09.1", !proxy.IsMethodOverloaded);\r
-                               \r
-                               objRem.Method2();\r
-                               Assert("#A09.2", proxy.IsMethodOverloaded);\r
-                       \r
+                               Assert.AreEqual ("Method1", proxy.MthBase.Name, "#A09");\r
+                               Assert.IsFalse (proxy.IsMethodOverloaded, "#A09.1");\r
+\r
+                               objRem.Method2 ();\r
+                               Assert.IsTrue (proxy.IsMethodOverloaded, "#A09.2");\r
+\r
                                // Tests RemotingServices.ExecuteMessage();\r
                                // If ExecuteMessage does it job well, Method1 should be called 2 times\r
-                               AssertEquals("#A10", 2, MarshalObject.Called);\r
-                       }\r
-                       finally\r
-                       {\r
-                               if(chn != null) ChannelServices.UnregisterChannel(chn);\r
+                               Assert.AreEqual (2, MarshalObject.Called, "#A10");\r
+                       } finally {\r
+                               ChannelServices.UnregisterChannel (chn);\r
                        }\r
                }\r
-               \r
+\r
                // Tests the IsOneWay method\r
                [Test]\r
-               public void IsOneWay()\r
+               public void IsOneWay ()\r
                {\r
-                       TcpChannel chn = null;\r
-                       try\r
-                       {\r
-                               chn = new TcpChannel(1238);\r
-                               ChannelServices.RegisterChannel(chn);\r
-                               RemotingConfiguration.RegisterWellKnownServiceType(typeof(MarshalObject), "MarshalObject.rem", WellKnownObjectMode.Singleton);\r
-                               \r
-                               MarshalObject objRem = (MarshalObject) Activator.GetObject(typeof(MarshalObject), "tcp://localhost:1238/MarshalObject.rem");\r
-                               \r
-                               Assert("#A10.1", RemotingServices.IsTransparentProxy(objRem));\r
-                               \r
-                               objRem.Method1();\r
-                               Thread.Sleep(20);\r
-                               Assert("#A10.2", !MarshalObject.IsMethodOneWay);\r
-                               objRem.Method3();\r
-                               Thread.Sleep(20);\r
-                               Assert("#A10.3", MarshalObject.IsMethodOneWay);\r
-                       }\r
-                       finally\r
-                       {\r
-                               if(chn != null) ChannelServices.UnregisterChannel(chn);\r
+                       TcpChannel chn = new TcpChannel (1238);\r
+                       ChannelServices.RegisterChannel (chn);\r
+                       try {\r
+                               RemotingConfiguration.RegisterWellKnownServiceType (typeof (MarshalObject), "MarshalObject.rem", WellKnownObjectMode.Singleton);\r
+\r
+                               MarshalObject objRem = (MarshalObject) Activator.GetObject (typeof (MarshalObject), "tcp://localhost:1238/MarshalObject.rem");\r
+\r
+                               Assert.IsTrue (RemotingServices.IsTransparentProxy (objRem), "#A10.1");\r
+\r
+                               objRem.Method1 ();\r
+                               Thread.Sleep (20);\r
+                               Assert.IsFalse (MarshalObject.IsMethodOneWay, "#A10.2");\r
+                               objRem.Method3 ();\r
+                               Thread.Sleep (20);\r
+                               Assert.IsTrue (MarshalObject.IsMethodOneWay, "#A10.3");\r
+                       } finally {\r
+                               ChannelServices.UnregisterChannel (chn);\r
                        }\r
                }\r
-               \r
+\r
                [Test]\r
-               public void GetObjRefForProxy()\r
+               public void GetObjRefForProxy ()\r
                {\r
-                       TcpChannel chn = null;\r
-                       try\r
-                       {\r
-                               chn = new TcpChannel(1239);\r
-                               ChannelServices.RegisterChannel(chn);\r
-                               \r
+                       TcpChannel chn = new TcpChannel (1239);\r
+                       ChannelServices.RegisterChannel (chn);\r
+                       try {\r
                                // Register le factory as a SAO\r
-                               RemotingConfiguration.RegisterWellKnownServiceType(typeof(MarshalObjectFactory), "MonoTests.System.Runtime.Remoting.RemotingServicesTest.Factory.soap", WellKnownObjectMode.Singleton);\r
-                               \r
-                               MarshalObjectFactory objFactory = (MarshalObjectFactory) Activator.GetObject(typeof(MarshalObjectFactory), "tcp://localhost:1239/MonoTests.System.Runtime.Remoting.RemotingServicesTest.Factory.soap");\r
-                               \r
+                               RemotingConfiguration.RegisterWellKnownServiceType (typeof (MarshalObjectFactory), "MonoTests.System.Runtime.Remoting.RemotingServicesTest.Factory.soap", WellKnownObjectMode.Singleton);\r
+\r
+                               MarshalObjectFactory objFactory = (MarshalObjectFactory) Activator.GetObject (typeof (MarshalObjectFactory), "tcp://localhost:1239/MonoTests.System.Runtime.Remoting.RemotingServicesTest.Factory.soap");\r
+\r
                                // Get a new "CAO"\r
-                               MarshalObject objRem = objFactory.GetNewMarshalObject();\r
-                               \r
-                               ObjRef objRefRem = RemotingServices.GetObjRefForProxy((MarshalByRefObject)objRem);\r
-                               \r
-                               Assert("#A11", objRefRem != null);\r
-                       }\r
-                       finally\r
-                       {\r
-                               if(chn != null) ChannelServices.UnregisterChannel(chn);                         \r
+                               MarshalObject objRem = objFactory.GetNewMarshalObject ();\r
+\r
+                               ObjRef objRefRem = RemotingServices.GetObjRefForProxy ((MarshalByRefObject) objRem);\r
+\r
+                               Assert.IsNotNull (objRefRem, "#A11");\r
+                       } finally {\r
+                               ChannelServices.UnregisterChannel (chn);\r
                        }\r
                }\r
-               \r
+\r
                // Tests GetRealProxy\r
                [Test]\r
-               public void GetRealProxy()\r
+               public void GetRealProxy ()\r
                {\r
-                       TcpChannel chn = null;\r
-                       try\r
-                       {\r
-                               chn = new TcpChannel(1241);\r
-                               ChannelServices.RegisterChannel(chn);\r
-                               \r
-                               RemotingConfiguration.RegisterWellKnownServiceType(typeof(MarshalObject), "MonoTests.System.Runtime.Remoting.RemotingServicesTest.MarshalObject.soap", WellKnownObjectMode.Singleton);\r
-                               \r
-                               MyProxy proxy = new  MyProxy(typeof(MarshalObject), (MarshalByRefObject)Activator.GetObject(typeof(MarshalObject), "tcp://localhost:1241/MonoTests.System.Runtime.Remoting.RemotingServicesTest.MarshalObject.soap"));\r
-                               MarshalObject objRem = (MarshalObject) proxy.GetTransparentProxy();\r
-                               \r
-                               RealProxy rp = RemotingServices.GetRealProxy(objRem);\r
-                               \r
-                               Assert("#A12", rp != null);\r
-                               AssertEquals("#A13", "MonoTests.System.Runtime.Remoting.RemotingServicesInternal.MyProxy", rp.GetType().ToString());\r
-                       }\r
-                       finally\r
-                       {\r
-                               if(chn != null) ChannelServices.UnregisterChannel(chn);\r
+                       TcpChannel chn = new TcpChannel (1241);\r
+                       ChannelServices.RegisterChannel (chn);\r
+                       try {\r
+                               RemotingConfiguration.RegisterWellKnownServiceType (typeof (MarshalObject), "MonoTests.System.Runtime.Remoting.RemotingServicesTest.MarshalObject.soap", WellKnownObjectMode.Singleton);\r
+\r
+                               MyProxy proxy = new MyProxy (typeof (MarshalObject), (MarshalByRefObject) Activator.GetObject (typeof (MarshalObject), "tcp://localhost:1241/MonoTests.System.Runtime.Remoting.RemotingServicesTest.MarshalObject.soap"));\r
+                               MarshalObject objRem = (MarshalObject) proxy.GetTransparentProxy ();\r
+\r
+                               RealProxy rp = RemotingServices.GetRealProxy (objRem);\r
+\r
+                               Assert.IsNotNull (rp, "#A12");\r
+                               Assert.AreEqual ("MonoTests.System.Runtime.Remoting.RemotingServicesInternal.MyProxy", rp.GetType ().ToString (), "#A13");\r
+                       } finally {\r
+                               ChannelServices.UnregisterChannel (chn);\r
                        }\r
                }\r
-               \r
+\r
                // Tests SetObjectUriForMarshal()\r
                [Test]\r
-               public void SetObjectUriForMarshal()\r
+               public void SetObjectUriForMarshal ()\r
                {\r
-                       TcpChannel chn = null;\r
-                       try\r
-                       {\r
-                               chn = new TcpChannel(1242);\r
-                               ChannelServices.RegisterChannel(chn);\r
-                               \r
-                               MarshalObject objRem = NewMarshalObject();\r
-                               RemotingServices.SetObjectUriForMarshal(objRem, objRem.Uri);\r
-                               RemotingServices.Marshal(objRem);\r
-                               \r
-                               objRem = (MarshalObject) Activator.GetObject(typeof(MarshalObject), "tcp://localhost:1242/"+objRem.Uri);\r
-                               Assert("#A14", objRem != null);\r
+                       TcpChannel chn = new TcpChannel (1242);\r
+                       ChannelServices.RegisterChannel (chn);\r
+                       try {\r
+                               MarshalObject objRem = NewMarshalObject ();\r
+                               RemotingServices.SetObjectUriForMarshal (objRem, objRem.Uri);\r
+                               RemotingServices.Marshal (objRem);\r
+\r
+                               objRem = (MarshalObject) Activator.GetObject (typeof (MarshalObject), "tcp://localhost:1242/" + objRem.Uri);\r
+                               Assert.IsNotNull (objRem, "#A14");\r
+                       } finally {\r
+                               ChannelServices.UnregisterChannel (chn);\r
                        }\r
-                       finally\r
-                       {\r
-                               if(chn != null) ChannelServices.UnregisterChannel(chn);\r
-                       }                       \r
-                       \r
+\r
                }\r
-               \r
+\r
                // Tests GetServeurTypeForUri()\r
                [Test]\r
-               public void GetServeurTypeForUri()\r
+               public void GetServeurTypeForUri ()\r
                {\r
-                       TcpChannel chn = null;\r
-                       Type type = typeof(MarshalObject);\r
-                       try\r
-                       {\r
-                               chn = new TcpChannel(1243);\r
-                               ChannelServices.RegisterChannel(chn);\r
-                               \r
-                               MarshalObject objRem = NewMarshalObject();\r
-                               RemotingServices.SetObjectUriForMarshal(objRem, objRem.Uri);\r
-                               RemotingServices.Marshal(objRem);\r
-                               \r
-                               Type typeRem = RemotingServices.GetServerTypeForUri(RemotingServices.GetObjectUri(objRem));\r
-                               AssertEquals("#A15", type, typeRem);\r
+                       TcpChannel chn = new TcpChannel (1243);\r
+                       Type type = typeof (MarshalObject);\r
+                       ChannelServices.RegisterChannel (chn);\r
+                       try {\r
+                               MarshalObject objRem = NewMarshalObject ();\r
+                               RemotingServices.SetObjectUriForMarshal (objRem, objRem.Uri);\r
+                               RemotingServices.Marshal (objRem);\r
+\r
+                               Type typeRem = RemotingServices.GetServerTypeForUri (RemotingServices.GetObjectUri (objRem));\r
+                               Assert.AreEqual (type, typeRem, "#A15");\r
+                       } finally {\r
+                               ChannelServices.UnregisterChannel (chn);\r
                        }\r
-                       finally\r
-                       {\r
-                               if(chn != null) ChannelServices.UnregisterChannel(chn);\r
-                       }                       \r
                }\r
-               \r
+\r
                // Tests IsObjectOutOfDomain\r
                // Tests IsObjectOutOfContext\r
                [Test]\r
-               public void IsObjectOutOf()\r
+               [Category ("NotWorking")]\r
+               public void IsObjectOutOf ()\r
                {\r
-                       TcpChannel chn = null;\r
-                       try\r
-                       {\r
-                               chn = new TcpChannel(1245);\r
-                               ChannelServices.RegisterChannel(chn);\r
-                               \r
-                               RemotingConfiguration.RegisterWellKnownServiceType(typeof(MarshalObject), "MarshalObject2.rem", WellKnownObjectMode.Singleton);\r
-                               \r
-                               MarshalObject objRem = (MarshalObject) Activator.GetObject(typeof(MarshalObject), "tcp://localhost:1245/MarshalObject2.rem");\r
-                               \r
-                               Assert("#A16", RemotingServices.IsObjectOutOfAppDomain(objRem));\r
-                               Assert("#A17", RemotingServices.IsObjectOutOfContext(objRem));\r
-                               \r
-                               MarshalObject objMarshal = new MarshalObject();\r
-                               Assert("#A18", !RemotingServices.IsObjectOutOfAppDomain(objMarshal));\r
-                               Assert("#A19", !RemotingServices.IsObjectOutOfContext(objMarshal));\r
+                       TcpChannel chn = new TcpChannel (1245);\r
+                       ChannelServices.RegisterChannel (chn);\r
+                       try {\r
+                               RemotingConfiguration.RegisterWellKnownServiceType (typeof (MarshalObject), "MarshalObject2.rem", WellKnownObjectMode.Singleton);\r
+\r
+                               MarshalObject objRem = (MarshalObject) Activator.GetObject (typeof (MarshalObject), "tcp://localhost:1245/MarshalObject2.rem");\r
+\r
+                               Assert.IsTrue (RemotingServices.IsObjectOutOfAppDomain (objRem), "#A16");\r
+                               Assert.IsTrue (RemotingServices.IsObjectOutOfContext (objRem), "#A17");\r
+\r
+                               MarshalObject objMarshal = new MarshalObject ();\r
+                               Assert.IsFalse (RemotingServices.IsObjectOutOfAppDomain (objMarshal), "#A18");\r
+                               Assert.IsFalse (RemotingServices.IsObjectOutOfContext (objMarshal), "#A19");\r
+                       } finally {\r
+                               ChannelServices.UnregisterChannel (chn);\r
                        }\r
-                       finally\r
-                       {\r
-                               ChannelServices.UnregisterChannel(chn);\r
+               }\r
+\r
+               [Test]\r
+               public void ApplicationNameTest ()\r
+               {\r
+                       RemotingConfiguration.ApplicationName = "app";\r
+                       TcpChannel chn = new TcpChannel (1246);\r
+                       ChannelServices.RegisterChannel (chn);\r
+                       try {\r
+                               RemotingConfiguration.RegisterWellKnownServiceType (typeof (MarshalObject), "obj3.rem", WellKnownObjectMode.Singleton);\r
+\r
+                               MarshalObject objRem = (MarshalObject) Activator.GetObject (typeof (MarshalObject), "tcp://localhost:1246/app/obj3.rem");\r
+                               MarshalObject objRem2 = (MarshalObject) Activator.GetObject (typeof (MarshalObject), "tcp://localhost:1246/obj3.rem");\r
+\r
+                               Assert.IsTrue (RemotingServices.IsTransparentProxy (objRem), "#AN1");\r
+                               Assert.IsTrue (RemotingServices.IsTransparentProxy (objRem2), "#AN2");\r
+\r
+                               Assert.IsNotNull (RemotingServices.GetServerTypeForUri ("obj3.rem"), "#AN3");\r
+                               Assert.IsNotNull (RemotingServices.GetServerTypeForUri ("/app/obj3.rem"), "#AN4");\r
+                               Assert.IsNull (RemotingServices.GetServerTypeForUri ("//app/obj3.rem"), "#AN5");\r
+                               Assert.IsNull (RemotingServices.GetServerTypeForUri ("app/obj3.rem"), "#AN6");\r
+                               Assert.IsNull (RemotingServices.GetServerTypeForUri ("/whatever/obj3.rem"), "#AN7");\r
+                               Assert.IsNotNull (RemotingServices.GetServerTypeForUri ("/obj3.rem"), "#AN8");\r
+                               Assert.IsNull (RemotingServices.GetServerTypeForUri ("//obj3.rem"), "#AN9");\r
+                       } finally {\r
+                               ChannelServices.UnregisterChannel (chn);\r
+                       }\r
+               }\r
+\r
+               [Test]\r
+               public void GetObjectWithChannelDataTest ()\r
+               {\r
+                       TcpChannel chn = new TcpChannel (1247);\r
+                       ChannelServices.RegisterChannel (chn);\r
+                       try {\r
+                               RemotingConfiguration.RegisterWellKnownServiceType (typeof (MarshalObject), "getobjectwithchanneldata.rem", WellKnownObjectMode.Singleton);\r
+\r
+                               string channelData = "test";\r
+                               Assert.IsNotNull (Activator.GetObject (typeof (MarshalObject), "tcp://localhost:1247/getobjectwithchanneldata.rem", channelData), "#01");\r
+                       } finally {\r
+                               ChannelServices.UnregisterChannel (chn);\r
                        }\r
                }\r
-               \r
+\r
                [Test]\r
+               [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
                public void ConnectProxyCast ()\r
                {\r
                        object o;\r
                        RemotingConfiguration.Configure (null);\r
-                       \r
-                       o = RemotingServices.Connect (typeof(MarshalByRefObject), "tcp://localhost:3434/ff1.rem");\r
-                       Assert ("#m1", o is DD);\r
-                       Assert ("#m2", o is A);\r
-                       Assert ("#m3", o is B);\r
-                       Assert ("#m4", !(o is CC));\r
-                       \r
-                       o = RemotingServices.Connect (typeof(A), "tcp://localhost:3434/ff3.rem");\r
-                       Assert ("#a1", o is DD);\r
-                       Assert ("#a2", o is A);\r
-                       Assert ("#a3", o is B);\r
-                       Assert ("#a4", !(o is CC));\r
-                       \r
-                       o = RemotingServices.Connect (typeof(DD), "tcp://localhost:3434/ff4.rem");\r
-                       Assert ("#d1", o is DD);\r
-                       Assert ("#d2", o is A);\r
-                       Assert ("#d3", o is B);\r
-                       Assert ("#d4", !(o is CC));\r
-                       \r
-                       o = RemotingServices.Connect (typeof(CC), "tcp://localhost:3434/ff5.rem");\r
-                       Assert ("#c1", !(o is DD));\r
-                       Assert ("#c2", o is A);\r
-                       Assert ("#c3", o is B);\r
-                       Assert ("#c4", o is CC);\r
-               }\r
-               \r
+\r
+                       o = RemotingServices.Connect (typeof (MarshalByRefObject), "tcp://localhost:3434/ff1.rem");\r
+                       Assert.IsInstanceOfType (typeof (DD), o, "#m1");\r
+                       Assert.IsInstanceOfType (typeof (A), o, "#m2");\r
+                       Assert.IsInstanceOfType (typeof (B), o, "#m3");\r
+                       AssertHelper.IsNotInstanceOfType (typeof (CC), !(o is CC), "#m4");\r
+\r
+                       o = RemotingServices.Connect (typeof (A), "tcp://localhost:3434/ff3.rem");\r
+                       Assert.IsInstanceOfType (typeof (DD), o, "#a1");\r
+                       Assert.IsInstanceOfType (typeof (A), o, "#a2");\r
+                       Assert.IsInstanceOfType (typeof (B), o, "#a3");\r
+                       AssertHelper.IsNotInstanceOfType (typeof (CC), o, "#a4");\r
+\r
+                       o = RemotingServices.Connect (typeof (DD), "tcp://localhost:3434/ff4.rem");\r
+                       Assert.IsInstanceOfType (typeof (DD), o, "#d1");\r
+                       Assert.IsInstanceOfType (typeof (A), o, "#d2");\r
+                       Assert.IsInstanceOfType (typeof (B), o, "#d3");\r
+                       AssertHelper.IsNotInstanceOfType (typeof (CC), o, "#d4");\r
+\r
+                       o = RemotingServices.Connect (typeof (CC), "tcp://localhost:3434/ff5.rem");\r
+                       AssertHelper.IsNotInstanceOfType (typeof (DD), o, "#c1");\r
+                       Assert.IsInstanceOfType (typeof (A), o, "#c2");\r
+                       Assert.IsInstanceOfType (typeof (B), o, "#c3");\r
+                       Assert.IsInstanceOfType (typeof (CC), o, "#c4");\r
+               }\r
+               // Don't add any tests that must create channels\r
+               // after ConnectProxyCast (), because this test calls\r
+               // RemotingConfiguration.Configure ().\r
        } // end class RemotingServicesTest\r
 } // end of namespace MonoTests.Remoting\r