Ejemplo n.º 1
0
        public void CanUseUpdateBindingForChildren()
        {
            //asign
            var controlManager = new ControlManager();
            var xForm          = new XForm();

            xForm.Root = new XContainer {
                Name = "BaseContainer"
            };

            var xAttribute1 = new XAttribute <string>(string.Empty)
            {
                Name = "StringAttribute1", Value = "StringAttribute", Use = XAttributeUse.Required
            };
            var xAttribute2 = new XAttribute <int>(1)
            {
                Name = "StringAttribute2", Use = XAttributeUse.Required
            };
            var xAttribute3 = new XAttribute <bool>(true)
            {
                Name = "StringAttribute3", Use = XAttributeUse.Required
            };
            var xAttribute4 = new XAttribute <DateTime>(DateTime.Now)
            {
                Name = "StringAttribute4", Use = XAttributeUse.Required
            };
            var xAttribute5 = new XEnumerationAttribute <string>(string.Empty)
            {
                Name = "StringAttribute5", Use = XAttributeUse.Required
            };
            var xContainer = new XContainer {
                Name = "ChildContainer", Value = "ChildContainerValue", ParentContainer = xForm.Root, MaxOccurs = 1234, MinOccurs = 0
            };

            xContainer.Attributes.Add(xAttribute1);
            var xElement = new XElement {
                Name = "Element", Value = "ElementValue"
            };

            xContainer.Elements.Add(xElement);

            xForm.Root.Attributes.Add(xAttribute1);
            xForm.Root.Attributes.Add(xAttribute2);
            xForm.Root.Attributes.Add(xAttribute3);
            xForm.Root.Attributes.Add(xAttribute4);
            xForm.Root.Attributes.Add(xAttribute5);
            xForm.Root.Containers.Add(xContainer);
            xForm.Root.Elements.Add(xElement);

            //action
            controlManager.GetGroupBoxGui(xForm.Root, xForm.Root);
            controlManager.UpdateBindingForVisibleContainer(xForm.Root);

            //assert
        }
Ejemplo n.º 2
0
        public void GetControlForXEnumerationAttributeTypeString()
        {
            //asign
            var xAttribute = new XEnumerationAttribute <string>("test");

            xAttribute.Enumeration.Add("test1");
            xAttribute.Enumeration.Add("test");
            xAttribute.Name  = "xAttribute";
            xAttribute.Value = "test";
            var controlFactory = new ControlFactory();

            //action
            var control = controlFactory.GetControl(xAttribute);

            //assert
            Assert.NotNull(control);
            Assert.AreEqual(control.Name, xAttribute.Name);
            Assert.True(control.Tag is XEnumerationAttribute <string>);
            Assert.True(control is ComboBox);
            Assert.AreEqual(((ComboBox)control).SelectedItem, "test");
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Provides correct IXAttribute depending on XmlTypeCode.
        /// </summary>
        /// <param name="attribute">Given XmlSchemaAttribute to process.</param>
        /// <returns>Coresponding IXAttribute.</returns>
        private IXAttribute GetXAttribute(XmlSchemaAttribute attribute)
        {
            IXAttribute xAttribute;
            var         xmlTypeCode = attribute.AttributeSchemaType.TypeCode;

            var restriction = attribute.AttributeSchemaType.Content as XmlSchemaSimpleTypeRestriction;

            //resolve restrictions for simple type (enumeration)
            if (restriction != null && restriction.Facets.Count > 0)
            {
                var xStringRestrictionAttribute = new XEnumerationAttribute <string>(attribute.DefaultValue);
                foreach (var enumerationFacet in restriction.Facets.OfType <XmlSchemaEnumerationFacet>())
                {
                    xStringRestrictionAttribute.Enumeration.Add(enumerationFacet.Value);
                }

                //IS ENUMERATION
                if (xStringRestrictionAttribute.Enumeration.Any())
                {
                    xStringRestrictionAttribute.Name  = string.IsNullOrEmpty(Attribute.Name) ? Attribute.QualifiedName.Name : Attribute.Name;
                    xStringRestrictionAttribute.Use   = (XAttributeUse)attribute.Use;
                    xStringRestrictionAttribute.Value = attribute.DefaultValue;
                    if (xStringRestrictionAttribute.Use == XAttributeUse.None)
                    {
                        xStringRestrictionAttribute.Use = XAttributeUse.Optional;//set default value defined here http://www.w3schools.com/schema/el_attribute.asp
                    }
                    return(xStringRestrictionAttribute);
                }
            }


            switch (xmlTypeCode)
            {
            case XmlTypeCode.String:
                xAttribute = new XAttribute <string>(attribute.DefaultValue);
                ((XAttribute <string>)xAttribute).Value = attribute.DefaultValue;
                break;

            case XmlTypeCode.Boolean:
                xAttribute = new XAttribute <bool>(bool.Parse(attribute.DefaultValue));
                if (!string.IsNullOrEmpty(attribute.DefaultValue))
                {
                    ((XAttribute <bool>)xAttribute).Value = bool.Parse(attribute.DefaultValue);
                }
                break;

            case XmlTypeCode.Date:

                var defaultValue = new DateTime();
                if (!string.IsNullOrEmpty(attribute.DefaultValue))
                {
                    defaultValue = DateTime.Parse(attribute.DefaultValue);
                }

                xAttribute = new XAttribute <DateTime>(defaultValue);
                ((XAttribute <DateTime>)xAttribute).Value = defaultValue;
                break;

            case XmlTypeCode.Integer:

                var defaultValueInteger = 0;
                if (!string.IsNullOrEmpty(attribute.DefaultValue))
                {
                    defaultValueInteger = int.Parse(attribute.DefaultValue);
                }

                xAttribute = new XAttribute <int>(defaultValueInteger);
                ((XAttribute <int>)xAttribute).Value = defaultValueInteger;
                break;

            default:
                throw new ArgumentOutOfRangeException("Unknown XmlTypeCode.");
            }

            xAttribute.Name = attribute.Name;
            xAttribute.Use  = (XAttributeUse)attribute.Use;
            if (xAttribute.Use == XAttributeUse.None)
            {
                //set default value defined here http://www.w3schools.com/schema/el_attribute.asp
                xAttribute.Use = XAttributeUse.Optional;
            }

            return(xAttribute);
        }
Ejemplo n.º 4
0
        public void CanUseUpdateBindingForChildren()
        {
            //asign
            var controlManager = new ControlManager();
            var xForm = new XForm();

            xForm.Root = new XContainer { Name = "BaseContainer" };

            var xAttribute1 = new XAttribute<string>(string.Empty) { Name = "StringAttribute1", Value = "StringAttribute", Use = XAttributeUse.Required };
            var xAttribute2 = new XAttribute<int>(1) { Name = "StringAttribute2", Use = XAttributeUse.Required };
            var xAttribute3 = new XAttribute<bool>(true) { Name = "StringAttribute3", Use = XAttributeUse.Required };
            var xAttribute4 = new XAttribute<DateTime>(DateTime.Now) { Name = "StringAttribute4", Use = XAttributeUse.Required };
            var xAttribute5 = new XEnumerationAttribute<string>(string.Empty) { Name = "StringAttribute5", Use = XAttributeUse.Required };
            var xContainer = new XContainer { Name = "ChildContainer", Value = "ChildContainerValue", ParentContainer = xForm.Root, MaxOccurs = 1234, MinOccurs = 0 };
            xContainer.Attributes.Add(xAttribute1);
            var xElement = new XElement { Name = "Element", Value = "ElementValue" };
            xContainer.Elements.Add(xElement);

            xForm.Root.Attributes.Add(xAttribute1);
            xForm.Root.Attributes.Add(xAttribute2);
            xForm.Root.Attributes.Add(xAttribute3);
            xForm.Root.Attributes.Add(xAttribute4);
            xForm.Root.Attributes.Add(xAttribute5);
            xForm.Root.Containers.Add(xContainer);
            xForm.Root.Elements.Add(xElement);

            //action
            controlManager.GetGroupBoxGui(xForm.Root, xForm.Root);
            controlManager.UpdateBindingForVisibleContainer(xForm.Root);

            //assert
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Provides correct IXAttribute depending on XmlTypeCode.
        /// </summary>
        /// <param name="attribute">Given XmlSchemaAttribute to process.</param>
        /// <returns>Coresponding IXAttribute.</returns>
        private IXAttribute GetXAttribute(XmlSchemaAttribute attribute)
        {
            IXAttribute xAttribute;
            var xmlTypeCode = attribute.AttributeSchemaType.TypeCode;

            var restriction = attribute.AttributeSchemaType.Content as XmlSchemaSimpleTypeRestriction;

            //resolve restrictions for simple type (enumeration)
            if (restriction != null && restriction.Facets.Count > 0)
            {
                var xStringRestrictionAttribute = new XEnumerationAttribute<string>(attribute.DefaultValue);
                foreach (var enumerationFacet in restriction.Facets.OfType<XmlSchemaEnumerationFacet>())
                {
                    xStringRestrictionAttribute.Enumeration.Add(enumerationFacet.Value);
                }

                //IS ENUMERATION
                if (xStringRestrictionAttribute.Enumeration.Any())
                {
                    xStringRestrictionAttribute.Name = attribute.Name;
                    xStringRestrictionAttribute.Use = (XAttributeUse)attribute.Use;
                    xStringRestrictionAttribute.Value = attribute.DefaultValue;
                    if (xStringRestrictionAttribute.Use == XAttributeUse.None)
                    {
                        xStringRestrictionAttribute.Use = XAttributeUse.Optional;//set default value defined here http://www.w3schools.com/schema/el_attribute.asp
                    }
                    return xStringRestrictionAttribute;
                }
            }

            switch (xmlTypeCode)
            {
                case XmlTypeCode.String:
                    xAttribute = new XAttribute<string>(attribute.DefaultValue);
                    ((XAttribute<string>)xAttribute).Value = attribute.DefaultValue;
                    break;
                case XmlTypeCode.Boolean:
                    xAttribute = new XAttribute<bool>(bool.Parse(attribute.DefaultValue));
                    if (!string.IsNullOrEmpty(attribute.DefaultValue))
                    {
                        ((XAttribute<bool>)xAttribute).Value = bool.Parse(attribute.DefaultValue);
                    }
                    break;
                case XmlTypeCode.Date:

                    var defaultValue = new DateTime();
                    if (!string.IsNullOrEmpty(attribute.DefaultValue))
                    {
                        defaultValue = DateTime.Parse(attribute.DefaultValue);
                    }

                    xAttribute = new XAttribute<DateTime>(defaultValue);
                    ((XAttribute<DateTime>)xAttribute).Value = defaultValue;
                    break;
                case XmlTypeCode.Integer:

                    var defaultValueInteger = 0;
                    if (!string.IsNullOrEmpty(attribute.DefaultValue))
                    {
                        defaultValueInteger = int.Parse(attribute.DefaultValue);
                    }

                    xAttribute = new XAttribute<int>(defaultValueInteger);
                    ((XAttribute<int>)xAttribute).Value = defaultValueInteger;
                    break;
                default:
                    throw new ArgumentOutOfRangeException("Unknown XmlTypeCode.");
            }

            xAttribute.Name = attribute.Name;
            xAttribute.Use = (XAttributeUse)attribute.Use;
            if (xAttribute.Use == XAttributeUse.None)
            {
                //set default value defined here http://www.w3schools.com/schema/el_attribute.asp
                xAttribute.Use = XAttributeUse.Optional;
            }

            return xAttribute;
        }
Ejemplo n.º 6
0
        public void GetControlForXEnumerationAttributeTypeString()
        {
            //asign
            var xAttribute = new XEnumerationAttribute<string>("test");
            xAttribute.Enumeration.Add("test1");
            xAttribute.Enumeration.Add("test");
            xAttribute.Name = "xAttribute";
            xAttribute.Value = "test";
            var controlFactory = new ControlFactory();

            //action
            var control = controlFactory.GetControl(xAttribute);

            //assert
            Assert.NotNull(control);
            Assert.AreEqual(control.Name, xAttribute.Name);
            Assert.True(control.Tag is XEnumerationAttribute<string>);
            Assert.True(control is ComboBox);
            Assert.AreEqual(((ComboBox)control).SelectedItem, "test");
        }