public void DefaultChildren()
        {
            IConfiguration config = GetConfiguration();

            IConfiguration child = config.GetChild("Child", false);
            Assertion.AssertNull( child );

            child = config.GetChild("Child", true);
            Assertion.AssertNotNull( child );

            for( int i = 0; i < 10; i++ )
            {
                DefaultConfiguration testChild = new DefaultConfiguration( "test", "Apache.AvalonFramework.DefaultConfigurationTest" );
                testChild.Value = "value";
                config.Children.Add( testChild );
            }

            Assertion.AssertEquals( 11, config.Children.Count );

            ConfigurationCollection coll = config.GetChildren( "test" );
            Assertion.AssertEquals( 10, coll.Count );

            foreach( IConfiguration testConfig in coll )
            {
                Assertion.AssertEquals( "test", testConfig.Name );
                Assertion.AssertEquals( "value", testConfig.Value );
            }
        }
        /// <summary>
        /// Makes a deserialization of <see cref="XmlNode"/> instance.
        /// </summary>
        /// <param name="node">The Node to deserialize.</param>
        /// <param name="parent">A Deserialized <see cref="DefaultConfiguration"/> parent instance.</param>
        /// <returns>A Deserialized <see cref="DefaultConfiguration"/> instance.</returns>
        public static DefaultConfiguration Deserialize(XmlNode node, DefaultConfiguration parent)
        {
            // node deserialization
            DefaultConfiguration configuration = null;

            if ((node.NodeType  == XmlNodeType.CDATA) || (node.NodeType == XmlNodeType.Text))
            {
                if (parent != null)
                {
                    parent.Value = string.Concat(parent.Value, node.Value);
                }
            }

            if ((node.NodeType  == XmlNodeType.Document) || (node.NodeType == XmlNodeType.Element))
            {
                configuration = new DefaultConfiguration(node.LocalName, "-", node.NamespaceURI, node.Prefix);

                // attribute deserialization
                if (node.Attributes != null)
                {
                    foreach (XmlAttribute attr in node.Attributes)
                    {
                        if (string.Compare(attr.Prefix, string.Empty) == 0)
                        {
                            configuration.Attributes[attr.Name] = attr.Value;
                        }
                    }
                }

                // child deserialization
                foreach (XmlNode child in node.ChildNodes)
                {
                    DefaultConfiguration childConfiguration = Deserialize(child, configuration);

                    if (childConfiguration != null)
                    {
                        configuration.Children.Add(childConfiguration);
                    }
                }
            }

            return configuration;
        }
        public void InsertRemove()
        {
            ConfigurationCollection collection = new ConfigurationCollection( arrayRange );
            IConfiguration config = new DefaultConfiguration( "test", "ConfigurationCollectionTest" );

            collection.Insert( 1, config );
            Assertion.Assert( collection.Contains( config ) );
            Assertion.AssertEquals( config, collection[1] );
            Assertion.AssertEquals( 4, collection.Count );

            collection.Remove( config );
            Assertion.AssertEquals( 3, collection.Count );
            Assertion.AssertEquals( false, collection.Contains( config ) );
        }
        public void Index()
        {
            ConfigurationCollection collection = new ConfigurationCollection( arrayRange );
            DefaultConfiguration testconfig = new DefaultConfiguration( "test", "ConfigurationCollectionTest" );
            testconfig.Value = "1";
            collection.Add( testconfig );

            Assertion.AssertEquals( 4, collection.Count );
            IConfiguration config = collection[3]; // 0 based indexes

            Assertion.AssertEquals( "test", config.Name );
            Assertion.AssertEquals( "ConfigurationCollectionTest" , config.Location );

            Assertion.Assert( ! ("1" == collection[0].Value) );
            Assertion.AssertEquals( "1", collection[3].Value );
        }
        public void CopyTo()
        {
            ConfigurationCollection collection = new ConfigurationCollection( collRange );

            IConfiguration[] array = new IConfiguration[4];
            array[0] = new DefaultConfiguration( "test", "ConfigurationCollectionTest" );

            collection.CopyTo( array, 1 );

            bool isFirst = true;
            foreach ( IConfiguration config in array )
            {
                if (isFirst)
                {
                    Assertion.AssertEquals("test", config.Name);
                    isFirst = false;
                }
                else
                {
                    Assertion.AssertEquals("collection", config.Name);
                }

                Assertion.AssertEquals("ConfigurationCollectionTest", config.Location);
            }
        }
        /// <summary>
        ///	Gets an <see cref="IConfiguration"/> instance encapsulating the specified
        /// child node.
        /// </summary>
        /// <param name="name">The Name of the child node.</param>
        /// <param name="createNew">
        ///	If <see langword="true"/>, a new <see cref="IConfiguration"/>
        /// will be created and returned if the specified child does not exist.
        /// If <see langword="true"/>, <see langword="null"/> will be returned when the specified
        /// child doesn't exist.
        /// </param>
        /// <returns>
        /// The <see cref="IConfiguration"/> instance encapsulating the specified child node.
        /// </returns>
        public override IConfiguration GetChild(string name, bool createNew )
        {
            IConfiguration result = null;

            if (Children.Count != 0)
            {
                foreach (IConfiguration configuration in Children)
                {
                    if (string.Compare(configuration.Name, name) == 0)
                    {
                        result = configuration;
                        break;
                    }
                }
            }

            if ( result == null )
            {
                if( createNew )
                {
                    result = new DefaultConfiguration( name, string.Empty );
                    Children.Add( result );
                }
            }

            return result;
        }
        /// <summary>
        /// Makes a serialization of a <see cref="DefaultConfiguration"/> instance.
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="configuration">A <see cref="DefaultConfiguration"/> instance to serialize.</param>
        public static void Serialize(XmlWriter writer, DefaultConfiguration configuration)
        {
            // serialize the configuration
            writer.WriteStartElement(configuration.Prefix, configuration.Name, configuration.Namespace);

            // attribute serialization
            foreach (DictionaryEntry attr in configuration.Attributes)
            {
                writer.WriteAttributeString(attr.Key.ToString(), attr.Value.ToString());
            }

            if (configuration.Value != null)
            {
                writer.WriteString(configuration.Value.ToString());
            }

            // child serialization
            foreach(IConfiguration child in configuration.Children)
            {
                Serialize(writer, (DefaultConfiguration) child);
            }

            writer.WriteEndElement();
        }
        /// <summary>
        /// Makes a serialization of a <see cref="DefaultConfiguration"/> instance.
        /// </summary>
        /// <param name="filename">
        /// The File name where <see cref="DefaultConfiguration"/> instance will be
        /// serialized to.
        /// </param>
        /// <param name="configuration">A <see cref="DefaultConfiguration"/> instance to serialize</param>
        public static void Serialize(string filename, DefaultConfiguration configuration)
        {
            XmlTextWriter writer = new XmlTextWriter(new StreamWriter(filename));

            //Use indentation for readability.
            writer.Formatting = Formatting.Indented;
            writer.Indentation = 4;

            writer.WriteStartDocument(true);

            Serialize(writer, configuration);

            writer.WriteEndDocument();
            writer.Close();
        }