2 // MonoTests.Remoting.GenericTest.cs
5 // Robert Jordan <robertj@gmx.net>
10 using System
.Collections
;
11 using System
.Runtime
.Remoting
;
12 using System
.Runtime
.Remoting
.Channels
;
13 using System
.Runtime
.Remoting
.Channels
.Tcp
;
14 using System
.Runtime
.Remoting
.Channels
.Http
;
15 using System
.Runtime
.Remoting
.Channels
.Ipc
;
16 using System
.Threading
;
17 using NUnit
.Framework
;
19 using MonoTests
.Helpers
;
21 namespace MonoTests
.Remoting
23 public interface INested
27 int Test (int a
, int b
);
29 V Test
<V
, T
> (V v
, T t
);
32 public interface ITest
35 int TestDirectIfaceImpl (int i
);
37 INested
GetNestedMbr ();
40 public class ServerBase
<T
> : MarshalByRefObject
, ITest
42 public virtual V TestVirt
<V
> (V v
)
47 public V TestIface
<V
> (V v
)
52 int ITest
.TestDirectIfaceImpl (int i
)
57 public int TestDirectIfaceImpl (int i
)
62 public INested
GetNested ()
67 public INested
GetNested (string s
)
72 public INested
GetNestedMbr ()
74 return new NestedMbr ();
78 public class Server
<T
> : ServerBase
<T
>
80 public override V TestVirt
<V
> (V v
)
87 public class Nested
: INested
99 public int Test (int i
)
104 int INested
.Test (int a
, int b
)
109 public V Test
<V
> (V v
)
114 V INested
.Test
<V
, T
> (V v
, T t
)
120 public class NestedMbr
: MarshalByRefObject
, INested
132 public int Test (int i
)
137 int INested
.Test (int a
, int b
)
142 public V Test
<V
> (V v
)
147 V INested
.Test
<V
, T
> (V v
, T t
)
155 public class GenericTest
157 // Under MS.NET, INested.Test<V>(V v) isn't supported over the
158 // xappdom channel anymore (as of .NET 3.5). The stacktrace
159 // looks like if INested.Test(int) is invoked in place of
160 // INested.Test<int>(int).
161 [Category("NotDotNet")]
163 public void TestCrossAppDomainChannel ()
165 RunTests (RegisterAndConnect
<Server
<object>> ());
169 public void TestTcpChannel ()
171 var port
= NetworkHelpers
.FindFreePort ();
172 IDictionary props
= new Hashtable ();
173 props
["name"] = Guid
.NewGuid ().ToString("N");
174 props
["port"] = port
;
175 TcpChannel chan
= new TcpChannel (props
, null, null);
176 ChannelServices
.RegisterChannel (chan
);
179 Register
<Server
<object>> ("gentcptest.rem");
180 RunTests (Connect
<Server
<object>> ($"tcp://localhost:{port}/gentcptest.rem"));
182 ChannelServices
.UnregisterChannel (chan
);
186 static T RegisterAndConnect
<T
> () where T
: MarshalByRefObject
188 AppDomain d
= BaseCallTest
.CreateDomain ("GenericTests");
189 return (T
) d
.CreateInstanceAndUnwrap (
190 typeof (T
).Assembly
.FullName
,
191 typeof (T
).FullName
);
194 static void Register
<T
> (string uri
) where T
: MarshalByRefObject
196 object obj
= Activator
.CreateInstance (typeof(T
));
197 RemotingServices
.Marshal ((MarshalByRefObject
)obj
, uri
);
200 static T Connect
<T
> (string uri
) where T
: MarshalByRefObject
202 return (T
) RemotingServices
.Connect (typeof (T
), uri
);
205 static void RunTests (ServerBase
<object> rem
)
207 Assert
.AreEqual (42, rem
.TestIface
<int>(42),
208 "#1 calling TestIface on object instance");
210 Assert
.AreEqual (42, rem
.TestVirt
<int>(42),
211 "#2 calling TestVirt");
214 Assert
.AreEqual (42, i
.TestIface
<int>(42),
215 "#3 calling TestIface on interface");
217 Assert
.AreEqual (42, i
.TestDirectIfaceImpl (42),
218 "#4 calling TestDirectIfaceImp");
220 INested cao
= rem
.GetNested ();
221 Assert
.AreEqual (42, cao
.Test (),
222 "#5a calling INested.Test ()");
224 Assert
.AreEqual (42 + 500, cao
.Test (42),
225 "#5 calling INested.Test (int)");
227 Assert
.AreEqual (42, cao
.Test (21, 21),
228 "#6 calling INested.Test (int, int)");
230 Assert
.AreEqual (42, cao
.Test
<int> (42),
231 "#7 calling INested.Test<V>");
233 Assert
.AreEqual (0, cao
.Test
<int, string> (42, "bar"),
234 "#8 calling INested.Test<V, T>");
236 cao
= rem
.GetNestedMbr ();
237 Assert
.AreEqual (42, cao
.Test (),
238 "#9a calling INested.Test ()");
240 Assert
.AreEqual (42 + 500, cao
.Test (42),
241 "#9 calling INested.Test (int)");
243 Assert
.AreEqual (42, cao
.Test (21, 21),
244 "#10 calling INested.Test (int, int)");
246 Assert
.AreEqual (42, cao
.Test
<int> (42),
247 "#11 calling INested.Test<V>");
249 Assert
.AreEqual (0, cao
.Test
<int, string> (42, "bar"),
250 "#12 calling INested.Test<V, T>");