2010-05-25 Jb Evain <jbevain@novell.com>
[mcs.git] / class / System.Runtime.Remoting / Test / HttpBugTests.cs
blob68930b0d640addd065d2408c87f3790d3fe5d006
2 using System;
3 using System.Xml;
4 using System.Collections;
5 using System.Runtime.Remoting;
6 using System.Runtime.Remoting.Channels;
7 using System.Runtime.Remoting.Channels.Http;
8 using NUnit.Framework;
10 namespace MonoTests.Remoting.Http
12 //Test for Bug 324362 - SoapFormatter cannot deserialize the same MBR twice
13 [TestFixture]
14 public class Bug324362
16 [Test]
17 // [Category ("NotWorking")] // the assertion fails, and if it's removed, there's an exception
18 [Ignore ("This test somehow keeps http channel registered and then blocks any further http tests working. This also happens under .NET, so this test itself is wrong with nunit 2.4.8.")]
19 public void Test ()
21 new HttpChannel (8086);
22 RemotingServices.Marshal (new Service (), "test");
24 Service remObj = (Service) RemotingServices.Connect (
25 typeof (Service), "http://localhost:8086/test");
27 ArrayList list;
28 remObj.Test (out list);
29 // it's of type 'ObjRef' instead of 'Service':
30 Assert.IsTrue (list [0] is Service);
32 Service [] array;
33 remObj.Test (out array);
36 public class Service : MarshalByRefObject
38 public Service Test (out Service[] a)
40 Service obj = new Service ();
41 a = new Service [] { obj };
42 return obj;
43 // return null or return otherObj works
46 public Service Test (out ArrayList a)
48 a = new ArrayList ();
49 Service obj = new Service ();
50 a.Add (obj);
51 return obj;
52 // return null or return otherObj works
57 //Bug 321420 - SoapReader fails to deserialize some method calls
58 [TestFixture]
59 public class Bug321420 : MarshalByRefObject
61 HttpChannel channel;
63 public void Method (string p1, string p2)
67 [Test]
68 public void Main ()
70 channel = new HttpChannel (3344);
71 ChannelServices.RegisterChannel (channel);
72 RemotingConfiguration.RegisterWellKnownServiceType
73 (typeof (Bug321420),"Server.soap", WellKnownObjectMode.Singleton);
75 Bug321420 s = (Bug321420) Activator.GetObject (typeof
76 (Bug321420), "http://localhost:3344/Server.soap");
78 // this works: s.Method ("a", "b");
79 s.Method ("a", "a");
82 [TestFixtureTearDown]
83 public void Stop ()
85 if (channel != null)
86 ChannelServices.UnregisterChannel (channel);
90 //Bug 315570 - Remoting over HTTP fails when returning a null reference.
91 [TestFixture]
92 public class Bug315570
94 Server server;
96 [Test]
97 [Ignore ("This test somehow keeps http channel registered and then blocks any further http tests working. This also happens under .NET, so this test itself is wrong with nunit 2.4.8.")]
98 public void Main ()
100 Foo foo = (Foo) Activator.GetObject (typeof (Foo),
101 "http://localhost:4321/Test");
103 Bar bar = foo.Login ();
104 if (bar != null)
105 bar.Foobar ();
108 [TestFixtureSetUp]
109 public void Start ()
111 AppDomain domain = BaseCallTest.CreateDomain ("testdomain");
112 server = (Server) domain.CreateInstanceAndUnwrap
113 (typeof (Server).Assembly.FullName, typeof (Server).FullName);
114 server.Start ();
117 [TestFixtureTearDown]
118 public void Stop ()
120 server.Stop ();
123 public class Foo: MarshalByRefObject
125 public Bar Login ()
127 return null;
131 public class Bar: MarshalByRefObject
133 public void Foobar ()
135 // Console.WriteLine("Bar::foo()");
139 public class Server : MarshalByRefObject
141 HttpChannel c;
143 public void Start ()
145 c = new HttpChannel (4321);
146 ChannelServices.RegisterChannel (c);
148 Type t = typeof(Foo);
149 RemotingConfiguration.RegisterWellKnownServiceType (t, "Test",
150 WellKnownObjectMode.SingleCall);
153 public void Stop ()
155 c.StopListening (null);
156 ChannelServices.UnregisterChannel (c);
161 //Bug 315170 - exception thrown in remoting if interface parameter names differ from the impelmentation method parameter names
162 [TestFixture]
163 public class Bug315170
165 Server server;
166 HttpChannel channel;
168 [Test]
169 public void Main ()
171 channel = new HttpChannel (0);
172 try {
173 ChannelServices.RegisterChannel (channel);
174 MarshalByRefObject obj = (MarshalByRefObject) RemotingServices.Connect (
175 typeof (IFactorial),
176 "http://localhost:60000/MyEndPoint");
177 IFactorial cal = (IFactorial) obj;
178 Assert.AreEqual (cal.CalculateFactorial (4), 24);
179 } finally {
180 ChannelServices.UnregisterChannel (channel);
184 [TestFixtureSetUp]
185 public void Start ()
187 AppDomain domain = BaseCallTest.CreateDomain ("testdomain");
188 server = (Server) domain.CreateInstanceAndUnwrap
189 (typeof (Server).Assembly.FullName, typeof (Server).FullName);
190 server.Start ();
193 [TestFixtureTearDown]
194 public void Stop ()
196 server.Stop ();
197 if (channel != null)
198 ChannelServices.UnregisterChannel (channel);
201 public interface IFactorial
203 // With this line everything works
204 //ulong CalculateFactorial(uint a);
205 // With this line it doesn't
206 ulong CalculateFactorial(uint b);
210 public class Server : MarshalByRefObject
212 HttpChannel c;
214 public void Start ()
216 c = new HttpChannel (60000);
217 ChannelServices.RegisterChannel (c);
219 Type t = typeof(Calculator);
220 RemotingConfiguration.RegisterWellKnownServiceType (t, "MyEndPoint",
221 WellKnownObjectMode.Singleton);
224 public void Stop ()
226 c.StopListening (null);
227 ChannelServices.UnregisterChannel (c);
231 public class Calculator : MarshalByRefObject, IFactorial
233 public ulong CalculateFactorial (uint a)
235 ulong res = 1;
236 for (uint i=1 ; i<=a; i++)
237 res = res * i;
238 return res;