Inheritance: ConfigurationElement
        public void CloneTest()
        {
            ElementConfiguration prototype = new ElementConfiguration();
            prototype.ElementType = ElementType.Delegate;
            prototype.Id = "Test";

            FilterBy filterBy = new FilterBy();
            filterBy.Condition = "$(Name) == 'Test'";
            prototype.FilterBy = filterBy;

            GroupBy groupBy = new GroupBy();
            groupBy.By = ElementAttributeType.Access;
            prototype.GroupBy = groupBy;

            SortBy sortBy = new SortBy();
            sortBy.By = ElementAttributeType.Name;
            prototype.SortBy = sortBy;

            ElementConfiguration clone = prototype.Clone() as ElementConfiguration;
            Assert.IsNotNull(clone, "Clone did not return an instance.");

            Assert.AreEqual(prototype.ElementType, clone.ElementType, "ElementType was not cloned correctly.");
            Assert.AreEqual(prototype.Id, clone.Id, "Id was not cloned correctly.");

            Assert.AreEqual(prototype.FilterBy.Condition, clone.FilterBy.Condition, "FilterBy was not cloned correctly.");
            Assert.AreEqual(prototype.GroupBy.By, clone.GroupBy.By, "GroupBy was not cloned correctly.");
            Assert.AreEqual(prototype.SortBy.By, clone.SortBy.By, "SortBy was not cloned correctly.");
        }
        public void ArrangeNestedRegionTest()
        {
            List<ICodeElement> elements = new List<ICodeElement>();

            TypeElement type = new TypeElement();
            type.Type = TypeElementType.Class;
            type.Name = "TestClass";

            FieldElement field = new FieldElement();
            field.Name = "val";
            field.Type = "int";

            type.AddChild(field);
            elements.Add(type);

            // Create a configuration with a nested region
            CodeConfiguration codeConfiguration = new CodeConfiguration();

            ElementConfiguration typeConfiguration = new ElementConfiguration();
            typeConfiguration.ElementType = ElementType.Type;

            RegionConfiguration regionConfiguration1 = new RegionConfiguration();
            regionConfiguration1.Name = "Region1";

            RegionConfiguration regionConfiguration2 = new RegionConfiguration();
            regionConfiguration2.Name = "Region2";

            ElementConfiguration fieldConfiguration = new ElementConfiguration();
            fieldConfiguration.ElementType = ElementType.Field;

            regionConfiguration2.Elements.Add(fieldConfiguration);
            regionConfiguration1.Elements.Add(regionConfiguration2);
            typeConfiguration.Elements.Add(regionConfiguration1);
            codeConfiguration.Elements.Add(typeConfiguration);

            CodeArranger arranger = new CodeArranger(codeConfiguration);

            ReadOnlyCollection<ICodeElement> arrangedElements = arranger.Arrange(elements.AsReadOnly());

            Assert.AreEqual(1, arrangedElements.Count, "Unexpected number of arranged elements.");

            TypeElement arrangedType = arrangedElements[0] as TypeElement;
            Assert.IsNotNull(arrangedType, "Expected a type element after arranging.");
            Assert.AreEqual(1, arrangedType.Children.Count, "Unexpected number of arranged child elements.");

            RegionElement arrangedRegion1 = arrangedType.Children[0] as RegionElement;
            Assert.IsNotNull(arrangedRegion1, "Expected a region element after arranging.");
            Assert.AreEqual(regionConfiguration1.Name, arrangedRegion1.Name);
            Assert.AreEqual(1, arrangedRegion1.Children.Count, "Unexpected number of arranged child elements.");

            RegionElement arrangedRegion2 = arrangedRegion1.Children[0] as RegionElement;
            Assert.IsNotNull(arrangedRegion2, "Expected a region element after arranging.");
            Assert.AreEqual(regionConfiguration2.Name, arrangedRegion2.Name);
            Assert.AreEqual(1, arrangedRegion2.Children.Count, "Unexpected number of arranged child elements.");

            FieldElement arrangedFieldElement = arrangedRegion2.Children[0] as FieldElement;
            Assert.IsNotNull(arrangedFieldElement, "Expected a field element after arranging.");
        }
        public void ToStringTest()
        {
            ElementConfiguration elementConfiguration = new ElementConfiguration();
            elementConfiguration.ElementType = ElementType.Method;

            string str = elementConfiguration.ToString();

            Assert.AreEqual("Element: Type - Method", str, "Unexpected string representation.");
        }
        public void CreateTest()
        {
            ElementConfiguration elementConfiguration = new ElementConfiguration();

            //
            // Verify default state
            //
            Assert.AreEqual(ElementType.NotSpecified, elementConfiguration.ElementType, "Unexpected default value for ElementType.");
            Assert.IsNull(elementConfiguration.Id, "Unexpected default value for Id.");
            Assert.IsNull(elementConfiguration.FilterBy, "Unexpected default value for FilterBy.");
            Assert.IsNull(elementConfiguration.GroupBy, "Unexpected default value for GroupBy.");
            Assert.IsNull(elementConfiguration.SortBy, "Unexpected default value for SortBy.");
            Assert.IsNotNull(elementConfiguration.Elements, "Elements collection should not be null.");
            Assert.AreEqual(0, elementConfiguration.Elements.Count, "Elements collection should be empty.");
        }
        public void CanArrangeTest()
        {
            RegionConfiguration methodRegionConfiguration = new RegionConfiguration();
            methodRegionConfiguration.Name = "Methods";
            ElementConfiguration methodConfiguration = new ElementConfiguration();
            methodConfiguration.ElementType = ElementType.Method;
            methodRegionConfiguration.Elements.Add(methodConfiguration);

            RegionConfiguration propertyRegionConfiguration = new RegionConfiguration();
            propertyRegionConfiguration.Name = "Properties";
            ElementConfiguration propertyConfiguration = new ElementConfiguration();
            propertyConfiguration.ElementType = ElementType.Property;
            propertyRegionConfiguration.Elements.Add(propertyConfiguration);

            ElementConfiguration parentConfiguration = new ElementConfiguration();
            parentConfiguration.ElementType = ElementType.Type;

            RegionArranger methodRegionArranger = new RegionArranger(
                methodRegionConfiguration, parentConfiguration);

            RegionArranger propertyRegionArranger = new RegionArranger(
                propertyRegionConfiguration, parentConfiguration);

            MethodElement method = new MethodElement();
            method.Name = "DoSomething";

            Assert.IsTrue(
                methodRegionArranger.CanArrange(method),
                "Expected region arranger to be able to arrange the element.");

            Assert.IsFalse(
                propertyRegionArranger.CanArrange(method),
                "Expected region arranger to not be able to arrange the element.");

            Assert.IsFalse(
                methodRegionArranger.CanArrange(null),
                "Expected region arranger to not be able to arrange a null element.");
        }
Exemple #6
0
        /// <summary>
        /// Creates a clone of this instance.
        /// </summary>
        /// <returns>Clone of the instance.</returns>
        protected override ConfigurationElement DoClone()
        {
            ElementConfiguration clone = new ElementConfiguration();

            clone._elementType = _elementType;
            clone._id          = _id;

            if (_filterBy != null)
            {
                clone._filterBy = _filterBy.Clone() as FilterBy;
            }

            if (_groupBy != null)
            {
                clone._groupBy = _groupBy.Clone() as GroupBy;
            }

            if (_sortBy != null)
            {
                clone._sortBy = _sortBy.Clone() as SortBy;
            }

            return(clone);
        }
Exemple #7
0
        /// <summary>
        /// Creates a new ElementArranger.
        /// </summary>
        /// <param name="elementConfiguration">Element configuration.</param>
        /// <param name="parentConfiguration">Parent configuration.</param>
        protected internal ElementArranger(
			ElementConfiguration elementConfiguration, ConfigurationElement parentConfiguration)
        {
            if (elementConfiguration == null)
            {
                throw new ArgumentNullException("elementConfiguration");
            }

            _elementConfiguration = elementConfiguration;
            _parentConfiguration = parentConfiguration;
        }
        /// <summary>
        /// Creates a clone of this instance.
        /// </summary>
        /// <returns>Clone of the instance.</returns>
        protected override ConfigurationElement DoClone()
        {
            ElementConfiguration clone = new ElementConfiguration();

            clone._elementType = _elementType;
            clone._id = _id;

            if (_filterBy != null)
            {
                clone._filterBy = _filterBy.Clone() as FilterBy;
            }

            if (_groupBy != null)
            {
                clone._groupBy = _groupBy.Clone() as GroupBy;
            }

            if (_sortBy != null)
            {
                clone._sortBy = _sortBy.Clone() as SortBy;
            }

            return clone;
        }
        public void SerializeAndDeserializeTest()
        {
            CodeConfiguration origConfig = new CodeConfiguration();

            ElementConfiguration elementConfiguration1 = new ElementConfiguration();
            elementConfiguration1.ElementType = ElementType.Using;
            elementConfiguration1.Id = "TestId";
            origConfig.Elements.Add(elementConfiguration1);

            ElementConfiguration elementConfiguration2 = new ElementConfiguration();
            elementConfiguration2.ElementType = ElementType.Namespace;
            origConfig.Elements.Add(elementConfiguration2);

            ElementReferenceConfiguration elementReferenceConfiguration = new ElementReferenceConfiguration();
            elementReferenceConfiguration.Id = "TestId";
            origConfig.Elements.Add(elementReferenceConfiguration);

            RegionConfiguration regionConfiguration = new RegionConfiguration();
            regionConfiguration.Name = "Test Region";
            origConfig.Elements.Add(regionConfiguration);

            origConfig.ResolveReferences();
            Assert.AreEqual(
                elementConfiguration1.Elements.Count,
                elementReferenceConfiguration.ReferencedElement.Elements.Count,
                "Element reference was not resolved.");

            string tempFile = Path.GetTempFileName();
            try
            {
                //
                // Save the configuration to an XML file
                //
                origConfig.Save(tempFile);

                //
                // Load the configuration from the XML file
                //
                CodeConfiguration loadedConfig = CodeConfiguration.Load(tempFile);
                Assert.IsNotNull(loadedConfig, "Loaded configuration should not be null.");

                Assert.AreEqual(origConfig.Elements.Count, loadedConfig.Elements.Count, "An unexpected number of config elements were deserialized.");

                for (int index = 0; index < origConfig.Elements.Count; index++)
                {
                    if (origConfig.Elements[index] is ElementConfiguration)
                    {
                        ElementConfiguration origElement =
                            origConfig.Elements[index] as ElementConfiguration;
                        ElementConfiguration loadedElement =
                            loadedConfig.Elements[index] as ElementConfiguration;

                        Assert.AreEqual(origElement.ElementType, loadedElement.ElementType, "Unexpected element type.");
                    }
                    else if (origConfig.Elements[index] is ElementReferenceConfiguration)
                    {
                        ElementReferenceConfiguration origElement =
                            origConfig.Elements[index] as ElementReferenceConfiguration;
                        ElementReferenceConfiguration loadedElement =
                            loadedConfig.Elements[index] as ElementReferenceConfiguration;

                        Assert.AreEqual(origElement.Id, loadedElement.Id, "Unexpected element type.");
                        Assert.AreEqual(
                            origElement.ReferencedElement.Id,
                            loadedElement.ReferencedElement.Id,
                            "Unexpected referenced element.");
                    }
                    else if (origConfig.Elements[index] is RegionConfiguration)
                    {
                        RegionConfiguration origRegion =
                            origConfig.Elements[index] as RegionConfiguration;
                        RegionConfiguration loadedRegion =
                            loadedConfig.Elements[index] as RegionConfiguration;

                        Assert.AreEqual(origRegion.Name, loadedRegion.Name, "Unexpected region name.");
                    }
                }
            }
            finally
            {
                File.Delete(tempFile);
            }
        }