2 // MonoTests.Remoting.TcpCalls.cs
4 // Author: Lluis Sanchez Gual (lluis@ximian.com)
6 // 2003 (C) Copyright, Ximian, Inc.
10 using System.Runtime.Remoting;
11 using System.Runtime.Remoting.Channels;
12 using System.Runtime.Remoting.Channels.Tcp;
13 using System.Runtime.Remoting.Channels.Http;
14 using NUnit.Framework;
16 namespace MonoTests.Remoting
19 public class ActivationTests
21 ActivationServer server;
28 AppDomain domain = AppDomain.CreateDomain ("testdomain_activation");
29 server = (ActivationServer) domain.CreateInstanceAndUnwrap(GetType().Assembly.FullName,"MonoTests.Remoting.ActivationServer");
31 RemotingConfiguration.RegisterActivatedClientType (typeof(CaObject1), "tcp://localhost:32433");
32 RemotingConfiguration.RegisterActivatedClientType (typeof(CaObject2), "http://localhost:32434");
33 RemotingConfiguration.RegisterWellKnownClientType (typeof(WkObjectSinglecall1), "tcp://localhost:32433/wkoSingleCall1");
34 RemotingConfiguration.RegisterWellKnownClientType (typeof(WkObjectSingleton1), "tcp://localhost:32433/wkoSingleton1");
35 RemotingConfiguration.RegisterWellKnownClientType (typeof(WkObjectSinglecall2), "http://localhost:32434/wkoSingleCall2");
36 RemotingConfiguration.RegisterWellKnownClientType (typeof(WkObjectSingleton2), "http://localhost:32434/wkoSingleton2");
40 Console.WriteLine (ex);
45 public void TestCreateTcpCao ()
47 CaObject1 ca = new CaObject1 ();
48 CaObject1 ca2 = new CaObject1 ();
49 RunTestCreateCao (ca, ca2);
53 public void TestCreateHttpCao ()
55 CaObject2 ca = new CaObject2 ();
56 CaObject2 ca2 = new CaObject2 ();
57 RunTestCreateCao (ca, ca2);
60 public void RunTestCreateCao (BaseObject ca, BaseObject ca2)
62 Assert.AreEqual (0, ca.counter, "#1");
65 Assert.AreEqual (1, ca.counter, "#2");
67 Assert.AreEqual (0, ca2.counter, "#3");
70 Assert.AreEqual (1, ca2.counter, "#4");
72 Assert.AreEqual (1, ca.counter, "#5");
76 public void TestCreateTcpWkoSingleCall ()
78 WkObjectSinglecall1 ca = new WkObjectSinglecall1 ();
79 WkObjectSinglecall1 ca2 = new WkObjectSinglecall1 ();
80 RunTestCreateWkoSingleCall (ca, ca2);
84 public void TestCreateTcpWkoSingleton ()
86 WkObjectSingleton1 ca = new WkObjectSingleton1 ();
87 WkObjectSingleton1 ca2 = new WkObjectSingleton1 ();
88 RunTestCreateWkoSingleton (ca, ca2);
92 public void TestCreateHttpWkoSingleCall ()
94 WkObjectSinglecall2 ca = new WkObjectSinglecall2 ();
95 WkObjectSinglecall2 ca2 = new WkObjectSinglecall2 ();
96 RunTestCreateWkoSingleCall (ca, ca2);
100 public void TestCreateHttpWkoSingleton ()
102 WkObjectSingleton2 ca = new WkObjectSingleton2 ();
103 WkObjectSingleton2 ca2 = new WkObjectSingleton2 ();
104 RunTestCreateWkoSingleton (ca, ca2);
107 public void RunTestCreateWkoSingleCall (BaseObject ca, BaseObject ca2)
109 Assert.AreEqual (0, ca.counter, "#1");
111 Assert.AreEqual (0, ca.counter, "#2");
113 Assert.AreEqual (0, ca2.counter, "#3");
115 Assert.AreEqual (0, ca2.counter, "#4");
118 public void RunTestCreateWkoSingleton (BaseObject ca, BaseObject ca2)
120 Assert.AreEqual (0, ca.counter, "#1");
122 Assert.AreEqual (1, ca.counter, "#2");
124 Assert.AreEqual (2, ca2.counter, "#3");
126 Assert.AreEqual (3, ca2.counter, "#4");
129 [TestFixtureTearDown]
136 public class ActivationServer: MarshalByRefObject
141 public ActivationServer ()
143 TcpChannel tcp = new TcpChannel (32433);
144 HttpChannel http = new HttpChannel (32434);
146 ChannelServices.RegisterChannel (tcp);
147 ChannelServices.RegisterChannel (http);
149 RemotingConfiguration.RegisterActivatedServiceType (typeof(CaObject1));
150 RemotingConfiguration.RegisterActivatedServiceType (typeof(CaObject2));
151 RemotingConfiguration.RegisterWellKnownServiceType (typeof(WkObjectSinglecall1), "wkoSingleCall1", WellKnownObjectMode.SingleCall);
152 RemotingConfiguration.RegisterWellKnownServiceType (typeof(WkObjectSingleton1), "wkoSingleton1", WellKnownObjectMode.Singleton);
153 RemotingConfiguration.RegisterWellKnownServiceType (typeof(WkObjectSinglecall2), "wkoSingleCall2", WellKnownObjectMode.SingleCall);
154 RemotingConfiguration.RegisterWellKnownServiceType (typeof(WkObjectSingleton2), "wkoSingleton2", WellKnownObjectMode.Singleton);
159 tcp.StopListening (null);
160 http.StopListening (null);
164 public class BaseObject: MarshalByRefObject
169 public class CaObject1: BaseObject
173 public class CaObject2: BaseObject
177 public class WkObjectSinglecall1: BaseObject
181 public class WkObjectSingleton1: BaseObject
185 public class WkObjectSinglecall2: BaseObject
189 public class WkObjectSingleton2: BaseObject