From ef64f08844d743ff1af6c0663b1e29ad461c21ac Mon Sep 17 00:00:00 2001 From: eeichinger Date: Sat, 18 Oct 2008 19:47:03 +0000 Subject: [PATCH] fixed SPRNET-957 --- .../Core/TypeResolution/TypeAssemblyHolder.cs | 10 ++- .../TypeResolution/TypeAssemblyHolderTests.cs | 85 +++++++++++++++++++ .../Spring.Core.Tests.2008.csproj | 1 + 3 files changed, 93 insertions(+), 3 deletions(-) create mode 100644 test/Spring/Spring.Core.Tests/Core/TypeResolution/TypeAssemblyHolderTests.cs diff --git a/src/Spring/Spring.Core/Core/TypeResolution/TypeAssemblyHolder.cs b/src/Spring/Spring.Core/Core/TypeResolution/TypeAssemblyHolder.cs index cdf98df4..4cb86d07 100644 --- a/src/Spring/Spring.Core/Core/TypeResolution/TypeAssemblyHolder.cs +++ b/src/Spring/Spring.Core/Core/TypeResolution/TypeAssemblyHolder.cs @@ -1,7 +1,7 @@ #region License /* - * Copyright © 2002-2005 the original author or authors. + * Copyright © 2002-2008 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. @@ -97,8 +97,12 @@ namespace Spring.Core.TypeResolution private void SplitTypeAndAssemblyNames(string originalTypeName) { - int typeAssemblyIndex - = originalTypeName.IndexOf(TypeAssemblySeparator); + // generic types may look like: + // Spring.Objects.TestGenericObject`2[[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]][] , Spring.Core.Tests, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + // + // start searching for assembly separator after the last bracket if any + int typeAssemblyIndex = originalTypeName.LastIndexOf(']'); + typeAssemblyIndex = originalTypeName.IndexOf(TypeAssemblySeparator, typeAssemblyIndex+1); if (typeAssemblyIndex < 0) { unresolvedTypeName = originalTypeName; diff --git a/test/Spring/Spring.Core.Tests/Core/TypeResolution/TypeAssemblyHolderTests.cs b/test/Spring/Spring.Core.Tests/Core/TypeResolution/TypeAssemblyHolderTests.cs new file mode 100644 index 00000000..85054f43 --- /dev/null +++ b/test/Spring/Spring.Core.Tests/Core/TypeResolution/TypeAssemblyHolderTests.cs @@ -0,0 +1,85 @@ +#region License + +/* + * Copyright © 2002-2008 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.Collections.Generic; +using NUnit.Framework; +using Spring.Objects; + +#endregion + +namespace Spring.Core.TypeResolution +{ + /// + /// + /// + /// Erich Eichinger + [TestFixture] + public class TypeAssemblyHolderTests + { + [Test] + public void CanTakeQualifiedType() + { + string tn = typeof(int[]).AssemblyQualifiedName; + tn = typeof(TestGenericObject[]).AssemblyQualifiedName; + tn = typeof(List).AssemblyQualifiedName; + + Type testType = typeof(TestObject); + TypeAssemblyHolder tah = new TypeAssemblyHolder(testType.AssemblyQualifiedName); + Assert.IsTrue(tah.IsAssemblyQualified); + Assert.AreEqual(testType.FullName, tah.TypeName); + Assert.AreEqual(testType.Assembly.FullName, tah.AssemblyName); + } + + [Test] + public void CanTakeUnqualifiedType() + { + Type testType = typeof(TestObject); + TypeAssemblyHolder tah = new TypeAssemblyHolder(testType.FullName); + Assert.IsFalse(tah.IsAssemblyQualified); + Assert.AreEqual(testType.FullName, tah.TypeName); + Assert.AreEqual(null, tah.AssemblyName); + } + +#if NET_2_0 + [Test] + public void CanTakeUnqualifiedGenericType() + { + Type testType = typeof(TestGenericObject); + TypeAssemblyHolder tah = new TypeAssemblyHolder(testType.FullName); + Assert.IsFalse(tah.IsAssemblyQualified); + Assert.AreEqual(testType.FullName, tah.TypeName); + Assert.AreEqual(null, tah.AssemblyName); + } + + [Test] + public void CanTakeQualifiedGenericType() + { + Type testType = typeof(TestGenericObject); + TypeAssemblyHolder tah = new TypeAssemblyHolder(testType.AssemblyQualifiedName); + Assert.IsTrue(tah.IsAssemblyQualified); + Assert.AreEqual(testType.FullName, tah.TypeName); + Assert.AreEqual(testType.Assembly.FullName, tah.AssemblyName); + } +#endif + } +} \ No newline at end of file diff --git a/test/Spring/Spring.Core.Tests/Spring.Core.Tests.2008.csproj b/test/Spring/Spring.Core.Tests/Spring.Core.Tests.2008.csproj index a8c5f282..7eef7baa 100644 --- a/test/Spring/Spring.Core.Tests/Spring.Core.Tests.2008.csproj +++ b/test/Spring/Spring.Core.Tests/Spring.Core.Tests.2008.csproj @@ -265,6 +265,7 @@ +