throw ArgumentException if no config location is passed into XmlApplicationContext 
always create DynamicMethod with "skipVisibility=true"
fixed bug introduced with the object definition's "scope" property when configuring prototypes in webapps
This commit is contained in:
eeichinger
2009-07-22 23:42:01 +00:00
parent f269366cb1
commit b72a4eda8d
14 changed files with 256 additions and 94 deletions

View File

@@ -40,13 +40,13 @@ namespace Spring.Aspects.Cache
[TestFixture]
public sealed class CacheAspectIntegrationTests
{
private IApplicationContext context;
private GenericApplicationContext context;
private CacheAspect cacheAspect;
[SetUp]
public void SetUp()
{
context = new XmlApplicationContext();
context = new GenericApplicationContext();
cacheAspect = new CacheAspect();
cacheAspect.ApplicationContext = context;
@@ -56,7 +56,7 @@ namespace Spring.Aspects.Cache
public void TestCaching()
{
ICache cache = new NonExpiringCache();
((IConfigurableApplicationContext)context).ObjectFactory.RegisterSingleton("inventors", cache);
context.ObjectFactory.RegisterSingleton("inventors", cache);
ProxyFactory pf = new ProxyFactory(new InventorStore());
pf.AddAdvisors(cacheAspect);
@@ -87,7 +87,7 @@ namespace Spring.Aspects.Cache
public void UseMethodInfoForKeyGeneration()
{
ICache cache = new NonExpiringCache();
((IConfigurableApplicationContext)context).ObjectFactory.RegisterSingleton("defaultCache", cache);
context.ObjectFactory.RegisterSingleton("defaultCache", cache);
ProxyFactory pf = new ProxyFactory(new GenericDao<string, int>());
pf.AddAdvisors(cacheAspect);

View File

@@ -81,6 +81,13 @@ namespace Spring.Context.Support
}
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void NoConfigLocation()
{
new XmlApplicationContext();
}
[Test]
public void SingleConfigLocation()
{

View File

@@ -19,6 +19,7 @@
#endregion
using System;
using System.Collections;
using NUnit.Framework;
#if NET_2_0
using System.Collections.Generic;
@@ -33,6 +34,32 @@ namespace Spring.Objects.Factory.Support
public class ManagedDictionaryTests
{
#if NET_2_0
internal class InternalType
{
public string Value = "OK";
}
[Test]
public void ResolvesInternalGenericTypes()
{
ManagedDictionary dict2 = new ManagedDictionary();
dict2.Add("1", "stringValue");
dict2.KeyTypeName = "int";
dict2.ValueTypeName = typeof(InternalType).FullName;
IDictionary resolved = (IDictionary) dict2.Resolve("other", new RootObjectDefinition(typeof (object)), "prop",
delegate(string name, RootObjectDefinition definition, string argumentName, object element)
{
if ("stringValue".Equals(element))
{
return new InternalType();
}
return element;
}
);
Assert.AreEqual( typeof(InternalType), resolved[1].GetType() );
}
[Test]
public void ResolvesGenericTypeNames()
{
@@ -41,12 +68,18 @@ namespace Spring.Objects.Factory.Support
dict.KeyTypeName = "string";
dict.ValueTypeName = "System.Collections.Generic.List<[string]>";
dict.Resolve("somename", new RootObjectDefinition(typeof (object)), "prop",
delegate(string name, RootObjectDefinition definition, string argumentName, object element)
{
return new List<string>();
}
);
IDictionary resolved = (IDictionary) dict.Resolve("somename", new RootObjectDefinition(typeof(object)), "prop",
delegate(string name, RootObjectDefinition definition, string argumentName, object element)
{
if ("value".Equals(element))
{
return new List<string>();
}
return element;
}
);
Assert.AreEqual(1, resolved.Count);
Assert.AreEqual(typeof(List<string>), resolved["key"].GetType());
}
#endif
}

View File

@@ -275,5 +275,39 @@ namespace Spring.Objects.Factory.Xml
NamespaceParserRegistry.Reset();
}
}
[Test]
public void ParsesObjectAttributes()
{
DefaultListableObjectFactory of = new DefaultListableObjectFactory();
XmlObjectDefinitionReader reader = new XmlObjectDefinitionReader(of);
reader.LoadObjectDefinitions(new StringResource(
@"<?xml version='1.0' encoding='UTF-8' ?>
<objects xmlns='http://www.springframework.net'>
<object id='test1' type='Spring.Objects.TestObject, Spring.Core.Tests' singleton='false' abstract='true' />
<object id='test2' type='Spring.Objects.TestObject, Spring.Core.Tests' singleton='true' abstract='false' lazy-init='true'
autowire='no' dependency-check='simple'
depends-on='test1'
init-method='init'
destroy-method='destroy'
/>
</objects>
"));
AbstractObjectDefinition od1 = (AbstractObjectDefinition) of.GetObjectDefinition("test1");
Assert.IsFalse(od1.IsSingleton);
Assert.IsTrue(od1.IsAbstract);
Assert.IsFalse(od1.IsLazyInit);
AbstractObjectDefinition od2 = (AbstractObjectDefinition) of.GetObjectDefinition("test2");
Assert.IsTrue(od2.IsSingleton);
Assert.IsFalse(od2.IsAbstract);
Assert.IsTrue(od2.IsLazyInit);
Assert.AreEqual(AutoWiringMode.No, od2.AutowireMode);
Assert.AreEqual("init", od2.InitMethodName);
Assert.AreEqual("destroy", od2.DestroyMethodName);
Assert.AreEqual(1, od2.DependsOn.Length);
Assert.AreEqual("test1", od2.DependsOn[0]);
Assert.AreEqual(DependencyCheckingMode.Simple, od2.DependencyCheck);
}
}
}

View File

@@ -24,6 +24,7 @@ using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Threading;
using NUnit.Framework;
using Spring.Context.Support;
using Spring.Util;
@@ -81,7 +82,46 @@ namespace Spring.Reflection.Dynamic
}
#endregion
#if NET_2_0
private void RespectsPermissionsPrivateMethod() {}
public void RespectsPermissionsPublicMethod() {}
[Test]
public void CanCreateWithRestrictedPermissions()
{
SecurityTemplate.MediumTrustInvoke(new ThreadStart(CanCreateWithRestrictedPermissionsImpl));
}
private void CanCreateWithRestrictedPermissionsImpl()
{
MethodInfo method = this.GetType().GetMethod("RespectsPermissionsPublicMethod");
IDynamicMethod m = DynamicMethod.Create(method);
m.Invoke(this, null);
}
[Test]
public void CanCreatePrivateMethodButThrowsOnInvoke()
{
SecurityTemplate.MediumTrustInvoke(new ThreadStart(CanCreatePrivateMethodButThrowsOnInvokeImpl));
}
private void CanCreatePrivateMethodButThrowsOnInvokeImpl()
{
MethodInfo privateMethod = this.GetType().GetMethod("RespectsPermissionsPrivateMethod", BindingFlags.NonPublic | BindingFlags.Instance);
IDynamicMethod m = DynamicMethod.Create(privateMethod);
try
{
m.Invoke(this, null);
Assert.Fail();
}
catch(MethodAccessException)
{}
}
#endif
[Test]
public void TestInstanceMethods()
{

View File

@@ -295,7 +295,7 @@ namespace Spring
}
if (trustSection.Level == "Full")
{
{
return null;
}

View File

@@ -141,6 +141,12 @@ namespace Spring.Util
{
ObjectUtils.InstantiateType(typeof(Dictionary<,>));
}
[Test]
public void InstantiateGenericTypeWithArguments()
{
// ObjectUtils.InstantiateType(typeof(Dictionary<string, int>), new object[] { new object() } );
}
#endif
[Test]

View File

@@ -54,7 +54,7 @@ namespace Spring.Web.Support
IApplicationContext appContext =
new XmlApplicationContext(AbstractApplicationContext.DefaultRootContextName, false, RES_OBJECTS);
ContextRegistry.RegisterContext(appContext);
appContext = new XmlApplicationContext("/controls/", false, appContext);
appContext = new GenericApplicationContext("/controls/", false, appContext);
ContextRegistry.RegisterContext(appContext);
}