Renamed RailsException to MonoRailException
[castle.git] / Tools / ManagedExtensions / ManagementExtensionsTest / RemoteTestCase.cs
blob8413150a8a527770dcf2ef1660346d749b2e50b6
1 // Copyright 2003-2004 DigitalCraftsmen - http://www.digitalcraftsmen.com.br/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.ManagementExtensions.Test
17 using System;
19 using NUnit.Framework;
21 using Castle.ManagementExtensions;
22 using Castle.ManagementExtensions.Default;
23 using Castle.ManagementExtensions.Remote.Server;
24 using Castle.ManagementExtensions.Remote.Client;
26 /// <summary>
27 /// Summary description for RemoteTestCase.
28 /// </summary>
29 [TestFixture]
30 public class RemoteTestCase : Assertion
32 MServer server = null;
34 [SetUp]
35 public void Init()
37 server = MServerFactory.CreateServer("test", true);
40 [TearDown]
41 public void Terminate()
43 MServerFactory.Release(server);
46 [Test]
47 public void TestServerCreation()
49 MConnectorServer serverConn =
50 MConnectorServerFactory.CreateServer( "provider:http:binary:test.rem", null, null );
52 AssertNotNull( serverConn );
54 ManagedObjectName name = new ManagedObjectName("connector.http:formatter=binary");
55 server.RegisterManagedObject( serverConn, name );
57 AssertEquals( name, serverConn.ManagedObjectName );
59 AppDomain child = null;
61 try
63 child = AppDomain.CreateDomain(
64 "Child",
65 new System.Security.Policy.Evidence(AppDomain.CurrentDomain.Evidence),
66 AppDomain.CurrentDomain.SetupInformation);
68 RemoteClient client = (RemoteClient)
69 child.CreateInstanceAndUnwrap( typeof(RemoteClient).Assembly.FullName, typeof(RemoteClient).FullName );
71 AssertNotNull( client.TestClientCreation() );
73 finally
75 server.UnregisterManagedObject( name );
77 if (child != null)
79 AppDomain.Unload(child);
84 [Test]
85 public void TestTcpServerCreation()
87 System.Collections.Specialized.NameValueCollection props =
88 new System.Collections.Specialized.NameValueCollection();
89 props.Add("port", "3131");
91 MConnectorServer serverConn =
92 MConnectorServerFactory.CreateServer( "provider:tcp:binary:test.rem", props, null );
93 AssertNotNull( serverConn );
95 ManagedObjectName name = new ManagedObjectName("connector.tcp:formatter=binary");
96 server.RegisterManagedObject( serverConn, name );
98 AssertEquals( name, serverConn.ManagedObjectName );
100 AppDomain child = null;
104 child = AppDomain.CreateDomain(
105 "Child",
106 new System.Security.Policy.Evidence(AppDomain.CurrentDomain.Evidence),
107 AppDomain.CurrentDomain.SetupInformation);
109 RemoteClient client = (RemoteClient)
110 child.CreateInstanceAndUnwrap( typeof(RemoteClient).Assembly.FullName, typeof(RemoteClient).FullName );
112 AssertNotNull( client.TestTcpClientCreation() );
114 finally
116 server.UnregisterManagedObject( name );
118 if (child != null)
120 AppDomain.Unload(child);
126 public class RemoteClient : MarshalByRefObject
128 public String[] TestClientCreation()
130 using(MConnector connector = MConnectorFactory.CreateConnector( "provider:http:binary:test.rem", null ))
132 Assertion.AssertNotNull( connector );
133 Assertion.AssertNotNull( connector.ServerConnection );
135 MServer server = (MServer) connector.ServerConnection;
136 String[] domains = server.GetDomains();
137 Assertion.AssertNotNull( domains );
138 return domains;
142 public String[] TestTcpClientCreation()
144 System.Collections.Specialized.NameValueCollection props =
145 new System.Collections.Specialized.NameValueCollection();
146 props.Add("port", "3131");
148 using(MConnector connector = MConnectorFactory.CreateConnector( "provider:tcp:binary:test.rem", props ))
150 Assertion.AssertNotNull( connector );
151 Assertion.AssertNotNull( connector.ServerConnection );
153 MServer server = (MServer) connector.ServerConnection;
154 Assertion.AssertNotNull( server.GetDomains() );
155 return server.GetDomains();