Return-Path: Delivered-To: apmail-avalon-cvs-archive@www.apache.org Received: (qmail 56781 invoked from network); 4 Sep 2004 02:57:29 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 4 Sep 2004 02:57:29 -0000 Received: (qmail 54141 invoked by uid 500); 4 Sep 2004 02:57:28 -0000 Delivered-To: apmail-avalon-cvs-archive@avalon.apache.org Received: (qmail 54079 invoked by uid 500); 4 Sep 2004 02:57:27 -0000 Mailing-List: contact cvs-help@avalon.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Avalon CVS List" Reply-To: "Avalon Developers List" Delivered-To: mailing list cvs@avalon.apache.org Received: (qmail 54066 invoked by uid 99); 4 Sep 2004 02:57:27 -0000 X-ASF-Spam-Status: No, hits=-2.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Fri, 03 Sep 2004 19:57:26 -0700 Received: (qmail 56717 invoked by uid 65534); 4 Sep 2004 02:57:25 -0000 Date: 4 Sep 2004 02:57:25 -0000 Message-ID: <20040904025725.56705.qmail@minotaur.apache.org> From: hammett@apache.org To: cvs@avalon.apache.org Subject: svn commit: rev 43311 - in avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel: . Lifestyle MicroKernelTest MicroKernelTest/Lifestyle MicroKernelTest/Lifestyle/Components MicroKernelTest/Model Model/Default X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N 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" /> - - - /// Summary description for AssertUtil. /// - 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); } /// @@ -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" /> @@ -169,36 +169,6 @@ 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 description for AssertUtilTestCase. + /// + [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(); } /// 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 description for CustomComponent. + /// + [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 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 description for DefaultComponentModelBuilderTestCase. + /// + [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: cvs-unsubscribe@avalon.apache.org For additional commands, e-mail: cvs-help@avalon.apache.org