From 9551238d097d796e7a23c57167d0794fe0b5040d Mon Sep 17 00:00:00 2001 From: bbaia Date: Wed, 14 Apr 2010 14:57:28 +0000 Subject: [PATCH] Add namespace parser for WCF integration [SPRNET-1324] --- Spring.build | 3 + .../Spring.WcfQuickStart.ClientApp/App.config | 5 +- .../Config/Aspects.xml | 37 +++++ .../Config/ServerApp.xml | 12 +- .../Config/ServerWeb.xml | 17 +- ...Spring.WcfQuickStart.ClientApp.2008.csproj | 11 ++ .../Spring.WcfQuickStart.ServerApp/App.config | 9 -- .../Factory/Xml/NamespaceParserRegistry.cs | 1 + .../ServiceModel/ChannelFactoryObject.cs | 121 ++++++++++++++ .../ChannelFactoryObjectDefinitionParser.cs | 108 +++++++++++++ .../ServiceModel/Config/WcfNamespaceParser.cs | 55 +++++++ .../ServiceModel/Config/spring-wcf-1.3.xsd | 70 ++++++++ .../ServiceModel/ServiceExporter.cs | 2 +- .../Spring.Services.2005.csproj | 8 +- .../Spring.Services.2008.csproj | 4 + .../Spring.Services/Spring.Services.build | 6 +- ...bjectDefinitionParserTests.BasicConfig.xml | 9 ++ ...DefinitionParserTests.CustomProperties.xml | 11 ++ ...ectDefinitionParserTests.WithTypeAlias.xml | 17 ++ ...yObjectDefinitionParserTests.WithoutId.xml | 8 + ...annelFactoryObjectDefinitionParserTests.cs | 149 ++++++++++++++++++ .../Config/WcfNamespaceParserTests.cs | 49 ++++++ .../Spring.Services.Tests.2005.csproj | 4 +- .../Spring.Services.Tests.2008.csproj | 6 + .../Spring.Services.Tests.dll.config | 8 + 25 files changed, 699 insertions(+), 31 deletions(-) create mode 100644 examples/Spring/Spring.WcfQuickStart/src/Spring.WcfQuickStart.ClientApp/Config/Aspects.xml create mode 100644 src/Spring/Spring.Services/ServiceModel/ChannelFactoryObject.cs create mode 100644 src/Spring/Spring.Services/ServiceModel/Config/ChannelFactoryObjectDefinitionParser.cs create mode 100644 src/Spring/Spring.Services/ServiceModel/Config/WcfNamespaceParser.cs create mode 100644 src/Spring/Spring.Services/ServiceModel/Config/spring-wcf-1.3.xsd create mode 100644 test/Spring/Spring.Services.Tests/ServiceModel/Config/ChannelFactoryObjectDefinitionParserTests.BasicConfig.xml create mode 100644 test/Spring/Spring.Services.Tests/ServiceModel/Config/ChannelFactoryObjectDefinitionParserTests.CustomProperties.xml create mode 100644 test/Spring/Spring.Services.Tests/ServiceModel/Config/ChannelFactoryObjectDefinitionParserTests.WithTypeAlias.xml create mode 100644 test/Spring/Spring.Services.Tests/ServiceModel/Config/ChannelFactoryObjectDefinitionParserTests.WithoutId.xml create mode 100644 test/Spring/Spring.Services.Tests/ServiceModel/Config/ChannelFactoryObjectDefinitionParserTests.cs create mode 100644 test/Spring/Spring.Services.Tests/ServiceModel/Config/WcfNamespaceParserTests.cs diff --git a/Spring.build b/Spring.build index c0a7435b..ccd409f2 100644 --- a/Spring.build +++ b/Spring.build @@ -1241,6 +1241,9 @@ Commandline Examples: + + diff --git a/examples/Spring/Spring.WcfQuickStart/src/Spring.WcfQuickStart.ClientApp/App.config b/examples/Spring/Spring.WcfQuickStart/src/Spring.WcfQuickStart.ClientApp/App.config index dc2e1734..9a46099b 100644 --- a/examples/Spring/Spring.WcfQuickStart/src/Spring.WcfQuickStart.ClientApp/App.config +++ b/examples/Spring/Spring.WcfQuickStart/src/Spring.WcfQuickStart.ClientApp/App.config @@ -9,13 +9,16 @@ - + + + + diff --git a/examples/Spring/Spring.WcfQuickStart/src/Spring.WcfQuickStart.ClientApp/Config/Aspects.xml b/examples/Spring/Spring.WcfQuickStart/src/Spring.WcfQuickStart.ClientApp/Config/Aspects.xml new file mode 100644 index 00000000..124cf3b2 --- /dev/null +++ b/examples/Spring/Spring.WcfQuickStart/src/Spring.WcfQuickStart.ClientApp/Config/Aspects.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + Spring.WcfQuickStart.* + + + + + perfAdvice + + + + + + diff --git a/examples/Spring/Spring.WcfQuickStart/src/Spring.WcfQuickStart.ClientApp/Config/ServerApp.xml b/examples/Spring/Spring.WcfQuickStart/src/Spring.WcfQuickStart.ClientApp/Config/ServerApp.xml index 2e9c6ddc..b7f9c62f 100644 --- a/examples/Spring/Spring.WcfQuickStart/src/Spring.WcfQuickStart.ClientApp/Config/ServerApp.xml +++ b/examples/Spring/Spring.WcfQuickStart/src/Spring.WcfQuickStart.ClientApp/Config/ServerApp.xml @@ -1,8 +1,10 @@ - + + - @@ -10,7 +12,11 @@ - + --> + + diff --git a/examples/Spring/Spring.WcfQuickStart/src/Spring.WcfQuickStart.ClientApp/Config/ServerWeb.xml b/examples/Spring/Spring.WcfQuickStart/src/Spring.WcfQuickStart.ClientApp/Config/ServerWeb.xml index 432d913c..3baa5799 100644 --- a/examples/Spring/Spring.WcfQuickStart/src/Spring.WcfQuickStart.ClientApp/Config/ServerWeb.xml +++ b/examples/Spring/Spring.WcfQuickStart/src/Spring.WcfQuickStart.ClientApp/Config/ServerWeb.xml @@ -1,8 +1,10 @@ - + + - @@ -10,8 +12,13 @@ - + --> + + + + + - - \ No newline at end of file diff --git a/examples/Spring/Spring.WcfQuickStart/src/Spring.WcfQuickStart.ClientApp/Spring.WcfQuickStart.ClientApp.2008.csproj b/examples/Spring/Spring.WcfQuickStart/src/Spring.WcfQuickStart.ClientApp/Spring.WcfQuickStart.ClientApp.2008.csproj index f4abca09..7c35e6d6 100644 --- a/examples/Spring/Spring.WcfQuickStart/src/Spring.WcfQuickStart.ClientApp/Spring.WcfQuickStart.ClientApp.2008.csproj +++ b/examples/Spring/Spring.WcfQuickStart/src/Spring.WcfQuickStart.ClientApp/Spring.WcfQuickStart.ClientApp.2008.csproj @@ -52,6 +52,10 @@ 4 + + False + ..\..\..\..\..\bin\net\2.0\debug\Spring.Aop.dll + False ..\..\..\..\..\bin\net\2.0\debug\Spring.Core.dll @@ -96,11 +100,18 @@ + + {B52BBAA3-1B30-4905-827C-1D81EBA56A15} + Spring.WcfQuickStart.Aspects + {53263837-0643-45FE-96A2-46D425E1A36F} Spring.WcfQuickStart.Contracts + + + - - - - diff --git a/src/Spring/Spring.Core/Objects/Factory/Xml/NamespaceParserRegistry.cs b/src/Spring/Spring.Core/Objects/Factory/Xml/NamespaceParserRegistry.cs index 89795201..cac20ebb 100644 --- a/src/Spring/Spring.Core/Objects/Factory/Xml/NamespaceParserRegistry.cs +++ b/src/Spring/Spring.Core/Objects/Factory/Xml/NamespaceParserRegistry.cs @@ -100,6 +100,7 @@ namespace Spring.Objects.Factory.Xml wellknownNamespaceParserTypeNames["http://www.springframework.net/aop"] = "Spring.Aop.Config.AopNamespaceParser, Spring.Aop"; wellknownNamespaceParserTypeNames["http://www.springframework.net/db"] = "Spring.Data.Config.DatabaseNamespaceParser, Spring.Data"; wellknownNamespaceParserTypeNames["http://www.springframework.net/remoting"] = "Spring.Remoting.Config.RemotingNamespaceParser, Spring.Services"; + wellknownNamespaceParserTypeNames["http://www.springframework.net/wcf"] = "Spring.ServiceModel.Config.WcfNamespaceParser, Spring.Services"; wellknownNamespaceParserTypeNames["http://www.springframework.net/nms"] = "Spring.Messaging.Nms.Config.NmsNamespaceParser, Spring.Messaging.Nms"; wellknownNamespaceParserTypeNames["http://www.springframework.net/ems"] = "Spring.Messaging.Ems.Config.EmsNamespaceParser, Spring.Messaging.Ems"; wellknownNamespaceParserTypeNames["http://www.springframework.net/validation"] = "Spring.Validation.Config.ValidationNamespaceParser, Spring.Core"; diff --git a/src/Spring/Spring.Services/ServiceModel/ChannelFactoryObject.cs b/src/Spring/Spring.Services/ServiceModel/ChannelFactoryObject.cs new file mode 100644 index 00000000..6971e616 --- /dev/null +++ b/src/Spring/Spring.Services/ServiceModel/ChannelFactoryObject.cs @@ -0,0 +1,121 @@ +#if NET_3_0 +#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 + +#region Imports + +using System; +using System.ServiceModel; + +using Spring.Objects.Factory; + + +#endregion + +namespace Spring.ServiceModel +{ + /// + /// that creates a channel that is used by clients + /// to send messages to a specified endpoint address. + /// + /// The type of channel produced by the channel factory. + /// Bruno Baia + public class ChannelFactoryObject : ChannelFactory, IFactoryObject + { + #region Logging + + private static readonly Common.Logging.ILog Log = Common.Logging.LogManager.GetLogger(typeof(ChannelFactoryObject<>)); + + #endregion + + private bool _isSingleton = true; + private string _endpointConfigurationName; + + /// + /// Creates a new instance of the class. + /// + /// + /// The configuration name used for the endpoint. + /// + public ChannelFactoryObject(string endpointConfigurationName) + : base(endpointConfigurationName) + { + this._endpointConfigurationName = endpointConfigurationName; + } + + /// + /// Gets the configuration name used for the endpoint. + /// + public string EndpointConfigurationName + { + get { return this._endpointConfigurationName; } + } + + #region IFactoryObject Membres + + /// + /// Return an instance (possibly shared or independent) of the channel + /// managed by this factory. + /// + /// + /// An instance (possibly shared or independent) of the channel managed by + /// this factory. + /// + public object GetObject() + { + #region Instrumentation + + if (Log.IsDebugEnabled) + { + Log.Debug(String.Format( + "Creating channel of type '{0}' for the specified endpoint '{1}'...", + typeof(T).FullName, this._endpointConfigurationName)); + } + + #endregion + + return this.CreateChannel(); + } + + /// + /// Return the of channel that this + /// creates. + /// + public Type ObjectType + { + get { return typeof(T); } + } + + /// + /// Is the object managed by this factory a singleton or a prototype ? + /// + /// + /// Default value is . + /// + public bool IsSingleton + { + get { return this._isSingleton; } + set { this._isSingleton = value; } + } + + #endregion + } +} +#endif diff --git a/src/Spring/Spring.Services/ServiceModel/Config/ChannelFactoryObjectDefinitionParser.cs b/src/Spring/Spring.Services/ServiceModel/Config/ChannelFactoryObjectDefinitionParser.cs new file mode 100644 index 00000000..43dec085 --- /dev/null +++ b/src/Spring/Spring.Services/ServiceModel/Config/ChannelFactoryObjectDefinitionParser.cs @@ -0,0 +1,108 @@ +#if NET_3_0 +#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 + +#region Imports + +using System; +using System.Xml; + +using Spring.Util; +using Spring.Objects.Factory.Xml; +using Spring.Objects.Factory.Config; +using Spring.Objects.Factory.Support; +using Spring.Core.TypeResolution; +using Spring.Objects; + +#endregion + +namespace Spring.ServiceModel.Config +{ + /// + /// The for the <wcf:channelFactory> tag. + /// + /// Bruno Baia + public class ChannelFactoryObjectDefinitionParser : ObjectsNamespaceParser, IObjectDefinitionParser + { + private static readonly string ChannelTypeAttribute = "channelType"; + private static readonly string EndpointConfigurationNameAttribute = "endpointConfigurationName"; + + #region IObjectDefinitionParser Members + + /// + /// Parse the specified XmlElement and register the resulting + /// ObjectDefinitions with the IObjectDefinitionRegistry + /// embedded in the supplied + /// + /// The element to be parsed. + /// The object encapsulating the current state of the parsing process. + /// Provides access to a IObjectDefinitionRegistry + /// The primary object definition. + /// + ///

+ /// This method is never invoked if the parser is namespace aware + /// and was called to process the root node. + ///

+ ///
+ IObjectDefinition IObjectDefinitionParser.ParseElement(XmlElement element, ParserContext parserContext) + { + AssertUtils.ArgumentNotNull(parserContext, "parserContext"); + + string id = element.GetAttribute(ObjectDefinitionConstants.IdAttribute); + string unresolvedChannelType = element.GetAttribute(ChannelTypeAttribute); + string endpointConfigurationName = element.GetAttribute(EndpointConfigurationNameAttribute); + + IObjectDefinition channelFactoryDefinition; + try + { + Type channelType = TypeResolutionUtils.ResolveType(unresolvedChannelType); + Type channelFactoryType = typeof(ChannelFactoryObject<>).MakeGenericType(new Type[1] { channelType }); + channelFactoryDefinition = new RootObjectDefinition(channelFactoryType); + } + catch + { + // Try to resolve type later (Can be a type alias) + channelFactoryDefinition = new RootObjectDefinition( + String.Format("Spring.ServiceModel.ChannelFactoryObject<{0}>, Spring.Services", unresolvedChannelType), + new ConstructorArgumentValues(), + new MutablePropertyValues()); + } + + if (!StringUtils.HasText(id)) + { + id = parserContext.ReaderContext.GenerateObjectName(channelFactoryDefinition); + } + + channelFactoryDefinition.ConstructorArgumentValues.AddNamedArgumentValue("endpointConfigurationName", endpointConfigurationName); + + foreach (PropertyValue pv in base.ParsePropertyElements(id, element, parserContext)) + { + channelFactoryDefinition.PropertyValues.Add(pv); + } + + parserContext.Registry.RegisterObjectDefinition(id, channelFactoryDefinition); + + return null; + } + + #endregion + } +} +#endif \ No newline at end of file diff --git a/src/Spring/Spring.Services/ServiceModel/Config/WcfNamespaceParser.cs b/src/Spring/Spring.Services/ServiceModel/Config/WcfNamespaceParser.cs new file mode 100644 index 00000000..a6c1ad1d --- /dev/null +++ b/src/Spring/Spring.Services/ServiceModel/Config/WcfNamespaceParser.cs @@ -0,0 +1,55 @@ +#if NET_3_0 +#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 + +#region Imports + +using Spring.Objects.Factory.Xml; + +#endregion + +namespace Spring.ServiceModel.Config +{ + /// + /// Namespace parser for the WCF namespace. + /// + /// Bruno Baia + [ + NamespaceParser( + Namespace = "http://www.springframework.net/wcf", + SchemaLocationAssemblyHint = typeof(WcfNamespaceParser), + SchemaLocation = "/Spring.ServiceModel.Config/spring-wcf-1.3.xsd") + ] + public sealed class WcfNamespaceParser : NamespaceParserSupport + { + private const string ChannelFactoryElement = "channelFactory"; + private const string ServiceHostElement = "serviceHost"; + private const string ServiceExporterElement = "serviceExporter"; + + /// + /// Register the for the WCF tags. + /// + public override void Init() + { + RegisterObjectDefinitionParser(ChannelFactoryElement, new ChannelFactoryObjectDefinitionParser()); + } + } +} +#endif \ No newline at end of file diff --git a/src/Spring/Spring.Services/ServiceModel/Config/spring-wcf-1.3.xsd b/src/Spring/Spring.Services/ServiceModel/Config/spring-wcf-1.3.xsd new file mode 100644 index 00000000..d9ea47a0 --- /dev/null +++ b/src/Spring/Spring.Services/ServiceModel/Config/spring-wcf-1.3.xsd @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Spring/Spring.Services/ServiceModel/ServiceExporter.cs b/src/Spring/Spring.Services/ServiceModel/ServiceExporter.cs index 35fb54cb..be040197 100644 --- a/src/Spring/Spring.Services/ServiceModel/ServiceExporter.cs +++ b/src/Spring/Spring.Services/ServiceModel/ServiceExporter.cs @@ -49,7 +49,7 @@ namespace Spring.ServiceModel { #region Logging - private static readonly Common.Logging.ILog LOG = Common.Logging.LogManager.GetLogger(typeof(ServiceExporter)); + //private static readonly Common.Logging.ILog LOG = Common.Logging.LogManager.GetLogger(typeof(ServiceExporter)); #endregion diff --git a/src/Spring/Spring.Services/Spring.Services.2005.csproj b/src/Spring/Spring.Services/Spring.Services.2005.csproj index 2a93cf8b..f7cbf165 100644 --- a/src/Spring/Spring.Services/Spring.Services.2005.csproj +++ b/src/Spring/Spring.Services/Spring.Services.2005.csproj @@ -30,7 +30,7 @@ false - TRACE;DEBUG;NET_2_0;NET_3_0 + TRACE;DEBUG;NET_2_0 Spring.Services.xml true 4096 @@ -83,7 +83,6 @@ system.enterpriseservices - system.web.services @@ -125,11 +124,6 @@ Code - - - - - Code diff --git a/src/Spring/Spring.Services/Spring.Services.2008.csproj b/src/Spring/Spring.Services/Spring.Services.2008.csproj index 38a6c16a..876acd86 100644 --- a/src/Spring/Spring.Services/Spring.Services.2008.csproj +++ b/src/Spring/Spring.Services/Spring.Services.2008.csproj @@ -131,6 +131,9 @@ Code + + + @@ -142,6 +145,7 @@ + diff --git a/src/Spring/Spring.Services/Spring.Services.build b/src/Spring/Spring.Services/Spring.Services.build index 192f6f4b..decede95 100644 --- a/src/Spring/Spring.Services/Spring.Services.build +++ b/src/Spring/Spring.Services/Spring.Services.build @@ -57,6 +57,9 @@ + + + @@ -67,8 +70,7 @@ - --> - + diff --git a/test/Spring/Spring.Services.Tests/ServiceModel/Config/ChannelFactoryObjectDefinitionParserTests.BasicConfig.xml b/test/Spring/Spring.Services.Tests/ServiceModel/Config/ChannelFactoryObjectDefinitionParserTests.BasicConfig.xml new file mode 100644 index 00000000..d596056b --- /dev/null +++ b/test/Spring/Spring.Services.Tests/ServiceModel/Config/ChannelFactoryObjectDefinitionParserTests.BasicConfig.xml @@ -0,0 +1,9 @@ + + + + + + diff --git a/test/Spring/Spring.Services.Tests/ServiceModel/Config/ChannelFactoryObjectDefinitionParserTests.CustomProperties.xml b/test/Spring/Spring.Services.Tests/ServiceModel/Config/ChannelFactoryObjectDefinitionParserTests.CustomProperties.xml new file mode 100644 index 00000000..d48acccf --- /dev/null +++ b/test/Spring/Spring.Services.Tests/ServiceModel/Config/ChannelFactoryObjectDefinitionParserTests.CustomProperties.xml @@ -0,0 +1,11 @@ + + + + + + + + diff --git a/test/Spring/Spring.Services.Tests/ServiceModel/Config/ChannelFactoryObjectDefinitionParserTests.WithTypeAlias.xml b/test/Spring/Spring.Services.Tests/ServiceModel/Config/ChannelFactoryObjectDefinitionParserTests.WithTypeAlias.xml new file mode 100644 index 00000000..5d8f81ad --- /dev/null +++ b/test/Spring/Spring.Services.Tests/ServiceModel/Config/ChannelFactoryObjectDefinitionParserTests.WithTypeAlias.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + diff --git a/test/Spring/Spring.Services.Tests/ServiceModel/Config/ChannelFactoryObjectDefinitionParserTests.WithoutId.xml b/test/Spring/Spring.Services.Tests/ServiceModel/Config/ChannelFactoryObjectDefinitionParserTests.WithoutId.xml new file mode 100644 index 00000000..855bc444 --- /dev/null +++ b/test/Spring/Spring.Services.Tests/ServiceModel/Config/ChannelFactoryObjectDefinitionParserTests.WithoutId.xml @@ -0,0 +1,8 @@ + + + + + + diff --git a/test/Spring/Spring.Services.Tests/ServiceModel/Config/ChannelFactoryObjectDefinitionParserTests.cs b/test/Spring/Spring.Services.Tests/ServiceModel/Config/ChannelFactoryObjectDefinitionParserTests.cs new file mode 100644 index 00000000..73d25907 --- /dev/null +++ b/test/Spring/Spring.Services.Tests/ServiceModel/Config/ChannelFactoryObjectDefinitionParserTests.cs @@ -0,0 +1,149 @@ +#if NET_3_0 +#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 + +#region Imports + +using System.Collections; +using System.ServiceModel; + +using Spring.Context; +using Spring.Context.Support; +using Spring.Objects.Factory.Xml; +using Spring.Objects.Factory.Support; + +using NUnit.Framework; + +#endregion + +namespace Spring.ServiceModel.Config +{ + /// + /// Unit tests for the class. + /// + /// Bruno Baia + [TestFixture] + public class ChannelFactoryObjectDefinitionParserTests + { + [Test] + public void BasicConfig() + { + NamespaceParserRegistry.RegisterParser(typeof(WcfNamespaceParser)); + IApplicationContext ctx = new XmlApplicationContext( + ReadOnlyXmlTestResource.GetFilePath("ChannelFactoryObjectDefinitionParserTests.BasicConfig.xml", this.GetType())); + + Assert.IsTrue(ctx.ContainsObjectDefinition("channel")); + + RootObjectDefinition rod = ((IObjectDefinitionRegistry)ctx).GetObjectDefinition("channel") as RootObjectDefinition; + Assert.IsNotNull(rod); + + Assert.IsTrue(rod.HasObjectType); + Assert.AreEqual(typeof(ChannelFactoryObject), rod.ObjectType); + Assert.AreEqual(1, rod.ConstructorArgumentValues.NamedArgumentValues.Count); + Assert.AreEqual("ecn", rod.ConstructorArgumentValues.GetNamedArgumentValue("endpointConfigurationName").Value); + + ChannelFactoryObject cfo = ctx.GetObject("&channel") as ChannelFactoryObject; + Assert.IsNotNull(cfo); + Assert.AreEqual(typeof(IContract), cfo.ObjectType); + + IContract contract = ctx.GetObject("channel") as IContract; + Assert.IsNotNull(contract); + } + + [Test] + public void CustomProperties() + { + NamespaceParserRegistry.RegisterParser(typeof(WcfNamespaceParser)); + IApplicationContext ctx = new XmlApplicationContext( + ReadOnlyXmlTestResource.GetFilePath("ChannelFactoryObjectDefinitionParserTests.CustomProperties.xml", this.GetType())); + + Assert.IsTrue(ctx.ContainsObjectDefinition("channel")); + + RootObjectDefinition rod = ((IObjectDefinitionRegistry)ctx).GetObjectDefinition("channel") as RootObjectDefinition; + Assert.IsNotNull(rod); + + Assert.IsTrue(rod.HasObjectType); + Assert.AreEqual(typeof(ChannelFactoryObject), rod.ObjectType); + Assert.AreEqual(1, rod.ConstructorArgumentValues.NamedArgumentValues.Count); + Assert.AreEqual("ecn", rod.ConstructorArgumentValues.GetNamedArgumentValue("endpointConfigurationName").Value); + Assert.IsTrue(rod.PropertyValues.Contains("Credentials.Windows.ClientCredential")); + Assert.AreEqual("Spring\\Bruno:gnirpS", rod.PropertyValues.GetPropertyValue("Credentials.Windows.ClientCredential").Value); + + ChannelFactoryObject cfo = ctx.GetObject("&channel") as ChannelFactoryObject; + Assert.IsNotNull(cfo); + Assert.AreEqual(typeof(IContract), cfo.ObjectType); + Assert.AreEqual("Spring", cfo.Credentials.Windows.ClientCredential.Domain); + Assert.AreEqual("Bruno", cfo.Credentials.Windows.ClientCredential.UserName); + Assert.AreEqual("gnirpS", cfo.Credentials.Windows.ClientCredential.Password); + + IContract contract = ctx.GetObject("channel") as IContract; + Assert.IsNotNull(contract); + } + + [Test] + public void WithoutId() + { + NamespaceParserRegistry.RegisterParser(typeof(WcfNamespaceParser)); + IApplicationContext ctx = new XmlApplicationContext( + ReadOnlyXmlTestResource.GetFilePath("ChannelFactoryObjectDefinitionParserTests.WithoutId.xml", this.GetType())); + + IDictionary channels = ctx.GetObjectsOfType(typeof(IContract)); + Assert.AreEqual(1, channels.Count); + } + + [Test] + public void WithTypeAlias() + { + NamespaceParserRegistry.RegisterParser(typeof(WcfNamespaceParser)); + IApplicationContext ctx = new XmlApplicationContext( + ReadOnlyXmlTestResource.GetFilePath("ChannelFactoryObjectDefinitionParserTests.WithTypeAlias.xml", this.GetType())); + + Assert.IsTrue(ctx.ContainsObjectDefinition("channel")); + + RootObjectDefinition rod = ((IObjectDefinitionRegistry)ctx).GetObjectDefinition("channel") as RootObjectDefinition; + Assert.IsNotNull(rod); + + Assert.IsFalse(rod.HasObjectType); + Assert.AreEqual("Spring.ServiceModel.ChannelFactoryObject, Spring.Services", rod.ObjectTypeName); + Assert.AreEqual(1, rod.ConstructorArgumentValues.NamedArgumentValues.Count); + Assert.AreEqual("ecn", rod.ConstructorArgumentValues.GetNamedArgumentValue("endpointConfigurationName").Value); + + ChannelFactoryObject cfo = ctx.GetObject("&channel") as ChannelFactoryObject; + Assert.IsNotNull(cfo); + Assert.AreEqual(typeof(IContract), cfo.ObjectType); + + IContract contract = ctx.GetObject("channel") as IContract; + Assert.IsNotNull(contract); + } + + + #region Test classes + + [ServiceContract(Namespace = "http://Spring.Services.Tests")] + public interface IContract + { + [OperationContract(Name = "MySomeMethod")] + string SomeMethod(int param); + } + + #endregion + } +} +#endif \ No newline at end of file diff --git a/test/Spring/Spring.Services.Tests/ServiceModel/Config/WcfNamespaceParserTests.cs b/test/Spring/Spring.Services.Tests/ServiceModel/Config/WcfNamespaceParserTests.cs new file mode 100644 index 00000000..7e2125a8 --- /dev/null +++ b/test/Spring/Spring.Services.Tests/ServiceModel/Config/WcfNamespaceParserTests.cs @@ -0,0 +1,49 @@ +#if NET_3_0 +#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 + +#region Imports + +using Spring.Objects.Factory.Xml; +using NUnit.Framework; + +#endregion + +namespace Spring.ServiceModel.Config +{ + /// + /// Unit tests for the class. + /// + /// Bruno Baia + [TestFixture] + public class WcfNamespaceParserTests + { + [Test] + public void Registered() + { + NamespaceParserRegistry.RegisterParser(typeof(WcfNamespaceParser)); + INamespaceParser namespaceParser = NamespaceParserRegistry.GetParser("http://www.springframework.net/wcf"); + + Assert.IsNotNull(namespaceParser); + Assert.IsTrue(namespaceParser is WcfNamespaceParser); + } + } +} +#endif \ No newline at end of file diff --git a/test/Spring/Spring.Services.Tests/Spring.Services.Tests.2005.csproj b/test/Spring/Spring.Services.Tests/Spring.Services.Tests.2005.csproj index 8b94f72d..e28d90c7 100644 --- a/test/Spring/Spring.Services.Tests/Spring.Services.Tests.2005.csproj +++ b/test/Spring/Spring.Services.Tests/Spring.Services.Tests.2005.csproj @@ -30,7 +30,7 @@ false - TRACE;DEBUG;NET_2_0;NET_3_0 + TRACE;DEBUG;NET_2_0 true @@ -90,7 +90,6 @@ - System.XML @@ -102,7 +101,6 @@ - Code diff --git a/test/Spring/Spring.Services.Tests/Spring.Services.Tests.2008.csproj b/test/Spring/Spring.Services.Tests/Spring.Services.Tests.2008.csproj index 2ff6aa06..69b2c4d4 100644 --- a/test/Spring/Spring.Services.Tests/Spring.Services.Tests.2008.csproj +++ b/test/Spring/Spring.Services.Tests/Spring.Services.Tests.2008.csproj @@ -111,6 +111,8 @@ + + @@ -209,6 +211,10 @@ Always + + + + diff --git a/test/Spring/Spring.Services.Tests/Spring.Services.Tests.dll.config b/test/Spring/Spring.Services.Tests/Spring.Services.Tests.dll.config index b8a6a51e..716b06bc 100644 --- a/test/Spring/Spring.Services.Tests/Spring.Services.Tests.dll.config +++ b/test/Spring/Spring.Services.Tests/Spring.Services.Tests.dll.config @@ -46,5 +46,13 @@ limitations under the License. + + + + + + + + \ No newline at end of file