SPRNET-1536 merge code and tests from SPRNET-CODECONFIG project

This commit is contained in:
Steve Bohlen
2013-01-07 10:55:43 -05:00
parent 06ea2587b1
commit 9b50c40a6b
89 changed files with 7341 additions and 324 deletions

View File

@@ -0,0 +1,354 @@
#region License
/*
* Copyright © 2010-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.
* 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
using System;
using NUnit.Framework;
using Spring.Context.Support;
using Spring.Objects.Factory.Support;
using Spring.Objects.Factory.Config;
using Spring.Objects.Factory.Xml;
namespace Spring.Context.Attributes
{
public abstract class AbstractConfigurationClassPostProcessorTests
{
protected AbstractApplicationContext _ctx;
[SetUp]
public void _SetUp()
{
SingletonParent.InstanceCount = 0;
SingletonChild.InstanceCount = 0;
PrototypeParent.InstanceCount = 0;
PrototypeChild.InstanceCount = 0;
CreateApplicationContext();
}
protected abstract void CreateApplicationContext();
[Test]
public void Can_Assign_Init_And_Destroy_Methods()
{
IObjectDefinition def = _ctx.GetObjectDefinition(typeof(ObjectWithInitAndDestroyMethods).Name);
Assert.That(def, Is.Not.Null);
Assert.That(def.InitMethodName, Is.EqualTo("CallToInit"));
Assert.That(def.DestroyMethodName, Is.EqualTo("CallToDestroy"));
}
[Test]
public void Can_Import_Configurations_From_Additional_Classes()
{
Assert.That(_ctx.GetObject(typeof(AnImportedType).Name), Is.Not.Null);
}
[Test]
public void Can_Respect_Assigned_Aliases()
{
var firstObject = _ctx["TheFirstAlias"];
var secondObject = _ctx["TheSecondAlias"];
Assert.That(firstObject, Is.InstanceOf<ObjectWithAnAlias>());
Assert.That(secondObject, Is.InstanceOf<ObjectWithAnAlias>());
}
[Test]
public void Can_Respect_Assigned_Name()
{
var result = _ctx["TheName"];
Assert.That(result, Is.InstanceOf<SingleNamedObject>());
}
[Test]
public void Can_Respect_Default_Singleton_Scope()
{
var firstObject = (SingletonChild)_ctx[typeof(SingletonChild).Name];
var secondObject = (SingletonChild)_ctx[typeof(SingletonChild).Name];
Assert.That(SingletonChild.InstanceCount, Is.EqualTo(1));
Assert.That(firstObject, Is.SameAs(secondObject));
}
[Test]
public void Can_Respect_Default_Singleton_Scope_With_Explicit_Prototype_Dependency()
{
var firstObject = (SingletonParent)_ctx[typeof(SingletonParent).Name];
var secondObject = (SingletonParent)_ctx[typeof(SingletonParent).Name];
Assert.That(SingletonParent.InstanceCount, Is.EqualTo(1));
//Assert.That(PrototypeChild.InstanceCount, Is.EqualTo(2)); // Requires scoped proxies
Assert.That(firstObject, Is.SameAs(secondObject));
}
[Test]
public void Can_Respect_Explicit_Prototype_Scope()
{
var firstObject = (PrototypeChild)_ctx[typeof(PrototypeChild).Name];
var secondObject = (PrototypeChild)_ctx[typeof(PrototypeChild).Name];
Assert.That(PrototypeChild.InstanceCount, Is.EqualTo(3)); // One instance used by SingletonParent
Assert.That(firstObject, Is.Not.SameAs(secondObject));
}
[Test]
public void Can_Respect_Explicit_Prototype_Scope_With_Default_Singleton_Dependency()
{
var firstObject = (PrototypeParent)_ctx[typeof(PrototypeParent).Name];
var secondObject = (PrototypeParent)_ctx[typeof(PrototypeParent).Name];
Assert.That(PrototypeParent.InstanceCount, Is.EqualTo(2));
Assert.That(SingletonChild.InstanceCount, Is.EqualTo(1));
Assert.That(firstObject, Is.Not.SameAs(secondObject));
}
[Test]
public void Can_Respect_Lazy_Attribute()
{
Assert.That(_ctx.GetObjectDefinition(typeof(ImplicitLazyInitObject).Name).IsLazyInit, Is.True);
Assert.That(_ctx.GetObjectDefinition(typeof(ExplicitLazyInitObject).Name).IsLazyInit, Is.True);
Assert.That(_ctx.GetObjectDefinition(typeof(ExplicitNonLazyInitObject).Name).IsLazyInit, Is.False);
}
[Test]
public void Can_Retreive_Actual_Objects_From_Context()
{
Assert.That(_ctx[typeof(SingletonParent).Name], Is.TypeOf<SingletonParent>());
Assert.That(_ctx[typeof(PrototypeChild).Name], Is.TypeOf<PrototypeChild>());
}
[Test]
public void Can_Satisfy_Dependencies_Of_Objects()
{
Assert.That(((SingletonParent)_ctx[typeof(SingletonParent).Name]).Child, Is.Not.Null);
}
[Test]
public void Can_Respect_Imported_Resources()
{
Assert.That(_ctx["xmlRegisteredObject"], Is.Not.Null);
}
}
public class ObjectWithInitAndDestroyMethods
{
public void CallToDestroy() { }
public void CallToInit() { }
}
[Configuration]
[ImportResource("assembly://Spring.Core.Tests/Spring.Context.Attributes/ObjectDefinitions.xml", DefinitionReader = typeof(XmlObjectDefinitionReader))]
[ImportResource("assembly://Spring.Core.Tests/Spring.Context.Attributes/ObjectDefinitionsTwo.xml")]
public class TheImportedConfigurationClass
{
[ObjectDef]
public virtual AnImportedType AnImportedType()
{
return new AnImportedType();
}
}
[Configuration]
[Import(typeof(TheImportedConfigurationClass))]
public class TheConfigurationClass
{
[ObjectDef(Names = "TheName")]
public virtual SingleNamedObject NamedObject()
{
return new SingleNamedObject();
}
[ObjectDef(DestroyMethod = "CallToDestroy", InitMethod = "CallToInit")]
public virtual ObjectWithInitAndDestroyMethods ObjectWithInitAndDestroyMethods()
{
return new ObjectWithInitAndDestroyMethods();
}
[ObjectDef(Names = "TheFirstAlias,TheSecondAlias")]
public virtual ObjectWithAnAlias ObjectWithAnAlias()
{
return new ObjectWithAnAlias();
}
[ObjectDef]
[Scope(ObjectScope.Prototype)]
public virtual PrototypeParent PrototypeParent()
{
return new PrototypeParent(SingletonChild());
}
[ObjectDef]
[Scope(ObjectScope.Prototype)]
public virtual PrototypeChild PrototypeChild()
{
return new PrototypeChild();
}
[ObjectDef]
public virtual SingletonParent SingletonParent()
{
return new SingletonParent(PrototypeChild());
}
[ObjectDef]
public virtual SingletonChild SingletonChild()
{
return new SingletonChild();
}
[ObjectDef]
[Lazy]
public virtual ImplicitLazyInitObject ImplicitLazyInitObject()
{
return new ImplicitLazyInitObject();
}
[ObjectDef]
[Lazy(true)]
public virtual ExplicitLazyInitObject ExplicitLazyInitObject()
{
return new ExplicitLazyInitObject();
}
[ObjectDef]
[Lazy(false)]
public virtual ExplicitNonLazyInitObject ExplicitNonLazyInitObject()
{
return new ExplicitNonLazyInitObject();
}
}
[Configuration]
public class DerivedConfiguration : BaseConfigurationClass
{
[ObjectDef]
public virtual TestObject DerivedDefinition()
{
return new TestObject(BaseDefinition());
}
}
public class BaseConfigurationClass
{
[ObjectDef]
public virtual string BaseDefinition()
{
return Guid.NewGuid().ToString();
}
}
public class TypeRegisteredInXml { }
public class TypeRegisteredInXmlTwo { }
public class AnImportedType { }
public class ImplicitLazyInitObject { }
public class ExplicitLazyInitObject { }
public class ExplicitNonLazyInitObject { }
public class ObjectWithAnAlias { }
public class SingleNamedObject { }
public class SingletonParent
{
public static int InstanceCount = 0;
private PrototypeChild _child;
public SingletonParent(PrototypeChild child)
{
InstanceCount++;
_child = child;
}
public PrototypeChild Child
{
get
{
return _child;
}
}
}
public class SingletonChild
{
public static int InstanceCount = 0;
public SingletonChild()
{
InstanceCount++;
}
}
public class PrototypeParent
{
public static int InstanceCount = 0;
private SingletonChild _child;
public PrototypeParent(SingletonChild child)
{
InstanceCount++;
_child = child;
}
public SingletonChild Child
{
get
{
return _child;
}
}
}
public class PrototypeChild
{
public static int InstanceCount = 0;
public PrototypeChild()
{
InstanceCount++;
}
}
public class TestObject
{
private readonly string _value;
public TestObject(string value)
{
_value = value;
}
public string Value
{
get { return _value; }
}
}
}

View File

@@ -0,0 +1,30 @@
#region License
/*
* Copyright <20> 2010-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.
* 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
using NUnit.Framework;
namespace Spring.Context.Attributes
{
[TestFixture]
public class AssemblyObjectDefinitionScannerTests
{
}
}

View File

@@ -0,0 +1,133 @@
#region License
/*
* Copyright © 2010-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.
* 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
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using Spring.Core;
using Spring.Util;
namespace Spring.Context.Attributes
{
[TestFixture]
public class AssemblyTypeScannerTests
{
#region Setup/Teardown
[SetUp]
public void _TestSetup()
{
_scanner = new AssemblyObjectDefinitionScanner();
}
#endregion
[Test]
public void AssemblyHavingType_T_Adds_Assembly()
{
_scanner.AssemblyHavingType<IOrdered>();
Assert.That(TypeSources.Any(t => t.Contains(typeof (IOrdered))));
}
[Test]
public void IncludeType_T_Adds_Type()
{
_scanner.IncludeType<IOrdered>();
_scanner.IncludeType<IPriorityOrdered>();
IncludePredicates.Any(p => p(typeof (IOrdered)));
IncludePredicates.Any(p => p(typeof (IPriorityOrdered)));
}
[Test]
public void WithExcludeFilter_Excludes_Type()
{
//var scanner1 = new AssemblyObjectDefinitionScanner();
_scanner.IncludeType<TheConfigurationClass>();
_scanner.IncludeType<TheImportedConfigurationClass>();
_scanner.WithExcludeFilter(t => t.Name.StartsWith("TheImported"));
IEnumerable<Type> types = _scanner.Scan();
//Assert.That(types.Any(t => t.Name == "TheConfigurationClass"));
//Assert.False(types.Any(t => t.Name == "TheImportedConfigurationClass"));
Assert.That(types, Contains.Item((typeof (TheConfigurationClass))));
Assert.False(types.Contains(typeof (TheImportedConfigurationClass)));
}
[Test]
public void WithIncludeFilter_Includes_Types()
{
_scanner.WithIncludeFilter(t => t.Name.Contains("ConfigurationClass"));
IEnumerable<Type> types = _scanner.Scan();
Assert.That(types, Contains.Item((typeof (TheConfigurationClass))));
Assert.That(types, Contains.Item((typeof (TheImportedConfigurationClass))));
Assert.That(types.Count(),Is.EqualTo(2));
}
[Serializable]
private class Scanner : AssemblyTypeScanner
{
protected override bool IsCompoundPredicateSatisfiedBy(Type type)
{
return IsIncludedType(type) && !IsExcludedType(type);
}
}
private AssemblyObjectDefinitionScanner _scanner;
private List<Predicate<Type>> ExcludePredicates
{
get
{
//get at the collection of excludePredicates from the private field
//(yuck!-- test smell, but at least its wrapped up in a neat private property getter!)
return
(List<Predicate<Type>>) (ReflectionUtils.GetInstanceFieldValue(_scanner, "TypeExclusionPredicates"));
}
}
private List<Predicate<Type>> IncludePredicates
{
get
{
//get at the collection of includePredicates from the private field
//(yuck!-- test smell, but at least its wrapped up in a neat private property getter!)
return
(List<Predicate<Type>>) (ReflectionUtils.GetInstanceFieldValue(_scanner, "TypeInclusionPredicates"));
}
}
private List<IEnumerable<Type>> TypeSources
{
get
{
//get at the collection of typeSources from the private field
//(yuck!-- test smell, but at least its wrapped up in a neat private property getter!)
return (List<IEnumerable<Type>>) (ReflectionUtils.GetInstanceFieldValue(_scanner, "TypeSources"));
}
}
}
}

View File

@@ -0,0 +1,44 @@
#region License
/*
* Copyright © 2010-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.
* 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
using NUnit.Framework;
using Spring.Context.Support;
namespace Spring.Context.Attributes
{
[TestFixture]
public class CodeConfigApplicationContextTests : AbstractConfigurationClassPostProcessorTests
{
protected override void CreateApplicationContext()
{
GenericApplicationContext ctx = new GenericApplicationContext();
ctx.ScanAllAssemblies();
ctx.Refresh();
_ctx = ctx;
}
}
}

View File

@@ -0,0 +1,39 @@
#region License
/*
* Copyright © 2010-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.
* 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
using NUnit.Framework;
using Spring.Objects.Factory.Support;
namespace Spring.Context.Attributes
{
[TestFixture]
public class ConfigurationClassObjectDefinitionReaderTests
{
[Test]
public void ShouldNotTryToResolveAbstractDefinitionsToType()
{
GenericObjectDefinition definition = new GenericObjectDefinition();
definition.ObjectTypeName = "~/Default.aspx";
definition.IsAbstract = true;
Assert.That(ConfigurationClassObjectDefinitionReader.CheckConfigurationClassCandidate(definition), Is.False);
}
}
}

View File

@@ -0,0 +1,74 @@
#region License
/*
* Copyright © 2010-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.
* 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
using NUnit.Framework;
using Spring.Context.Attributes;
using Spring.Objects.Factory.Parsing;
namespace Spring.Context.Attributes
{
[TestFixture]
public class ConfigurationClassParserTests
{
private ConfigurationClassParser _parser;
[SetUp]
public void SetUp()
{
_parser = new ConfigurationClassParser(new FailFastProblemReporter());
}
[Test]
public void ShouldBeAbleToRegisterSameNamedConfigurationClassesFromDifferentNamespaces()
{
_parser.Parse(typeof(ConfigurationNameSpace1.SpringConfiguration), "1");
_parser.Parse(typeof(ConfigurationNameSpace2.SpringConfiguration), "2");
Assert.That(_parser.ConfigurationClasses.Count, Is.EqualTo(2), "Did not find two configuration classes");
}
}
}
namespace ConfigurationNameSpace1
{
[Configuration]
public class SpringConfiguration
{
[ObjectDef]
public virtual string ConfigurationNameSpaceObjectA()
{
return "A";
}
}
}
namespace ConfigurationNameSpace2
{
[Configuration]
public class SpringConfiguration
{
[ObjectDef]
public virtual string ConfigurationNameSpaceObjectB()
{
return "B";
}
}
}

View File

@@ -0,0 +1,71 @@
#region License
/*
* Copyright © 2010-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.
* 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
using NUnit.Framework;
using Spring.Context.Support;
using Spring.Objects.Factory.Support;
namespace Spring.Context.Attributes
{
[TestFixture]
public class ConfigurationClassPostProcessorTests : AbstractConfigurationClassPostProcessorTests
{
protected override void CreateApplicationContext()
{
GenericApplicationContext ctx = new GenericApplicationContext();
var configDefinitionBuilder = ObjectDefinitionBuilder.GenericObjectDefinition(typeof(TheConfigurationClass));
ctx.RegisterObjectDefinition(configDefinitionBuilder.ObjectDefinition.ObjectTypeName, configDefinitionBuilder.ObjectDefinition);
var postProcessorDefintionBuilder = ObjectDefinitionBuilder.GenericObjectDefinition(typeof(ConfigurationClassPostProcessor));
ctx.RegisterObjectDefinition(postProcessorDefintionBuilder.ObjectDefinition.ObjectTypeName, postProcessorDefintionBuilder.ObjectDefinition);
Assert.That(ctx.ObjectDefinitionCount, Is.EqualTo(2));
ctx.Refresh();
_ctx = ctx;
}
[Test]
public void ShouldAllowConfigurationClassInheritance()
{
var factory = new DefaultListableObjectFactory();
factory.RegisterObjectDefinition("DerivedConfiguration", new GenericObjectDefinition
{
ObjectType = typeof(DerivedConfiguration)
});
var processor = new ConfigurationClassPostProcessor();
processor.PostProcessObjectFactory(factory);
// we should get singleton instances only
TestObject testObject = (TestObject) factory.GetObject("DerivedDefinition");
string singletonParent = (string) factory.GetObject("BaseDefinition");
Assert.That(testObject.Value, Is.SameAs(singletonParent));
}
}
}

View File

@@ -0,0 +1,207 @@
#region License
/*
* Copyright <20> 2010-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.
* 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
using System;
using NUnit.Framework;
using Spring.Context.Support;
using Spring.Objects.Factory;
using Spring.Objects.Factory.Parsing;
using Spring.Objects.Factory.Support;
namespace Spring.Context.Attributes
{
[TestFixture]
public class FailAssemblyObjectDefinitionScannerTests
{
#region Setup/Teardown
[SetUp]
public void _SetUp()
{
_scanner = new AssemblyObjectDefinitionScanner();
_context = new CodeConfigApplicationContext();
}
#endregion
private void ScanForAndRegisterSingleType(Type type)
{
_scanner.WithIncludeFilter(t => t.Name == type.Name);
_scanner.ScanAndRegisterTypes(_context.DefaultListableObjectFactory);
AttributeConfigUtils.RegisterAttributeConfigProcessors((IObjectDefinitionRegistry)_context.ObjectFactory);
}
private CodeConfigApplicationContext _context;
private AssemblyObjectDefinitionScanner _scanner;
[Test]
public void Can_Ignore_Abstract_Configuration_Types()
{
ScanForAndRegisterSingleType(typeof(ConfigurationClassThatIsAbstract));
Assert.That(_context.GetObjectNamesForType(typeof(ConfigurationClassThatIsAbstract)).Count, Is.EqualTo(0), "Abstract Type erroneously registered with the Context.");
}
[Test]
public void Can_Prevent_Methods_With_Parameters()
{
ScanForAndRegisterSingleType(typeof(ConfigurationClassWithMethodHavingParameters));
Assert.Throws<ObjectDefinitionParsingException>(_context.Refresh);
}
[Test]
public void Can_Prevent_Static_Methods()
{
ScanForAndRegisterSingleType(typeof(ConfigurationClassWithStaticMethod));
Assert.Throws<ObjectDefinitionParsingException>(_context.Refresh);
}
[Test]
public void Can_Prevent_Non_Virtual_Methods()
{
ScanForAndRegisterSingleType(typeof(ConfigurationClassWithNonVirtualMethod));
Assert.Throws<ObjectDefinitionParsingException>(_context.Refresh);
}
[Test]
public void Can_Prevent_Sealed_Configuration_Types()
{
ScanForAndRegisterSingleType(typeof(ConfigurationClassThatIsSealed));
Assert.Throws<ObjectDefinitionParsingException>(_context.Refresh);
}
[Test]
public void Can_Prevent_Overloaded_Methods()
{
ScanForAndRegisterSingleType(typeof(ConfigurationClassWithOverloadedMethods));
Assert.Throws<ObjectDefinitionParsingException>(_context.Refresh);
}
[Test]
public void Can_Prevent_Circular_ConfigurationClass_Refereces()
{
ScanForAndRegisterSingleType(typeof(FirstConfigurationClassWithCircularReference));
try
{
_context.Refresh();
}
catch (ObjectDefinitionStoreException ex)
{
Assert.That(ex.InnerException, Is.TypeOf(typeof(ObjectDefinitionParsingException)));
}
}
}
public class SomeType
{
}
[Configuration]
public class ConfigurationClassWithNonVirtualMethod
{
[ObjectDef]
public SomeType MethodThatRegistersSomeType()
{
return new SomeType();
}
}
[Configuration]
public class ConfigurationClassWithStaticMethod
{
[ObjectDef]
public static SomeType MethodThatRegistersSomeType()
{
return new SomeType();
}
}
[Configuration]
public class ConfigurationClassWithOverloadedMethods
{
[ObjectDef]
public virtual SomeType MethodThatRegistersSomeType()
{
return new SomeType();
}
[ObjectDef]
public virtual SomeType MethodThatRegistersSomeType(int i)
{
return new SomeType();
}
}
[Configuration]
[Import(typeof(SecondConfigurationClassWithCircularReference))]
public class FirstConfigurationClassWithCircularReference
{
[ObjectDef]
public virtual SomeType MethodThatRegistersSomeType()
{
return new SomeType();
}
}
[Configuration]
[Import(typeof(FirstConfigurationClassWithCircularReference))]
public class SecondConfigurationClassWithCircularReference
{
[ObjectDef]
public virtual SomeType MethodThatRegistersSomeType()
{
return new SomeType();
}
}
[Configuration]
public class ConfigurationClassWithMethodHavingParameters
{
[ObjectDef]
public virtual SomeType MethodThatRegistersSomeType(int i)
{
return new SomeType();
}
}
[Configuration]
public abstract class ConfigurationClassThatIsAbstract
{
[ObjectDef]
public virtual SomeType MethodThatRegistersSomeType()
{
return new SomeType();
}
}
[Configuration]
public sealed class ConfigurationClassThatIsSealed
{
[ObjectDef]
public SomeType MethodThatRegistersSomeType()
{
return new SomeType();
}
}
}

View File

@@ -0,0 +1,65 @@
#region License
/*
* Copyright © 2010-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.
* 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
using System;
using NUnit.Framework;
using Spring.Objects.Factory.Xml;
using Spring.Objects.Factory.Support;
namespace Spring.Context.Attributes
{
[TestFixture]
public class ImportResourceAttributeTests
{
[Test]
public void Uses_XmlObjectDefinitionReader_By_Default()
{
var attrib = new ImportResourceAttribute("the resource");
Assert.That(attrib.DefinitionReader, Is.EqualTo(typeof(XmlObjectDefinitionReader)));
}
[Test]
public void Can_Assign_NonDefault_DefinitionReader()
{
var attrib = new ImportResourceAttribute("the resource");
attrib.DefinitionReader = typeof(AbstractObjectDefinitionReader);
Assert.That(attrib.DefinitionReader, Is.EqualTo(typeof(AbstractObjectDefinitionReader)));
}
[Test]
public void DefinitionReader_Can_Prevent_Improper_Types()
{
ImportResourceAttribute attrib = new ImportResourceAttribute("the resource");
try
{
attrib.DefinitionReader = typeof(Object);// <--need to pass *anything* ensured *not* to implement IObjectDefinitionReader
Assert.Fail("Expected Exception of type ArgumentException not thrown!");
}
catch (ArgumentException)
{
//swallow the expected exception
}
}
}
}

View File

@@ -0,0 +1,54 @@
#region License
/*
* Copyright © 2010-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.
* 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
using NUnit.Framework;
namespace Spring.Context.Attributes
{
[TestFixture]
public class ObjectDefAttributeTests
{
[Test]
public void Can_Accept_Single_Name()
{
var def = new ObjectDefAttribute();
def.Names = "Steve";
Assert.That(def.NamesToArray[0], Is.EqualTo("Steve"));
}
[Test]
public void Can_Accept_Multiple_Names()
{
var def = new ObjectDefAttribute();
var names = "Name1,Name2,Name3";
def.Names = names;
Assert.That(def.NamesToArray[0], Is.EqualTo("Name1"));
Assert.That(def.NamesToArray[1], Is.EqualTo("Name2"));
Assert.That(def.NamesToArray[2], Is.EqualTo("Name3"));
}
}
}

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net" >
<object id="xmlRegisteredObject" type="Spring.Context.Attributes.TypeRegisteredInXml, Spring.Core.Tests" />
</objects>

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net" >
<object id="xmlRegisteredObjectTwo" type="Spring.Context.Attributes.TypeRegisteredInXmlTwo, Spring.Core.Tests" />
</objects>

View File

@@ -0,0 +1,44 @@
#region License
/*
* Copyright © 2010-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.
* 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
using NUnit.Framework;
using Spring.Context.Config;
using Spring.Context.Support;
using Spring.Objects.Factory.Xml;
namespace Spring.Context.Attributes
{
[TestFixture]
public class ScanningConfigurationClassPostProcessorTests : AbstractConfigurationClassPostProcessorTests
{
protected override void CreateApplicationContext()
{
NamespaceParserRegistry.RegisterParser(typeof(ContextNamespaceParser));
_ctx = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("SimpleScanTest.xml", GetType()));
}
[Test]
public void ContextNotNull()
{
Assert.That(_ctx, Is.Not.Null);
}
}
}

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net"
xmlns:context="http://www.springframework.net/context">
<context:component-scan base-assemblies=""/>
</objects>

View File

@@ -0,0 +1,92 @@
#region License
/*
* Copyright <20> 2010-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.
* 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
using System;
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using Spring.Context.Config;
using Spring.Context.Support;
using Spring.Example.Scannable;
using Spring.Objects.Factory;
using Spring.Objects.Factory.Xml;
namespace Spring.Context.Attributes
{
public class SimpleScanTests
{
private IApplicationContext _applicationContext;
[SetUp]
public void Setup()
{
NamespaceParserRegistry.RegisterParser(typeof(ContextNamespaceParser));
_applicationContext = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("SimpleScanTest.xml", GetType()));
}
//[Test]
public void FooService()
{
IFooService fooService = GetObject<IFooService>();
}
public T GetObject<T>()
{
return (T)DoGetInstance(typeof(T), null);
}
public T GetObject<T>(string name)
{
return (T)DoGetInstance(typeof(T), name);
}
protected object DoGetInstance(Type serviceType, string key)
{
if (key == null)
{
IEnumerator it = DoGetAllInstances(serviceType).GetEnumerator();
if (it.MoveNext())
{
return it.Current;
}
throw new ObjectCreationException(string.Format("no services of type '{0}' defined", serviceType.FullName));
}
return _applicationContext.GetObject(key, serviceType);
}
/// <summary>
/// Resolves service instances by type.
/// </summary>
/// <param name="serviceType">Type of service requested.</param>
/// <returns>
/// Sequence of service instance objects matching the <paramref name="serviceType"/>.
/// </returns>
protected IEnumerable<object> DoGetAllInstances(Type serviceType)
{
foreach (string objectName in _applicationContext.GetObjectNamesForType(serviceType))
{
yield return _applicationContext.GetObject(objectName);
}
}
}
}

View File

@@ -0,0 +1,51 @@
#region License
/*
* Copyright 2002-2010 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
using NUnit.Framework;
using Spring.Context.Attributes;
using Spring.Context.Support;
using Spring.Objects.Factory.Xml;
namespace Spring.Context.Config
{
[TestFixture]
public class AttributeConfigObjectDefinitionParserTests
{
private XmlApplicationContext _applicationContext;
[SetUp]
public void Setup()
{
NamespaceParserRegistry.RegisterParser(typeof(ContextNamespaceParser));
}
[Test]
public void RegisteredComponents()
{
_applicationContext = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("ConfigFiles.AttributeConfigParser.xml", GetType()));
var objectDefintionNames = _applicationContext.ObjectFactory.GetObjectDefinitionNames();
Assert.That(objectDefintionNames.Contains(AttributeConfigUtils.CONFIGURATION_ATTRIBUTE_PROCESSOR_OBJECT_NAME), Is.True);
Assert.That(objectDefintionNames.Contains(AttributeConfigUtils.AUTOWIRED_ATTRIBUTE_PROCESSOR_OBJECT_NAME), Is.True);
Assert.That(objectDefintionNames.Contains(AttributeConfigUtils.REQUIRED_ATTRIBUTE_PROCESSOR_OBJECT_NAME), Is.True);
Assert.That(objectDefintionNames.Contains(AttributeConfigUtils.INITDESTROY_ATTRIBUTE_PROCESSOR_OBJECT_NAME), Is.True);
}
}
}

View File

@@ -0,0 +1,49 @@
using NUnit.Framework;
using Spring.Context.Support;
using Spring.Objects.Factory.Xml;
namespace Spring.Context.Config
{
[TestFixture]
public class ComponentScanObjectDefinitionParserAssemblyFilterTests
{
private IApplicationContext _applicationContext;
[SetUp]
public void Setup()
{
NamespaceParserRegistry.RegisterParser(typeof(ContextNamespaceParser));
}
[Test]
public void BaseAssembliesAttributeRequired()
{
Assert.That(delegate { _applicationContext = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("ConfigFiles.BaseAssemblyTestWithout.xml", GetType())); },
Throws.Exception);
}
[Test]
public void SingleAssemblyNameProvided()
{
_applicationContext = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("ConfigFiles.BaseAssemblyTestSingle.xml", GetType()));
Assert.That(_applicationContext.GetObjectDefinitionNames().Count, Is.GreaterThan(0));
}
[Test]
public void MultipleAssemblyNameProvided()
{
_applicationContext = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("ConfigFiles.BaseAssemblyTestMultiple.xml", GetType()));
Assert.That(_applicationContext.GetObjectDefinitionNames().Count, Is.GreaterThan(0));
}
[Test]
public void NegativeAssemblyNameProvided()
{
_applicationContext = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("ConfigFiles.BaseAssemblyTestNegative.xml", GetType()));
Assert.That(_applicationContext.GetObjectDefinitionNames().Count, Is.EqualTo(4));
}
}
}

View File

@@ -0,0 +1,323 @@
#region License
/*
* Copyright 2002-2010 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
using NUnit.Framework;
using Spring.Context.Attributes;
using Spring.Context.Support;
using Spring.Objects.Factory.Config;
using Spring.Objects.Factory.Support;
using Spring.Objects.Factory.Xml;
using Spring.Stereotype;
using Spring.Objects.Factory.Attributes;
using ComponentScan.Qualifier;
namespace Spring.Context.Config
{
[TestFixture]
public class ComponentScanObjectDefinitionParserTests
{
private XmlApplicationContext _applicationContext;
[SetUp]
public void Setup()
{
NamespaceParserRegistry.RegisterParser(typeof(ContextNamespaceParser));
}
[Test]
public void ScanComponentsAndAddToContext()
{
var prefix = "ComponentScan.ScanComponentsAndAddToContext.";
_applicationContext = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("ConfigFiles.ComponentScan1.xml", GetType()));
var objectDefinitionNames = _applicationContext.ObjectFactory.GetObjectDefinitionNames();
Assert.That(objectDefinitionNames.Count, Is.EqualTo(5+4));
Assert.That(_applicationContext.GetObject(prefix + "ComponentImpl"), Is.Not.Null);
Assert.That(_applicationContext.GetObject(prefix + "ServiceImpl"), Is.Not.Null);
Assert.That(_applicationContext.GetObject(prefix + "RepositoryImpl"), Is.Not.Null);
Assert.That(_applicationContext.GetObject(prefix + "ControllerImpl"), Is.Not.Null);
Assert.That(_applicationContext.GetObject(prefix + "ConfigurationImpl"), Is.Not.Null);
}
[Test]
public void ComponentsUseSpecifiedName()
{
_applicationContext = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("ConfigFiles.ComponentScan2.xml", GetType()));
var objectDefinitionNames = _applicationContext.ObjectFactory.GetObjectDefinitionNames();
Assert.That(objectDefinitionNames.Count, Is.EqualTo(5 + 4));
Assert.That(_applicationContext.GetObject("Component"), Is.Not.Null);
Assert.That(_applicationContext.GetObject("Service"), Is.Not.Null);
Assert.That(_applicationContext.GetObject("Repository"), Is.Not.Null);
Assert.That(_applicationContext.GetObject("Controller"), Is.Not.Null);
Assert.That(_applicationContext.GetObject("Configuration"), Is.Not.Null);
}
[Test]
public void UseSpecifiedObjectNameGenerator()
{
_applicationContext = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("ConfigFiles.ComponentScan3.xml", GetType()));
var objectDefinitionNames = _applicationContext.ObjectFactory.GetObjectDefinitionNames();
Assert.That(objectDefinitionNames.Contains("prototype"), Is.True);
}
[Test]
public void UseWrongObjectNameGeneratorTypeString()
{
_applicationContext = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("ConfigFiles.ComponentScan31.xml", GetType()));
var objectDefinitionNames = _applicationContext.ObjectFactory.GetObjectDefinitionNames();
Assert.That(objectDefinitionNames.Contains("prototype"), Is.False);
Assert.That(objectDefinitionNames.Contains("ComponentScan.NameGenerator.Prototype"), Is.True);
}
[Test]
public void ComponentsLazyLoaded()
{
_applicationContext = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("ConfigFiles.ComponentScan4.xml", GetType()));
var objectDefinition = _applicationContext.ObjectFactory.GetObjectDefinition("LazyInit");
Assert.That(objectDefinition.IsLazyInit, Is.True);
}
[Test]
public void ComponentsInDifferentScope()
{
_applicationContext = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("ConfigFiles.ComponentScan4.xml", GetType()));
var singletonDef = _applicationContext.ObjectFactory.GetObjectDefinition("Singleton");
var prototypeDef = _applicationContext.ObjectFactory.GetObjectDefinition("Prototype");
Assert.That(singletonDef.IsSingleton, Is.True);
Assert.That(singletonDef.Scope, Is.EqualTo(ObjectScope.Singleton.ToString().ToLower()));
Assert.That(prototypeDef.IsSingleton, Is.False);
Assert.That(prototypeDef.Scope, Is.EqualTo(ObjectScope.Prototype.ToString().ToLower()));
}
[Test]
public void ComponentsUseDefaults()
{
_applicationContext = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("ConfigFiles.ComponentScan5.xml", GetType()));
var prototypeDef = _applicationContext.ObjectFactory.GetObjectDefinition("Prototype");
Assert.That(prototypeDef.IsLazyInit, Is.True);
}
[Test]
public void ComponentWithQualifier()
{
_applicationContext = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("ConfigFiles.ComponentScan6.xml", GetType()));
var objectDef = _applicationContext.ObjectFactory.GetObjectDefinition("Prototype") as ScannedGenericObjectDefinition;
Assert.That(objectDef.HasQualifier(typeof(QualifierAttribute).Name), Is.True);
var attr = objectDef.GetQualifier(typeof (QualifierAttribute).Name).GetAttribute(AutowireCandidateQualifier.VALUE_KEY);
Assert.That(attr, Is.EqualTo("action"));
}
[Test]
public void ComponentWithQualifierAttributes()
{
_applicationContext = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("ConfigFiles.ComponentScan6.xml", GetType()));
var objectDef = _applicationContext.ObjectFactory.GetObjectDefinition("Attribute") as ScannedGenericObjectDefinition;
var qualifier = objectDef.GetQualifier(typeof (MyQualifier).Name);
Assert.That(qualifier, Is.Not.Null);
var attr = qualifier.GetMetadataAttribute("Foo");
Assert.That(attr, Is.Not.Null);
Assert.That(attr.Value, Is.EqualTo("Funny"));
}
[Test]
public void DontRegisterAttributeConfig()
{
_applicationContext = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("ConfigFiles.ComponentScanAttributeConfigFalse.xml", GetType()));
var objectDefintionNames = _applicationContext.ObjectFactory.GetObjectDefinitionNames();
Assert.That(objectDefintionNames.Count, Is.EqualTo(0));
Assert.That(objectDefintionNames.Contains(AttributeConfigUtils.CONFIGURATION_ATTRIBUTE_PROCESSOR_OBJECT_NAME), Is.False);
Assert.That(objectDefintionNames.Contains(AttributeConfigUtils.AUTOWIRED_ATTRIBUTE_PROCESSOR_OBJECT_NAME), Is.False);
Assert.That(objectDefintionNames.Contains(AttributeConfigUtils.REQUIRED_ATTRIBUTE_PROCESSOR_OBJECT_NAME), Is.False);
Assert.That(objectDefintionNames.Contains(AttributeConfigUtils.INITDESTROY_ATTRIBUTE_PROCESSOR_OBJECT_NAME), Is.False);
}
[Test]
public void RegisterAttributeConfig()
{
_applicationContext = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("ConfigFiles.ComponentScanAttributeConfigTrue.xml", GetType()));
var objectDefintionNames = _applicationContext.ObjectFactory.GetObjectDefinitionNames();
Assert.That(objectDefintionNames.Count, Is.EqualTo(4));
Assert.That(objectDefintionNames.Contains(AttributeConfigUtils.CONFIGURATION_ATTRIBUTE_PROCESSOR_OBJECT_NAME), Is.True);
Assert.That(objectDefintionNames.Contains(AttributeConfigUtils.AUTOWIRED_ATTRIBUTE_PROCESSOR_OBJECT_NAME), Is.True);
Assert.That(objectDefintionNames.Contains(AttributeConfigUtils.REQUIRED_ATTRIBUTE_PROCESSOR_OBJECT_NAME), Is.True);
Assert.That(objectDefintionNames.Contains(AttributeConfigUtils.INITDESTROY_ATTRIBUTE_PROCESSOR_OBJECT_NAME), Is.True);
}
}
}
namespace ComponentScan.ScanComponentsAndAddToContext
{
public interface IFoo
{
}
[Component]
public class ComponentImpl : IFoo
{
}
[Service]
public class ServiceImpl : IFoo
{
}
[Repository]
public class RepositoryImpl : IFoo
{
}
[Controller]
public class ControllerImpl : IFoo
{
}
[Configuration]
public class ConfigurationImpl : IFoo
{
}
}
namespace ComponentScan.ComponentsUseSpecifiedName
{
public interface IFoo
{
}
[Component("Component")]
public class ComponentImpl : IFoo
{
}
[Service("Service")]
public class ServiceImpl : IFoo
{
}
[Repository("Repository")]
public class RepositoryImpl : IFoo
{
}
[Controller("Controller")]
public class ControllerImpl : IFoo
{
}
[Configuration("Configuration")]
public class ConfigurationImpl : IFoo
{
}
}
namespace ComponentScan.ComponentsAttributeLoad
{
public interface IFoo
{
}
[Component("LazyInit")]
[Lazy]
public class LazyImpl : IFoo
{
}
[Component("Singleton")]
[Scope(ObjectScope.Singleton)]
public class SingletonImpl : IFoo
{
}
[Component("Prototype")]
[Scope(ObjectScope.Prototype)]
public class PrototypeImpl : IFoo
{
}
}
namespace ComponentScan.ComponentsUseDefaults
{
public interface IFoo
{
}
[Component("Prototype")]
public class PrototypeImpl : IFoo
{
}
}
namespace ComponentScan.Qualifier
{
public interface IFoo
{
}
public class MyQualifier : QualifierAttribute
{
public string Foo { get; set; }
}
[Component("Prototype")]
[Qualifier("action")]
public class PrototypeImpl : IFoo
{
}
[Component("Attribute")]
[MyQualifier(Foo="Funny")]
public class QualifierAttributeImpl : IFoo
{
}
}
namespace ComponentScan.NameGenerator
{
public interface IFoo
{
}
public class MyGenerator : IObjectNameGenerator
{
public string GenerateObjectName(IObjectDefinition definition, IObjectDefinitionRegistry registry)
{
string typeName = definition.ObjectType.Name;
return typeName.ToLower();
}
}
[Component]
public class Prototype : IFoo
{
}
}

View File

@@ -0,0 +1,224 @@
#region License
/*
* Copyright 2002-2010 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
using System;
using NUnit.Framework;
using Spring.Context.Attributes;
using Spring.Context.Attributes.TypeFilters;
using Spring.Objects.Factory;
using Spring.Objects.Factory.Xml;
using Spring.Context.Support;
using Spring.Stereotype;
namespace Spring.Context.Config
{
[TestFixture]
public class ComponentScanObjectDefinitionParserTypeFilterTests
{
private IApplicationContext _applicationContext;
[SetUp]
public void Setup()
{
NamespaceParserRegistry.RegisterParser(typeof(ContextNamespaceParser));
}
[Test]
public void IncludeRegExpressionFilter()
{
_applicationContext = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("ConfigFiles.TypeScannerTestRegExInclude.xml", GetType()));
Assert.That(_applicationContext.GetObjectDefinitionNames().Count, Is.EqualTo(6));
Assert.That(_applicationContext.GetObject("SomeIncludeType1"), Is.Not.Null);
Assert.That(delegate { _applicationContext.GetObject("SomeExcludeType"); }, Throws.Exception.TypeOf<NoSuchObjectDefinitionException>());
}
[Test]
public void IncludeMultipleRegExpressionFilter()
{
_applicationContext = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("ConfigFiles.TypeScannerTestRegExInclude2.xml", GetType()));
Assert.That(_applicationContext.GetObjectDefinitionNames().Count, Is.EqualTo(8));
Assert.That(_applicationContext.GetObject("SomeIncludeType1"), Is.Not.Null);
Assert.That(_applicationContext.GetObject("SomeIncludeType2"), Is.Not.Null);
Assert.That(delegate { _applicationContext.GetObject("SomeExcludeType"); }, Throws.Exception.TypeOf<NoSuchObjectDefinitionException>());
}
[Test]
public void ExcludeRegExpressionFilter()
{
_applicationContext = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("ConfigFiles.TypeScannerTestRegExExclude.xml", GetType()));
Assert.That(_applicationContext.GetObjectDefinitionNames().Count, Is.EqualTo(8));
Assert.That(_applicationContext.GetObject("SomeIncludeType1"), Is.Not.Null);
Assert.That(delegate { _applicationContext.GetObject("SomeExcludeType"); }, Throws.Exception.TypeOf<NoSuchObjectDefinitionException>());
}
[Test]
public void IncludeAttributeExpressionFilter()
{
_applicationContext = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("ConfigFiles.TypeScannerTestAttributeInclude.xml", GetType()));
Assert.That(_applicationContext.GetObjectDefinitionNames().Count, Is.EqualTo(6));
Assert.That(_applicationContext.GetObject("SomeIncludeType2"), Is.Not.Null);
Assert.That(delegate { _applicationContext.GetObject("SomeExcludeType"); }, Throws.Exception.TypeOf<NoSuchObjectDefinitionException>());
}
[Test]
public void ExcludeAttributeExpressionFilter()
{
_applicationContext = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("ConfigFiles.TypeScannerTestAttributeExclude.xml", GetType()));
Assert.That(_applicationContext.GetObjectDefinitionNames().Count, Is.EqualTo(8));
Assert.That(_applicationContext.GetObject("SomeIncludeType2"), Is.Not.Null);
Assert.That(_applicationContext.GetObject("SomeExcludeType"), Is.Not.Null);
Assert.That(delegate { _applicationContext.GetObject("SomeIncludeType1"); }, Throws.Exception.TypeOf<NoSuchObjectDefinitionException>());
}
[Test]
public void IncludeAssignableExpressionFilter()
{
_applicationContext = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("ConfigFiles.TypeScannerTestAssignableInclude.xml", GetType()));
Assert.That(_applicationContext.GetObjectDefinitionNames().Count, Is.EqualTo(8));
Assert.That(_applicationContext.GetObject("SomeIncludeType1"), Is.Not.Null);
Assert.That(_applicationContext.GetObject("SomeIncludeType2"), Is.Not.Null);
Assert.That(delegate { _applicationContext.GetObject("SomeExcludeType"); }, Throws.Exception.TypeOf<NoSuchObjectDefinitionException>());
}
[Test]
public void ExcludeAssignableExpressionFilter()
{
_applicationContext = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("ConfigFiles.TypeScannerTestAssignableExclude.xml", GetType()));
Assert.That(_applicationContext.GetObjectDefinitionNames().Count, Is.EqualTo(8));
Assert.That(_applicationContext.GetObject("SomeIncludeType1"), Is.Not.Null);
Assert.That(_applicationContext.GetObject("SomeExcludeType"), Is.Not.Null);
Assert.That(delegate { _applicationContext.GetObject("SomeIncludeType2"); }, Throws.Exception.TypeOf<NoSuchObjectDefinitionException>());
}
[Test]
public void IncludeCustomExpressionFilter()
{
_applicationContext = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("ConfigFiles.TypeScannerTestCustomInclude.xml", GetType()));
Assert.That(_applicationContext.GetObjectDefinitionNames().Count, Is.EqualTo(6));
Assert.That(_applicationContext.GetObject("SomeIncludeType1"), Is.Not.Null);
Assert.That(delegate { _applicationContext.GetObject("SomeIncludeType2"); }, Throws.Exception.TypeOf<NoSuchObjectDefinitionException>());
}
[Test]
public void ExcludeCustomExpressionFilter()
{
_applicationContext = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("ConfigFiles.TypeScannerTestCustomExclude.xml", GetType()));
Assert.That(_applicationContext.GetObjectDefinitionNames().Count, Is.EqualTo(8));
Assert.That(_applicationContext.GetObject("SomeIncludeType2"), Is.Not.Null);
Assert.That(_applicationContext.GetObject("SomeExcludeType"), Is.Not.Null);
Assert.That(delegate { _applicationContext.GetObject("SomeIncludeType1"); }, Throws.Exception.TypeOf<NoSuchObjectDefinitionException>());
}
}
}
namespace XmlAssemblyTypeScanner.Test.Include1
{
[AttributeUsage(AttributeTargets.Class)]
public class DoNotIncludeAttribute : Attribute
{
}
[Configuration]
[DoNotInclude]
public class SomeIncludeConfiguration1 : IFunny
{
[ObjectDef]
public virtual SomeIncludeType1 SomeIncludeType1()
{
return new SomeIncludeType1();
}
}
public class SomeIncludeType1
{
}
public interface IFunny
{}
public class TestFilter : ITypeFilter
{
public bool Match(Type type)
{
return type.Name.Equals("SomeIncludeConfiguration1");
}
}
}
namespace XmlAssemblyTypeScanner.Test.Include2
{
[AttributeUsage(AttributeTargets.Class)]
public class DoIncludeAttribute : Attribute
{
}
[Configuration]
[DoInclude]
public class SomeIncludeConfiguration2 : FunnyAbstract
{
public override void Test() { }
[ObjectDef]
public virtual SomeIncludeType2 SomeIncludeType2()
{
return new SomeIncludeType2();
}
}
public class SomeIncludeType2
{
}
public abstract class FunnyAbstract
{
public abstract void Test();
}
}
namespace XmlAssemblyTypeScanner.Test.Include
{
[Configuration]
public class SomeExcludeConfiguration3
{
[ObjectDef]
public virtual SomeExcludeType SomeExcludeType()
{
return new SomeExcludeType();
}
}
public class SomeExcludeType
{
}
}

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net"
xmlns:context="http://www.springframework.net/context">
<context:attribute-config />
</objects>

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net"
xmlns:context="http://www.springframework.net/context">
<context:component-scan base-assemblies="Spring.Core.Tests,AnotherAssembly"/>
</objects>

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net"
xmlns:context="http://www.springframework.net/context">
<context:component-scan base-assemblies="DoesNotExists"/>
</objects>

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net"
xmlns:context="http://www.springframework.net/context">
<context:component-scan base-assemblies="Spring.Core.Tests"/>
</objects>

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net"
xmlns:context="http://www.springframework.net/context">
<context:component-scan />
</objects>

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net"
xmlns:context="http://www.springframework.net/context">
<context:component-scan base-assemblies="Spring.Core.Tests">
<context:include-filter type="regex" expression="ComponentScan.ScanComponentsAndAddToContext.*"/>
</context:component-scan>
</objects>

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net"
xmlns:context="http://www.springframework.net/context">
<context:component-scan base-assemblies="Spring.Core.Tests">
<context:include-filter type="regex" expression="ComponentScan.ComponentsUseSpecifiedName.*"/>
</context:component-scan>
</objects>

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net"
xmlns:context="http://www.springframework.net/context">
<context:component-scan base-assemblies="Spring.Core.Tests"
name-generator="ComponentScan.NameGenerator.MyGenerator, Spring.Core.Tests">
<context:include-filter type="regex" expression="ComponentScan.NameGenerator.*"/>
</context:component-scan>
</objects>

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net"
xmlns:context="http://www.springframework.net/context">
<context:component-scan base-assemblies="Spring.Core.Tests"
name-generator="ComponentScan.NameGenerator.NotExistsGenerator, Spring.Core.Tests">
<context:include-filter type="regex" expression="ComponentScan.NameGenerator.*"/>
</context:component-scan>
</objects>

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net"
xmlns:context="http://www.springframework.net/context">
<context:component-scan base-assemblies="Spring.Core.Tests">
<context:include-filter type="regex" expression="ComponentScan.ComponentsAttributeLoad.*"/>
</context:component-scan>
</objects>

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net"
xmlns:context="http://www.springframework.net/context"
default-lazy-init="true">
<context:component-scan base-assemblies="Spring.Core.Tests">
<context:include-filter type="regex" expression="ComponentScan.ComponentsUseDefaults.*"/>
</context:component-scan>
</objects>

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net"
xmlns:context="http://www.springframework.net/context">
<context:component-scan base-assemblies="Spring.Core.Tests">
<context:include-filter type="regex" expression="ComponentScan.Qualifier.*"/>
</context:component-scan>
</objects>

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net"
xmlns:context="http://www.springframework.net/context">
<context:component-scan base-assemblies="Spring.Core.Configuration.Invalid" attribute-config="false" />
</objects>

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net"
xmlns:context="http://www.springframework.net/context">
<context:component-scan base-assemblies="Spring.Core.Configuration.Invalid" />
</objects>

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net"
xmlns:context="http://www.springframework.net/context">
<context:component-scan base-assemblies="Spring.Core.Tests">
<context:include-filter type="regex" expression=".*Test.*"/>
<context:exclude-filter type="assignable" expression="XmlAssemblyTypeScanner.Test.Include2.FunnyAbstract, Spring.Core.Tests"/>
</context:component-scan>
</objects>

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net"
xmlns:context="http://www.springframework.net/context">
<context:component-scan base-assemblies="Spring.Core.Tests">
<!-- to test type load exception -->
<context:include-filter type="assignable" expression="XmlAssemblyTypeScanner.Test.Include1.NotValid, Spring.Core.Tests"/>
<context:include-filter type="assignable" expression="XmlAssemblyTypeScanner.Test.Include1.IFunny, Spring.Core.Tests"/>
<context:include-filter type="assignable" expression="XmlAssemblyTypeScanner.Test.Include2.FunnyAbstract, Spring.Core.Tests"/>
</context:component-scan>
</objects>

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net"
xmlns:context="http://www.springframework.net/context">
<context:component-scan base-assemblies="Spring.Core.Tests">
<context:include-filter type="regex" expression=".*Test.*"/>
<context:exclude-filter type="attribute" expression="XmlAssemblyTypeScanner.Test.Include1.DoNotIncludeAttribute, Spring.Core.Tests"/>
</context:component-scan>
</objects>

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net"
xmlns:context="http://www.springframework.net/context">
<context:component-scan base-assemblies="Spring.Core.Tests">
<!-- to test type load exception -->
<context:include-filter type="attribute" expression="Spring.Stereotype.ServiceAttribute, notvalid"/>
<context:include-filter type="attribute" expression="XmlAssemblyTypeScanner.Test.Include2.DoIncludeAttribute, Spring.Core.Tests"/>
</context:component-scan>
</objects>

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net"
xmlns:context="http://www.springframework.net/context">
<context:component-scan base-assemblies="Spring.Core.Tests">
<context:include-filter type="regex" expression=".*Test.*"/>
<context:exclude-filter type="custom" expression="XmlAssemblyTypeScanner.Test.Include1.TestFilter, Spring.Core.Tests"/>
</context:component-scan>
</objects>

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net"
xmlns:context="http://www.springframework.net/context">
<context:component-scan base-assemblies="Spring.Core.Tests">
<!-- to test type load exception -->
<context:include-filter type="custom" expression="XmlAssemblyTypeScanner.Test.Include1.NotValid, Spring.Core.Tests"/>
<context:include-filter type="custom" expression="XmlAssemblyTypeScanner.Test.Include1.TestFilter, Spring.Core.Tests"/>
</context:component-scan>
</objects>

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net"
xmlns:context="http://www.springframework.net/context">
<context:component-scan base-assemblies="Spring.Core.Tests">
<context:include-filter type="regex" expression=".*Test.*"/>
<context:exclude-filter type="regex" expression=".*Test.*Exclude"/>
</context:component-scan>
</objects>

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net"
xmlns:context="http://www.springframework.net/context">
<context:component-scan base-assemblies="Spring.Core.Tests">
<context:include-filter type="regex" expression=".*Test.*Include1"/>
</context:component-scan>
</objects>

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net"
xmlns:context="http://www.springframework.net/context">
<context:component-scan base-assemblies="Spring.Core.Tests">
<context:include-filter type="regex" expression=".*Test.*Include1"/>
<context:include-filter type="regex" expression=".*Test.*Include2"/>
</context:component-scan>
</objects>

View File

@@ -0,0 +1,42 @@
#region License
/*
* Copyright <20> 2010-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.
* 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
using NUnit.Framework;
using Spring.Objects.Factory.Xml;
namespace Spring.Context.Config
{
[TestFixture]
public class ContextNamespaceParserTests
{
[SetUp]
public void Setup()
{
NamespaceParserRegistry.RegisterParser(typeof(ContextNamespaceParser));
}
[Test]
public void Registered()
{
Assert.IsNotNull(NamespaceParserRegistry.GetParser("http://www.springframework.net/context"));
}
}
}

View File

@@ -0,0 +1,142 @@
#region License
/*
* Copyright © 2010-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.
* 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
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using Spring.Context.Attributes;
namespace Spring.Context.Support
{
[TestFixture]
public class CodeConfigApplicationContextTests
{
private CodeConfigApplicationContext _context;
[SetUp]
public void _TestSetup()
{
_context = new CodeConfigApplicationContext();
}
[Test]
public void Can_Filter_For_Assembly_Based_On_Assembly_Metadata()
{
_context.ScanWithAssemblyFilter(a => a.GetName().Name.StartsWith("Spring.Core."));
_context.Refresh();
AssertExpectedObjectsAreRegisteredWith(_context, 45);
}
[Test]
public void Can_Filter_For_Assembly_Containing_Specific_Type_But_Having_NO_Definitions()
{
//specifically filter assemblies for one that we *know* will result in NO [Configuration] types in it
_context.ScanWithAssemblyFilter(assy => assy.GetTypes().Any(type => type.FullName.Contains(typeof(Spring.Core.IOrdered).Name)));
_context.Refresh();
Assert.That(_context.DefaultListableObjectFactory.ObjectDefinitionCount, Is.EqualTo(4));
}
[Test]
public void Can_Filter_For_Assembly_Containing_Specific_Type()
{
_context.ScanWithAssemblyFilter(assy => assy.GetTypes().Any(type => type.FullName.Contains(typeof(MarkerTypeForScannerToFind).Name)));
_context.Refresh();
AssertExpectedObjectsAreRegisteredWith(_context, 45);
}
[Test]
public void Can_Filter_For_Specific_Type()
{
_context.ScanWithTypeFilter(type => type.FullName.Contains(typeof(TheImportedConfigurationClass).Name));
_context.Refresh();
Assert.That(_context.DefaultListableObjectFactory.ObjectDefinitionCount, Is.EqualTo(8));
}
[Test]
public void Can_Filter_For_Specific_Types_With_Compound_Predicate()
{
_context.ScanWithTypeFilter(type => type.FullName.Contains(typeof(TheImportedConfigurationClass).Name) || type.FullName.Contains(typeof(TheConfigurationClass).Name));
_context.Refresh();
AssertExpectedObjectsAreRegisteredWith(_context, 19);
}
[Test]
public void Can_Filter_For_Specific_Types_With_Multiple_Include_Filters()
{
var scanner = new AssemblyObjectDefinitionScanner();
scanner.WithIncludeFilter(type => type.FullName.Contains(typeof(TheImportedConfigurationClass).Name));
scanner.WithIncludeFilter(type => type.FullName.Contains(typeof(TheConfigurationClass).Name));
_context.Scan(scanner);
_context.Refresh();
AssertExpectedObjectsAreRegisteredWith(_context, 19);
}
[Test]
public void Scanner()
{
AssemblyObjectDefinitionScanner scanner = new AssemblyObjectDefinitionScanner();
scanner.AssemblyHavingType<TheConfigurationClass>();
}
[Test]
public void Can_Perform_Scan_With_No_Filtering()
{
_context.ScanAllAssemblies();
_context.Refresh();
AssertExpectedObjectsAreRegisteredWith(_context, 45);
}
private void AssertExpectedObjectsAreRegisteredWith(GenericApplicationContext context, int expectedDefinitionCount)
{
// only check names that are not part of configuration namespace test
List<string> names = new List<string>(context.DefaultListableObjectFactory.GetObjectDefinitionNames());
names.RemoveAll(x => x.StartsWith("ConfigurationNameSpace"));
if (names.Count != expectedDefinitionCount)
{
Console.WriteLine("Actual types registered with the container:");
foreach (var name in names)
{
Console.WriteLine(name);
}
}
Assert.That(names.Count, Is.EqualTo(expectedDefinitionCount));
}
}
public class MarkerTypeForScannerToFind
{
}
}

View File

@@ -0,0 +1,51 @@
#region License
/*
* Copyright <20> 2010-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.
* 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
using Spring.Stereotype;
namespace Spring.Example.Scannable
{
/// <summary>
///
/// </summary>
/// <author>Mark Pollack</author>
[Service]
public class FooService : IFooService
{
private string foo;
private bool initCalled;
public string Foo
{
get { return foo; }
set { foo = value; }
}
public bool InitCalled
{
get { return initCalled; }
set { initCalled = value; }
}
}
}

View File

@@ -0,0 +1,32 @@
#region License
/*
* Copyright <20> 2010-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.
* 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
namespace Spring.Example.Scannable
{
/// <summary>
///
/// </summary>
/// <author>Mark Pollack</author>
public interface IFooDao
{
string FindFoo(string id);
}
}

View File

@@ -0,0 +1,35 @@
#region License
/*
* Copyright <20> 2010-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.
* 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
namespace Spring.Example.Scannable
{
/// <summary>
/// Simple service for testing of component scanning
/// </summary>
/// <author>Mark Pollack</author>
public interface IFooService
{
string Foo { get; set; }
bool InitCalled { get; set; }
}
}

View File

@@ -0,0 +1,38 @@
#region License
/*
* Copyright <20> 2010-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.
* 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
using Spring.Stereotype;
namespace Spring.Example.Scannable
{
/// <summary>
///
/// </summary>
/// <author>Mark Pollack</author>
[Repository]
public class StubFooDao : IFooDao
{
public string FindFoo(string id)
{
return "bar";
}
}
}

View File

@@ -152,9 +152,25 @@
<Compile Include="Context\ApplicationEventArgsTests.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Context\Attributes\AbstractConfigurationClassPostProcessorTests.cs" />
<Compile Include="Context\Attributes\AssemblyObjectDefinitionScannerTests.cs" />
<Compile Include="Context\Attributes\AssemblyTypeScannerTests.cs" />
<Compile Include="Context\Attributes\CodeConfigApplicationContextTests.cs" />
<Compile Include="Context\Attributes\ConfigurationClassObjectDefinitionReaderTests.cs" />
<Compile Include="Context\Attributes\ConfigurationClassParserTests.cs" />
<Compile Include="Context\Attributes\ConfigurationClassPostProcessorTests.cs" />
<Compile Include="Context\Attributes\ImportResourceAttributeTests.cs" />
<Compile Include="Context\Attributes\ObjectDefAttributeTests.cs" />
<Compile Include="Context\Attributes\ScanningConfigurationClassPostProcessorTests.cs" />
<Compile Include="Context\Attributes\SimpleScanTests.cs" />
<Compile Include="Context\CommonTypes.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Context\Config\AttributeConfigObjectDefinitionParserTests.cs" />
<Compile Include="Context\Config\ComponentScanObjectDefinitionParserAssemblyFilterTests.cs" />
<Compile Include="Context\Config\ComponentScanObjectDefinitionParserTests.cs" />
<Compile Include="Context\Config\ComponentScanObjectDefinitionParserTypeFilterTests.cs" />
<Compile Include="Context\Config\ContextNamespaceParserTests.cs" />
<Compile Include="Context\ContextExceptionTests.cs">
<SubType>Code</SubType>
</Compile>
@@ -183,6 +199,7 @@
<SubType>Code</SubType>
</Compile>
<Compile Include="Context\Support\Assembler.cs" />
<Compile Include="Context\Support\CodeConfigApplicationContextTests.cs" />
<Compile Include="Context\Support\ContextLocatorHandlerTests.cs">
<SubType>Code</SubType>
</Compile>
@@ -281,6 +298,10 @@
<Compile Include="CompilerOptionsTests.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Example\Scannable\FooService.cs" />
<Compile Include="Example\Scannable\IFooDao.cs" />
<Compile Include="Example\Scannable\IFooService.cs" />
<Compile Include="Example\Scannable\StubFooDao.cs" />
<Compile Include="ExceptionsTest.cs" />
<Compile Include="Expressions\ConstructorNodeTests.cs" />
<Compile Include="Expressions\ExpressionEvaluatorTests.cs">
@@ -804,6 +825,32 @@
<EmbeddedResource Include="Context\Support\innerObjectsWithPostProcessor.xml" />
<EmbeddedResource Include="Core\IO\ConfigSectionResourceTests_config1.xml" />
<EmbeddedResource Include="Context\Support\XmlApplicationContextTests-SPRNET1231.xml" />
<EmbeddedResource Include="Context\Attributes\ObjectDefinitions.xml" />
<EmbeddedResource Include="Context\Attributes\ObjectDefinitionsTwo.xml" />
<EmbeddedResource Include="Context\Attributes\SimpleScanTest.xml" />
<EmbeddedResource Include="Context\Config\ConfigFiles\AttributeConfigParser.xml" />
<EmbeddedResource Include="Context\Config\ConfigFiles\BaseAssemblyTestMultiple.xml" />
<EmbeddedResource Include="Context\Config\ConfigFiles\BaseAssemblyTestNegative.xml" />
<EmbeddedResource Include="Context\Config\ConfigFiles\BaseAssemblyTestSingle.xml" />
<EmbeddedResource Include="Context\Config\ConfigFiles\BaseAssemblyTestWithout.xml" />
<EmbeddedResource Include="Context\Config\ConfigFiles\ComponentScan1.xml" />
<EmbeddedResource Include="Context\Config\ConfigFiles\ComponentScan2.xml" />
<EmbeddedResource Include="Context\Config\ConfigFiles\ComponentScan3.xml" />
<EmbeddedResource Include="Context\Config\ConfigFiles\ComponentScan31.xml" />
<EmbeddedResource Include="Context\Config\ConfigFiles\ComponentScan4.xml" />
<EmbeddedResource Include="Context\Config\ConfigFiles\ComponentScan5.xml" />
<EmbeddedResource Include="Context\Config\ConfigFiles\ComponentScan6.xml" />
<EmbeddedResource Include="Context\Config\ConfigFiles\ComponentScanAttributeConfigFalse.xml" />
<EmbeddedResource Include="Context\Config\ConfigFiles\ComponentScanAttributeConfigTrue.xml" />
<EmbeddedResource Include="Context\Config\ConfigFiles\TypeScannerTestAssignableExclude.xml" />
<EmbeddedResource Include="Context\Config\ConfigFiles\TypeScannerTestAssignableInclude.xml" />
<EmbeddedResource Include="Context\Config\ConfigFiles\TypeScannerTestAttributeExclude.xml" />
<EmbeddedResource Include="Context\Config\ConfigFiles\TypeScannerTestAttributeInclude.xml" />
<EmbeddedResource Include="Context\Config\ConfigFiles\TypeScannerTestCustomExclude.xml" />
<EmbeddedResource Include="Context\Config\ConfigFiles\TypeScannerTestCustomInclude.xml" />
<EmbeddedResource Include="Context\Config\ConfigFiles\TypeScannerTestRegExExclude.xml" />
<EmbeddedResource Include="Context\Config\ConfigFiles\TypeScannerTestRegExInclude.xml" />
<EmbeddedResource Include="Context\Config\ConfigFiles\TypeScannerTestRegExInclude2.xml" />
<Content Include="Data\PathMatcher\EmptyPattern.test" />
<Content Include="Data\PathMatcher\Examples.test" />
<Content Include="Data\PathMatcher\InBetween.test" />