hammett 2004/04/03 14:58:31 Modified: avalon-net/Castle/MicroKernel/MicroKernelTest BaseKernelTestCase.cs MicroKernelTest.csproj SimpleComponentFactoryTestCase.cs avalon-net/Castle/MicroKernel/MicroKernelTest/Components AvalonMailService.cs AvalonSpamService.cs SimpleMailService.cs Added: avalon-net/Castle/MicroKernel/MicroKernelTest AbstractHandlerTestCase.cs AssemblerTestCase.cs ConcernManagerTestCase.cs DefaultComponentModelBuilderTestCase.cs DefaultKernelTestCase.cs avalon-net/Castle/MicroKernel/MicroKernelTest/Components AvalonSpamService2.cs AvalonSpamService3.cs ISpamService2.cs SimpleMailServiceWithLogger.cs avalon-net/Castle/MicroKernel/MicroKernelTest/Concerns AbstractConcernTestCase.cs ConfigureConcernTestCase.cs ContextConcernTestCase.cs EnableLoggerConcernTestCase.cs EnableLookupConcernTestCase.cs InitializeConcernTestCase.cs ShutdownConcernTestCase.cs StartConcernTestCase.cs Log: MicroKernel for Avalon Castle - Test Cases. Revision Changes Path 1.2 +20 -2 avalon-sandbox/avalon-net/Castle/MicroKernel/MicroKernelTest/BaseKernelTestCase.cs Index: BaseKernelTestCase.cs =================================================================== RCS file: /home/cvs/avalon-sandbox/avalon-net/Castle/MicroKernel/MicroKernelTest/BaseKernelTestCase.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- BaseKernelTestCase.cs 31 Mar 2004 00:43:30 -0000 1.1 +++ BaseKernelTestCase.cs 3 Apr 2004 22:58:30 -0000 1.2 @@ -47,7 +47,25 @@ service.Send("hammett at apache dot org", "johndoe at yahoo dot org", "Aloha!", "What's up?"); - handler.Release( ); + handler.Release( service ); + } + + [Test] + public void ComponentDependingOnLogger() + { + BaseKernel container = new BaseKernel(); + container.AddComponent( "a", typeof(IMailService), typeof(SimpleMailServiceWithLogger) ); + + IHandler handler = container[ "a" ]; + + IMailService service = handler.Resolve() as IMailService; + + AssertNotNull( service ); + + service.Send("hammett at apache dot org", + "johndoe at yahoo dot org", "Aloha!", "What's up?"); + + handler.Release( service ); } /// <summary> @@ -75,7 +93,7 @@ service.Send("hammett at apache dot org", "johndoe at yahoo dot org", "Aloha!", "What's up?"); - handler.Release( ); + handler.Release( service ); AssertEquals( 2, aspect.m_invocations.Count ); AssertEquals( "Before Send", aspect.m_invocations[0] ); 1.3 +85 -0 avalon-sandbox/avalon-net/Castle/MicroKernel/MicroKernelTest/MicroKernelTest.csproj Index: MicroKernelTest.csproj =================================================================== RCS file: /home/cvs/avalon-sandbox/avalon-net/Castle/MicroKernel/MicroKernelTest/MicroKernelTest.csproj,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- MicroKernelTest.csproj 31 Mar 2004 03:45:08 -0000 1.2 +++ MicroKernelTest.csproj 3 Apr 2004 22:58:30 -0000 1.3 @@ -99,6 +99,16 @@ <Files> <Include> <File + RelPath = "AbstractHandlerTestCase.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "AssemblerTestCase.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "AssemblyInfo.cs" SubType = "Code" BuildAction = "Compile" @@ -109,6 +119,21 @@ BuildAction = "Compile" /> <File + RelPath = "ConcernManagerTestCase.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "DefaultComponentModelBuilderTestCase.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "DefaultKernelTestCase.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "SimpleComponentFactoryTestCase.cs" SubType = "Code" BuildAction = "Compile" @@ -124,6 +149,16 @@ BuildAction = "Compile" /> <File + RelPath = "Components\AvalonSpamService2.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Components\AvalonSpamService3.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "Components\ICustomerManager.cs" SubType = "Code" BuildAction = "Compile" @@ -144,6 +179,11 @@ BuildAction = "Compile" /> <File + RelPath = "Components\ISpamService2.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "Components\SimpleCustomerManager.cs" SubType = "Code" BuildAction = "Compile" @@ -159,7 +199,52 @@ BuildAction = "Compile" /> <File + RelPath = "Components\SimpleMailServiceWithLogger.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "Components\SimpleSpamService.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Concerns\AbstractConcernTestCase.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Concerns\ConfigureConcernTestCase.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Concerns\ContextConcernTestCase.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Concerns\EnableLoggerConcernTestCase.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Concerns\EnableLookupConcernTestCase.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Concerns\InitializeConcernTestCase.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Concerns\ShutdownConcernTestCase.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Concerns\StartConcernTestCase.cs" SubType = "Code" BuildAction = "Compile" /> 1.3 +16 -18 avalon-sandbox/avalon-net/Castle/MicroKernel/MicroKernelTest/SimpleComponentFactoryTestCase.cs Index: SimpleComponentFactoryTestCase.cs =================================================================== RCS file: /home/cvs/avalon-sandbox/avalon-net/Castle/MicroKernel/MicroKernelTest/SimpleComponentFactoryTestCase.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- SimpleComponentFactoryTestCase.cs 31 Mar 2004 03:45:08 -0000 1.2 +++ SimpleComponentFactoryTestCase.cs 3 Apr 2004 22:58:30 -0000 1.3 @@ -22,6 +22,10 @@ using Apache.Avalon.Castle.MicroKernel; using Apache.Avalon.Castle.MicroKernel.Factory; + using Apache.Avalon.Castle.MicroKernel.Factory.Default; + using Apache.Avalon.Castle.MicroKernel.Handler; + using Apache.Avalon.Castle.MicroKernel.Model; + using Apache.Avalon.Castle.MicroKernel.Model.Default; using Apache.Avalon.Castle.MicroKernel.Test.Components; /// <summary> @@ -30,7 +34,7 @@ [TestFixture] public class SimpleComponentFactoryTestCase : Assertion { - BaseKernel kernel; + private BaseKernel kernel; [SetUp] public void CreateKernel() @@ -46,18 +50,17 @@ kernel.AddComponent( "a", service, implementation ); - ConstructorInfo constructor = implementation.GetConstructor( Type.EmptyTypes ); - ConstructionInfo info = new ConstructionInfo( constructor, null ); + IComponentModel model = new DefaultComponentModelBuilder(kernel).BuildModel( "a", service, implementation ); SimpleComponentFactory factory = new SimpleComponentFactory( - service, implementation, new IAspect[0], new IAspect[0], info ); + new IAspect[0], new IAspect[0], model, new Hashtable() ); Object instance = factory.Incarnate(); AssertNotNull( instance ); AssertNotNull( instance as IMailService ); - factory.Etherialize(); + factory.Etherialize( instance ); } [Test] @@ -71,16 +74,14 @@ kernel.AddComponent( "a", service, implementation ); kernel.AddComponent( "b", serviceDep, implementationDep ); - ConstructorInfo constructor = - implementation.GetConstructor( new Type[] { typeof(IMailService) } ); + IComponentModel model = new DefaultComponentModelBuilder(kernel).BuildModel( + "a", service, implementation ); Hashtable serv2Handler = new Hashtable(); serv2Handler[ serviceDep ] = kernel.GetHandlerForService( serviceDep ); - ConstructionInfo info = new ConstructionInfo( constructor, serv2Handler ); - SimpleComponentFactory factory = new SimpleComponentFactory( - service, implementation, new IAspect[0], new IAspect[0], info ); + new IAspect[0], new IAspect[0], model, serv2Handler ); Object instance = factory.Incarnate(); @@ -90,7 +91,7 @@ SimpleSpamService spamService = (SimpleSpamService) instance; AssertNotNull( spamService.m_mailService ); - factory.Etherialize(); + factory.Etherialize( instance ); } [Test] @@ -107,18 +108,15 @@ kernel.AddComponent( "b", serviceDep1, implementationDep1 ); kernel.AddComponent( "c", serviceDep2, implementationDep2 ); - ConstructorInfo constructor = - implementation.GetConstructor( Type.EmptyTypes ); + IComponentModel model = new DefaultComponentModelBuilder(kernel).BuildModel( + "a", service, implementation ); Hashtable serv2Handler = new Hashtable(); serv2Handler[ serviceDep1 ] = kernel.GetHandlerForService( serviceDep1 ); serv2Handler[ serviceDep2 ] = kernel.GetHandlerForService( serviceDep2 ); - ConstructionInfo info = new ConstructionInfo( constructor, serv2Handler ); - info.Properties = service.GetProperties(); - SimpleComponentFactory factory = new SimpleComponentFactory( - service, implementation, new IAspect[0], new IAspect[0], info ); + new IAspect[0], new IAspect[0], model, serv2Handler ); Object instance = factory.Incarnate(); @@ -131,7 +129,7 @@ mailMarketing.AnnoyMillionsOfPeople( "Say something" ); - factory.Etherialize(); + factory.Etherialize( instance ); } } } 1.1 avalon-sandbox/avalon-net/Castle/MicroKernel/MicroKernelTest/AbstractHandlerTestCase.cs Index: AbstractHandlerTestCase.cs =================================================================== // Copyright 2004 The Apache Software Foundation // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. namespace Apache.Avalon.Castle.MicroKernel.Test { using System; using NUnit.Framework; using Apache.Avalon.Castle.MicroKernel.Model; using Apache.Avalon.Castle.MicroKernel.Model.Default; using Apache.Avalon.Castle.MicroKernel.Handler; using Apache.Avalon.Castle.MicroKernel.Handler.Default; using Apache.Avalon.Castle.MicroKernel.Test.Components; /// <summary> /// Summary description for AbstractHandlerTestCase. /// </summary> [TestFixture] public class AbstractHandlerTestCase : Assertion { private Kernel kernel = new DefaultKernel(); private Type service = typeof( IMailService ); private Type implementation = typeof( SimpleMailService ); private IComponentModel model; [SetUp] public void Init() { model = new DefaultComponentModelBuilder(kernel).BuildModel( "a", service, implementation ); } [Test] public void TransientReferences() { MyHandler handler = new MyHandler( model ); object instance = handler.Resolve(); AssertNotNull( instance ); Assert( handler.IsOwner( instance ) ); handler.Release( instance ); Assert( !handler.IsOwner( instance ) ); } [Test] public void MultipleTransientReferences() { MyHandler handler = new MyHandler( model ); object instance1 = handler.Resolve(); object instance2 = handler.Resolve(); object instance3 = handler.Resolve(); AssertNotNull( instance1 ); AssertNotNull( instance2 ); AssertNotNull( instance3 ); Assert( handler.IsOwner( instance1 ) ); Assert( handler.IsOwner( instance2 ) ); Assert( handler.IsOwner( instance3 ) ); Assert( !handler.IsOwner( new object() ) ); handler.Release( instance3 ); Assert( !handler.IsOwner( instance3 ) ); handler.Release( instance2 ); Assert( !handler.IsOwner( instance2 ) ); handler.Release( instance1 ); Assert( !handler.IsOwner( instance1 ) ); } public class MyHandler : AbstractHandler { public MyHandler( IComponentModel model ) : base( model ) { } public override object Resolve() { object instance = new object(); base.RegisterInstance( instance ); return instance; } public override void Release(object instance) { if (IsOwner( instance )) { UnregisterInstance(instance); } } } [Test] public void SingletonReferences() { MySingletonHandler handler = new MySingletonHandler( model ); object instance1 = handler.Resolve(); object instance2 = handler.Resolve(); AssertNotNull( instance1 ); AssertNotNull( instance2 ); AssertEquals( instance1, instance2 ); Assert( handler.IsOwner( instance1 ) ); Assert( handler.IsOwner( instance2 ) ); handler.Release( instance1 ); handler.Release( instance2 ); Assert( !handler.IsOwner( instance1 ) ); Assert( !handler.IsOwner( instance2 ) ); } public class MySingletonHandler : AbstractHandler { public object instance = new object(); public MySingletonHandler( IComponentModel model ) : base( model ) { } public override object Resolve() { base.RegisterInstance( instance ); return instance; } public override void Release(object instance) { if (IsOwner( instance )) { UnregisterInstance(instance); } } } } } 1.1 avalon-sandbox/avalon-net/Castle/MicroKernel/MicroKernelTest/AssemblerTestCase.cs Index: AssemblerTestCase.cs =================================================================== // Copyright 2004 The Apache Software Foundation // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. namespace Apache.Avalon.Castle.MicroKernel.Test { using System; using NUnit.Framework; /// <summary> /// Summary description for AssemblerTestCase. /// </summary> public class AssemblerTestCase : Assertion { public void BuildingConstructorArgs() { // object[] arguments = Assembler.BuildConstructorArguments( model ); // Assembler.AssembleProperties( properties, model ); } public void AssembleProperties() { } } } 1.1 avalon-sandbox/avalon-net/Castle/MicroKernel/MicroKernelTest/ConcernManagerTestCase.cs Index: ConcernManagerTestCase.cs =================================================================== // Copyright 2004 The Apache Software Foundation // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. namespace Apache.Avalon.Castle.MicroKernel.Test { using System; using NUnit.Framework; using Apache.Avalon.Castle.MicroKernel.Concerns; using Apache.Avalon.Castle.MicroKernel.Concerns.Default; /// <summary> /// Summary description for ConcernManagerTestCase. /// </summary> [TestFixture] public class ConcernManagerTestCase : Assertion { private Kernel m_kernel; [SetUp] public void CreateKernel() { m_kernel = new DefaultKernel(); } [Test] public void Creation() { ConcernManager manager = new ConcernManager(); AssertNotNull( manager ); } [Test] public void GetDefaultCommissionChain() { ConcernManager manager = new ConcernManager(); IConcern concern = manager.GetCommissionChain( m_kernel ); AssertNotNull( concern ); AssertNotNull( concern is ICreationConcern ); AssertNotNull( concern is CreationConcern ); AssertNotNull( concern.Next ); concern = concern.Next; AssertNotNull( concern ); AssertNotNull( concern is ICommissionConcern ); AssertNotNull( concern is EnableLoggerConcern ); concern = concern.Next; AssertNotNull( concern ); AssertNotNull( concern is ICommissionConcern ); AssertNotNull( concern is ContextConcern ); concern = concern.Next; AssertNotNull( concern ); AssertNotNull( concern is ICommissionConcern ); AssertNotNull( concern is EnableLookupConcern ); concern = concern.Next; AssertNotNull( concern ); AssertNotNull( concern is ICommissionConcern ); AssertNotNull( concern is ConfigureConcern ); concern = concern.Next; AssertNotNull( concern ); AssertNotNull( concern is ICommissionConcern ); AssertNotNull( concern is InitializeConcern ); concern = concern.Next; AssertNotNull( concern ); AssertNotNull( concern is ICommissionConcern ); AssertNotNull( concern is StartConcern ); AssertNull( concern.Next ); } [Test] public void GetDefaultDecommissionChain() { ConcernManager manager = new ConcernManager(); IConcern concern = manager.GetDecommissionChain( m_kernel ); AssertNotNull( concern ); AssertNotNull( concern is IDecommissionConcern ); AssertNotNull( concern is ShutdownConcern ); AssertNull( concern.Next ); } } } 1.1 avalon-sandbox/avalon-net/Castle/MicroKernel/MicroKernelTest/DefaultComponentModelBuilderTestCase.cs Index: DefaultComponentModelBuilderTestCase.cs =================================================================== // Copyright 2004 The Apache Software Foundation // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. namespace Apache.Avalon.Castle.MicroKernel.Test { using System; using NUnit.Framework; using Apache.Avalon.Castle.MicroKernel; using Apache.Avalon.Castle.MicroKernel.Model; using Apache.Avalon.Castle.MicroKernel.Model.Default; using Apache.Avalon.Castle.MicroKernel.Test.Components; /// <summary> /// Summary description for DefaultComponentModelBuilderTestCase. /// </summary> [TestFixture] public class DefaultComponentModelBuilderTestCase : Assertion { private Kernel m_kernel; [SetUp] public void CreateKernel() { m_kernel = new BaseKernel(); } [Test] public void SimpleComponent() { DefaultComponentModelBuilder builder = new DefaultComponentModelBuilder( m_kernel ); Type service = typeof( IMailService ); Type implementation = typeof( SimpleMailService ); IComponentModel model = builder.BuildModel( "a", service, implementation ); AssertNotNull( model ); AssertNotNull( model.Logger ); AssertNotNull( model.Configuration ); AssertNotNull( model.Context ); AssertNotNull( model.Dependencies ); AssertEquals( 0, model.Dependencies.Length ); } [Test] public void DependencyInConstructor() { DefaultComponentModelBuilder builder = new DefaultComponentModelBuilder( m_kernel ); Type service = typeof( ISpamService ); Type implementation = typeof( SimpleSpamService ); IComponentModel model = builder.BuildModel( "a", service, implementation ); AssertNotNull( model ); AssertNotNull( model.Logger ); AssertNotNull( model.Configuration ); AssertNotNull( model.Context ); AssertNotNull( model.Dependencies ); AssertEquals( 1, model.Dependencies.Length ); } [Test] public void DependencyInSetters() { DefaultComponentModelBuilder builder = new DefaultComponentModelBuilder( m_kernel ); Type service = typeof( IMailMarketingService ); Type implementation = typeof( SimpleMailMarketingService ); IComponentModel model = builder.BuildModel( "a", service, implementation ); AssertNotNull( model ); AssertNotNull( model.Logger ); AssertNotNull( model.Configuration ); AssertNotNull( model.Context ); AssertNotNull( model.Dependencies ); AssertEquals( 2, model.Dependencies.Length ); } [Test] public void AvalonSimpleService() { DefaultComponentModelBuilder builder = new DefaultComponentModelBuilder( m_kernel ); Type service = typeof( IMailService ); Type implementation = typeof( AvalonMailService ); IComponentModel model = builder.BuildModel( "a", service, implementation ); AssertNotNull( model ); AssertNotNull( model.Logger ); AssertNotNull( model.Configuration ); AssertNotNull( model.Context ); AssertNotNull( model.Dependencies ); AssertEquals( 0, model.Dependencies.Length ); } [Test] public void AvalonServiceWithDependencies() { DefaultComponentModelBuilder builder = new DefaultComponentModelBuilder( m_kernel ); Type service = typeof( ISpamService ); Type implementation = typeof( AvalonSpamService ); IComponentModel model = builder.BuildModel( "a", service, implementation ); AssertNotNull( model ); AssertNotNull( model.Logger ); AssertNotNull( model.Configuration ); AssertNotNull( model.Context ); AssertNotNull( model.Dependencies ); AssertEquals( 1, model.Dependencies.Length ); } } } 1.1 avalon-sandbox/avalon-net/Castle/MicroKernel/MicroKernelTest/DefaultKernelTestCase.cs Index: DefaultKernelTestCase.cs =================================================================== // Copyright 2004 The Apache Software Foundation // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. namespace Apache.Avalon.Castle.MicroKernel.Test { using System; using NUnit.Framework; using Apache.Avalon.Castle.MicroKernel.Test.Components; /// <summary> /// Summary description for DefaultKernelTestCase. /// </summary> [TestFixture] public class DefaultKernelTestCase : Assertion { [Test] public void Creation() { DefaultKernel kernel = new DefaultKernel(); AssertNotNull(kernel); } /// <summary> /// Just a simple Service resolution. /// No concerns or aspects involved. /// </summary> [Test] public void SimpleUsage() { AvalonKernel container = new DefaultKernel(); container.AddComponent( "a", typeof(IMailService), typeof(SimpleMailService) ); IHandler handler = container[ "a" ]; IMailService service = handler.Resolve() as IMailService; AssertNotNull( service ); service.Send("hammett at apache dot org", "johndoe at yahoo dot org", "Aloha!", "What's up?"); handler.Release( service ); } [Test] public void SimpleAvalonComponent() { AvalonKernel container = new DefaultKernel(); container.AddComponent( "a", typeof(IMailService), typeof(AvalonMailService) ); IHandler handler = container[ "a" ]; IMailService service = handler.Resolve() as IMailService; AssertNotNull( service ); AvalonMailService realInstance = (AvalonMailService) service; Assert( realInstance.initialized ); Assert( realInstance.configured ); Assert( !realInstance.disposed ); service.Send("hammett at apache dot org", "johndoe at yahoo dot org", "Aloha!", "What's up?"); handler.Release( service ); Assert( realInstance.disposed ); } [Test] public void AvalonComponentWithDependencies() { AvalonKernel container = new DefaultKernel(); container.AddComponent( "a", typeof(IMailService), typeof(AvalonMailService) ); container.AddComponent( "b", typeof(ISpamService), typeof(AvalonSpamService) ); IHandler handler = container[ "b" ]; ISpamService service = handler.Resolve() as ISpamService; AssertNotNull( service ); service.AnnoyPeople( "Work at home and earn a thousand dollars per second!" ); handler.Release( service ); } [Test] public void HybridAvalonComponent() { AvalonKernel container = new DefaultKernel(); container.AddComponent( "a", typeof(IMailService), typeof(AvalonMailService) ); container.AddComponent( "b", typeof(ISpamService), typeof(AvalonSpamService2) ); IHandler handler = container[ "b" ]; ISpamService service = handler.Resolve() as ISpamService; AssertNotNull( service ); service.AnnoyPeople( "Work at home and earn a thousand dollars per second!" ); handler.Release( service ); } [Test] public void HybridAvalonComponentUsingSetters() { AvalonKernel container = new DefaultKernel(); container.AddComponent( "a", typeof(IMailService), typeof(AvalonMailService) ); container.AddComponent( "b", typeof(ISpamService2), typeof(AvalonSpamService3) ); IHandler handler = container[ "b" ]; ISpamService service = handler.Resolve() as ISpamService; AssertNotNull( service ); service.AnnoyPeople( "Work at home and earn a thousand dollars per second!" ); handler.Release( service ); } } } 1.2 +9 -0 avalon-sandbox/avalon-net/Castle/MicroKernel/MicroKernelTest/Components/AvalonMailService.cs Index: AvalonMailService.cs =================================================================== RCS file: /home/cvs/avalon-sandbox/avalon-net/Castle/MicroKernel/MicroKernelTest/Components/AvalonMailService.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- AvalonMailService.cs 31 Mar 2004 00:43:30 -0000 1.1 +++ AvalonMailService.cs 3 Apr 2004 22:58:30 -0000 1.2 @@ -21,8 +21,14 @@ /// <summary> /// Summary description for AvalonMailService. /// </summary> + [AvalonComponent("mailservice", Lifestyle.Singleton)] + [AvalonService( typeof(IMailService) )] public class AvalonMailService : IMailService, IInitializable, IConfigurable, IDisposable { + public bool initialized; + public bool configured; + public bool disposed; + public AvalonMailService() { } @@ -39,6 +45,7 @@ public void Initialize() { + initialized = true; } #endregion @@ -47,6 +54,7 @@ public void Configure(IConfiguration config) { + configured = true; } #endregion @@ -55,6 +63,7 @@ public void Dispose() { + disposed = true; } #endregion 1.2 +4 -1 avalon-sandbox/avalon-net/Castle/MicroKernel/MicroKernelTest/Components/AvalonSpamService.cs Index: AvalonSpamService.cs =================================================================== RCS file: /home/cvs/avalon-sandbox/avalon-net/Castle/MicroKernel/MicroKernelTest/Components/AvalonSpamService.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- AvalonSpamService.cs 31 Mar 2004 00:43:31 -0000 1.1 +++ AvalonSpamService.cs 3 Apr 2004 22:58:30 -0000 1.2 @@ -36,7 +36,10 @@ public void AnnoyPeople(String contents) { - // TODO: Add AvalonSpamService.AnnoyPeople implementation + if (m_mailService == null) + { + throw new Exception("Dependency not satisfied."); + } } #endregion 1.2 +0 -1 avalon-sandbox/avalon-net/Castle/MicroKernel/MicroKernelTest/Components/SimpleMailService.cs Index: SimpleMailService.cs =================================================================== RCS file: /home/cvs/avalon-sandbox/avalon-net/Castle/MicroKernel/MicroKernelTest/Components/SimpleMailService.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- SimpleMailService.cs 31 Mar 2004 00:43:31 -0000 1.1 +++ SimpleMailService.cs 3 Apr 2004 22:58:30 -0000 1.2 @@ -21,7 +21,6 @@ /// </summary> public class SimpleMailService : IMailService { - public SimpleMailService() { } 1.1 avalon-sandbox/avalon-net/Castle/MicroKernel/MicroKernelTest/Components/AvalonSpamService2.cs Index: AvalonSpamService2.cs =================================================================== // Copyright 2004 The Apache Software Foundation // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. namespace Apache.Avalon.Castle.MicroKernel.Test.Components { using System; using Apache.Avalon.Framework; /// <summary> /// Summary description for AvalonSpamService2. /// </summary> [AvalonComponent("spamservice2", Lifestyle.Singleton)] [AvalonService( typeof(ISpamService) )] public class AvalonSpamService2 : ISpamService, IInitializable { public IMailService m_mailService; public AvalonSpamService2(IMailService mailservice) { m_mailService = mailservice; } #region ISpamService Members public void AnnoyPeople(String contents) { if (m_mailService == null) { throw new Exception("Dependency not satisfied."); } } #endregion #region IInitializable Members public void Initialize() { } #endregion } } 1.1 avalon-sandbox/avalon-net/Castle/MicroKernel/MicroKernelTest/Components/AvalonSpamService3.cs Index: AvalonSpamService3.cs =================================================================== // Copyright 2004 The Apache Software Foundation // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. namespace Apache.Avalon.Castle.MicroKernel.Test.Components { using System; using Apache.Avalon.Framework; /// <summary> /// Summary description for AvalonSpamService3. /// </summary> [AvalonComponent("spamservice2", Lifestyle.Singleton)] [AvalonService( typeof(ISpamService2) )] public class AvalonSpamService3 : IInitializable, ISpamService2 { public IMailService m_mailService; public AvalonSpamService3() { } #region IInitializable Members public void Initialize() { } #endregion #region ISpamService2 Members public IMailService MailService { get { return m_mailService; } set { m_mailService = value; } } #endregion #region ISpamService Members public void AnnoyPeople(String contents) { if (m_mailService == null) { throw new Exception("Dependency not satisfied."); } } #endregion } } 1.1 avalon-sandbox/avalon-net/Castle/MicroKernel/MicroKernelTest/Components/ISpamService2.cs Index: ISpamService2.cs =================================================================== // Copyright 2004 The Apache Software Foundation // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. namespace Apache.Avalon.Castle.MicroKernel.Test.Components { using System; /// <summary> /// Summary description for ISpamService2. /// </summary> public interface ISpamService2 : ISpamService { IMailService MailService { get; set; } } } 1.1 avalon-sandbox/avalon-net/Castle/MicroKernel/MicroKernelTest/Components/SimpleMailServiceWithLogger.cs Index: SimpleMailServiceWithLogger.cs =================================================================== // Copyright 2004 The Apache Software Foundation // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. namespace Apache.Avalon.Castle.MicroKernel.Test.Components { using System; using Apache.Avalon.Framework; /// <summary> /// Summary description for SimpleMailServiceWithLogger. /// </summary> public class SimpleMailServiceWithLogger : SimpleMailService { public SimpleMailServiceWithLogger( ILogger logger ) { } } } 1.1 avalon-sandbox/avalon-net/Castle/MicroKernel/MicroKernelTest/Concerns/AbstractConcernTestCase.cs Index: AbstractConcernTestCase.cs =================================================================== // Copyright 2004 The Apache Software Foundation // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. namespace Apache.Avalon.Castle.MicroKernel.Test.Concerns { using System; using NUnit.Framework; using Apache.Avalon.Framework; using Apache.Avalon.Castle.MicroKernel.Model; using Apache.Avalon.Castle.MicroKernel.Model.Default; using Apache.Avalon.Castle.MicroKernel.Concerns; /// <summary> /// Summary description for AbstractConcernTestCase. /// </summary> public abstract class AbstractConcernTestCase : Assertion { protected Kernel m_kernel = new DefaultKernel(); public abstract IConcern Create(); public abstract void AssertComponent( IComponentModel model, DummyComponent component ); [Test] public void TestApply() { IConcern concern = Create(); AssertNotNull( concern ); concern.Init( m_kernel ); IComponentModel model = new DefaultComponentModelBuilder(m_kernel).BuildModel( "a", typeof(IMyService), typeof(DummyComponent) ); DummyComponent component = new DummyComponent(); concern.Apply( model, component ); AssertComponent( model, component ); } } public interface IMyService { } public class DummyComponent : IMyService, ILogEnabled, IConfigurable, IInitializable, IStartable, IContextualizable, IDisposable, ILookupEnabled { public bool logEnabled; public bool configure; public bool context; public bool initialize; public bool start; public bool stop; public bool dispose; public bool lookup; #region ILogEnabled Members public void EnableLogging(ILogger logger) { logEnabled = true; } #endregion #region IConfigurable Members public void Configure(IConfiguration config) { configure = true; } #endregion #region IInitializable Members public void Initialize() { initialize = true; } #endregion #region IStartable Members public void Start() { start = true; } public void Stop() { stop = true; } #endregion #region IContextualizable Members public void Contextualize(IContext arg) { context = true; } #endregion #region IDisposable Members public void Dispose() { dispose = true; } #endregion #region ILookupEnabled Members public void EnableLookups(ILookupManager manager) { lookup = true; } #endregion } } 1.1 avalon-sandbox/avalon-net/Castle/MicroKernel/MicroKernelTest/Concerns/ConfigureConcernTestCase.cs Index: ConfigureConcernTestCase.cs =================================================================== // Copyright 2004 The Apache Software Foundation // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. namespace Apache.Avalon.Castle.MicroKernel.Test.Concerns { using System; using NUnit.Framework; using Apache.Avalon.Castle.MicroKernel.Model; using Apache.Avalon.Castle.MicroKernel.Concerns; using Apache.Avalon.Castle.MicroKernel.Concerns.Default; /// <summary> /// Summary description for ConfigureConcernTestCase. /// </summary> [TestFixture] public class ConfigureConcernTestCase : AbstractConcernTestCase { public override IConcern Create() { return new ConfigureConcern( null ); } public override void AssertComponent( IComponentModel model, DummyComponent component ) { Assert( component.configure ); } } } 1.1 avalon-sandbox/avalon-net/Castle/MicroKernel/MicroKernelTest/Concerns/ContextConcernTestCase.cs Index: ContextConcernTestCase.cs =================================================================== // Copyright 2004 The Apache Software Foundation // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. namespace Apache.Avalon.Castle.MicroKernel.Test.Concerns { using System; using NUnit.Framework; using Apache.Avalon.Castle.MicroKernel.Model; using Apache.Avalon.Castle.MicroKernel.Concerns; using Apache.Avalon.Castle.MicroKernel.Concerns.Default; /// <summary> /// Summary description for ContextConcernTestCase. /// </summary> [TestFixture] public class ContextConcernTestCase : AbstractConcernTestCase { public override IConcern Create() { return new ContextConcern( null ); } public override void AssertComponent( IComponentModel model, DummyComponent component ) { Assert( component.context ); } } } 1.1 avalon-sandbox/avalon-net/Castle/MicroKernel/MicroKernelTest/Concerns/EnableLoggerConcernTestCase.cs Index: EnableLoggerConcernTestCase.cs =================================================================== // Copyright 2004 The Apache Software Foundation // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. namespace Apache.Avalon.Castle.MicroKernel.Test.Concerns { using System; using NUnit.Framework; using Apache.Avalon.Castle.MicroKernel.Model; using Apache.Avalon.Castle.MicroKernel.Concerns; using Apache.Avalon.Castle.MicroKernel.Concerns.Default; /// <summary> /// Summary description for EnableLoggerConcernTestCase. /// </summary> [TestFixture] public class EnableLoggerConcernTestCase : AbstractConcernTestCase { public override IConcern Create() { return new EnableLoggerConcern( null ); } public override void AssertComponent( IComponentModel model, DummyComponent component ) { Assert( component.logEnabled ); } } } 1.1 avalon-sandbox/avalon-net/Castle/MicroKernel/MicroKernelTest/Concerns/EnableLookupConcernTestCase.cs Index: EnableLookupConcernTestCase.cs =================================================================== // Copyright 2004 The Apache Software Foundation // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. namespace Apache.Avalon.Castle.MicroKernel.Test.Concerns { using System; using NUnit.Framework; using Apache.Avalon.Castle.MicroKernel.Model; using Apache.Avalon.Castle.MicroKernel.Concerns; using Apache.Avalon.Castle.MicroKernel.Concerns.Default; /// <summary> /// Summary description for EnableLookupConcernTestCase. /// </summary> [TestFixture] public class EnableLookupConcernTestCase : AbstractConcernTestCase { public override IConcern Create() { return new EnableLookupConcern( null ); } public override void AssertComponent( IComponentModel model, DummyComponent component ) { Assert( component.lookup ); } } } 1.1 avalon-sandbox/avalon-net/Castle/MicroKernel/MicroKernelTest/Concerns/InitializeConcernTestCase.cs Index: InitializeConcernTestCase.cs =================================================================== // Copyright 2004 The Apache Software Foundation // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. namespace Apache.Avalon.Castle.MicroKernel.Test.Concerns { using System; using NUnit.Framework; using Apache.Avalon.Castle.MicroKernel.Model; using Apache.Avalon.Castle.MicroKernel.Concerns; using Apache.Avalon.Castle.MicroKernel.Concerns.Default; /// <summary> /// Summary description for InitializeConcernTestCase. /// </summary> [TestFixture] public class InitializeConcernTestCase : AbstractConcernTestCase { public override IConcern Create() { return new InitializeConcern( null ); } public override void AssertComponent( IComponentModel model, DummyComponent component ) { Assert( component.initialize ); } } } 1.1 avalon-sandbox/avalon-net/Castle/MicroKernel/MicroKernelTest/Concerns/ShutdownConcernTestCase.cs Index: ShutdownConcernTestCase.cs =================================================================== // Copyright 2004 The Apache Software Foundation // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. namespace Apache.Avalon.Castle.MicroKernel.Test.Concerns { using System; using NUnit.Framework; using Apache.Avalon.Castle.MicroKernel.Model; using Apache.Avalon.Castle.MicroKernel.Concerns; using Apache.Avalon.Castle.MicroKernel.Concerns.Default; /// <summary> /// Summary description for ShutdownConcernTestCase. /// </summary> [TestFixture] public class ShutdownConcernTestCase : AbstractConcernTestCase { public override IConcern Create() { return new ShutdownConcern( null ); } public override void AssertComponent( IComponentModel model, DummyComponent component ) { Assert( component.stop ); Assert( component.dispose ); } } } 1.1 avalon-sandbox/avalon-net/Castle/MicroKernel/MicroKernelTest/Concerns/StartConcernTestCase.cs Index: StartConcernTestCase.cs =================================================================== // Copyright 2004 The Apache Software Foundation // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. namespace Apache.Avalon.Castle.MicroKernel.Test.Concerns { using System; using NUnit.Framework; using Apache.Avalon.Castle.MicroKernel.Model; using Apache.Avalon.Castle.MicroKernel.Concerns; using Apache.Avalon.Castle.MicroKernel.Concerns.Default; /// <summary> /// Summary description for StartConcernTestCase. /// </summary> [TestFixture] public class StartConcernTestCase : AbstractConcernTestCase { public override IConcern Create() { return new StartConcern( null ); } public override void AssertComponent( IComponentModel model, DummyComponent component ) { Assert( component.start ); } } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]