SPRNET-1262
-add tests to verify proper behavior from service exporter when applying declarative attributes to exported services -relocate recent ConstructorInstantiationInfo class into Utils namespace
This commit is contained in:
@@ -696,7 +696,7 @@
|
||||
<Compile Include="Objects\Factory\Config\VariableAccessor.cs" />
|
||||
<Compile Include="Objects\Factory\Config\VariablePlaceholderConfigurer.cs" />
|
||||
<Compile Include="Objects\Factory\Parsing\ReaderContext.cs" />
|
||||
<Compile Include="Objects\Factory\Support\ConstructorInstantiationInfo.cs" />
|
||||
<Compile Include="Util\ConstructorInstantiationInfo.cs" />
|
||||
<Compile Include="Objects\Factory\Support\GenericObjectDefinition.cs" />
|
||||
<Compile Include="Objects\Factory\Support\IAutowireCandidateResolver.cs" />
|
||||
<Compile Include="Objects\Factory\Support\ConstructorResolver.cs" />
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
using System.Reflection;
|
||||
|
||||
namespace Spring.Objects.Factory.Support
|
||||
namespace Spring.Util
|
||||
{
|
||||
/// <summary>
|
||||
/// Collects information on the constructor to use to create the instance and the argument instances to pass into the
|
||||
@@ -3,9 +3,6 @@
|
||||
<description>
|
||||
Tests for list and map handling in an XML object definition file.
|
||||
</description>
|
||||
|
||||
|
||||
|
||||
<object id="foo" type="Spring.Objects.TestObject, Spring.Core.Tests" abstract="true">
|
||||
<constructor-arg index="0" value="foo"/>
|
||||
<constructor-arg index="1" value="2"/>
|
||||
|
||||
@@ -32,6 +32,7 @@ using Spring.Core.IO;
|
||||
using Spring.Expressions;
|
||||
using Spring.Objects.Factory.Config;
|
||||
using Spring.Objects.Factory.Support;
|
||||
using Spring.Util;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -56,7 +57,7 @@ namespace Spring.Objects.Factory.Xml
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WalkThrough()
|
||||
public void CanApplyConstructorArgsToAbstractType()
|
||||
{
|
||||
IResource resource = new ReadOnlyXmlTestResource("ctor-args.xml", GetType());
|
||||
XmlObjectFactory xof = new XmlObjectFactory(resource);
|
||||
@@ -66,6 +67,7 @@ namespace Spring.Objects.Factory.Xml
|
||||
RootObjectDefinition def = (RootObjectDefinition) xof.GetObjectDefinition("rod");
|
||||
ConstructorResolver resolver = new ConstructorResolver(xof, xof, new SimpleInstantiationStrategy(),
|
||||
new ObjectDefinitionValueResolver(xof));
|
||||
|
||||
ConstructorInstantiationInfo ci = resolver.GetConstructorInstantiationInfo("rod", def, null, null);
|
||||
|
||||
AbstractObjectDefinition objDef = (AbstractObjectDefinition)xof.GetObjectDefinition("foo");
|
||||
|
||||
@@ -131,27 +131,6 @@ namespace Spring.Proxy
|
||||
"Custom attribute not applied to member method.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Ignore]
|
||||
// SPRNET-1262
|
||||
public void AppliesSpecificTypeAttributeWithNoPropertySettersToTargetType()
|
||||
{
|
||||
IProxyTypeBuilder builder = GetProxyBuilder();
|
||||
builder.TargetType = typeof(ClassWithFakeServiceKnownTypeAttribute);
|
||||
builder.TypeAttributes.Add(new FakeServiceKnownTypeAttribute(typeof(TestObject)));
|
||||
|
||||
Type proxy = builder.BuildProxyType();
|
||||
Assert.IsNotNull(proxy, "The proxy generated by a (valid) call to BuildProxy() was null.");
|
||||
|
||||
object[] attrs = proxy.GetCustomAttributes(false);
|
||||
Assert.IsNotNull(attrs, "Should have had 1 attribute applied to the target type.");
|
||||
Assert.AreEqual(1, attrs.Length, "Should have had 1 attribute applied to the target type.");
|
||||
Assert.AreEqual(typeof(FakeServiceKnownTypeAttribute), attrs[0].GetType(), "Wrong System.Type of Attribute applied to the target type.");
|
||||
|
||||
FakeServiceKnownTypeAttribute fgsta = attrs[0] as FakeServiceKnownTypeAttribute;
|
||||
Assert.AreEqual(typeof(TestObject), fgsta.Type, "Property 'Type' on Target Attribute not set!");
|
||||
}
|
||||
|
||||
[Test]
|
||||
// SPRNET-1262
|
||||
public void AppliesSpecificTypeAttributeWithNoPropertySettersToTargetTypeUsingCustomAttributeBuilder()
|
||||
|
||||
@@ -34,6 +34,7 @@ using Spring.ServiceModel;
|
||||
using Spring.Core.IO;
|
||||
using Spring.Objects.Factory;
|
||||
using Spring.Objects.Factory.Xml;
|
||||
using System.Collections.Generic;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -53,16 +54,73 @@ namespace Spring.ServiceModel
|
||||
{
|
||||
const string xml =
|
||||
@"<?xml version='1.0' encoding='UTF-8' ?>
|
||||
<objects xmlns='http://www.springframework.net'>
|
||||
<object id='service' type='Spring.ServiceModel.ServiceExporterTests+Service, Spring.Services.Tests'/>
|
||||
<object id='serviceWithMultipleInterfaces' type='Spring.ServiceModel.ServiceExporterTests+ServiceWithMultipleInterfaces, Spring.Services.Tests'/>
|
||||
<object id='decoratedService' type='Spring.ServiceModel.ServiceExporterTests+DecoratedService, Spring.Services.Tests'/>
|
||||
</objects>";
|
||||
Stream stream = new MemoryStream(Encoding.UTF8.GetBytes(xml));
|
||||
IObjectFactory objectFactory = new XmlObjectFactory(new InputStreamResource(stream, string.Empty));
|
||||
<objects xmlns='http://www.springframework.net'>
|
||||
<object id='service' type='Spring.ServiceModel.ServiceExporterTests+Service, Spring.Services.Tests'/>
|
||||
<object id='serviceWithMultipleInterfaces' type='Spring.ServiceModel.ServiceExporterTests+ServiceWithMultipleInterfaces, Spring.Services.Tests'/>
|
||||
<object id='decoratedService' type='Spring.ServiceModel.ServiceExporterTests+DecoratedService, Spring.Services.Tests'/>
|
||||
</objects>";
|
||||
|
||||
se = new ServiceExporter();
|
||||
se.ObjectFactory = objectFactory;
|
||||
using (Stream stream = new MemoryStream(Encoding.UTF8.GetBytes(xml)))
|
||||
{
|
||||
IObjectFactory objectFactory = new XmlObjectFactory(new InputStreamResource(stream, string.Empty));
|
||||
se = new ServiceExporter();
|
||||
se.ObjectFactory = objectFactory;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
//SPRNET-1262
|
||||
public void ProxiesDeclarativeAttributeWithConstructorArguments()
|
||||
{
|
||||
XmlObjectFactory objectFactory = null;
|
||||
|
||||
const string xml =
|
||||
@"<?xml version='1.0' encoding='UTF-8' ?>
|
||||
<objects xmlns='http://www.springframework.net'>
|
||||
<object id='theService' type='Spring.ServiceModel.ServiceExporterTests+Service, Spring.Services.Tests'/>
|
||||
<object id='service' type='Spring.ServiceModel.ServiceExporter, Spring.Services'>
|
||||
<property name='TargetName' value='theService'/>
|
||||
<property name='TypeAttributes'>
|
||||
<list>
|
||||
<object type='System.ServiceModel.ServiceKnownTypeAttribute, System.ServiceModel' abstract='true'>
|
||||
<constructor-arg name='type' value='System.Collections.Generic.List<int>' />
|
||||
</object>
|
||||
</list>
|
||||
</property>
|
||||
</object>
|
||||
</objects>";
|
||||
|
||||
|
||||
using (Stream stream = new MemoryStream(Encoding.UTF8.GetBytes(xml)))
|
||||
{
|
||||
objectFactory = new XmlObjectFactory(new InputStreamResource(stream, string.Empty));
|
||||
}
|
||||
|
||||
Type proxyType = (Type)objectFactory.GetObject("service");
|
||||
object[] attrs = proxyType.GetCustomAttributes(false);
|
||||
|
||||
ServiceKnownTypeAttribute attrib = null;
|
||||
|
||||
//loop thru all retreived attributes, attempting to find the one that is of the expected type
|
||||
for (int i = 0; i < attrs.Length; i++)
|
||||
{
|
||||
attrib = attrs[i] as ServiceKnownTypeAttribute;
|
||||
|
||||
//break out of the loop once we find the one we want
|
||||
if (attrib != null)
|
||||
break;
|
||||
}
|
||||
|
||||
Assert.NotNull(attrib, String.Format("No attributes of the expecte type {0} were found.", typeof(ServiceKnownTypeAttribute)));
|
||||
Assert.AreEqual(typeof(List<int>), attrib.Type, "Property 'Type' on Target Attribute not set!");
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -214,6 +214,9 @@
|
||||
<None Include="ServiceComponentExporterTests.TestServicedComponents.exe.config">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<Content Include="Data\Xml\watcher-0.xml" />
|
||||
<Content Include="Data\Xml\watcher-1.xml" />
|
||||
<Content Include="Data\Xml\watcher-simple.xml" />
|
||||
<Content Include="ServiceComponentExporterTests.TestServicedComponents.Services.xml">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
|
||||
Reference in New Issue
Block a user