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;
30 tcp = new TcpChannel (0);
31 http = new HttpChannel (0);
33 ChannelServices.RegisterChannel (tcp);
34 ChannelServices.RegisterChannel (http);
36 AppDomain domain = AppDomain.CreateDomain ("testdomain_activation");
37 server = (ActivationServer) domain.CreateInstanceAndUnwrap(GetType().Assembly.FullName,"MonoTests.Remoting.ActivationServer");
39 RemotingConfiguration.RegisterActivatedClientType (typeof(CaObject1), "tcp://localhost:9433");
40 RemotingConfiguration.RegisterActivatedClientType (typeof(CaObject2), "http://localhost:9434");
41 RemotingConfiguration.RegisterWellKnownClientType (typeof(WkObjectSinglecall1), "tcp://localhost:9433/wkoSingleCall1");
42 RemotingConfiguration.RegisterWellKnownClientType (typeof(WkObjectSingleton1), "tcp://localhost:9433/wkoSingleton1");
43 RemotingConfiguration.RegisterWellKnownClientType (typeof(WkObjectSinglecall2), "http://localhost:9434/wkoSingleCall2");
44 RemotingConfiguration.RegisterWellKnownClientType (typeof(WkObjectSingleton2), "http://localhost:9434/wkoSingleton2");
48 Console.WriteLine (ex);
53 public void TestCreateTcpCao ()
55 CaObject1 ca = new CaObject1 ();
56 CaObject1 ca2 = new CaObject1 ();
57 Assert.IsTrue (BaseObject.CreationCount == 0, "Objects created locally");
58 RunTestCreateCao (ca, ca2);
62 public void TestCreateHttpCao ()
64 CaObject2 ca = new CaObject2 ();
65 CaObject2 ca2 = new CaObject2 ();
66 Assert.IsTrue (BaseObject.CreationCount == 0, "Objects created locally");
67 RunTestCreateCao (ca, ca2);
70 public void RunTestCreateCao (BaseObject ca, BaseObject ca2)
72 Assert.AreEqual (0, ca.counter, "#1");
75 Assert.AreEqual (1, ca.counter, "#2");
77 Assert.AreEqual (0, ca2.counter, "#3");
80 Assert.AreEqual (1, ca2.counter, "#4");
82 Assert.AreEqual (1, ca.counter, "#5");
86 public void TestCreateTcpWkoSingleCall ()
88 WkObjectSinglecall1 ca = new WkObjectSinglecall1 ();
89 WkObjectSinglecall1 ca2 = new WkObjectSinglecall1 ();
90 Assert.IsTrue (BaseObject.CreationCount == 0, "Objects created locally");
91 RunTestCreateWkoSingleCall (ca, ca2);
95 public void TestCreateTcpWkoSingleton ()
97 WkObjectSingleton1 ca = new WkObjectSingleton1 ();
98 WkObjectSingleton1 ca2 = new WkObjectSingleton1 ();
99 Assert.IsTrue (BaseObject.CreationCount == 0, "Objects created locally");
100 RunTestCreateWkoSingleton (ca, ca2);
104 public void TestCreateHttpWkoSingleCall ()
106 WkObjectSinglecall2 ca = new WkObjectSinglecall2 ();
107 WkObjectSinglecall2 ca2 = new WkObjectSinglecall2 ();
108 Assert.IsTrue (BaseObject.CreationCount == 0, "Objects created locally");
109 RunTestCreateWkoSingleCall (ca, ca2);
113 public void TestCreateHttpWkoSingleton ()
115 WkObjectSingleton2 ca = new WkObjectSingleton2 ();
116 WkObjectSingleton2 ca2 = new WkObjectSingleton2 ();
117 Assert.IsTrue (BaseObject.CreationCount == 0, "Objects created locally");
118 RunTestCreateWkoSingleton (ca, ca2);
121 public void RunTestCreateWkoSingleCall (BaseObject ca, BaseObject ca2)
123 Assert.AreEqual (0, ca.counter, "#1");
125 Assert.AreEqual (0, ca.counter, "#2");
127 Assert.AreEqual (0, ca2.counter, "#3");
129 Assert.AreEqual (0, ca2.counter, "#4");
132 public void RunTestCreateWkoSingleton (BaseObject ca, BaseObject ca2)
134 Assert.AreEqual (0, ca.counter, "#1");
136 Assert.AreEqual (1, ca.counter, "#2");
138 Assert.AreEqual (2, ca2.counter, "#3");
140 Assert.AreEqual (3, ca2.counter, "#4");
143 [TestFixtureTearDown]
146 ChannelServices.UnregisterChannel (tcp);
147 ChannelServices.UnregisterChannel (http);
152 public class ActivationServer: MarshalByRefObject
157 public ActivationServer ()
159 tcp = new TcpChannel (9433);
160 http = new HttpChannel (9434);
162 ChannelServices.RegisterChannel (tcp);
163 ChannelServices.RegisterChannel (http);
165 RemotingConfiguration.RegisterActivatedServiceType (typeof(CaObject1));
166 RemotingConfiguration.RegisterActivatedServiceType (typeof(CaObject2));
167 RemotingConfiguration.RegisterWellKnownServiceType (typeof(WkObjectSinglecall1), "wkoSingleCall1", WellKnownObjectMode.SingleCall);
168 RemotingConfiguration.RegisterWellKnownServiceType (typeof(WkObjectSingleton1), "wkoSingleton1", WellKnownObjectMode.Singleton);
169 RemotingConfiguration.RegisterWellKnownServiceType (typeof(WkObjectSinglecall2), "wkoSingleCall2", WellKnownObjectMode.SingleCall);
170 RemotingConfiguration.RegisterWellKnownServiceType (typeof(WkObjectSingleton2), "wkoSingleton2", WellKnownObjectMode.Singleton);
175 ChannelServices.UnregisterChannel (tcp);
176 ChannelServices.UnregisterChannel (http);
180 public class BaseObject: MarshalByRefObject
183 public static int CreationCount;
191 public class CaObject1: BaseObject
195 public class CaObject2: BaseObject
199 public class WkObjectSinglecall1: BaseObject
203 public class WkObjectSingleton1: BaseObject
207 public class WkObjectSinglecall2: BaseObject
211 public class WkObjectSingleton2: BaseObject