Beispiel #1
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 #2
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 #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 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);
        }