From: <fli...@us...> - 2007-05-01 02:17:26
|
Revision: 44 http://structuremap.svn.sourceforge.net/structuremap/?rev=44&view=rev Author: flimflan Date: 2007-04-30 19:17:17 -0700 (Mon, 30 Apr 2007) Log Message: ----------- Implemented PullConfigurationFromAppConfig. Created ObjectFactory.ReInitialize() to allow more isolated unit tests. Modified Paths: -------------- trunk/Source/StructureMap/Configuration/StructureMapConfigurationSection.cs trunk/Source/StructureMap/ObjectFactory.cs trunk/Source/StructureMap/StructureMapConfiguration.cs trunk/Source/StructureMap/StructureMapException.resx trunk/Source/StructureMap.Testing/AlternativeConfigurationTester.cs trunk/Source/StructureMap.Testing/StructureMapConfigurationTester.cs trunk/cruise.build Property Changed: ---------------- trunk/Source/ trunk/Source/StructureMap.DataAccess/ trunk/Source/StructureMap.Testing.GenericWidgets/ Property changes on: trunk/Source ___________________________________________________________________ Name: svn:ignore - *.suo + *.suo _ReSharper.StructureMap PrecompiledWeb *.resharper *.user Modified: trunk/Source/StructureMap/Configuration/StructureMapConfigurationSection.cs =================================================================== --- trunk/Source/StructureMap/Configuration/StructureMapConfigurationSection.cs 2007-04-27 21:54:32 UTC (rev 43) +++ trunk/Source/StructureMap/Configuration/StructureMapConfigurationSection.cs 2007-05-01 02:17:17 UTC (rev 44) @@ -5,28 +5,27 @@ { public class StructureMapConfigurationSection : IConfigurationSectionHandler { - private XmlNode _node; - public object Create(object parent, object configContext, XmlNode section) { - return _node; + XmlNode parentNode = parent as XmlNode; + if (parentNode == null) return section; + // Might need to make this more intelligent, to merge nodes that override eachother + foreach (XmlNode childNode in section.ChildNodes) + { + XmlNode importedNode = parentNode.OwnerDocument.ImportNode(childNode, true); + parentNode.AppendChild(importedNode); + } + return parentNode; } public static XmlNode GetStructureMapConfiguration() { - object config = ConfigurationManager.GetSection(XmlConstants.STRUCTUREMAP); - - - return null; - /* - object o = ConfigurationSettings.GetConfig(XmlConstants.STRUCTUREMAP); - XmlNode node = o as XmlNode; + XmlNode node = ConfigurationSettings.GetConfig(XmlConstants.STRUCTUREMAP) as XmlNode; if (node == null) { - throw new ApplicationException("No <StructureMap> section was found in the application config file"); + throw new StructureMapException(105, XmlConstants.STRUCTUREMAP); } return node; - */ } } } \ No newline at end of file Modified: trunk/Source/StructureMap/ObjectFactory.cs =================================================================== --- trunk/Source/StructureMap/ObjectFactory.cs 2007-04-27 21:54:32 UTC (rev 43) +++ trunk/Source/StructureMap/ObjectFactory.cs 2007-05-01 02:17:17 UTC (rev 44) @@ -27,6 +27,16 @@ ObjectFactoryCacheCallback callback = new ObjectFactoryCacheCallback(); } + /// <summary> + /// Used for testing only (kills singletons). In non-test scenarios, use Reset() instead. + /// </summary> + public static void ReInitialize() + { + _profile = string.Empty; + _notify = null; + _manager = null; + } + #region InstanceManager and setting defaults private static InstanceManager manager Modified: trunk/Source/StructureMap/StructureMapConfiguration.cs =================================================================== --- trunk/Source/StructureMap/StructureMapConfiguration.cs 2007-04-27 21:54:32 UTC (rev 43) +++ trunk/Source/StructureMap/StructureMapConfiguration.cs 2007-05-01 02:17:17 UTC (rev 44) @@ -12,9 +12,9 @@ public static class StructureMapConfiguration { private const string CONFIG_FILE_NAME = "StructureMap.config"; - private static ConfigurationParserCollection _collection = new ConfigurationParserCollection(); - private static Registry _registry = new Registry(); - private static List<Registry> _registries = new List<Registry>(); + private static ConfigurationParserCollection _collection; + private static Registry _registry; + private static List<Registry> _registries; private static StartUp _startUp; private static bool _pullConfigurationFromAppConfig; @@ -58,6 +58,7 @@ _registries = new List<Registry>(); _registries.Add(_registry); _startUp = null; + _pullConfigurationFromAppConfig = false; } /// <summary> @@ -138,15 +139,10 @@ set { _collection.UseDefaultFile = value; } } - [Obsolete("Not ready yet")] public static bool PullConfigurationFromAppConfig { get { return _pullConfigurationFromAppConfig; } - set - { - throw new NotImplementedException("This feature has not been completed"); - _pullConfigurationFromAppConfig = value; - } + set { _pullConfigurationFromAppConfig = value; } } /// <summary> Modified: trunk/Source/StructureMap/StructureMapException.resx =================================================================== --- trunk/Source/StructureMap/StructureMapException.resx 2007-04-27 21:54:32 UTC (rev 43) +++ trunk/Source/StructureMap/StructureMapException.resx 2007-05-01 02:17:17 UTC (rev 44) @@ -246,4 +246,7 @@ <data name="305" xml:space="preserve"> <value>There is no constructor property found of type {0}</value> </data> + <data name="105" xml:space="preserve"> + <value>The <{0}> section could not be loaded from the application configuration file.</value> + </data> </root> \ No newline at end of file Property changes on: trunk/Source/StructureMap.DataAccess ___________________________________________________________________ Name: svn:ignore + bin obj Modified: trunk/Source/StructureMap.Testing/AlternativeConfigurationTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/AlternativeConfigurationTester.cs 2007-04-27 21:54:32 UTC (rev 43) +++ trunk/Source/StructureMap.Testing/AlternativeConfigurationTester.cs 2007-05-01 02:17:17 UTC (rev 44) @@ -12,6 +12,7 @@ [SetUp] public void SetUp() { + ObjectFactory.ReInitialize(); StructureMapConfiguration.ResetAll(); DataMother.WriteDocument("Config1.xml"); DataMother.WriteDocument("Config2.xml"); Modified: trunk/Source/StructureMap.Testing/StructureMapConfigurationTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/StructureMapConfigurationTester.cs 2007-04-27 21:54:32 UTC (rev 43) +++ trunk/Source/StructureMap.Testing/StructureMapConfigurationTester.cs 2007-05-01 02:17:17 UTC (rev 44) @@ -1,5 +1,6 @@ using System; using System.IO; +using System.Xml; using NUnit.Framework; using StructureMap.Configuration; using StructureMap.Graph; @@ -13,6 +14,7 @@ [SetUp] public void SetUp() { + ObjectFactory.ReInitialize(); StructureMapConfiguration.ResetAll(); } @@ -31,8 +33,7 @@ } [Test, - ExpectedException(typeof (ApplicationException), - "StructureMap detected configuration or environmental problems. Check the StructureMap error file")] + ExpectedException(typeof(ApplicationException), ExpectedMessage = "StructureMap detected configuration or environmental problems. Check the StructureMap error file")] public void OnStartUpFail() { StructureMapConfiguration.OnStartUp().FailOnException(); @@ -77,7 +78,7 @@ } - [Test, Ignore("Not complete")] + [Test] public void PullConfigurationFromTheAppConfig() { StructureMapConfiguration.UseDefaultStructureMapConfigFile = false; @@ -87,6 +88,37 @@ (ColorThing<string, bool>) ObjectFactory.GetInstance<IThing<string, bool>>(); Assert.AreEqual("Cornflower", thing.Color, "Cornflower is the color from the App.config file"); } + + [Test] + public void AppConfigShouldIncludeSettingsFromParentConfig() + { + StructureMapConfigurationSection configurationSection = new StructureMapConfigurationSection(); + + XmlNode fromMachineConfig = createNodeFromText(@"<StructureMap><Assembly Name=""SomeAssembly""/></StructureMap>"); + XmlNode fromWebConfig = createNodeFromText(@"<StructureMap><Assembly Name=""AnotherAssembly""/></StructureMap>"); + + XmlNode effectiveConfig = configurationSection.Create(fromMachineConfig, null, fromWebConfig) as XmlNode; + + Assert.IsNotNull(effectiveConfig, "A configuration node should have been returned."); + Assert.AreEqual(2, effectiveConfig.ChildNodes.Count, "Both Assembly entries should have been returned."); + Assert.IsTrue(hasAttributeValue("Name", "SomeAssembly", effectiveConfig.ChildNodes[0]), "The parent Assembly entry should have been returned first."); + Assert.IsTrue(hasAttributeValue("Name", "AnotherAssembly", effectiveConfig.ChildNodes[1]), "The child Assembly entry should have been returned second."); + + } + + private static XmlNode createNodeFromText(string outerXml) + { + XmlDocument document = new XmlDocument(); + document.LoadXml(outerXml); + return document.DocumentElement; + } + + private static bool hasAttributeValue(string attributeName, string attributeValue, XmlNode node) + { + XmlAttribute namedAttribute = node.Attributes[attributeName]; + if (namedAttribute == null) return false; + return namedAttribute.Value == attributeValue; + } } public interface ISomething @@ -100,4 +132,6 @@ throw new ApplicationException("You can't make me!"); } } + + } \ No newline at end of file Property changes on: trunk/Source/StructureMap.Testing.GenericWidgets ___________________________________________________________________ Name: svn:ignore + obj Modified: trunk/cruise.build =================================================================== --- trunk/cruise.build 2007-04-27 21:54:32 UTC (rev 43) +++ trunk/cruise.build 2007-05-01 02:17:17 UTC (rev 44) @@ -71,7 +71,7 @@ <include name="**\bin\${project.config}\*.exe" /> <include name="**\bin\${project.config}\*.xml" /> <include name="**\bin\${project.config}\*.xml.actual" /> - <include name="StructureMap.Testing\StructureMap.config" /> + <include name="StructureMap.Testing\*.config" /> </fileset> </copy> <copy todir="${build.dir}\..\" flatten="true" overwrite="true"> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |