Author: hammett Date: Fri Sep 3 19:57:24 2004 New Revision: 43311 Added: avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/MicroKernelTest/AssertUtilTestCase.cs (contents, props changed) avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/MicroKernelTest/Lifestyle/Components/CustomComponent.cs avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/MicroKernelTest/Model/ avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/MicroKernelTest/Model/DefaultComponentModelBuilderTestCase.cs (contents, props changed) Modified: avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/AbstractKernelEvents.cs avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/Apache.Avalon.Castle.MicroKernel.csproj avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/AssertUtil.cs avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/BaseKernel.cs avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/Lifestyle/UnsupportedLifestyleException.cs avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/MicroKernelTest/Apache.Avalon.Castle.MicroKernel.Test.csproj avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/MicroKernelTest/BaseKernelTestCase.cs avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/MicroKernelTest/Lifestyle/LifestyleManagerTestCase.cs avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/Model/Default/DefaultComponentModel.cs Log: More test cases.
Modified: avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/AbstractKernelEvents.cs ============================================================================== --- avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/AbstractKernelEvents.cs (original) +++ avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/AbstractKernelEvents.cs Fri Sep 3 19:57:24 2004 @@ -51,7 +51,7 @@ m_service2Key = new Hashtable(); m_dependencyToSatisfy = new Hashtable(); m_proxy2ComponentWrapper = new Hashtable(); - m_interceptedComponentBuilder = new DefaultInterceptedComponentBuilder(); + InterceptedComponentBuilder = new DefaultInterceptedComponentBuilder(); } #region IKernelEvents Modified: avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/Apache.Avalon.Castle.MicroKernel.csproj ============================================================================== --- avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/Apache.Avalon.Castle.MicroKernel.csproj (original) +++ avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/Apache.Avalon.Castle.MicroKernel.csproj Fri Sep 3 19:57:24 2004 @@ -159,21 +159,6 @@ BuildAction = "Compile" /> <File - RelPath = "Aspects\AspectInvocationHandler.cs" - SubType = "Code" - BuildAction = "Compile" - /> - <File - RelPath = "Aspects\AspectPointCutFlags.cs" - SubType = "Code" - BuildAction = "Compile" - /> - <File - RelPath = "Aspects\IAspect.cs" - SubType = "Code" - BuildAction = "Compile" - /> - <File RelPath = "Assemble\Assembler.cs" SubType = "Code" BuildAction = "Compile" Modified: avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/AssertUtil.cs ============================================================================== --- avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/AssertUtil.cs (original) +++ avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/AssertUtil.cs Fri Sep 3 19:57:24 2004 @@ -19,12 +19,8 @@ /// <summary> /// Summary description for AssertUtil. /// </summary> - internal class AssertUtil + public abstract class AssertUtil { - private AssertUtil() - { - } - public static void ArgumentNotNull( object argValue, String argName ) { if (argValue == null) Modified: avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/BaseKernel.cs ============================================================================== --- avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/BaseKernel.cs (original) +++ avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/BaseKernel.cs Fri Sep 3 19:57:24 2004 @@ -51,9 +51,9 @@ m_key2Handler = new Hashtable(CaseInsensitiveHashCodeProvider.Default, CaseInsensitiveComparer.Default); m_subsystems = new Hashtable(); m_facilities = new Hashtable(); - m_handlerFactory = new SimpleHandlerFactory(); - m_componentModelBuilder = new DefaultComponentModelBuilder(this); - m_lifestyleManagerFactory = new SimpleLifestyleManagerFactory(); + HandlerFactory = new SimpleHandlerFactory(); + ModelBuilder = new DefaultComponentModelBuilder(this); + LifestyleManagerFactory = new SimpleLifestyleManagerFactory(); InitializeSubsystems(); } @@ -150,12 +150,9 @@ IKernelFacility facility = m_facilities[ key ] as IKernelFacility; - if (facility != null) - { - m_facilities.Remove(key); + RemoveFacility( facility ); - facility.Terminate(this); - } + m_facilities.Remove(key); } /// <summary> @@ -270,7 +267,7 @@ { DisposeStartedInstances(); DisposeHandlers(); - // DisposeFacilities(); + DisposeFacilities(); } #endregion @@ -293,6 +290,23 @@ { IHandler handler = GetHandlerForService( vertex.Content as Type ); HandlerFactory.ReleaseHandler( handler ); + } + } + + protected virtual void DisposeFacilities() + { + foreach( IKernelFacility facility in m_facilities.Values ) + { + RemoveFacility( facility ); + } + m_facilities.Clear(); + } + + protected virtual void RemoveFacility( IKernelFacility facility ) + { + if (facility != null) + { + facility.Terminate(this); } } Modified: avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/Lifestyle/UnsupportedLifestyleException.cs ============================================================================== --- avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/Lifestyle/UnsupportedLifestyleException.cs (original) +++ avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/Lifestyle/UnsupportedLifestyleException.cs Fri Sep 3 19:57:24 2004 @@ -22,10 +22,6 @@ [Serializable] public class UnsupportedLifestyleException : System.Exception { - public UnsupportedLifestyleException() - { - } - public UnsupportedLifestyleException(String message) : base(message) { } Modified: avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/MicroKernelTest/Apache.Avalon.Castle.MicroKernel.Test.csproj ============================================================================== --- avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/MicroKernelTest/Apache.Avalon.Castle.MicroKernel.Test.csproj (original) +++ avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/MicroKernelTest/Apache.Avalon.Castle.MicroKernel.Test.csproj Fri Sep 3 19:57:24 2004 @@ -114,27 +114,27 @@ BuildAction = "Compile" /> <File - RelPath = "BaseKernelTestCase.cs" + RelPath = "AssertUtilTestCase.cs" SubType = "Code" BuildAction = "Compile" /> <File - RelPath = "ComponentWrapperTestCase.cs" + RelPath = "BaseKernelTestCase.cs" SubType = "Code" BuildAction = "Compile" /> <File - RelPath = "ConcernManagerTestCase.cs" + RelPath = "ComponentWrapperTestCase.cs" SubType = "Code" BuildAction = "Compile" /> <File - RelPath = "DefaultAvalonKernelTestCase.cs" + RelPath = "ConcernManagerTestCase.cs" SubType = "Code" BuildAction = "Compile" /> <File - RelPath = "DefaultComponentModelBuilderTestCase.cs" + RelPath = "DefaultAvalonKernelTestCase.cs" SubType = "Code" BuildAction = "Compile" /> @@ -169,36 +169,6 @@ BuildAction = "Compile" /> <File - RelPath = "Business\Components\AbstractBusinessObject.cs" - SubType = "Code" - BuildAction = "Compile" - /> - <File - RelPath = "Business\Components\BusinessObject.cs" - SubType = "Code" - BuildAction = "Compile" - /> - <File - RelPath = "Business\Components\CustomerBusinessObject.cs" - SubType = "Code" - BuildAction = "Compile" - /> - <File - RelPath = "Business\Components\CustomerBusinessObjectImpl.cs" - SubType = "Code" - BuildAction = "Compile" - /> - <File - RelPath = "Business\Components\CustomerDataAccess.cs" - SubType = "Code" - BuildAction = "Compile" - /> - <File - RelPath = "Business\Components\CustomerDataAccessImpl.cs" - SubType = "Code" - BuildAction = "Compile" - /> - <File RelPath = "Components\AvalonMailService.cs" SubType = "Code" BuildAction = "Compile" @@ -359,6 +329,11 @@ BuildAction = "Compile" /> <File + RelPath = "Lifestyle\Components\CustomComponent.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "Lifestyle\Components\IComponent.cs" SubType = "Code" BuildAction = "Compile" @@ -375,6 +350,11 @@ /> <File RelPath = "Lifestyle\Components\TransientComponent.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Model\DefaultComponentModelBuilderTestCase.cs" SubType = "Code" BuildAction = "Compile" /> Added: avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/MicroKernelTest/AssertUtilTestCase.cs ============================================================================== --- (empty file) +++ avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/MicroKernelTest/AssertUtilTestCase.cs Fri Sep 3 19:57:24 2004 @@ -0,0 +1,116 @@ +// 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 System.Collections; + + using NUnit.Framework; + + /// <summary> + /// Summary description for AssertUtilTestCase. + /// </summary> + [TestFixture] + public class AssertUtilTestCase : Assertion + { + [Test] + public void ArgumentNotNull() + { + try + { + AssertUtil.ArgumentNotNull( "", "value" ); + } + catch(ArgumentNullException) + { + Fail("The argument wasn't null"); + } + + try + { + AssertUtil.ArgumentNotNull( null, "value" ); + Fail("The argument was null"); + } + catch(ArgumentNullException) + { + } + } + + [Test] + public void ArgumentMustNotBeInterface() + { + try + { + AssertUtil.ArgumentMustNotBeInterface( typeof(String), "value" ); + } + catch(ArgumentNullException) + { + Fail("The argument wasn't an interface"); + } + + try + { + AssertUtil.ArgumentMustNotBeInterface( typeof(IList), "value" ); + Fail("The argument was an interface"); + } + catch(ArgumentNullException) + { + } + } + + [Test] + public void ArgumentMustNotBeAbstract() + { + try + { + AssertUtil.ArgumentMustNotBeAbstract( typeof(String), "value" ); + } + catch(ArgumentNullException) + { + Fail("The argument wasn't invalid"); + } + + try + { + AssertUtil.ArgumentMustNotBeAbstract( typeof(AssertUtil), "value" ); + Fail("The argument was invalid"); + } + catch(ArgumentNullException) + { + } + } + + [Test] + public void ArgumentMustBeInterface() + { + try + { + AssertUtil.ArgumentMustBeInterface( typeof(IList), "value" ); + } + catch(ArgumentNullException) + { + Fail("The argument wasn't invalid"); + } + + try + { + AssertUtil.ArgumentMustBeInterface( typeof(AssertUtil), "value" ); + Fail("The argument was invalid"); + } + catch(ArgumentNullException) + { + } + } + } +} Modified: avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/MicroKernelTest/BaseKernelTestCase.cs ============================================================================== --- avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/MicroKernelTest/BaseKernelTestCase.cs (original) +++ avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/MicroKernelTest/BaseKernelTestCase.cs Fri Sep 3 19:57:24 2004 @@ -39,7 +39,7 @@ [TearDown] public void Terminate() { - ContainerUtil.Dispose( m_container ); + m_container.Dispose(); } /// <summary> Added: avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/MicroKernelTest/Lifestyle/Components/CustomComponent.cs ============================================================================== --- (empty file) +++ avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/MicroKernelTest/Lifestyle/Components/CustomComponent.cs Fri Sep 3 19:57:24 2004 @@ -0,0 +1,44 @@ +// 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.Lifestyle.Components +{ + using System; + + using Apache.Avalon.Framework; + + /// <summary> + /// Summary description for CustomComponent. + /// </summary> + [AvalonComponent("component4", Lifestyle.Custom)] + [AvalonService( typeof(IComponent) )] + public class CustomComponent : IComponent + { + public CustomComponent() + { + } + + #region IComponent Members + + public int ID + { + get + { + return this.GetHashCode(); + } + } + + #endregion + } +} Modified: avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/MicroKernelTest/Lifestyle/LifestyleManagerTestCase.cs ============================================================================== --- avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/MicroKernelTest/Lifestyle/LifestyleManagerTestCase.cs (original) +++ avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/MicroKernelTest/Lifestyle/LifestyleManagerTestCase.cs Fri Sep 3 19:57:24 2004 @@ -21,6 +21,7 @@ using Apache.Avalon.Castle.MicroKernel; using Apache.Avalon.Castle.MicroKernel.Test.Lifestyle.Components; + using Apache.Avalon.Castle.MicroKernel.Lifestyle; /// <summary> /// Summary description for LifestyleManagerTestCase. @@ -36,6 +37,26 @@ public void CreateContainer() { m_kernel = new DefaultAvalonKernel(); + } + + [TearDown] + public void DisposeContainer() + { + m_kernel.Dispose(); + } + + [Test] + public void TestUnsupported() + { + try + { + m_kernel.AddComponent( "a", typeof(IComponent), typeof(CustomComponent) ); + Fail( "Custom lifestyle is not supported." ); + } + catch(UnsupportedLifestyleException) + { + // Expected + } } [Test] Added: avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/MicroKernelTest/Model/DefaultComponentModelBuilderTestCase.cs ============================================================================== --- (empty file) +++ avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/MicroKernelTest/Model/DefaultComponentModelBuilderTestCase.cs Fri Sep 3 19:57:24 2004 @@ -0,0 +1,148 @@ +// 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.Model +{ + 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 IKernel 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.Name ); + AssertNotNull( model.Configuration ); + AssertNotNull( model.Context ); + AssertNotNull( model.Dependencies ); + AssertNotNull( model.Properties ); + + AssertEquals( 0, model.Properties.Count ); + AssertEquals( 0, model.Dependencies.Length ); + AssertEquals( "SimpleMailService", model.Name ); + AssertEquals( Avalon.Framework.Lifestyle.Transient, model.SupportedLifestyle ); + AssertEquals( Avalon.Framework.Activation.Undefined, model.ActivationPolicy ); + } + + [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 ); + + AssertEquals( Apache.Avalon.Framework.Lifestyle.Singleton, model.SupportedLifestyle ); + 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 ); + } + } +} Modified: avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/Model/Default/DefaultComponentModel.cs ============================================================================== --- avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/Model/Default/DefaultComponentModel.cs (original) +++ avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/Model/Default/DefaultComponentModel.cs Fri Sep 3 19:57:24 2004 @@ -39,7 +39,7 @@ protected DefaultComponentModel() { - m_context = new DefaultContext(); + Context = new DefaultContext(); } public DefaultComponentModel( @@ -57,12 +57,12 @@ m_name = data.Name; m_service = service; - m_lifestyle = data.SupportedLifestyle; - m_activation = data.ActivationPolicy; - m_logger = logger; - m_config = configuration; - m_dependencies = data.DependencyModel; m_constructionModel = constructionModel; + SupportedLifestyle = data.SupportedLifestyle; + ActivationPolicy = data.ActivationPolicy; + Logger = logger; + Configuration = configuration; + Dependencies = data.DependencyModel; } #region IComponentModel Members --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]