From ba0966d4b5e9bbbddc72b3a7aab06927cf90335a Mon Sep 17 00:00:00 2001 From: sbohlen Date: Thu, 29 Jul 2010 20:01:35 +0000 Subject: [PATCH] SPRNET-1124 fixing broken build from inadvertent use of still more non-.NET 1.1-compatible elements in code (and a broken test due to changes in .NET 1.1 SP1) --- .../Context/Support/ContextRegistryTests.cs | 23 ++++++++++---- .../Config/DictionaryVariableSourceTests.cs | 25 +++++++++++----- .../VariablePlaceholderConfigurerTests.cs | 30 +++++++++++++------ ...nsactionalMessageListenerContainerTests.cs | 12 ++++++-- 4 files changed, 64 insertions(+), 26 deletions(-) diff --git a/test/Spring/Spring.Core.Tests/Context/Support/ContextRegistryTests.cs b/test/Spring/Spring.Core.Tests/Context/Support/ContextRegistryTests.cs index 6c60b05e..4c204b5a 100644 --- a/test/Spring/Spring.Core.Tests/Context/Support/ContextRegistryTests.cs +++ b/test/Spring/Spring.Core.Tests/Context/Support/ContextRegistryTests.cs @@ -58,14 +58,24 @@ namespace Spring.Context.Support { return; } - FieldInfo initStateRef = typeof(ConfigurationManager).GetField("s_initState",BindingFlags.NonPublic|BindingFlags.Static); + FieldInfo initStateRef = typeof(ConfigurationManager).GetField("s_initState", BindingFlags.NonPublic | BindingFlags.Static); object notStarted = Activator.CreateInstance(initStateRef.FieldType); - initStateRef.SetValue(null,notStarted); + initStateRef.SetValue(null, notStarted); #endif #if NET_1_1 FieldInfo initStateRef = typeof(ConfigurationSettings).GetField("_initState",BindingFlags.NonPublic|BindingFlags.Static); - object notStarted = Activator.CreateInstance(initStateRef.FieldType); - initStateRef.SetValue(null,notStarted); + + if (initStateRef!=null) + { + object notStarted = Activator.CreateInstance(initStateRef.FieldType); + initStateRef.SetValue(null,notStarted); + } + else + { + FieldInfo configurationInitializedRef = typeof(ConfigurationSettings).GetField("_configurationInitialized",BindingFlags.NonPublic|BindingFlags.Static); + configurationInitializedRef.SetValue(null, false); + } + #endif #if NET_1_0 FieldInfo initStateRef = typeof(ConfigurationSettings).GetField("_configurationInitialized",BindingFlags.NonPublic|BindingFlags.Static); @@ -90,7 +100,7 @@ namespace Spring.Context.Support { return ContextRegistry.GetContext(); // this must fail! } - +#if !NET_1_1 [Test] public void ThrowsInvalidOperationExceptionOnRecursiveCallsToGetContext() { @@ -109,6 +119,7 @@ namespace Spring.Context.Support } } } +#endif [Test] public void RegisterRootContext() @@ -163,7 +174,7 @@ namespace Spring.Context.Support } [Test] -// [Ignore("How can we test that one ???")] + // [Ignore("How can we test that one ???")] [ExpectedException(typeof(ApplicationContextException), ExpectedMessage = "No context registered. Use the 'RegisterContext' method or the 'spring/context' section from your configuration file.")] public void GetRootContextNotRegisteredThrowsException() diff --git a/test/Spring/Spring.Core.Tests/Objects/Factory/Config/DictionaryVariableSourceTests.cs b/test/Spring/Spring.Core.Tests/Objects/Factory/Config/DictionaryVariableSourceTests.cs index 9b20e0a9..1e98a2be 100644 --- a/test/Spring/Spring.Core.Tests/Objects/Factory/Config/DictionaryVariableSourceTests.cs +++ b/test/Spring/Spring.Core.Tests/Objects/Factory/Config/DictionaryVariableSourceTests.cs @@ -1,6 +1,5 @@ using System; using System.Collections; -using System.Text; using NUnit.Framework; namespace Spring.Objects.Factory.Config @@ -50,13 +49,18 @@ namespace Spring.Objects.Factory.Config Assert.AreEqual("value2", dvs.ResolveVariable("key2")); } -#if NET_2_0 [Test] public void Iniitialize_WithStringArray_ThrowsException_WhenOddNumberOfStringsProvided() { - Assert.Throws(() => new DictionaryVariableSource(new string[] { "key1", "value1", "key2", "value2", "orphanedKey1" })); + try + { + new DictionaryVariableSource(new string[] { "key1", "value1", "key2", "value2", "orphanedKey1" }); + Assert.Fail("Expected ArgumentOutOfRangeException not thrown."); + } + catch (ArgumentOutOfRangeException) + { + } } -#endif [Test] public void Initialize_WithCaseSensitiveFlag_AddsCaseSensitiveKeys() @@ -119,7 +123,7 @@ namespace Spring.Objects.Factory.Config Assert.AreEqual("value2", dvs.ResolveVariable("key2")); } -#if NET_2_0 +#if (!NET_2_0 && !NET_1_0 && !NET_1_1) [Test] public void Initialize_WithInlineDictionarySyntax() { @@ -131,7 +135,6 @@ namespace Spring.Objects.Factory.Config } #endif -#if NET_2_0 [Test] public void Requesting_KeyNotFound_ThrowsException() { @@ -140,8 +143,14 @@ namespace Spring.Objects.Factory.Config DictionaryVariableSource dvs = new DictionaryVariableSource(); dvs.Add(THE_KEY, "value-found"); - Assert.Throws(() => dvs.ResolveVariable("not" + THE_KEY)); + try + { + dvs.ResolveVariable("not" + THE_KEY); + Assert.Fail("Expected ArgumentException not thrown."); + } + catch (ArgumentException) + { + } } -#endif } } diff --git a/test/Spring/Spring.Core.Tests/Objects/Factory/Config/VariablePlaceholderConfigurerTests.cs b/test/Spring/Spring.Core.Tests/Objects/Factory/Config/VariablePlaceholderConfigurerTests.cs index 039c1287..ffd8583d 100644 --- a/test/Spring/Spring.Core.Tests/Objects/Factory/Config/VariablePlaceholderConfigurerTests.cs +++ b/test/Spring/Spring.Core.Tests/Objects/Factory/Config/VariablePlaceholderConfigurerTests.cs @@ -34,28 +34,40 @@ namespace Spring.Objects.Factory.Config public class VariablePlaceholderConfigurerTests { -#if NET_2_0 [Test] public void ThrowsOnMissingVariableSources() { StaticApplicationContext ac = new StaticApplicationContext(); VariablePlaceholderConfigurer vphc = new VariablePlaceholderConfigurer(); - - Assert.Throws(() => vphc.PostProcessObjectFactory(ac.ObjectFactory)); - } -#endif -#if NET_2_0 + try + { + vphc.PostProcessObjectFactory(ac.ObjectFactory); + Assert.Fail("Expected ArgumentException not thrown."); + } + catch (ArgumentException) + { + } + } + + [Test] public void ThrowsOnInvalidVariableSourcesElement() { StaticApplicationContext ac = new StaticApplicationContext(); VariablePlaceholderConfigurer vphc = new VariablePlaceholderConfigurer(); vphc.VariableSources = new ArrayList(new object[] { new object() }); - - Assert.Throws(() => vphc.PostProcessObjectFactory(ac.ObjectFactory)); + + try + { + vphc.PostProcessObjectFactory(ac.ObjectFactory); + Assert.Fail("Expected ArgumentException not thrown."); + } + catch (ArgumentException) + { + } } -#endif + [Test] public void SunnyDay() diff --git a/test/Spring/Spring.Messaging.Tests/Messaging/Listener/TransactionalMessageListenerContainerTests.cs b/test/Spring/Spring.Messaging.Tests/Messaging/Listener/TransactionalMessageListenerContainerTests.cs index f2fd2cd3..e993e060 100644 --- a/test/Spring/Spring.Messaging.Tests/Messaging/Listener/TransactionalMessageListenerContainerTests.cs +++ b/test/Spring/Spring.Messaging.Tests/Messaging/Listener/TransactionalMessageListenerContainerTests.cs @@ -67,9 +67,15 @@ namespace Spring.Messaging.Listener { TransactionalMessageListenerContainer container = new TransactionalMessageListenerContainer(); - ArgumentException ex = Assert.Throws(() => container.AfterPropertiesSet()); - Assert.AreEqual("Property 'MessageQueueObjectName' is required", ex.Message); - + try + { + container.AfterPropertiesSet(); + Assert.Fail("Expected ArgumentException not thrown."); + } + catch (ArgumentException ex) + { + Assert.AreEqual("Property 'MessageQueueObjectName' is required", ex.Message); + } } [Test]