Exemplo n.º 1
0
 public Restriction Clone()
 {
     var restriction = new Restriction();
     foreach (var item in Enumerations)
     {
         restriction.Enumerations.Add(item);
     }
     return restriction;
 }
        public void Clone_SuccessNoValue()
        {
            Restriction restriction = new Restriction();
            restriction.Enumerations.Add("restrictionEnum");
            restriction.Enumerations.Add("restrictionEnum2");
            restriction.Enumerations.Add("restrictionEnum3");

            Restriction clone = restriction.Clone();

            if (restriction.Enumerations.Count != clone.Enumerations.Count)
            {
                Assert.Fail("Clone.Enumerations.Count does not match base.");
            }
            else
            {
                for (int i = 0; i < restriction.Enumerations.Count; i++ )
                {
                    if(restriction.Enumerations[i] != clone.Enumerations[i])
                    {
                        Assert.Fail("Clone.Enumeration: " + clone.Enumerations[i] + " does not match base of: " + restriction.Enumerations[i]  + ".");
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void ProcessAttributes(XmlSchemaComplexType schemaComplexType, Element element)
        {
            var enumerator = schemaComplexType.AttributeUses.GetEnumerator();

            while (enumerator.MoveNext())
            {
                var xmlAttribute = (XmlSchemaAttribute)enumerator.Value;

                var attribute = new Parts.Attribute();
                attribute.Name = xmlAttribute.Name;
                attribute.Type = xmlAttribute.SchemaTypeName.Name;
                attribute.Default = xmlAttribute.DefaultValue == null ? "" : xmlAttribute.DefaultValue;
                attribute.Use = xmlAttribute.Use.ToString();
                attribute.Documentation = GetDocumentation(xmlAttribute.Annotation);

                attribute.Parent = element;
                attribute.IsAdvanced = SpecialCaseHandlers.IsAdvanced(attribute);
                attribute.RootObject = "Xsd";

                if(xmlAttribute.AttributeSchemaType.Content.GetType().ToString() == "System.Xml.Schema.XmlSchemaSimpleTypeRestriction")
                {
                    var xmlRestrication = xmlAttribute.AttributeSchemaType.Content as XmlSchemaSimpleTypeRestriction;
                    if (xmlRestrication != null)
                    {
                        var restriction = new Restriction();

                        foreach (XmlSchemaEnumerationFacet facet in xmlRestrication.Facets)
                        {
                            restriction.Enumerations.Add(facet.Value);
                        }

                        attribute.Restriction = restriction;
                    }
                }

                attribute.SpecialLength = SpecialCaseHandlers.SpecialLength(attribute);
                element.Attributes.Add(attribute);
            }
        }
        public void Clone_SuccessNoValue()
        {
            NewRelic.AgentConfiguration.Parts.Attribute attribute = new NewRelic.AgentConfiguration.Parts.Attribute();
            attribute.Default = "baseDefault";
            attribute.Use = "baseUse";
            attribute.Name = "baseAttribute";
            attribute.Parent = null;

            Restriction restriction = new Restriction();
            restriction.Enumerations.Add("restrictionEnum");

            attribute.Restriction = restriction;
            attribute.SpecialLength = false;
            attribute.Type = "DataType.String";
            attribute.Value = "baseAttribute";
            attribute.Documentation = "baseAttribute";
            attribute.IsAdvanced = true;

            NewRelic.AgentConfiguration.Parts.Attribute clone = attribute.Clone();

            if (attribute.Default != clone.Default)
            {
                Assert.Fail("Clone.Default does not match base.");
            }

            if (attribute.Use != clone.Use)
            {
                Assert.Fail("Clone.Use does not match base.");
            }

            if (attribute.Name != clone.Name)
            {
                Assert.Fail("Clone.Name does not match base.");
            }

            if (attribute.Parent != null)
            {
                if (attribute.Parent.Name != clone.Parent.Name)
                {
                    Assert.Fail("Clone.Parent does not match base.");
                }
            }
            else
            {
                if (clone.Parent != null)
                {
                    Assert.Fail("Clone.Parent not null, base is null");
                }
            }

            if (attribute.Restriction.Enumerations.Count != clone.Restriction.Enumerations.Count)
            {
                Assert.Fail("Clone.Restriction.Enumerations.Count does not match base.");
            }

            if (attribute.SpecialLength != clone.SpecialLength)
            {
                Assert.Fail("Clone.SpecialLength does not match base.");
            }

            if (attribute.Type != clone.Type)
            {
                Assert.Fail("Clone.Type does not match base.");
            }

            if (attribute.Documentation != clone.Documentation)
            {
                Assert.Fail("Clone.Documentation does not match base.");
            }

            if (attribute.IsAdvanced != clone.IsAdvanced)
            {
                Assert.Fail("Clone.IsAdvanced does not match base.");
            }

            if (attribute.Value == clone.Value)
            {
                Assert.Fail("Clone.Value matches base.");
            }
        }