1 // Copyright 2003-2004 DigitalCraftsmen - http://www.digitalcraftsmen.com.br/
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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
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
;
27 /// Summary description for RemoteTestCase.
30 public class RemoteTestCase
: Assertion
32 MServer server
= null;
37 server
= MServerFactory
.CreateServer("test", true);
41 public void Terminate()
43 MServerFactory
.Release(server
);
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;
63 child
= AppDomain
.CreateDomain(
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() );
75 server
.UnregisterManagedObject( name
);
79 AppDomain
.Unload(child
);
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(
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() );
116 server
.UnregisterManagedObject( name
);
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
);
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();