You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by ha...@apache.org on 2004/04/18 05:26:02 UTC

cvs commit: avalon-sandbox/avalon-net/Castle/MicroKernel/MicroKernelTest/Lifestyle LifestyleManagerTestCase.cs

hammett     2004/04/17 20:26:02

  Modified:    avalon-net/Castle/MicroKernel/MicroKernelTest
                        AssemblerTestCase.cs ConcernManagerTestCase.cs
                        DefaultComponentModelBuilderTestCase.cs
                        DefaultKernelTestCase.cs
               avalon-net/Castle/MicroKernel/MicroKernelTest/Components
                        AvalonMailService.cs AvalonSpamService3.cs
  Added:       avalon-net/Castle/MicroKernel/MicroKernelTest
                        Apache.Avalon.Castle.MicroKernel.Test.csproj
                        DefaultConfigurationManagerTestCase.cs
                        DependencyDisposeTestCase.cs
               avalon-net/Castle/MicroKernel/MicroKernelTest/Components
                        AvalonMailService2.cs
               avalon-net/Castle/MicroKernel/MicroKernelTest/Lifestyle/Components
                        IComponent.cs PerThreadComponent.cs
                        SingletonComponent.cs TransientComponent.cs
               avalon-net/Castle/MicroKernel/MicroKernelTest/Lifestyle
                        LifestyleManagerTestCase.cs
  Log:
  More test cases to microkernel
  
  Revision  Changes    Path
  1.2       +89 -3     avalon-sandbox/avalon-net/Castle/MicroKernel/MicroKernelTest/AssemblerTestCase.cs
  
  Index: AssemblerTestCase.cs
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/avalon-net/Castle/MicroKernel/MicroKernelTest/AssemblerTestCase.cs,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AssemblerTestCase.cs	3 Apr 2004 22:58:30 -0000	1.1
  +++ AssemblerTestCase.cs	18 Apr 2004 03:26:02 -0000	1.2
  @@ -18,20 +18,106 @@
   
   	using NUnit.Framework;
   
  +	using Apache.Avalon.Framework;
  +	using Apache.Avalon.Castle.MicroKernel.Assemble;
  +	using Apache.Avalon.Castle.MicroKernel.Model;
  +	using Apache.Avalon.Castle.MicroKernel.Model.Default;
  +	using Apache.Avalon.Castle.MicroKernel.Test.Components;
  +
   	/// <summary>
   	/// Summary description for AssemblerTestCase.
   	/// </summary>
  +	[TestFixture]
   	public class AssemblerTestCase : Assertion
   	{
  -		public void BuildingConstructorArgs()
  +		private AvalonKernel m_kernel = new DefaultKernel();
  +
  +		private DefaultComponentModelBuilder m_builder;
  +
  +		[SetUp]
  +		public void CreateComponentModelBuilder()
  +		{
  +			m_builder = new DefaultComponentModelBuilder( m_kernel );
  +		}
  +
  +		[Test]
  +		public void BuildingConstructorArgsWithDefaultConstructor()
  +		{
  +			Type service = typeof( IMailService );
  +			Type implementation = typeof( SimpleMailService );
  +
  +			IComponentModel model = m_builder.BuildModel( "a", service, implementation );
  +
  +			object[] args = Assembler.BuildConstructorArguments( 
  +				model, new object(), new ResolveTypeHandler(Resolver) );
  +
  +			AssertNotNull( args );
  +			AssertEquals( 0, args.Length );
  +		}
  +
  +		[Test]
  +		public void BuildingConstructorArgsWithLoggerConstructor()
   		{
  -			// object[] arguments = Assembler.BuildConstructorArguments( model );
  +			Type service = typeof( IMailService );
  +			Type implementation = typeof( SimpleMailServiceWithLogger );
   
  -			// Assembler.AssembleProperties( properties, model );
  +			IComponentModel model = m_builder.BuildModel( "a", service, implementation );
  +
  +			object[] args = Assembler.BuildConstructorArguments( 
  +				model, new object(), new ResolveTypeHandler(Resolver) );
  +
  +			AssertNotNull( args );
  +			AssertEquals( 1, args.Length );
  +			Assert( typeof(ILogger).IsAssignableFrom( args[0].GetType() ) );
   		}
   
  +		[Test]
  +		public void BuildingConstructorArgsWithDependencyConstructor()
  +		{
  +			Type service = typeof( ISpamService );
  +			Type implementation = typeof( SimpleSpamService );
  +
  +			IComponentModel model = m_builder.BuildModel( "a", service, implementation );
  +
  +			object[] args = Assembler.BuildConstructorArguments( 
  +				model, new object(), new ResolveTypeHandler(Resolver) );
  +
  +			AssertNotNull( args );
  +			AssertEquals( 1, args.Length );
  +			Assert( typeof(IMailService).IsAssignableFrom( args[0].GetType() ) );
  +		}
  +
  +		[Test]
  +		public void IsKnown()
  +		{
  +			Assert( Assembler.IsKnown( typeof(ILogger), "arg" ) );
  +			Assert( !Assembler.IsKnown( typeof(IMailService), "arg" ) );
  +		}
  +
  +		[Test]
   		public void AssembleProperties()
   		{
  +			Type service = typeof( ISpamService2 );
  +			Type implementation = typeof( AvalonSpamService3 );
  +
  +			object instance = Activator.CreateInstance( implementation );
  +
  +			IComponentModel model = m_builder.BuildModel( "a", service, implementation );
  +
  +			Assembler.AssembleProperties( instance, model, new object(), new ResolveTypeHandler(Resolver) );
  +
  +			ISpamService2 serviceInstance = instance as ISpamService2;
  +
  +			AssertNotNull( serviceInstance );
  +			Assert( typeof(IMailService).IsAssignableFrom( serviceInstance.MailService.GetType() ) );
  +		}
  +
  +		private void Resolver(
  +			IComponentModel model, Type typeRequest, String argumentOrPropertyName, 
  +			object key, out object value )
  +		{
  +			AssertEquals( typeof(IMailService), typeRequest );
  +			value = new SimpleMailService();
   		}
   	}
   }
  
  
  
  1.2       +5 -0      avalon-sandbox/avalon-net/Castle/MicroKernel/MicroKernelTest/ConcernManagerTestCase.cs
  
  Index: ConcernManagerTestCase.cs
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/avalon-net/Castle/MicroKernel/MicroKernelTest/ConcernManagerTestCase.cs,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ConcernManagerTestCase.cs	3 Apr 2004 22:58:30 -0000	1.1
  +++ ConcernManagerTestCase.cs	18 Apr 2004 03:26:02 -0000	1.2
  @@ -93,6 +93,11 @@
   			AssertNotNull( concern );
   			AssertNotNull( concern is IDecommissionConcern );
   			AssertNotNull( concern is ShutdownConcern );
  +			AssertNotNull( concern.Next );
  +
  +			concern = concern.Next;
  +			AssertNotNull( concern is IDestructionConcern );
  +			AssertNotNull( concern is DestructionConcern );
   			AssertNull( concern.Next );
   		}
   	}
  
  
  
  1.2       +1 -0      avalon-sandbox/avalon-net/Castle/MicroKernel/MicroKernelTest/DefaultComponentModelBuilderTestCase.cs
  
  Index: DefaultComponentModelBuilderTestCase.cs
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/avalon-net/Castle/MicroKernel/MicroKernelTest/DefaultComponentModelBuilderTestCase.cs,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DefaultComponentModelBuilderTestCase.cs	3 Apr 2004 22:58:30 -0000	1.1
  +++ DefaultComponentModelBuilderTestCase.cs	18 Apr 2004 03:26:02 -0000	1.2
  @@ -109,6 +109,7 @@
   			IComponentModel model = 
   				builder.BuildModel( "a", service, implementation );
   
  +			AssertEquals( Apache.Avalon.Framework.Lifestyle.Singleton, model.SupportedLifestyle );
   			AssertNotNull( model );
   			AssertNotNull( model.Logger );
   			AssertNotNull( model.Configuration );
  
  
  
  1.2       +1 -1      avalon-sandbox/avalon-net/Castle/MicroKernel/MicroKernelTest/DefaultKernelTestCase.cs
  
  Index: DefaultKernelTestCase.cs
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/avalon-net/Castle/MicroKernel/MicroKernelTest/DefaultKernelTestCase.cs,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DefaultKernelTestCase.cs	3 Apr 2004 22:58:30 -0000	1.1
  +++ DefaultKernelTestCase.cs	18 Apr 2004 03:26:02 -0000	1.2
  @@ -58,7 +58,7 @@
   		public void SimpleAvalonComponent()
   		{
   			AvalonKernel container = new DefaultKernel();
  -			container.AddComponent( "a", typeof(IMailService), typeof(AvalonMailService) );
  +			container.AddComponent( "a", typeof(IMailService), typeof(AvalonMailService2) );
   
   			IHandler handler = container[ "a" ];
   
  
  
  
  1.1                  avalon-sandbox/avalon-net/Castle/MicroKernel/MicroKernelTest/Apache.Avalon.Castle.MicroKernel.Test.csproj
  
  Index: Apache.Avalon.Castle.MicroKernel.Test.csproj
  ===================================================================
  <VisualStudioProject>
      <CSHARP
          ProjectType = "Local"
          ProductVersion = "7.10.3077"
          SchemaVersion = "2.0"
          ProjectGuid = "{50442F0D-987F-4A8D-B38C-DFA855B9249E}"
      >
          <Build>
              <Settings
                  ApplicationIcon = ""
                  AssemblyKeyContainerName = ""
                  AssemblyName = "Apache.Avalon.Castle.MicroKernel.Test"
                  AssemblyOriginatorKeyFile = ""
                  DefaultClientScript = "JScript"
                  DefaultHTMLPageLayout = "Grid"
                  DefaultTargetSchema = "IE50"
                  DelaySign = "false"
                  OutputType = "Library"
                  PreBuildEvent = ""
                  PostBuildEvent = ""
                  RootNamespace = "Apache.Avalon.Castle.MicroKernel.Test"
                  RunPostBuildEvent = "OnBuildSuccess"
                  StartupObject = ""
              >
                  <Config
                      Name = "Debug"
                      AllowUnsafeBlocks = "false"
                      BaseAddress = "285212672"
                      CheckForOverflowUnderflow = "false"
                      ConfigurationOverrideFile = ""
                      DefineConstants = "DEBUG;TRACE"
                      DocumentationFile = ""
                      DebugSymbols = "true"
                      FileAlignment = "4096"
                      IncrementalBuild = "false"
                      NoStdLib = "false"
                      NoWarn = ""
                      Optimize = "false"
                      OutputPath = "..\..\bin\"
                      RegisterForComInterop = "false"
                      RemoveIntegerChecks = "false"
                      TreatWarningsAsErrors = "false"
                      WarningLevel = "4"
                  />
                  <Config
                      Name = "Release"
                      AllowUnsafeBlocks = "false"
                      BaseAddress = "285212672"
                      CheckForOverflowUnderflow = "false"
                      ConfigurationOverrideFile = ""
                      DefineConstants = "TRACE"
                      DocumentationFile = ""
                      DebugSymbols = "false"
                      FileAlignment = "4096"
                      IncrementalBuild = "false"
                      NoStdLib = "false"
                      NoWarn = ""
                      Optimize = "true"
                      OutputPath = "bin\Release\"
                      RegisterForComInterop = "false"
                      RemoveIntegerChecks = "false"
                      TreatWarningsAsErrors = "false"
                      WarningLevel = "4"
                  />
              </Settings>
              <References>
                  <Reference
                      Name = "System"
                      AssemblyName = "System"
                      HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.dll"
                  />
                  <Reference
                      Name = "System.Data"
                      AssemblyName = "System.Data"
                      HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Data.dll"
                  />
                  <Reference
                      Name = "System.XML"
                      AssemblyName = "System.Xml"
                      HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.XML.dll"
                  />
                  <Reference
                      Name = "nunit.framework"
                      AssemblyName = "nunit.framework"
                      HintPath = "..\..\..\..\..\..\..\..\dotnet\NUnit2\bin\nunit.framework.dll"
                  />
                  <Reference
                      Name = "MicroKernel"
                      Project = "{1E57B734-BA4B-4ADE-B4C2-78C7D4993AD4}"
                      Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"
                  />
                  <Reference
                      Name = "Apache.Avalon.Framework"
                      AssemblyName = "Apache.Avalon.Framework"
                      HintPath = "..\..\bin\Apache.Avalon.Framework.dll"
                  />
              </References>
          </Build>
          <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"
                  />
                  <File
                      RelPath = "BaseKernelTestCase.cs"
                      SubType = "Code"
                      BuildAction = "Compile"
                  />
                  <File
                      RelPath = "ConcernManagerTestCase.cs"
                      SubType = "Code"
                      BuildAction = "Compile"
                  />
                  <File
                      RelPath = "DefaultComponentModelBuilderTestCase.cs"
                      SubType = "Code"
                      BuildAction = "Compile"
                  />
                  <File
                      RelPath = "DefaultConfigurationManagerTestCase.cs"
                      SubType = "Code"
                      BuildAction = "Compile"
                  />
                  <File
                      RelPath = "DefaultKernelTestCase.cs"
                      SubType = "Code"
                      BuildAction = "Compile"
                  />
                  <File
                      RelPath = "DependencyDisposeTestCase.cs"
                      SubType = "Code"
                      BuildAction = "Compile"
                  />
                  <File
                      RelPath = "SimpleComponentFactoryTestCase.cs"
                      SubType = "Code"
                      BuildAction = "Compile"
                  />
                  <File
                      RelPath = "Components\AvalonMailService.cs"
                      SubType = "Code"
                      BuildAction = "Compile"
                  />
                  <File
                      RelPath = "Components\AvalonMailService2.cs"
                      SubType = "Code"
                      BuildAction = "Compile"
                  />
                  <File
                      RelPath = "Components\AvalonSpamService.cs"
                      SubType = "Code"
                      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"
                  />
                  <File
                      RelPath = "Components\IMailMarketingService.cs"
                      SubType = "Code"
                      BuildAction = "Compile"
                  />
                  <File
                      RelPath = "Components\IMailService.cs"
                      SubType = "Code"
                      BuildAction = "Compile"
                  />
                  <File
                      RelPath = "Components\ISpamService.cs"
                      SubType = "Code"
                      BuildAction = "Compile"
                  />
                  <File
                      RelPath = "Components\ISpamService2.cs"
                      SubType = "Code"
                      BuildAction = "Compile"
                  />
                  <File
                      RelPath = "Components\SimpleCustomerManager.cs"
                      SubType = "Code"
                      BuildAction = "Compile"
                  />
                  <File
                      RelPath = "Components\SimpleMailMarketingService.cs"
                      SubType = "Code"
                      BuildAction = "Compile"
                  />
                  <File
                      RelPath = "Components\SimpleMailService.cs"
                      SubType = "Code"
                      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"
                  />
                  <File
                      RelPath = "Lifestyle\LifestyleManagerTestCase.cs"
                      SubType = "Code"
                      BuildAction = "Compile"
                  />
                  <File
                      RelPath = "Lifestyle\Components\IComponent.cs"
                      SubType = "Code"
                      BuildAction = "Compile"
                  />
                  <File
                      RelPath = "Lifestyle\Components\PerThreadComponent.cs"
                      SubType = "Code"
                      BuildAction = "Compile"
                  />
                  <File
                      RelPath = "Lifestyle\Components\SingletonComponent.cs"
                      SubType = "Code"
                      BuildAction = "Compile"
                  />
                  <File
                      RelPath = "Lifestyle\Components\TransientComponent.cs"
                      SubType = "Code"
                      BuildAction = "Compile"
                  />
              </Include>
          </Files>
      </CSHARP>
  </VisualStudioProject>
  
  
  
  
  1.1                  avalon-sandbox/avalon-net/Castle/MicroKernel/MicroKernelTest/DefaultConfigurationManagerTestCase.cs
  
  Index: DefaultConfigurationManagerTestCase.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.Framework;
  	using Apache.Avalon.Castle.MicroKernel;
  	using Apache.Avalon.Castle.MicroKernel.Model;
  	using Apache.Avalon.Castle.MicroKernel.Model.Default;
  	using Apache.Avalon.Castle.MicroKernel.Configuration;
  	using Apache.Avalon.Castle.MicroKernel.Configuration.Default;
  	using Apache.Avalon.Castle.MicroKernel.Test.Components;
  
  	/// <summary>
  	/// Summary description for DefaultConfigurationManagerTestCase.
  	/// </summary>
  	[TestFixture]
  	public class DefaultConfigurationManagerTestCase : Assertion
  	{
  		[Test]
  		public void TestUsage()
  		{
  			DefaultConfigurationManager config = new DefaultConfigurationManager();
  			IConfiguration componentConfig = config.GetConfiguration( "component1" );
  
  			AssertNotNull( componentConfig );
  			AssertEquals( "johndoe", componentConfig.GetChild("name", true).Value );
  			AssertEquals( "1099", componentConfig.GetChild("port", true).Value );
  		}
  
  		[Test]
  		public void TestNoContentConfig()
  		{
  			DefaultConfigurationManager config = new DefaultConfigurationManager();
  			IConfiguration componentConfig = config.GetConfiguration( "component2" );
  
  			AssertNotNull( componentConfig );
  			AssertEquals( 0, componentConfig.Attributes.Count );
  			AssertEquals( 0, componentConfig.Children.Count );
  		}
  	}
  }
  
  
  
  1.1                  avalon-sandbox/avalon-net/Castle/MicroKernel/MicroKernelTest/DependencyDisposeTestCase.cs
  
  Index: DependencyDisposeTestCase.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.Test.Components;
  
  	/// <summary>
  	/// Summary description for DependencyDisposeTestCase.
  	/// </summary>
  	[TestFixture]
  	public class DependencyDisposeTestCase : Assertion
  	{
  		[Test]
  		public void SingletonDependencyDisposal()
  		{
  			AvalonKernel container = new DefaultKernel();
  			container.AddComponent( "a", typeof(IMailService), typeof(AvalonMailService) );
  			container.AddComponent( "b", typeof(ISpamService2), typeof(AvalonSpamService3) );
  
  			IHandler handler = container[ "b" ];
  			ISpamService2 spamService = handler.Resolve() as ISpamService2;
  			AssertNotNull( spamService );
  
  			AssertNotNull( spamService.MailService );
  			AvalonMailService mailService = (AvalonMailService) spamService.MailService;
  
  			Assert( !mailService.disposed );
  
  			handler.Release( spamService );
  
  			Assert( "A singleton component should have not been disposed", !mailService.disposed );
  		}
  
  		[Test]
  		public void TransientDependencyDisposal()
  		{
  			AvalonKernel container = new DefaultKernel();
  			container.AddComponent( "a", typeof(IMailService), typeof(AvalonMailService2) );
  			container.AddComponent( "b", typeof(ISpamService2), typeof(AvalonSpamService3) );
  
  			IHandler handler = container[ "b" ];
  			ISpamService2 spamService = handler.Resolve() as ISpamService2;
  			AssertNotNull( spamService );
  
  			AssertNotNull( spamService.MailService );
  			AvalonMailService mailService = (AvalonMailService) spamService.MailService;
  
  			Assert( !mailService.disposed );
  
  			handler.Release( spamService );
  
  			Assert( "A transient component should have been disposed", mailService.disposed );
  		}
  
  	}
  }
  
  
  
  1.3       +2 -1      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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AvalonMailService.cs	3 Apr 2004 22:58:30 -0000	1.2
  +++ AvalonMailService.cs	18 Apr 2004 03:26:02 -0000	1.3
  @@ -23,7 +23,8 @@
   	/// </summary>
   	[AvalonComponent("mailservice", Lifestyle.Singleton)]
   	[AvalonService( typeof(IMailService) )]
  -	public class AvalonMailService : IMailService, IInitializable, IConfigurable, IDisposable
  +	public class AvalonMailService : 
  +		IMailService, IInitializable, IConfigurable, IDisposable
   	{
   		public bool initialized;
   		public bool configured;
  
  
  
  1.2       +13 -2     avalon-sandbox/avalon-net/Castle/MicroKernel/MicroKernelTest/Components/AvalonSpamService3.cs
  
  Index: AvalonSpamService3.cs
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/avalon-net/Castle/MicroKernel/MicroKernelTest/Components/AvalonSpamService3.cs,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AvalonSpamService3.cs	3 Apr 2004 22:58:30 -0000	1.1
  +++ AvalonSpamService3.cs	18 Apr 2004 03:26:02 -0000	1.2
  @@ -21,12 +21,14 @@
   	/// <summary>
   	/// Summary description for AvalonSpamService3.
   	/// </summary>
  -	[AvalonComponent("spamservice2", Lifestyle.Singleton)]
  +	[AvalonComponent("spamservice2", Lifestyle.Transient)]
   	[AvalonService( typeof(ISpamService2) )]
  -	public class AvalonSpamService3 : IInitializable, ISpamService2
  +	public class AvalonSpamService3 : IInitializable, ISpamService2, IDisposable
   	{
   		public IMailService m_mailService;
   
  +		public bool disposed = false;
  +
   		public AvalonSpamService3()
   		{
   		}
  @@ -63,6 +65,15 @@
   			{
   				throw new Exception("Dependency not satisfied.");
   			}
  +		}
  +
  +		#endregion
  +
  +		#region IDisposable Members
  +
  +		public void Dispose()
  +		{
  +			disposed = true;
   		}
   
   		#endregion
  
  
  
  1.1                  avalon-sandbox/avalon-net/Castle/MicroKernel/MicroKernelTest/Components/AvalonMailService2.cs
  
  Index: AvalonMailService2.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 AvalonMailService2.
  	/// </summary>
  	[AvalonComponent("mailservice", Lifestyle.Transient)]
  	[AvalonService( typeof(IMailService) )]
  	public class AvalonMailService2 : 
  		AvalonMailService
  	{
  		public AvalonMailService2()
  		{
  		}
  	}
  }
  
  
  
  1.1                  avalon-sandbox/avalon-net/Castle/MicroKernel/MicroKernelTest/Lifestyle/Components/IComponent.cs
  
  Index: IComponent.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.Lifestyle.Components
  {
  	using System;
  
  	/// <summary>
  	/// Summary description for IComponent.
  	/// </summary>
  	public interface IComponent
  	{
  		int ID
  		{
  			get;
  		}
  	}
  }
  
  
  
  1.1                  avalon-sandbox/avalon-net/Castle/MicroKernel/MicroKernelTest/Lifestyle/Components/PerThreadComponent.cs
  
  Index: PerThreadComponent.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.Lifestyle.Components
  {
  	using System;
  
  	using Apache.Avalon.Framework;
  
  	/// <summary>
  	/// Summary description for PerThreadComponent.
  	/// </summary>
  	[AvalonComponent("component2", Lifestyle.Thread)]
  	[AvalonService( typeof(IComponent) )]
  	public class PerThreadComponent : IComponent
  	{
  		public PerThreadComponent()
  		{
  		}
  
  		#region IComponent Members
  
  		public int ID
  		{
  			get
  			{
  				return this.GetHashCode();
  			}
  		}
  
  		#endregion
  	}
  }
  
  
  
  1.1                  avalon-sandbox/avalon-net/Castle/MicroKernel/MicroKernelTest/Lifestyle/Components/SingletonComponent.cs
  
  Index: SingletonComponent.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.Lifestyle.Components
  {
  	using System;
  
  	using Apache.Avalon.Framework;
  
  	/// <summary>
  	/// Summary description for SingletonComponent.
  	/// </summary>
  	[AvalonComponent("component3", Lifestyle.Singleton)]
  	[AvalonService( typeof(IComponent) )]
  	public class SingletonComponent : IComponent
  	{
  		public SingletonComponent()
  		{
  		}
  
  		#region IComponent Members
  
  		public int ID
  		{
  			get
  			{
  				return this.GetHashCode();
  			}
  		}
  
  		#endregion
  	}
  }
  
  
  
  1.1                  avalon-sandbox/avalon-net/Castle/MicroKernel/MicroKernelTest/Lifestyle/Components/TransientComponent.cs
  
  Index: TransientComponent.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.Lifestyle.Components
  {
  	using System;
  
  	using Apache.Avalon.Framework;
  
  	/// <summary>
  	/// Summary description for TransientComponent.
  	/// </summary>
  	[AvalonComponent("component1", Lifestyle.Transient)]
  	[AvalonService( typeof(IComponent) )]
  	public class TransientComponent : IComponent
  	{
  		public TransientComponent()
  		{
  		}
  
  		#region IComponent Members
  
  		public int ID
  		{
  			get
  			{
  				return this.GetHashCode();
  			}
  		}
  
  		#endregion
  	}
  }
  
  
  
  1.1                  avalon-sandbox/avalon-net/Castle/MicroKernel/MicroKernelTest/Lifestyle/LifestyleManagerTestCase.cs
  
  Index: LifestyleManagerTestCase.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.Lifestyle
  {
  	using System;
  	using System.Threading;
  
  	using NUnit.Framework;
  
  	using Apache.Avalon.Castle.MicroKernel;
  	using Apache.Avalon.Castle.MicroKernel.Test.Lifestyle.Components;
  
  	/// <summary>
  	/// Summary description for LifestyleManagerTestCase.
  	/// </summary>
  	[TestFixture]
  	public class LifestyleManagerTestCase : Assertion
  	{
  		private AvalonKernel m_kernel;
  
  		private IComponent m_instance3;
  
  		[SetUp]
  		public void CreateContainer()
  		{
  			m_kernel = new DefaultKernel();
  		}
  
  		[Test]
  		public void TestTransient()
  		{
  			m_kernel.AddComponent( "a", typeof(IComponent), typeof(TransientComponent) );
  
  			IHandler handler = m_kernel[ "a" ];
  			
  			IComponent instance1 = handler.Resolve() as IComponent;
  			IComponent instance2 = handler.Resolve() as IComponent;
  
  			AssertNotNull( instance1 );
  			AssertNotNull( instance2 );
  
  			Assert( !instance1.Equals( instance2 ) );
  			Assert( instance1.ID != instance2.ID );
  
  			handler.Release( instance1 );
  			handler.Release( instance2 );
  		}
  
  		[Test]
  		public void TestSingleton()
  		{
  			m_kernel.AddComponent( "a", typeof(IComponent), typeof(SingletonComponent) );
  
  			IHandler handler = m_kernel[ "a" ];
  			
  			IComponent instance1 = handler.Resolve() as IComponent;
  			IComponent instance2 = handler.Resolve() as IComponent;
  
  			AssertNotNull( instance1 );
  			AssertNotNull( instance2 );
  
  			Assert( instance1.Equals( instance2 ) );
  			Assert( instance1.ID == instance2.ID );
  
  			handler.Release( instance1 );
  			handler.Release( instance2 );
  		}
  
  		[Test]
  		public void TestPerThread()
  		{
  			m_kernel.AddComponent( "a", typeof(IComponent), typeof(PerThreadComponent) );
  
  			IHandler handler = m_kernel[ "a" ];
  			
  			IComponent instance1 = handler.Resolve() as IComponent;
  			IComponent instance2 = handler.Resolve() as IComponent;
  
  			AssertNotNull( instance1 );
  			AssertNotNull( instance2 );
  
  			Assert( instance1.Equals( instance2 ) );
  			Assert( instance1.ID == instance2.ID );
  
  			Thread thread = new Thread( new ThreadStart(OtherThread) );
  			thread.Start();
  			thread.Join();
  
  			AssertNotNull( m_instance3 );
  			Assert( !instance1.Equals( m_instance3 ) );
  			Assert( instance1.ID != m_instance3.ID );
  
  			handler.Release( instance1 );
  			handler.Release( instance2 );
  		}
  
  		private void OtherThread()
  		{
  			IHandler handler = m_kernel[ "a" ];
  			m_instance3 = handler.Resolve() as IComponent;
  		}
  	}
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org