Esempio n. 1
0
        public void TestCreateFromOther()
        {
            var xd = new HXmlDeclaration("version", "encoding", "standalone");

            var anotherXd = new HXmlDeclaration(xd);

            Assert.Equal("version", anotherXd.Version);
            Assert.Equal("encoding", anotherXd.Encoding);
            Assert.Equal("standalone", anotherXd.Standalone);

            Assert.Throws <ArgumentNullException>(() => new HXmlDeclaration(null));
        }
Esempio n. 2
0
        public void TestCreate()
        {
            // Create default
            var xd = new HXmlDeclaration();

            Assert.Equal("1.0", xd.Version);
            Assert.Equal("utf-8", xd.Encoding);
            Assert.Equal(null, xd.Standalone);

            // Create by elements
            xd = new HXmlDeclaration("version", "encoding", "standalone");
            Assert.Equal("version", xd.Version);
            Assert.Equal("encoding", xd.Encoding);
            Assert.Equal("standalone", xd.Standalone);
        }
Esempio n. 3
0
        public void TestXmlDeclaration()
        {
            var hDoc = new HDocument();

            Assert.Null(hDoc.XmlDeclaration);

            hDoc.Add("  ");
            Assert.Null(hDoc.XmlDeclaration);

            hDoc.Add(new HText("  "));
            Assert.Null(hDoc.DocumentType);

            var xd = new HXmlDeclaration();

            hDoc.Add(xd);
            Assert.Same(xd, hDoc.XmlDeclaration);

            // Can't add a second xml declaration
            var ae = Assert.Throws <ArgumentException>(() => hDoc.Add(new HXmlDeclaration()));

            Assert.Equal("Xml declaration is alreay defined.", ae.Message);

            // Can't add a xml declaration after the document type
            hDoc = new HDocument(
                new HDocumentType()
                );
            ae = Assert.Throws <ArgumentException>(() => hDoc.Add(new HXmlDeclaration()));
            Assert.Equal("Can't add a xml declaration after the document type.", ae.Message);

            // Can't add a xml declaration after root
            hDoc = new HDocument(
                new HElement("root")
                );
            ae = Assert.Throws <ArgumentException>(() => hDoc.Add(new HXmlDeclaration()));
            Assert.Equal("Can't add a xml declaration after the root node.", ae.Message);
        }