Simple impl to MockRailsEngineContext.Url
[castle.git] / Tools / ManagedExtensions / ManagementExtensionsTest / MDefaultServerTestCase.cs
blobc5f5352d06240d39b7f31400ccb2d868791cd187
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.Default;
22 using Castle.ManagementExtensions.Test.Components;
24 /// <summary>
25 /// Summary description for MDefaultServerTestCase.
26 /// </summary>
27 [TestFixture]
28 public class MDefaultServerTestCase : Assertion
30 protected MDefaultServer server = new MDefaultServer();
31 protected Type httpServerType = typeof(DummyHttpServer);
32 protected Type smtpServerType = typeof(DummySmtpServer);
34 [Test]
35 public void TestInstantiate()
37 Object obj = server.Instantiate( httpServerType.Assembly.FullName, httpServerType.FullName );
38 AssertNotNull( obj );
39 AssertEquals( httpServerType, obj.GetType() );
42 [Test]
43 public void TestCreateManagedObject()
45 ManagedObjectName name = new ManagedObjectName("domain.org:type=httpServer");
47 try
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 );
55 finally
57 server.UnregisterManagedObject( name );
61 [Test]
62 public void TestRegisterManagedObject()
64 ManagedObjectName name = new ManagedObjectName("domain.org:type=httpServer");
66 try
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 );
75 finally
77 server.UnregisterManagedObject( name );
81 [Test]
82 public void TestGetManagementInfo()
84 ManagedObjectName name1 = new ManagedObjectName("domain.org:type=httpServer");
85 ManagedObjectName name2 = new ManagedObjectName("domain.net:type=smtpServer");
87 try
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 );
99 try
101 server.RegisterManagedObject( smtpServer, name1 );
103 Fail("Should not allow register with same name.");
105 catch(InstanceAlreadyRegistredException)
107 // OK
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 );
117 finally
119 server.UnregisterManagedObject( name1 );
120 server.UnregisterManagedObject( name2 );
124 [Test]
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 );
143 finally
145 server.UnregisterManagedObject( name );
149 [Test]
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 );
172 finally
174 server.UnregisterManagedObject( name );