sprnet-1047, sprnet-1027, sprnet-1046, sprnet-1048

This commit is contained in:
eeichinger
2008-10-05 20:53:22 +00:00
parent eb9be5a0f0
commit 83098fe045
46 changed files with 2844 additions and 2395 deletions

View File

@@ -138,6 +138,11 @@ namespace Spring
return false;
}
public object CreateObject(string name, Type requiredType, object[] arguments)
{
return null;
}
public string[] GetAliases(string name)
{
return null;
@@ -232,7 +237,13 @@ namespace Spring
return null;
}
public object GetObject(string name, Type requiredType)
public object CreateObject(string name, Type requiredType, object[] arguments)
{
innerExecute();
return null;
}
public object GetObject(string name, Type requiredType)
{
innerExecute();
return null;

View File

@@ -431,6 +431,11 @@ namespace Spring.Context
return null;
}
public object CreateObject(string name, Type requiredType, object[] arguments)
{
return null;
}
public object GetObject(string name, Type requiredType)
{
return null;

View File

@@ -173,6 +173,11 @@ namespace Spring.Context.Support
return null;
}
public object CreateObject(string name, Type requiredType, object[] arguments)
{
return null;
}
public object GetObject(string name, Type requiredType)
{
return null;

View File

@@ -31,11 +31,6 @@ namespace Spring.Objects.Factory
{
public class TestAbstractObjectFactory : AbstractObjectFactory
{
protected override object CreateObject(string name, RootObjectDefinition definition, object[] arguments)
{
throw new System.NotImplementedException();
}
protected override void DestroyObject(string name, object target)
{
throw new System.NotImplementedException();
@@ -66,8 +61,8 @@ namespace Spring.Objects.Factory
throw new System.NotImplementedException();
}
protected override object CreateObject(string name, RootObjectDefinition definition, object[] arguments,
bool allowEagerCaching)
protected override object InstantiateObject(string name, RootObjectDefinition definition, object[] arguments,
bool allowEagerCaching, bool suppressConfigure)
{
throw new NotImplementedException();
}

View File

@@ -0,0 +1,232 @@
#region License
/*
* Copyright <20> 2002-2008 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using System.Collections;
using System.Web.UI;
using NUnit.Framework;
using Rhino.Mocks;
using Spring.Objects.Factory.Support;
using Spring.Objects.Support;
#endregion
namespace Spring.Objects.Factory.Config
{
/// <summary>
///
/// </summary>
/// <author>Erich Eichinger</author>
[TestFixture]
public class SharedStateAwareProcessorTests
{
[Test]
public void DoesNotAllowNullOrEmptyFactoryList()
{
// check default ctor init
SharedStateAwareProcessor ssap = new SharedStateAwareProcessor();
Assert.IsNotNull( ssap.SharedStateFactories );
Assert.AreEqual( 0, ssap.SharedStateFactories.Length );
// check we accept a list at all
ssap = new SharedStateAwareProcessor( new ISharedStateFactory[] { new ByTypeSharedStateFactory() }, Int32.MaxValue );
// now ensure that SharedStateFactories will never be null or empty
ssap = new SharedStateAwareProcessor();
try
{
ssap.SharedStateFactories = null;
Assert.Fail( "should throw ArgumentException" );
}
catch (ArgumentException)
{ }
try
{
ssap.SharedStateFactories = new ISharedStateFactory[0];
Assert.Fail( "should throw ArgumentException" );
}
catch (ArgumentException)
{ }
try
{
ssap.SharedStateFactories = new ISharedStateFactory[] { null };
Assert.Fail( "should throw ArgumentException" );
}
catch (ArgumentException)
{ }
try
{
ssap = new SharedStateAwareProcessor( null, Int32.MaxValue );
Assert.Fail( "should throw ArgumentException" );
}
catch (ArgumentException)
{ }
try
{
ssap = new SharedStateAwareProcessor( new ISharedStateFactory[0], Int32.MaxValue );
Assert.Fail( "should throw ArgumentException" );
}
catch (ArgumentException)
{ }
try
{
ssap = new SharedStateAwareProcessor( new ISharedStateFactory[] { null }, Int32.MaxValue );
Assert.Fail( "should throw ArgumentException" );
}
catch (ArgumentException)
{ }
}
[Test]
public void BeforeInitializationIsNoOp()
{
SharedStateAwareProcessor ssap = new SharedStateAwareProcessor();
object res = ssap.PostProcessBeforeInitialization( this, null );
Assert.AreSame( this, res );
}
[Test]
public void IgnoresAlreadyPopulatedState()
{
DefaultListableObjectFactory of = new DefaultListableObjectFactory();
MockRepository mocks = new MockRepository();
ISharedStateFactory ssf1 = (ISharedStateFactory)mocks.CreateMock( typeof( ISharedStateFactory ) );
ISharedStateAware ssa = (ISharedStateAware)mocks.DynamicMock( typeof( ISharedStateAware ) );
SharedStateAwareProcessor ssap = new SharedStateAwareProcessor();
ssap.SharedStateFactories = new ISharedStateFactory[] { ssf1 };
of.RegisterSingleton( "ssap", ssap );
using (Record( mocks ))
{
// preset SharedState - ssap must ignore it
Expect.Call( ssa.SharedState ).Return( new Hashtable() );
// expect nothing else!
}
using (Playback( mocks ))
{
ssap.PostProcessBeforeInitialization( ssa, "myPage" );
}
}
[Test]
public void ProbesSharedStateFactories()
{
DefaultListableObjectFactory of = new DefaultListableObjectFactory();
MockRepository mocks = new MockRepository();
ISharedStateFactory ssf1 = (ISharedStateFactory)mocks.CreateMock( typeof( ISharedStateFactory ) );
ISharedStateFactory ssf2 = (ISharedStateFactory)mocks.CreateMock( typeof( ISharedStateFactory ) );
ISharedStateFactory ssf3 = (ISharedStateFactory)mocks.CreateMock( typeof( ISharedStateFactory ) );
ISharedStateFactory ssf4 = (ISharedStateFactory)mocks.CreateMock( typeof( ISharedStateFactory ) );
IDictionary ssf3ProvidedState = new Hashtable();
SharedStateAwareProcessor ssap = new SharedStateAwareProcessor();
ssap.SharedStateFactories = new ISharedStateFactory[] { ssf1, ssf2, ssf3, ssf4 };
of.RegisterSingleton( "ssap", ssap );
ISharedStateAware ssa = (ISharedStateAware)mocks.DynamicMock( typeof( ISharedStateAware ) );
// Ensure we iterate over configured SharedStateFactories until
// the first provider is found that
// a) true == provider.CanProvideState( instance, name )
// b) null != provider.GetSharedState( instance, name )
using (Record( mocks ))
{
Expect.Call( ssa.SharedState ).Return( null );
Expect.Call( ssf1.CanProvideState( ssa, "pageName" ) ).Return( false );
Expect.Call( ssf2.CanProvideState( ssa, "pageName" ) ).Return( true );
Expect.Call( ssf2.GetSharedStateFor( ssa, "pageName" ) ).Return( null );
Expect.Call( ssf3.CanProvideState( ssa, "pageName" ) ).Return( true );
Expect.Call( ssf3.GetSharedStateFor( ssa, "pageName" ) ).Return( ssf3ProvidedState );
Expect.Call( ssa.SharedState = ssf3ProvidedState );
}
using (Playback( mocks ))
{
ssap.PostProcessBeforeInitialization( ssa, "pageName" );
}
}
#region Rhino.Mocks Compatibility Adapter
private static IDisposable Record( MockRepository mocks )
{
#if !NET_1_1
return mocks.Record();
#else
return new RecordModeChanger(mocks);
#endif
}
private static IDisposable Playback( MockRepository mocks )
{
#if !NET_1_1
return mocks.Playback();
#else
return new PlaybackModeChanger(mocks);
#endif
}
#if NET_1_1
private class RecordModeChanger : IDisposable
{
private MockRepository _mocks;
public RecordModeChanger(MockRepository mocks)
{
_mocks = mocks;
}
public void Dispose()
{
_mocks.ReplayAll();
}
}
private class PlaybackModeChanger : IDisposable
{
private MockRepository _mocks;
public PlaybackModeChanger(MockRepository mocks)
{
_mocks = mocks;
}
public void Dispose()
{
_mocks.VerifyAll();
}
}
#endif
#endregion Rhino.Mocks Compatibility Adapter
}
}

View File

@@ -0,0 +1,110 @@
#region License
/*
* Copyright <20> 2002-2008 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using System.Collections;
using NUnit.Framework;
#endregion
namespace Spring.Objects.Support
{
/// <summary>
///
/// </summary>
/// <author>Erich Eichinger</author>
[TestFixture]
public class AbstractSharedStateFactoryTests
{
private class TestSharedStateFactory : AbstractSharedStateFactory
{
public static readonly object SPECIAL_OBJECT = new object();
protected override object GetKey(object instance, string name)
{
if (instance == SPECIAL_OBJECT) return null;
return name+"|"+instance.GetHashCode();
}
}
[Test]
public void DefaultsToCaseInsensitiveState()
{
TestSharedStateFactory p = new TestSharedStateFactory();
Assert.IsFalse(p.CaseSensitiveState);
IDictionary state = p.GetSharedStateFor(new object(), "no name" );
state["foo"] = this;
Assert.AreSame(this, state["FOO"]);
}
[Test]
public void StateDictionaryBehavesAccordingToCaseSensitiveState()
{
TestSharedStateFactory p = new TestSharedStateFactory();
// create case-insensitive dict
Assert.IsFalse(p.CaseSensitiveState);
IDictionary state = p.GetSharedStateFor(new object(), "no name" );
state["foo"] = this;
Assert.AreSame(this, state["FOO"]);
// create case-sensitive dict
p.CaseSensitiveState = true;
state = p.GetSharedStateFor(new object(), "no name" );
state["foo"] = this;
Assert.IsFalse(state.Contains("FOO"));
}
[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void ThrowsOnNullInstance()
{
TestSharedStateFactory p = new TestSharedStateFactory();
// allow "null" for name
IDictionary state = p.GetSharedStateFor(new object(), null);
Assert.IsNotNull(state);
// throws on null for instance
p.GetSharedStateFor(null, "no name");
}
[Test]
public void SharedStateCacheIsCaseSensitive()
{
TestSharedStateFactory p = new TestSharedStateFactory();
// allow "null" for name
IDictionary state = p.GetSharedStateFor(this, "foo");
IDictionary state2 = p.GetSharedStateFor(this, "FOO");
Assert.IsNotNull(state);
Assert.IsNotNull(state2);
Assert.AreNotSame(state, state2);
}
[Test]
public void ReturnsNullStateIfKeyIsNull()
{
TestSharedStateFactory p = new TestSharedStateFactory();
// force provider to produce a null key
IDictionary state = p.GetSharedStateFor(TestSharedStateFactory.SPECIAL_OBJECT, null);
Assert.IsNull(state);
}
}
}

View File

@@ -0,0 +1,39 @@
#region License
/*
* Copyright <20> 2002-2008 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using NUnit.Framework;
#endregion
namespace Spring.Objects.Support
{
/// <summary>
///
/// </summary>
/// <author>Erich Eichinger</author>
[TestFixture]
public class ByTypeSharedStateProviderTests
{
// TODO
}
}

View File

@@ -315,6 +315,7 @@
<Compile Include="Objects\Factory\Config\ObjectDefinitionVisitorTests.cs" />
<Compile Include="Objects\Factory\Config\ResourceHandlerConfigurerTests.cs" />
<Compile Include="Objects\Factory\Config\PropertyFileVariableSourceTests.cs" />
<Compile Include="Objects\Factory\Config\SharedStateAwareProcessorTests.cs" />
<Compile Include="Objects\Factory\Config\SpecialFolderVariableSourceTests.cs" />
<Compile Include="Objects\Factory\Config\EnvironmentVariableSourceTests.cs" />
<Compile Include="Objects\Factory\Config\RegistryVariableSourceTests.cs" />
@@ -330,6 +331,8 @@
<Compile Include="Objects\Factory\Xml\ObjectNameGenerationTests.cs" />
<Compile Include="Objects\Factory\Xml\SiimpleCtorWiringTests.cs" />
<Compile Include="Objects\LazyTestObject.cs" />
<Compile Include="Objects\Support\AbstractSharedStateFactoryTests.cs" />
<Compile Include="Objects\Support\ByTypeSharedStateProviderTests.cs" />
<Compile Include="Objects\Support\MethodInvokerTests.cs">
<SubType>Code</SubType>
</Compile>

View File

@@ -1,7 +1,7 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<ProjectType>Local</ProjectType>
<ProductVersion>9.0.21022</ProductVersion>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{44B16BAA-6DF8-447C-9D7F-3AD3D854D904}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -315,6 +315,7 @@
<Compile Include="Objects\Factory\Config\ObjectDefinitionVisitorTests.cs" />
<Compile Include="Objects\Factory\Config\ResourceHandlerConfigurerTests.cs" />
<Compile Include="Objects\Factory\Config\PropertyFileVariableSourceTests.cs" />
<Compile Include="Objects\Factory\Config\SharedStateAwareProcessorTests.cs" />
<Compile Include="Objects\Factory\Config\SpecialFolderVariableSourceTests.cs" />
<Compile Include="Objects\Factory\Config\EnvironmentVariableSourceTests.cs" />
<Compile Include="Objects\Factory\Config\RegistryVariableSourceTests.cs" />
@@ -329,6 +330,8 @@
<Compile Include="Objects\Factory\Xml\ObjectFactorySectionHandlerTests.cs" />
<Compile Include="Objects\Factory\Xml\SiimpleCtorWiringTests.cs" />
<Compile Include="Objects\LazyTestObject.cs" />
<Compile Include="Objects\Support\AbstractSharedStateFactoryTests.cs" />
<Compile Include="Objects\Support\ByTypeSharedStateProviderTests.cs" />
<Compile Include="Objects\Support\MethodInvokerTests.cs">
<SubType>Code</SubType>
</Compile>

View File

@@ -147,5 +147,32 @@ namespace Spring.Util
{
AssertUtils.ArgumentHasLength(new byte[1], "foo", "Bang!");
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void ArgumentHasElementsArgumentIsNull()
{
AssertUtils.ArgumentHasElements(null, "foo");
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void ArgumentHasElementsArgumentIsEmpty()
{
AssertUtils.ArgumentHasElements(new object[0], "foo");
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void ArgumentHasElementsArgumentContainsNull()
{
AssertUtils.ArgumentHasElements(new object[] { new object(), null, new object() }, "foo");
}
[Test]
public void ArgumentHasElementsArgumentContainsNonNullsOnly()
{
AssertUtils.ArgumentHasElements(new object[] { new object(), new object(), new object() }, "foo");
}
}
}

View File

@@ -1,7 +1,7 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<ProjectType>Local</ProjectType>
<ProductVersion>9.0.21022</ProductVersion>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{C67E47AA-1ACD-41B4-A465-4D336A2319CA}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>

View File

@@ -25,6 +25,7 @@ using System.Web;
using NUnit.Framework;
using Rhino.Mocks;
using Spring.Context;
using Spring.Objects.Factory.Config;
using Spring.Objects.Factory.Support;
#endregion