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
.Default
;
22 using Castle
.ManagementExtensions
.Test
.Components
;
25 /// Summary description for MDefaultServerTestCase.
28 public class MDefaultServerTestCase
: Assertion
30 protected MDefaultServer server
= new MDefaultServer();
31 protected Type httpServerType
= typeof(DummyHttpServer
);
32 protected Type smtpServerType
= typeof(DummySmtpServer
);
35 public void TestInstantiate()
37 Object obj
= server
.Instantiate( httpServerType
.Assembly
.FullName
, httpServerType
.FullName
);
39 AssertEquals( httpServerType
, obj
.GetType() );
43 public void TestCreateManagedObject()
45 ManagedObjectName name
= new ManagedObjectName("domain.org:type=httpServer");
49 ManagedInstance inst
= server
.CreateManagedObject(
50 httpServerType
.Assembly
.FullName
, httpServerType
.FullName
, name
);
51 AssertNotNull( inst
);
52 AssertEquals( httpServerType
.FullName
, inst
.TypeName
);
53 AssertEquals( name
, inst
.Name
);
57 server
.UnregisterManagedObject( name
);
62 public void TestRegisterManagedObject()
64 ManagedObjectName name
= new ManagedObjectName("domain.org:type=httpServer");
68 Object httpServer
= server
.Instantiate( httpServerType
.Assembly
.FullName
, httpServerType
.FullName
);
70 ManagedInstance inst
= server
.RegisterManagedObject( httpServer
, name
);
71 AssertNotNull( inst
);
72 AssertEquals( httpServerType
.FullName
, inst
.TypeName
);
73 AssertEquals( name
, inst
.Name
);
77 server
.UnregisterManagedObject( name
);
82 public void TestGetManagementInfo()
84 ManagedObjectName name1
= new ManagedObjectName("domain.org:type=httpServer");
85 ManagedObjectName name2
= new ManagedObjectName("domain.net:type=smtpServer");
89 Object httpServer
= server
.Instantiate( httpServerType
.Assembly
.FullName
, httpServerType
.FullName
);
90 server
.RegisterManagedObject( httpServer
, name1
);
92 ManagementInfo info
= server
.GetManagementInfo( name1
);
93 AssertNotNull( info
);
94 AssertEquals( 3, info
.Operations
.Count
);
95 AssertEquals( 1, info
.Attributes
.Count
);
97 Object smtpServer
= server
.Instantiate( smtpServerType
.Assembly
.FullName
, smtpServerType
.FullName
);
101 server
.RegisterManagedObject( smtpServer
, name1
);
103 Fail("Should not allow register with same name.");
105 catch(InstanceAlreadyRegistredException
)
110 server
.RegisterManagedObject( smtpServer
, name2
);
112 info
= server
.GetManagementInfo( name2
);
113 AssertNotNull( info
);
114 AssertEquals( 2, info
.Operations
.Count
);
115 AssertEquals( 1, info
.Attributes
.Count
);
119 server
.UnregisterManagedObject( name1
);
120 server
.UnregisterManagedObject( name2
);
125 public void TestAttributes()
127 ManagedObjectName name
= new ManagedObjectName("domain.net:type=smtpServer");
131 Object smtpServer
= server
.Instantiate( smtpServerType
.Assembly
.FullName
, smtpServerType
.FullName
);
133 ManagedInstance inst
= server
.RegisterManagedObject( smtpServer
, name
);
135 int port
= (int) server
.GetAttribute(name
, "Port");
136 AssertEquals( 1088, port
);
138 server
.SetAttribute( name
, "Port", 25 );
140 port
= (int) server
.GetAttribute(name
, "Port");
141 AssertEquals( 25, port
);
145 server
.UnregisterManagedObject( name
);
150 public void TestInvoke()
152 ManagedObjectName name
= new ManagedObjectName("domain.org:type=httpServer");
156 Object httpServer
= server
.Instantiate( httpServerType
.Assembly
.FullName
, httpServerType
.FullName
);
158 ManagedInstance inst
= server
.RegisterManagedObject( httpServer
, name
);
160 bool state
= (bool) server
.GetAttribute(name
, "Started");
161 AssertEquals( false, state
);
163 server
.Invoke( name
, "Start", null, null );
165 state
= (bool) server
.GetAttribute(name
, "Started");
166 AssertEquals( true, state
);
168 server
.Invoke( name
, "Stop", null, null );
169 state
= (bool) server
.GetAttribute(name
, "Started");
170 AssertEquals( false, state
);
174 server
.UnregisterManagedObject( name
);