public void CanUseAreControlsValid() { //asign var controlManager = new ControlManager(); var xForm = new XForm(); xForm.Root = new XContainer { Name = "BaseContainer" }; var xAttribute = new XAttribute<string>("StringAttribute") { Name = "StringAttribute", Value = "StringAttribute", Use = XAttributeUse.Required }; var xContainer = new XContainer { Name = "ChildContainer", Value = "ChildContainerValue", ParentContainer = xForm.Root, MaxOccurs = 1234, MinOccurs = 0 }; xContainer.Attributes.Add(xAttribute); var xElement = new XElement { Name = "Element", Value = "ElementValue" }; xContainer.Elements.Add(xElement); xForm.Root.Attributes.Add(xAttribute); xForm.Root.Containers.Add(xContainer); xForm.Root.Elements.Add(xElement); xContainer.Value = "test"; //action controlManager.GetGroupBoxGui(xForm.Root, xForm.Root); var areControlsValid = controlManager.AreControlsValid(); //assert Assert.False(areControlsValid); }
/// <summary> /// Creates Control control from given XElement. /// </summary> /// <param name="element">Given XElement.</param> /// <returns>Label control according to given XElement.</returns> internal Control GetControl(XElement element) { var textBox = new TextBox(); textBox.DataBindings.Add("Text", element, "Value"); textBox.Name = element.Name; textBox.Tag = element; return textBox; }
public void CanUseGenerateGui() { //asign var controlManager = new ControlManager(); var xForm = new XForm(); xForm.Root = new XContainer { Name = "BaseContainer" }; var xAttribute = new XAttribute<string>(string.Empty) { Name = "StringAttribute", Value = "StringAttribute", Use = XAttributeUse.Required }; var xContainer = new XContainer { Name = "ChildContainer", Value = "ChildContainerValue", ParentContainer = xForm.Root, MaxOccurs = 1234, MinOccurs = 0 }; xContainer.Attributes.Add(xAttribute); var xElement = new XElement { Name = "Element", Value = "ElementValue" }; xContainer.Elements.Add(xElement); xForm.Root.Attributes.Add(xAttribute); xForm.Root.Containers.Add(xContainer); xForm.Root.Elements.Add(xElement); //action var groupBoxGui = controlManager.GetGroupBoxGui(xForm.Root, xForm.Root); //assert Assert.NotNull(groupBoxGui); }
public void CanParseXFormFromXmlFileDocumentumArchivageSettingsXsd() { //asign var xmlWriter = new XmlWriter(); var xForm = new XForm(); xForm.Root = new XContainer { Name = "BaseContainer" }; var xAttribute = new XAttribute<string>(string.Empty) { Name = "StringAttribute", Value = "StringAttribute" }; var xContainer = new XContainer { Name = "ChildContainer", Value = "ChildContainerValue", ParentContainer = xForm.Root }; xContainer.Attributes.Add(xAttribute); var xElement = new XElement { Name = "Element", Value = "ElementValue" }; xContainer.Elements.Add(xElement); xForm.Root.Attributes.Add(xAttribute); xForm.Root.Containers.Add(xContainer); xForm.Root.Elements.Add(xElement); var fileStream = new FileStream(@"testXml.txt", FileMode.OpenOrCreate); //action xmlWriter.WriteXFormToXmlFile(fileStream, xForm); //assert var xml = File.ReadAllText(@"testXml.txt"); var resultXml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" + "<BaseContainer xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" StringAttribute=\"StringAttribute\">" + "\r\n <Element>ElementValue</Element>" + "\r\n <ChildContainer StringAttribute=\"StringAttribute\">ChildContainerValue" + "<Element>ElementValue</Element>" + "</ChildContainer>" + "\r\n</BaseContainer>"; Assert.AreEqual(xml, resultXml); }
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 }
/// <summary> /// Creates Label control from given XElement. /// </summary> /// <param name="xElement">Given XElement.</param> /// <returns>Label control according to given XElement.</returns> internal Label GetLabel(XElement xElement) { var label = new Label(); label.AutoSize = true; label.Name = xElement.Name + "Label"; label.Size = new Size(35, 13); label.TabIndex = 0; label.Text = xElement.Name; return label; }
/// <summary> /// Build new XForm from XmlSchema. /// </summary> /// <param name="xmlSchemaElement">Current XmlSchemaElement.</param> /// <param name="parent">Parent XContainer to keep parent reference.</param> private void BuildXForm(XmlSchemaElement xmlSchemaElement, XContainer parent) { var container = new XContainer(); container.MaxOccurs = xmlSchemaElement.MaxOccurs; container.MinOccurs = xmlSchemaElement.MinOccurs; if (xmlSchemaElement.Parent is XmlSchemaGroupBase) { var xmlSchemaGroupBase = ((XmlSchemaGroupBase)xmlSchemaElement.Parent); if (!string.IsNullOrEmpty(xmlSchemaGroupBase.MaxOccursString)) { container.MaxOccurs = ((XmlSchemaGroupBase)xmlSchemaElement.Parent).MaxOccurs; container.MinOccurs = ((XmlSchemaGroupBase)xmlSchemaElement.Parent).MinOccurs; } } container.ParentContainer = parent; container.Name = xmlSchemaElement.Name; container.Id = 1; var complexType = xmlSchemaElement.ElementSchemaType as XmlSchemaComplexType; var simpleType = xmlSchemaElement.ElementSchemaType as XmlSchemaSimpleType; if (simpleType != null) { var element = new XElement(); element.Name = xmlSchemaElement.Name; _lastContainer.Elements.Add(element); //TODO IMPLEMENT ANOTHER RESTRICTION FACETS LIKE enumeration, maxExclusive, pattern, etc. } if (complexType != null) { // If the complex type has any attributes, get an enumerator // and write each attribute name to the container. if (complexType.AttributeUses.Count > 0) { IDictionaryEnumerator enumerator = complexType.AttributeUses.GetEnumerator(); while (enumerator.MoveNext()) { var attribute = (XmlSchemaAttribute)enumerator.Value; var xAttribute = GetXAttribute(attribute); container.Attributes.Add(xAttribute); } } if (_xFormRoot == null) { _xFormRoot = container; } else { _lastContainer.Containers.Add(container); } //xs:all, xs:choice, xs:sequence if (complexType.ContentTypeParticle is XmlSchemaGroupBase) { var baseParticle = complexType.ContentTypeParticle as XmlSchemaGroupBase; foreach (XmlSchemaElement subParticle in baseParticle.Items) { _lastContainer = container; BuildXForm(subParticle, container); } } else { //TODO IMPLEMENT ANOTHER XmlSchemaContentType if (complexType.ContentType == XmlSchemaContentType.TextOnly) { container.Value = string.Empty; } } } _lastContainer = null; }
public void GetControlForXElement() { //asign var xElement = new XElement(); xElement.Name = "xElement"; var controlFactory = new ControlFactory(); //action var control = controlFactory.GetControl(xElement); //assert Assert.NotNull(control); Assert.AreEqual(control.Name, xElement.Name); Assert.True(control.Tag is XElement); Assert.True(control is TextBox); }
public void GetLabelForXElement() { //asign var xElement = new XElement(); xElement.Name = "xElement"; var controlFactory = new ControlFactory(); //action var control = controlFactory.GetLabel(xElement); //assert Assert.NotNull(control); Assert.AreEqual(control.Name, xElement.Name + "Label"); }