コード例 #1
0
        public void CheckValidationXmlModelPositiveTest()
        {
            if (File.Exists(path))
            {
                File.Delete(path);
            }

            Katalog           katalog           = new Katalog();
            TestXmlDataFiller testXmlDataFiller = new TestXmlDataFiller();

            testXmlDataFiller.Fill(katalog);

            XmlSerialization.Serialize(katalog, path, "Katalog.xslt");

            XmlSerialization.ValidateXml(".\\XmlModel\\KatalogSchema.xsd", path);
        }
コード例 #2
0
        public void CheckTransformationXmlModelTest()
        {
            if (File.Exists(path))
            {
                File.Delete(path);
            }

            Katalog           katalog           = new Katalog();
            TestXmlDataFiller testXmlDataFiller = new TestXmlDataFiller();

            testXmlDataFiller.Fill(katalog);

            XmlSerialization.Serialize(katalog, path, "Katalog.xslt");

            XmlSerialization.XsltTransform(".\\XmlModel\\Katalog.xslt", path, "htmlTest.html");

            Assert.IsTrue(File.Exists("htmlTest.html"));
        }
コード例 #3
0
        public void CheckDeserializedXmlModelTest()
        {
            if (File.Exists(path))
            {
                File.Delete(path);
            }

            Katalog           katalog           = new Katalog();
            TestXmlDataFiller testXmlDataFiller = new TestXmlDataFiller();

            testXmlDataFiller.Fill(katalog);

            XmlSerialization.Serialize(katalog, path, "Katalog.xslt");

            Katalog kolekcjaDeserialized = XmlSerialization.Deserialize <Katalog>(path);

            Assert.AreNotSame(katalog, kolekcjaDeserialized);
            Assert.AreNotSame(null, kolekcjaDeserialized.Samochody);
            Assert.AreNotSame(katalog.Samochody, kolekcjaDeserialized.Samochody);

            CollectionAssert.AreEqual(katalog.Samochody, kolekcjaDeserialized.Samochody);
        }
コード例 #4
0
        public void CheckValidationXmlModelNegativeTest()
        {
            if (File.Exists(path))
            {
                File.Delete(path);
            }

            Katalog           katalog           = new Katalog();
            TestXmlDataFiller testXmlDataFiller = new TestXmlDataFiller();

            testXmlDataFiller.Fill(katalog);

            XmlSerialization.Serialize(katalog, path, "Katalog.xslt");

            XmlDocument document = new XmlDocument();

            document.Load(path);
            XmlNode root = document.DocumentElement;

            document.GetElementsByTagName("Samochod")[0].AppendChild(document.CreateNode("element", "pages", ""));
            document.Save(path);

            Assert.ThrowsException <XmlSchemaValidationException>(() => XmlSerialization.ValidateXml(".\\XmlModel\\KatalogSchema.xsd", path));
        }