#164 add working metadata caching
This commit is contained in:
@@ -55,7 +55,7 @@ namespace Spring.Aop.Framework.AutoProxy
|
||||
public void DefaultExclusionPrefix()
|
||||
{
|
||||
DefaultAdvisorAutoProxyCreator aapc = (DefaultAdvisorAutoProxyCreator)ObjectFactory.GetObject(ADVISOR_APC_OBJECT_NAME);
|
||||
Assert.AreEqual(ADVISOR_APC_OBJECT_NAME + DefaultAdvisorAutoProxyCreator.SEPARATOR, aapc.AdvisorObjectNamePrefix);
|
||||
Assert.AreEqual(ADVISOR_APC_OBJECT_NAME + DefaultAdvisorAutoProxyCreator.Separator, aapc.AdvisorObjectNamePrefix);
|
||||
Assert.IsFalse(aapc.UsePrefix);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
#endregion
|
||||
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using Spring.Context.Attributes;
|
||||
using Spring.Context.Support;
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
#endregion
|
||||
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using Spring.Context.Attributes;
|
||||
using Spring.Context.Support;
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright <EFBFBD> 2002-2011 the original author or authors.
|
||||
* Copyright © 2002-2011 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.
|
||||
@@ -16,10 +14,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
#region Imports
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
@@ -28,8 +22,6 @@ using Spring.Core.IO;
|
||||
using Spring.Objects.Factory;
|
||||
using Spring.Objects.Factory.Config;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Spring.Context.Support
|
||||
{
|
||||
[TestFixture]
|
||||
@@ -47,20 +39,14 @@ namespace Spring.Context.Support
|
||||
{
|
||||
}
|
||||
|
||||
protected override Type RequiredType
|
||||
{
|
||||
get { return typeof (MockApplicationContext); }
|
||||
}
|
||||
protected override Type RequiredType => typeof (MockApplicationContext);
|
||||
|
||||
protected override void InitApplicationContext()
|
||||
{
|
||||
_init = true;
|
||||
}
|
||||
|
||||
public bool Init
|
||||
{
|
||||
get { return _init; }
|
||||
}
|
||||
public bool Init => _init;
|
||||
}
|
||||
|
||||
internal class MyContext2 : IApplicationContext
|
||||
@@ -69,43 +55,25 @@ namespace Spring.Context.Support
|
||||
{
|
||||
}
|
||||
|
||||
#region IApplicationContext Members
|
||||
public IApplicationContext ParentContext => null;
|
||||
|
||||
public IApplicationContext ParentContext
|
||||
{
|
||||
get { return null; }
|
||||
set
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public DateTime StartupDate
|
||||
{
|
||||
get { return new DateTime(); }
|
||||
}
|
||||
public DateTime StartupDate => new DateTime();
|
||||
|
||||
#pragma warning disable 67
|
||||
public event ApplicationEventHandler ContextEvent;
|
||||
#pragma warning restore 67
|
||||
|
||||
public long StartupDateMilliseconds
|
||||
{
|
||||
get { return 0; }
|
||||
}
|
||||
public long StartupDateMilliseconds => 0;
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return AbstractApplicationContext.DefaultRootContextName; }
|
||||
get => AbstractApplicationContext.DefaultRootContextName;
|
||||
set
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IListableObjectFactory Members
|
||||
|
||||
public IObjectDefinition GetObjectDefinition(string name)
|
||||
public IObjectDefinition GetObjectDefinition(string name)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@@ -115,7 +83,7 @@ namespace Spring.Context.Support
|
||||
return null;
|
||||
}
|
||||
|
||||
public IList<string> GetObjectDefinitionNames(bool includeAncestors)
|
||||
public IReadOnlyList<string> GetObjectDefinitionNames(bool includeAncestors)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@@ -125,47 +93,47 @@ namespace Spring.Context.Support
|
||||
return null;
|
||||
}
|
||||
|
||||
public IList<string> GetObjectNamesForType(Type type)
|
||||
public IReadOnlyList<string> GetObjectNamesForType(Type type)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public IList<string> GetObjectNames<T>()
|
||||
public IReadOnlyList<string> GetObjectNames<T>()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public IList<string> GetObjectNamesForType(Type type, bool includePrototypes, bool includeFactoryObjects)
|
||||
public IReadOnlyList<string> GetObjectNamesForType(Type type, bool includePrototypes, bool includeFactoryObjects)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public IList<string> GetObjectNames<T>(bool includePrototypes, bool includeFactoryObjects)
|
||||
public IReadOnlyList<string> GetObjectNames<T>(bool includePrototypes, bool includeFactoryObjects)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
IList<string> IListableObjectFactory.GetObjectDefinitionNames()
|
||||
IReadOnlyList<string> IListableObjectFactory.GetObjectDefinitionNames()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public IDictionary<string, object> GetObjectsOfType(Type type)
|
||||
public IReadOnlyDictionary<string, object> GetObjectsOfType(Type type)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public IDictionary<string, T> GetObjects<T>()
|
||||
public IReadOnlyDictionary<string, T> GetObjects<T>()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public IDictionary<string, object> GetObjectsOfType(Type type, bool includePrototypes, bool includeFactoryObjects)
|
||||
public IReadOnlyDictionary<string, object> GetObjectsOfType(Type type, bool includePrototypes, bool includeFactoryObjects)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public IDictionary<string, T> GetObjects<T>(bool includePrototypes, bool includeFactoryObjects)
|
||||
public IReadOnlyDictionary<string, T> GetObjects<T>(bool includePrototypes, bool includeFactoryObjects)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@@ -175,36 +143,23 @@ namespace Spring.Context.Support
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public int ObjectDefinitionCount
|
||||
{
|
||||
get { return 0; }
|
||||
}
|
||||
public int ObjectDefinitionCount => 0;
|
||||
|
||||
public bool ContainsObjectDefinition(string name)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
public bool IsCaseSensitive => true;
|
||||
|
||||
#region IObjectFactory Members
|
||||
|
||||
public bool IsCaseSensitive
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public object this[string name]
|
||||
{
|
||||
get { return null; }
|
||||
}
|
||||
public object this[string name] => null;
|
||||
|
||||
public bool ContainsObject(string name)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public IList<string> GetAliases(string name)
|
||||
public IReadOnlyList<string> GetAliases(string name)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@@ -291,24 +246,13 @@ namespace Spring.Context.Support
|
||||
return null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
public IObjectFactory ParentObjectFactory => null;
|
||||
|
||||
#region IHierarchicalObjectFactory Members
|
||||
|
||||
public IObjectFactory ParentObjectFactory
|
||||
{
|
||||
get { return null; }
|
||||
}
|
||||
|
||||
public bool ContainsLocalObject(string name)
|
||||
public bool ContainsLocalObject(string name)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IMessageSource Members
|
||||
|
||||
public string GetMessage(IMessageSourceResolvable resolvable, CultureInfo culture)
|
||||
{
|
||||
return null;
|
||||
@@ -353,19 +297,11 @@ namespace Spring.Context.Support
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IResourceLoader Members
|
||||
|
||||
public IResource GetResource(string location)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IEventRepository Members
|
||||
|
||||
public void PublishEvents(object sourceObject)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
@@ -392,8 +328,6 @@ namespace Spring.Context.Support
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public void PublishEvent(object sender, ApplicationEventArgs e)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
@@ -422,10 +356,7 @@ namespace Spring.Context.Support
|
||||
_init = true;
|
||||
}
|
||||
|
||||
public bool Init
|
||||
{
|
||||
get { return _init; }
|
||||
}
|
||||
public bool Init => _init;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -22,21 +22,20 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using NUnit.Framework;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Spring.Objects.Factory {
|
||||
|
||||
/// <summary>
|
||||
/// Unit tests for the AbstractListableObjectFactory class.
|
||||
namespace Spring.Objects.Factory
|
||||
{
|
||||
/// <summary>
|
||||
/// Unit tests for the AbstractListableObjectFactory class.
|
||||
/// </summary>
|
||||
/// <author>Rod Johnson</author>
|
||||
/// <author>Rick Evans (.NET)</author>
|
||||
public abstract class AbstractListableObjectFactoryTests :
|
||||
AbstractObjectFactoryTests {
|
||||
|
||||
AbstractObjectFactoryTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Subclasses must initialize this (via the derived ObjectFactory property).
|
||||
/// </summary>
|
||||
@@ -46,73 +45,70 @@ namespace Spring.Objects.Factory {
|
||||
{
|
||||
if (!(ObjectFactory is IListableObjectFactory))
|
||||
{
|
||||
throw new SystemException ("IListableObjectFactory required...");
|
||||
throw new SystemException("IListableObjectFactory required...");
|
||||
}
|
||||
|
||||
return (IListableObjectFactory) ObjectFactory;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Subclasses can override this.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public virtual void Count ()
|
||||
public virtual void Count()
|
||||
{
|
||||
AssertCount (19);
|
||||
AssertCount(19);
|
||||
}
|
||||
|
||||
protected internal void AssertCount (int count)
|
||||
|
||||
protected internal void AssertCount(int count)
|
||||
{
|
||||
IList<string> defnames = ListableObjectFactory.GetObjectDefinitionNames(true);
|
||||
Assert.IsTrue (
|
||||
var defnames = ListableObjectFactory.GetObjectDefinitionNames(true);
|
||||
Assert.IsTrue(
|
||||
defnames.Count == count,
|
||||
string.Format ("We should have {0} objects, not {1}.", count, defnames.Count));
|
||||
$"We should have {count} objects, not {defnames.Count}.");
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public virtual void ObjectCount ()
|
||||
public virtual void ObjectCount()
|
||||
{
|
||||
AssertTestObjectCount (12);
|
||||
AssertTestObjectCount(12);
|
||||
}
|
||||
|
||||
public virtual void AssertTestObjectCount (int count)
|
||||
|
||||
public virtual void AssertTestObjectCount(int count)
|
||||
{
|
||||
IList<string> defnames =
|
||||
ListableObjectFactory.GetObjectNamesForType(typeof (TestObject));
|
||||
Assert.IsTrue (
|
||||
var defnames = ListableObjectFactory.GetObjectNamesForType(typeof(TestObject));
|
||||
Assert.IsTrue(
|
||||
defnames.Count == count,
|
||||
string.Format ("We should have {0} objects for class {1}, not {2}.", count, typeof (TestObject).FullName, defnames.Count));
|
||||
$"We should have {count} objects for class {typeof(TestObject).FullName}, not {defnames.Count}.");
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public virtual void GetDefinitionsForNoSuchClass ()
|
||||
public virtual void GetDefinitionsForNoSuchClass()
|
||||
{
|
||||
IList<string> defnames =
|
||||
ListableObjectFactory.GetObjectNamesForType (typeof (string));
|
||||
Assert.IsTrue (defnames.Count == 0, "No string definitions");
|
||||
var defnames = ListableObjectFactory.GetObjectNamesForType(typeof(string));
|
||||
Assert.IsTrue(defnames.Count == 0, "No string definitions");
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Check that count refers to factory class, not
|
||||
/// object class (we don't know what type factories may return,
|
||||
/// and it may even change over time).
|
||||
/// </summary>
|
||||
[Test]
|
||||
public virtual void GetCountForFactoryClass ()
|
||||
public virtual void GetCountForFactoryClass()
|
||||
{
|
||||
int count =
|
||||
ListableObjectFactory.GetObjectNamesForType (
|
||||
typeof (IFactoryObject)).Count;
|
||||
Assert.IsTrue (
|
||||
int count = ListableObjectFactory.GetObjectNamesForType(typeof(IFactoryObject)).Count;
|
||||
Assert.IsTrue(
|
||||
count == 2,
|
||||
string.Format ("Should have 2 factories, not {0}.", count));
|
||||
$"Should have 2 factories, not {count}.");
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public virtual void ContainsObjectDefinition ()
|
||||
public virtual void ContainsObjectDefinition()
|
||||
{
|
||||
Assert.IsTrue (ListableObjectFactory.ContainsObjectDefinition ("rod"));
|
||||
Assert.IsTrue (ListableObjectFactory.ContainsObjectDefinition ("roderick"));
|
||||
Assert.IsTrue(ListableObjectFactory.ContainsObjectDefinition("rod"));
|
||||
Assert.IsTrue(ListableObjectFactory.ContainsObjectDefinition("roderick"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright <EFBFBD> 2002-2011 the original author or authors.
|
||||
* Copyright © 2002-2011 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.
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2004 the original author or authors.
|
||||
*
|
||||
@@ -16,12 +14,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Serialization;
|
||||
using NUnit.Framework;
|
||||
@@ -139,7 +136,7 @@ namespace Spring.Objects.Factory
|
||||
def.FactoryMethodName = "CreateTestObject";
|
||||
DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
|
||||
lof.RegisterObjectDefinition("factoryObject", def);
|
||||
IDictionary<string, TestObject> objs = lof.GetObjects<TestObject>();
|
||||
var objs = lof.GetObjects<TestObject>();
|
||||
Assert.AreEqual(1, objs.Count);
|
||||
}
|
||||
|
||||
@@ -153,7 +150,7 @@ namespace Spring.Objects.Factory
|
||||
DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
|
||||
lof.RegisterObjectDefinition("factoryObject", def);
|
||||
lof.RegisterObjectDefinition("target", new RootObjectDefinition(typeof(TestObjectCreator)));
|
||||
IDictionary<string, TestObject> objs = lof.GetObjects<TestObject>();
|
||||
var objs = lof.GetObjects<TestObject>();
|
||||
Assert.AreEqual(1, objs.Count);
|
||||
}
|
||||
|
||||
@@ -165,7 +162,7 @@ namespace Spring.Objects.Factory
|
||||
= new RootObjectDefinition(typeof(TestGenericObject<int, string>));
|
||||
def.FactoryMethodName = "CreateList<int>";
|
||||
lof.RegisterObjectDefinition("foo", def);
|
||||
IDictionary<string, object> objs = lof.GetObjectsOfType(typeof(List<int>));
|
||||
var objs = lof.GetObjectsOfType(typeof(List<int>));
|
||||
Assert.AreEqual(1, objs.Count);
|
||||
}
|
||||
|
||||
@@ -179,7 +176,7 @@ namespace Spring.Objects.Factory
|
||||
DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
|
||||
lof.RegisterObjectDefinition("factoryObject", def);
|
||||
lof.RegisterObjectDefinition("target", new RootObjectDefinition(typeof(TestGenericObject<int, string>)));
|
||||
IDictionary<string, object> objs = lof.GetObjectsOfType(typeof(TestGenericObject<string, int>));
|
||||
var objs = lof.GetObjectsOfType(typeof(TestGenericObject<string, int>));
|
||||
Assert.AreEqual(1, objs.Count);
|
||||
}
|
||||
|
||||
@@ -217,7 +214,7 @@ namespace Spring.Objects.Factory
|
||||
typeof(StaticFactoryMethodObject));
|
||||
def.FactoryMethodName = "CreateObject";
|
||||
lof.RegisterObjectDefinition("foo", def);
|
||||
IDictionary<string, object> objs = lof.GetObjectsOfType(typeof(DBNull));
|
||||
var objs = lof.GetObjectsOfType(typeof(DBNull));
|
||||
Assert.AreEqual(1, objs.Count,
|
||||
"Must be looking at the RETURN TYPE of the factory method, " +
|
||||
"and hence get one DBNull object back.");
|
||||
@@ -394,15 +391,11 @@ namespace Spring.Objects.Factory
|
||||
return true;
|
||||
}
|
||||
|
||||
#region IInstantiationAwareObjectPostProcessor Members
|
||||
|
||||
public IPropertyValues PostProcessPropertyValues(IPropertyValues pvs, IList<PropertyInfo> pis, object objectInstance, string objectName)
|
||||
{
|
||||
return pvs;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public object PostProcessAfterInitialization(object obj, string objectName)
|
||||
{
|
||||
return obj;
|
||||
@@ -444,15 +437,11 @@ namespace Spring.Objects.Factory
|
||||
return true;
|
||||
}
|
||||
|
||||
#region IInstantiationAwareObjectPostProcessor Members
|
||||
|
||||
public IPropertyValues PostProcessPropertyValues(IPropertyValues pvs, IList<PropertyInfo> pis, object objectInstance, string objectName)
|
||||
{
|
||||
return pvs;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public object PostProcessAfterInitialization(object obj, string objectName)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
@@ -582,7 +571,7 @@ namespace Spring.Objects.Factory
|
||||
TestObject test = (TestObject)lof.GetObject("test");
|
||||
Assert.AreEqual(singletonObject, lof.GetObject("singletonObject"));
|
||||
Assert.AreEqual(singletonObject, test.Spouse);
|
||||
IDictionary<string, object> objectsOfType = lof.GetObjectsOfType(typeof(TestObject), false, true);
|
||||
var objectsOfType = lof.GetObjectsOfType(typeof(TestObject), false, true);
|
||||
Assert.AreEqual(2, objectsOfType.Count);
|
||||
Assert.IsTrue(objectsOfType.Values.Contains(test));
|
||||
Assert.IsTrue(objectsOfType.Values.Contains(singletonObject));
|
||||
@@ -1450,7 +1439,7 @@ namespace Spring.Objects.Factory
|
||||
{
|
||||
TestObject instance = new TestObject();
|
||||
DefaultListableObjectFactory fac = new DefaultListableObjectFactory();
|
||||
Assert.Throws<ArgumentException>(() => fac.ConfigureObject(instance, null));
|
||||
Assert.Throws<ArgumentNullException>(() => fac.ConfigureObject(instance, null));
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -1663,8 +1652,6 @@ namespace Spring.Objects.Factory
|
||||
Assert.AreSame(testObject, resultObject);
|
||||
}
|
||||
|
||||
#region TestObjectPostProcessor
|
||||
|
||||
private class TestObjectPostProcessor : IObjectPostProcessor
|
||||
{
|
||||
private object other;
|
||||
@@ -1685,9 +1672,6 @@ namespace Spring.Objects.Factory
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
[Test]
|
||||
public void ConfigureObjectAppliesObjectPostProcessorsUsingDefinition()
|
||||
{
|
||||
@@ -1724,8 +1708,6 @@ namespace Spring.Objects.Factory
|
||||
Assert.IsNotNull(c);
|
||||
}
|
||||
|
||||
#region GetObjectNamesForTypeFindsFactoryObjects
|
||||
|
||||
private class A : IFactoryObject, ISerializable
|
||||
{
|
||||
public object GetObject()
|
||||
@@ -1749,8 +1731,6 @@ namespace Spring.Objects.Factory
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
[Test]
|
||||
public void GetObjectDefinitionNamesOnlyFromChild()
|
||||
{
|
||||
@@ -1817,13 +1797,56 @@ namespace Spring.Objects.Factory
|
||||
DefaultListableObjectFactory of = new DefaultListableObjectFactory();
|
||||
of.RegisterObjectDefinition("mod", new RootObjectDefinition(typeof(A)));
|
||||
|
||||
IList<string> names = of.GetObjectNamesForType(typeof (ISerializable), false, false);
|
||||
var names = of.GetObjectNamesForType(typeof (ISerializable), false, false);
|
||||
Assert.IsNotEmpty((ICollection) names);
|
||||
Assert.AreEqual("&mod", names[0]);
|
||||
}
|
||||
|
||||
[Test, MaxTime(1000)]
|
||||
public void TestRegistrationOfManyBeanDefinitionsIsFastEnough()
|
||||
{
|
||||
var bf = new DefaultListableObjectFactory();
|
||||
bf.RegisterObjectDefinition("b", new RootObjectDefinition(typeof(B)));
|
||||
|
||||
for (int i = 0; i < 100_000; i++) {
|
||||
bf.RegisterObjectDefinition("a" + i, new RootObjectDefinition(typeof(A)));
|
||||
}
|
||||
}
|
||||
|
||||
#region Helper Classes
|
||||
[Test, MaxTime(1000)]
|
||||
public void TestRegistrationOfManySingletonsIsFastEnough()
|
||||
{
|
||||
// Assume.group(TestGroup.PERFORMANCE);
|
||||
var bf = new DefaultListableObjectFactory();
|
||||
bf.RegisterObjectDefinition("b", new RootObjectDefinition(typeof(B)));
|
||||
// bf.getBean("b");
|
||||
|
||||
for (int i = 0; i < 100000; i++) {
|
||||
bf.RegisterSingleton("a" + i, new A());
|
||||
}
|
||||
}
|
||||
|
||||
[Test, MaxTime(3000)]
|
||||
public void TestPrototypeCreationIsFastEnough()
|
||||
{
|
||||
var lbf = new DefaultListableObjectFactory();
|
||||
var rbd = new RootObjectDefinition(typeof(TestObject))
|
||||
{
|
||||
Scope = "prototype"
|
||||
};
|
||||
lbf.RegisterObjectDefinition("test", rbd);
|
||||
//lbf.FreezeConfiguration();
|
||||
|
||||
for (int i = 0; i < 100_000; i++)
|
||||
{
|
||||
lbf.GetObject("test");
|
||||
}
|
||||
}
|
||||
|
||||
public class B
|
||||
{
|
||||
}
|
||||
|
||||
public interface IParent
|
||||
{
|
||||
|
||||
@@ -1928,8 +1951,6 @@ namespace Spring.Objects.Factory
|
||||
InitWasCalled = true;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public class Foo
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
|
||||
using Spring.Objects.Factory.Config;
|
||||
@@ -68,14 +69,14 @@ namespace Spring.Objects.Factory
|
||||
[Test]
|
||||
public void ObjectNamesIncludingAncestors()
|
||||
{
|
||||
IList<string> names = ObjectFactoryUtils.ObjectNamesIncludingAncestors(_factory);
|
||||
var names = ObjectFactoryUtils.ObjectNamesIncludingAncestors(_factory);
|
||||
Assert.AreEqual(6, names.Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ObjectNamesForTypeIncludingAncestors()
|
||||
{
|
||||
IList<string> names = ObjectFactoryUtils.ObjectNamesForTypeIncludingAncestors(_factory, typeof(ITestObject));
|
||||
var names = ObjectFactoryUtils.ObjectNamesForTypeIncludingAncestors(_factory, typeof(ITestObject));
|
||||
// includes 2 TestObjects from IFactoryObjects (DummyFactory definitions)
|
||||
Assert.AreEqual(4, names.Count);
|
||||
Assert.IsTrue(names.Contains("test"));
|
||||
@@ -92,7 +93,7 @@ namespace Spring.Objects.Factory
|
||||
DefaultListableObjectFactory child = new DefaultListableObjectFactory(root);
|
||||
child.RegisterObjectDefinition("excludeLocalObject", new RootObjectDefinition(typeof(Hashtable)));
|
||||
|
||||
IList<string> names = ObjectFactoryUtils.ObjectNamesForTypeIncludingAncestors(child, typeof(ArrayList));
|
||||
var names = ObjectFactoryUtils.ObjectNamesForTypeIncludingAncestors(child, typeof(ArrayList));
|
||||
// "excludeLocalObject" matches on the parent, but not the local object definition
|
||||
Assert.AreEqual(0, names.Count);
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace Spring.Objects.Factory
|
||||
[Test]
|
||||
public void ObjectNamesIncludingAncestorsPreserveOrderOfRegistration()
|
||||
{
|
||||
IList<string> names = ObjectFactoryUtils.ObjectNamesIncludingAncestors(_factory);
|
||||
var names = ObjectFactoryUtils.ObjectNamesIncludingAncestors(_factory);
|
||||
Assert.AreEqual(5, names.Count);
|
||||
Assert.AreEqual(new string[] { "objA", "objB", "objC", "obj2A", "obj2C" }, names);
|
||||
}
|
||||
@@ -43,7 +43,7 @@ namespace Spring.Objects.Factory
|
||||
[Test]
|
||||
public void ObjectNamesForTypeIncludingAncestorsPreserveOrderOfRegistration()
|
||||
{
|
||||
IList<string> names = ObjectFactoryUtils.ObjectNamesForTypeIncludingAncestors(_factory, _expectedtype);
|
||||
var names = ObjectFactoryUtils.ObjectNamesForTypeIncludingAncestors(_factory, _expectedtype);
|
||||
Assert.AreEqual(5, names.Count);
|
||||
Assert.AreEqual(new string[] { "objA", "objB", "objC", "obj2A", "obj2C" }, names);
|
||||
}
|
||||
@@ -51,7 +51,7 @@ namespace Spring.Objects.Factory
|
||||
[Test]
|
||||
public void ObjectNamesForTypeIncludingAncestorsPrototypesAndFactoryObjectsPreserveOrderOfRegistration()
|
||||
{
|
||||
IList<string> names = ObjectFactoryUtils.ObjectNamesForTypeIncludingAncestors(_factory, _expectedtype, false, false);
|
||||
var names = ObjectFactoryUtils.ObjectNamesForTypeIncludingAncestors(_factory, _expectedtype, false, false);
|
||||
Assert.AreEqual(5, names.Count);
|
||||
Assert.AreEqual(new string[] { "objA", "objB", "objC", "obj2A", "obj2C" }, names);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright <EFBFBD> 2002-2011 the original author or authors.
|
||||
* Copyright © 2002-2011 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.
|
||||
|
||||
@@ -22,6 +22,7 @@ using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Common.Logging;
|
||||
using Common.Logging.Simple;
|
||||
@@ -195,12 +196,12 @@ namespace Spring.Objects.Factory.Xml
|
||||
{
|
||||
IResource resource = new ReadOnlyXmlTestResource("collections.xml", GetType());
|
||||
XmlObjectFactory xof = new XmlObjectFactory(resource);
|
||||
IList<string> objectNames = xof.GetObjectDefinitionNames();
|
||||
var objectNames = xof.GetObjectDefinitionNames();
|
||||
TestObject tb1 = (TestObject) xof.GetObject("aliased");
|
||||
TestObject alias1 = (TestObject) xof.GetObject("myalias");
|
||||
Assert.IsTrue(tb1 == alias1);
|
||||
|
||||
IList<string> tb1Aliases = xof.GetAliases("aliased");
|
||||
var tb1Aliases = xof.GetAliases("aliased");
|
||||
Assert.AreEqual(1, tb1Aliases.Count);
|
||||
Assert.IsTrue(tb1Aliases.Contains("myalias"));
|
||||
Assert.IsTrue(objectNames.Contains("aliased"));
|
||||
@@ -211,7 +212,7 @@ namespace Spring.Objects.Factory.Xml
|
||||
TestObject alias3 = (TestObject) xof.GetObject("alias2");
|
||||
Assert.IsTrue(tb2 == alias2);
|
||||
Assert.IsTrue(tb2 == alias3);
|
||||
IList<string> tb2Aliases = xof.GetAliases("multiAliased");
|
||||
var tb2Aliases = xof.GetAliases("multiAliased");
|
||||
Assert.AreEqual(2, tb2Aliases.Count);
|
||||
Assert.IsTrue(tb2Aliases.Contains("alias1"));
|
||||
Assert.IsTrue(tb2Aliases.Contains("alias2"));
|
||||
@@ -225,7 +226,7 @@ namespace Spring.Objects.Factory.Xml
|
||||
Assert.IsTrue(tb3 == alias4);
|
||||
Assert.IsTrue(tb3 == alias5);
|
||||
|
||||
IList<string> tb3Aliases = xof.GetAliases("aliasWithoutId1");
|
||||
var tb3Aliases = xof.GetAliases("aliasWithoutId1");
|
||||
Assert.AreEqual(2, tb2Aliases.Count);
|
||||
Assert.IsTrue(tb3Aliases.Contains("aliasWithoutId2"));
|
||||
Assert.IsTrue(tb3Aliases.Contains("aliasWithoutId3"));
|
||||
|
||||
@@ -439,7 +439,7 @@ namespace Spring.Objects.Factory.Xml
|
||||
</objects>";
|
||||
stream = new MemoryStream(Encoding.UTF8.GetBytes(xml));
|
||||
XmlObjectFactory factory = new XmlObjectFactory(new InputStreamResource(stream, string.Empty));
|
||||
IList<string> names = factory.GetObjectDefinitionNames();
|
||||
var names = factory.GetObjectDefinitionNames();
|
||||
// mmm, how is one to test this? I have no idea what the generated name is...
|
||||
Assert.AreEqual(2, names.Count, "Should have got two object names, one of which is autogenerated.");
|
||||
}
|
||||
@@ -765,7 +765,7 @@ namespace Spring.Objects.Factory.Xml
|
||||
|
||||
// abstract objects should not match
|
||||
//TODO add overloaded GetObjectOfType with 1 arg
|
||||
IDictionary<string, object> tbs = parent.GetObjectsOfType(typeof(TestObject), true, true);
|
||||
var tbs = parent.GetObjectsOfType(typeof(TestObject), true, true);
|
||||
Assert.AreEqual(2, tbs.Count);
|
||||
Assert.IsTrue(tbs.ContainsKey("inheritedTestObjectPrototype"));
|
||||
Assert.IsTrue(tbs.ContainsKey("inheritedTestObjectSingleton"));
|
||||
|
||||
@@ -30,17 +30,14 @@ namespace Spring.Validation
|
||||
{
|
||||
private bool _wasCalled;
|
||||
|
||||
public bool WasCalled
|
||||
{
|
||||
get { return _wasCalled; }
|
||||
}
|
||||
public bool WasCalled => _wasCalled;
|
||||
|
||||
public override bool Validate(object validationContext, IDictionary<string, object> contextParams, IValidationErrors errors)
|
||||
public override bool Validate(object validationContext, IDictionary<string, object> contextParams,
|
||||
IValidationErrors errors)
|
||||
{
|
||||
_wasCalled = true;
|
||||
return base.Validate (validationContext, contextParams, errors);
|
||||
return base.Validate(validationContext, contextParams, errors);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -49,9 +46,9 @@ namespace Spring.Validation
|
||||
/// <author>Aleksandar Seovic</author>
|
||||
public class TrueValidator : BaseTestValidator
|
||||
{
|
||||
|
||||
public TrueValidator()
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates test object.
|
||||
@@ -68,7 +65,7 @@ namespace Spring.Validation
|
||||
{
|
||||
public FalseValidator()
|
||||
{
|
||||
this.Actions.Add(new ErrorMessageAction("error", "errors"));
|
||||
Actions.Add(new ErrorMessageAction("error", "errors"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -84,26 +81,23 @@ namespace Spring.Validation
|
||||
|
||||
public sealed class MockObjectDefinitionRegistry : IObjectDefinitionRegistry
|
||||
{
|
||||
private IDictionary<string, IObjectDefinition> objects = new Dictionary<string, IObjectDefinition>();
|
||||
private readonly IDictionary<string, IObjectDefinition> objects = new Dictionary<string, IObjectDefinition>();
|
||||
|
||||
public int ObjectDefinitionCount
|
||||
public int ObjectDefinitionCount => objects.Count;
|
||||
|
||||
public IReadOnlyList<string> GetObjectDefinitionNames()
|
||||
{
|
||||
get { return this.objects.Count; }
|
||||
return new List<string>(objects.Keys);
|
||||
}
|
||||
|
||||
public IList<string> GetObjectDefinitionNames()
|
||||
public IReadOnlyList<string> GetObjectDefinitionNames(bool includeAncestor)
|
||||
{
|
||||
return new List<string>(this.objects.Keys);
|
||||
}
|
||||
|
||||
public IList<string> GetObjectDefinitionNames(bool includeAncestor)
|
||||
{
|
||||
return new List<string>(this.objects.Keys);
|
||||
return new List<string>(objects.Keys);
|
||||
}
|
||||
|
||||
public IList<IObjectDefinition> GetObjectDefinitions()
|
||||
{
|
||||
return new List<IObjectDefinition>(this.objects.Values);
|
||||
return new List<IObjectDefinition>(objects.Values);
|
||||
}
|
||||
|
||||
public bool ContainsObjectDefinition(string name)
|
||||
@@ -113,17 +107,16 @@ namespace Spring.Validation
|
||||
|
||||
public IObjectDefinition GetObjectDefinition(string name)
|
||||
{
|
||||
IObjectDefinition definition;
|
||||
objects.TryGetValue(name, out definition);
|
||||
objects.TryGetValue(name, out var definition);
|
||||
return definition;
|
||||
}
|
||||
|
||||
public void RegisterObjectDefinition(string name, IObjectDefinition definition)
|
||||
{
|
||||
this.objects[name] = definition;
|
||||
objects[name] = definition;
|
||||
}
|
||||
|
||||
public IList<string> GetAliases(string name)
|
||||
public IReadOnlyList<string> GetAliases(string name)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
@@ -135,8 +128,7 @@ namespace Spring.Validation
|
||||
|
||||
public bool IsObjectNameInUse(string objectName)
|
||||
{
|
||||
return this.objects[objectName] != null;
|
||||
return objects[objectName] != null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -193,7 +193,7 @@ namespace Spring.Data.Common
|
||||
//Initialize internal application context. factory
|
||||
DbProviderFactory.GetDbProvider("SqlServer-2.0");
|
||||
IApplicationContext ctx = DbProviderFactory.ApplicationContext;
|
||||
IList<string> dbProviderNames = ctx.GetObjectNamesForType(typeof (IDbProvider));
|
||||
var dbProviderNames = ctx.GetObjectNamesForType(typeof (IDbProvider));
|
||||
Assert.IsTrue(dbProviderNames.Count > 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright <20> 2002-2011 the original author or authors.
|
||||
* Copyright <20> 2002-2011 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.
|
||||
@@ -68,14 +68,14 @@ namespace Spring.Messaging.Nms.Config
|
||||
[Test]
|
||||
public void ObjectsCreated()
|
||||
{
|
||||
IDictionary<string, SimpleMessageListenerContainer> containers = ctx.GetObjects<SimpleMessageListenerContainer>();
|
||||
var containers = ctx.GetObjects<SimpleMessageListenerContainer>();
|
||||
Assert.AreEqual(3, containers.Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ContainerConfiguration()
|
||||
{
|
||||
IDictionary<string, SimpleMessageListenerContainer> containers = ctx.GetObjects<SimpleMessageListenerContainer>();
|
||||
var containers = ctx.GetObjects<SimpleMessageListenerContainer>();
|
||||
IConnectionFactory defaultConnectionFactory = (IConnectionFactory) ctx.GetObject(DEFAULT_CONNECTION_FACTORY);
|
||||
IConnectionFactory explicitConnectionFactory = (IConnectionFactory) ctx.GetObject(EXPLICIT_CONNECTION_FACTORY);
|
||||
|
||||
|
||||
@@ -103,7 +103,7 @@ namespace Spring.ServiceModel.Config
|
||||
IApplicationContext ctx = new XmlApplicationContext(
|
||||
ReadOnlyXmlTestResource.GetFilePath("ChannelFactoryObjectDefinitionParserTests.WithoutId.xml", this.GetType()));
|
||||
|
||||
IDictionary<string, IContract> channels = ctx.GetObjects<IContract>();
|
||||
var channels = ctx.GetObjects<IContract>();
|
||||
Assert.AreEqual(1, channels.Count);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user