Uses the chain of responsibility pattern to arrange an element using the provided ArrangedCodeBuilder.
Inheritance: IElementArranger
        public void CanArrangeTest()
        {
            ChainElementArranger chain = new ChainElementArranger();
            FieldElement fieldElement = new FieldElement();

            //
            // No arrangers in chain
            //
            Assert.IsFalse(
                chain.CanArrange(fieldElement),
                "Empty chain element arranger should not be able to arrange an element.");

            //
            // Add an arranger that can't arrange the element
            //
            TestElementArranger disabledArranger = new TestElementArranger(false);
            chain.AddArranger(disabledArranger);
            Assert.IsFalse(chain.CanArrange(fieldElement), "Unexpected return value from CanArrange.");

            //
            // Add an arranger that can arrange the element
            //
            TestElementArranger enabledArranger = new TestElementArranger(true);
            chain.AddArranger(enabledArranger);
            Assert.IsTrue(chain.CanArrange(fieldElement), "Unexpected return value from CanArrange.");

            //
            // Null
            //
            Assert.IsFalse(chain.CanArrange(null), "Unexpected return value from CanArrange.");
        }
        public void UnsupportedArrangeNoParentTest()
        {
            ChainElementArranger chain = new ChainElementArranger();
            FieldElement fieldElement = new FieldElement();

            //
            // Add an arranger that can't arrange the element
            //
            TestElementArranger disabledArranger = new TestElementArranger(false);
            chain.AddArranger(disabledArranger);
            Assert.IsFalse(chain.CanArrange(fieldElement), "Unexpected return value from CanArrange.");

            chain.ArrangeElement(null, fieldElement);
        }
Example #3
0
        /// <summary>
        /// Creates an arranger for the children of elements associated with the
        /// specified cofiguration.
        /// </summary>
        /// <param name="parentConfiguration">Parent configuration.</param>
        /// <returns>Element arranger for children.</returns>
        internal static IElementArranger CreateChildrenArranger(ConfigurationElement parentConfiguration)
        {
            ChainElementArranger childrenArranger = new ChainElementArranger();

            foreach (ConfigurationElement childConfiguration in parentConfiguration.Elements)
            {
                IElementArranger childElementArranger = CreateElementArranger(
                    childConfiguration, parentConfiguration);

                if (childElementArranger != null)
                {
                    childrenArranger.AddArranger(childElementArranger);
                }
            }

            return(childrenArranger);
        }
        /// <summary>
        /// Creates an arranger for the children of elements associated with the 
        /// specified cofiguration.
        /// </summary>
        /// <param name="parentConfiguration">Parent configuration.</param>
        /// <returns>Element arranger for children.</returns>
        internal static IElementArranger CreateChildrenArranger(ConfigurationElement parentConfiguration)
        {
            ChainElementArranger childrenArranger = new ChainElementArranger();
            foreach (ConfigurationElement childConfiguration in parentConfiguration.Elements)
            {
                IElementArranger childElementArranger = CreateElementArranger(
                    childConfiguration, parentConfiguration);

                if (childElementArranger != null)
                {
                    childrenArranger.AddArranger(childElementArranger);
                }
            }

            return childrenArranger;
        }
        public void UnsupportedArrangeWithParentTest()
        {
            GroupElement parentElement = new GroupElement();
            ChainElementArranger chain = new ChainElementArranger();
            FieldElement fieldElement = new FieldElement();

            //
            // Add an arranger that can't arrange the element
            //
            TestElementArranger disabledArranger = new TestElementArranger(false);
            chain.AddArranger(disabledArranger);
            Assert.IsFalse(chain.CanArrange(fieldElement), "Unexpected return value from CanArrange.");

            chain.ArrangeElement(parentElement, fieldElement);
            Assert.IsTrue(parentElement.Children.Contains(fieldElement));
        }
 public void AddArrangerNullTest()
 {
     ChainElementArranger chainArranger = new ChainElementArranger();
     chainArranger.AddArranger(null);
 }