[netcore] Remove local copy of static alc resolve methods
[mono-project.git] / mcs / class / System.Runtime.Remoting / Test / GenericTest.cs
bloba8a9a7bfead8a0783b18a9a827bcfd2743d36827
1 //
2 // MonoTests.Remoting.GenericTest.cs
3 //
4 // Authors:
5 // Robert Jordan <robertj@gmx.net>
6 //
9 using System;
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
25 int Test ();
26 int Test (int i);
27 int Test (int a, int b);
28 V Test <V> (V v);
29 V Test <V, T> (V v, T t);
32 public interface ITest
34 V TestIface<V> (V v);
35 int TestDirectIfaceImpl (int i);
36 INested GetNested ();
37 INested GetNestedMbr ();
40 public class ServerBase<T> : MarshalByRefObject, ITest
42 public virtual V TestVirt<V> (V v)
44 return default (V);
47 public V TestIface<V> (V v)
49 return v;
52 int ITest.TestDirectIfaceImpl (int i)
54 return i;
57 public int TestDirectIfaceImpl (int i)
59 return -1;
62 public INested GetNested ()
64 return new Nested ();
67 public INested GetNested (string s)
69 return new Nested ();
72 public INested GetNestedMbr ()
74 return new NestedMbr ();
78 public class Server<T> : ServerBase<T>
80 public override V TestVirt<V> (V v)
82 return v;
86 [Serializable]
87 public class Nested : INested
89 public int Test ()
91 return 47;
94 int INested.Test ()
96 return 42;
99 public int Test (int i)
101 return i + 500;
104 int INested.Test (int a, int b)
106 return a + b;
109 public V Test <V> (V v)
111 return v;
114 V INested.Test <V, T> (V v, T t)
116 return default (V);
120 public class NestedMbr : MarshalByRefObject, INested
122 public int Test ()
124 return 47;
127 int INested.Test ()
129 return 42;
132 public int Test (int i)
134 return i + 500;
137 int INested.Test (int a, int b)
139 return a + b;
142 public V Test <V> (V v)
144 return v;
147 V INested.Test <V, T> (V v, T t)
149 return default (V);
154 [TestFixture]
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")]
162 [Test]
163 public void TestCrossAppDomainChannel ()
165 RunTests (RegisterAndConnect <Server<object>> ());
168 [Test]
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);
178 try {
179 Register <Server<object>> ("gentcptest.rem");
180 RunTests (Connect <Server<object>> ($"tcp://localhost:{port}/gentcptest.rem"));
181 } finally {
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");
213 ITest i = rem;
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>");