Пример #1
0
        public void NewDocumentWithIdRefErrors()
        {
            v.Detach();
            v = new ValidationManager();

            XmlElement a1 = doc.CreateElement("anchor");

            a1.SetAttribute("id", "id1");

            XmlElement a2 = doc.CreateElement("anchor");

            a2.SetAttribute("id", "id1");

            XmlElement l1 = doc.CreateElement("xref");

            l1.SetAttribute("idref", "undefined");

            doc.DocumentElement.AppendChild(a1);
            doc.DocumentElement.AppendChild(a2);
            doc.DocumentElement.AppendChild(l1);

            Assert.AreEqual(0, v.InvalidNodes.AllErrors.Length, "Errors before attaching");

            v.Attach(doc, null);

            Assert.AreEqual(3, v.InvalidNodes.AllErrors.Length, "Expected errors after attaching");
        }
Пример #2
0
        public void DuplicateIdInEntityAttached()
        {
            v.Detach();

            XmlElement a1 = doc.CreateElement("anchor");

            a1.SetAttribute("id", "id1");

            XmlEntityReference xer = doc.CreateEntityReference("test");

            // no errors at this point (not added to doc yet)
            Assert.AreEqual(0, v.InvalidNodes.AllErrors.Length);

            doc.DocumentElement.AppendChild(a1);
            doc.DocumentElement.AppendChild(xer);

            v = new ValidationManager();
            v.Attach(doc, null);

            Assert.AreEqual(2, v.InvalidNodes.AllErrors.Length, "Expected duplicate ids");

            doc.DocumentElement.RemoveChild(a1);

            Assert.AreEqual(0, v.InvalidNodes.AllErrors.Length, "Errors remain after removing duplicate");
        }
Пример #3
0
        public void NewDocumentWithValidationErrors()
        {
            v.Detach();
            v = new ValidationManager();

            XmlElement a1 = doc.CreateElement("unknown");

            doc.DocumentElement.AppendChild(a1);

            Assert.AreEqual(0, v.InvalidNodes.AllErrors.Length, "Errors before attaching");

            v.Attach(doc, null);
            v.ValidateAll();
            Assert.AreEqual(1, v.InvalidNodes.AllErrors.Length, "Expected errors after attaching");
        }
Пример #4
0
        public void UnknownElementInEntityAttached()
        {
            v.Detach();

            XmlEntityReference xer = doc.CreateEntityReference("unk");

            // no errors at this point (not added to doc yet)
            Assert.AreEqual(0, v.InvalidNodes.AllErrors.Length);

            doc.DocumentElement.AppendChild(xer);

            v = new ValidationManager();
            v.Attach(doc, null);
            v.ValidateAll();

            Assert.AreEqual(2, v.InvalidNodes.AllErrors.Length, "Expected some errors");

            doc.DocumentElement.RemoveChild(xer);

            Assert.AreEqual(0, v.InvalidNodes.AllErrors.Length, "Errors remain after removing duplicate");
        }
Пример #5
0
        public void ValidationSetup()
        {
            Console.WriteLine("Init setup for tests");

            Assembly a    = typeof(ValidationTests).Assembly;
            string   name = a.FullName.Split(',')[0] + ".validationSample.xml";
            Stream   stm  = a.GetManifestResourceStream(name);

            if (stm == null)
            {
                throw new FileNotFoundException("Failed to load sample XML for validation from manifest");
            }
            XmlTextReader       xtr = new XmlTextReader(stm);
            XmlValidatingReader xvr = new XmlValidatingReader(xtr);

            doc = new XmlDocument();
            doc.Load(xvr);

            v = new ValidationManager();
            v.Attach(doc, null);

            stm.Close();
        }