Beispiel #1
0
        public void ParseLabel()
        {
            ViewConverter converter = ViewConverter.GetInstance();

            XmlDocument document = converter.LoadXmlDocument(TEST3);
            XmlNodeList rootNode = document.GetElementsByTagName("GroupBox");

            Assert.AreEqual(1, rootNode.Count);
            Assert.AreEqual("GroupBox", rootNode[0].Name);

            GroupBox box = new GroupBox();

            converter.ConvertDocument(rootNode[0], box);

            Assert.AreEqual(1, box.Controls.Count);

            GroupBox parent = box.Controls[0] as GroupBox;

            Assert.AreEqual("groupBox1", parent.Text);
            Assert.AreEqual("groupBox1", parent.Name);
            Assert.AreEqual(new Size(50, 50), parent.Size);

            Label label = parent.Controls[0] as Label;

            Assert.AreEqual("label1", label.Name);
            Assert.AreEqual("How are you?", label.Text);
        }
Beispiel #2
0
        public void ConvertFromXmlRecursivelyTest()
        {
            ViewConverter converter = ViewConverter.GetInstance();

            XmlDocument document = converter.LoadXmlDocument(TEST2);
            XmlNodeList formNode = document.GetElementsByTagName("Form");

            Assert.AreEqual(1, formNode.Count);
            Assert.AreEqual("Form", formNode[0].Name);

            GroupBox box = new GroupBox();

            converter.ConvertDocument(formNode[0], box);

            Assert.AreEqual(1, box.Controls.Count);

            GroupBox parent = box.Controls[0] as GroupBox;

            Assert.AreEqual("Hello, World", parent.Text);
            Assert.AreEqual("Form1", parent.Name);
            Assert.AreEqual(new Size(100, 100), parent.Size);

            Assert.AreEqual("groupBox1", box.Controls[0].Controls[0].Name);
            Assert.AreEqual("groupBox1", box.Controls[0].Controls[0].Text);
            Assert.AreEqual(new Size(50, 50), box.Controls[0].Controls[0].Size);
        }
Beispiel #3
0
        private void richTextBox1_TextChanged(object sender, EventArgs e)
        {
            groupBox1.Controls.Clear();
            int pos = richTextBox1.SelectionStart;

            try
            {
                ViewConverter converter = ViewConverter.GetInstance();

                XmlDocument document = converter.LoadXmlDocument(richTextBox1.Text);
                XmlNode     rootNode = document.FirstChild;
                converter.ConvertDocument(rootNode, groupBox1);

                HashSet <string> names = new HashSet <string>();
                converter.GetAllTagsNames(rootNode, names);

                UpdateRichTextStyle(names.ToArray());
            }
            catch (XmlException xmlException)
            {
                UpdateRichTextStyle(null, xmlException.LineNumber);
            }
            catch (Exception exception)
            {
                //MessageBox.Show(exception.Message);
            }
            finally
            {
                richTextBox1.SelectionStart = pos;
            }
        }
Beispiel #4
0
        public void ConvertFromXmlTest()
        {
            ViewConverter converter = ViewConverter.GetInstance();

            XmlDocument document = converter.LoadXmlDocument(TEST1);
            XmlNodeList formNode = document.GetElementsByTagName("Form");

            Assert.AreEqual(1, formNode.Count);
            Assert.AreEqual("Hello, World", formNode[0].Attributes["Text"]?.InnerText);
            Assert.AreEqual("Form1", formNode[0].Attributes["Name"]?.InnerText);
            Assert.AreEqual(null, formNode[0].Attributes["DoubleBuffered"]?.InnerText);
        }
Beispiel #5
0
        public void GetAllTagsNamesTest()
        {
            ViewConverter converter = ViewConverter.GetInstance();

            XmlDocument      document = converter.LoadXmlDocument(TEST2);
            XmlNode          rootNode = document.FirstChild;
            HashSet <string> names    = new HashSet <string>();

            converter.GetAllTagsNames(rootNode, names);

            Assert.AreEqual(2, names.Count);
            Assert.IsTrue(names.Contains("Form"));
            Assert.IsTrue(names.Contains("GroupBox"));
        }
Beispiel #6
0
        public void ConvertFromXmlNestedElementsTest()
        {
            ViewConverter converter = ViewConverter.GetInstance();

            XmlDocument document = converter.LoadXmlDocument(TEST2);
            XmlNodeList formNode = document.GetElementsByTagName("Form");

            Assert.AreEqual(1, formNode.Count);
            Assert.AreEqual("Hello, World", formNode[0].Attributes["Text"]?.InnerText);
            Assert.AreEqual("Form1", formNode[0].Attributes["Name"]?.InnerText);
            Assert.AreEqual(null, formNode[0].Attributes["DoubleBuffered"]?.InnerText);
            Assert.AreEqual("Form", formNode[0].Name);

            XmlNode groupBoxNode = formNode[0].FirstChild;

            Assert.AreEqual("GroupBox", groupBoxNode.Name);
            Assert.AreEqual("groupBox1", groupBoxNode.Attributes["Text"]?.InnerText);
            Assert.AreEqual("groupBox1", groupBoxNode.Attributes["Name"]?.InnerText);
        }
Beispiel #7
0
        public void ConvertLocation()
        {
            ViewConverter converter = ViewConverter.GetInstance();
            XmlDocument   document  = converter.LoadXmlDocument(TEST4);
            XmlNode       rootNode  = document.FirstChild;

            Assert.AreEqual("Label", rootNode.Name);

            GroupBox box = new GroupBox();

            converter.ConvertDocument(rootNode, box);

            Assert.AreEqual(1, box.Controls.Count);

            Label label = box.Controls[0] as Label;

            Assert.AreEqual("Привет", label.Text);
            Assert.AreEqual("label1", label.Name);
            Assert.AreEqual(new Point(20, 20), label.Location);
            Assert.AreEqual(new Size(50, 50), label.Size);
        }