public void TestCantAddDocumentTypeInElement() { var elm = new HElement("test"); var dt = new HDocumentType(); var ex = Assert.Throws <ArgumentException>(() => elm.Add(dt)); Assert.Equal("Can't add a document type in a element.", ex.Message); }
public void TestCreateFromOther() { var dt = new HDocumentType(StandardDoctype.Html401Transitional); var anotherDt = new HDocumentType(dt); Assert.Equal("HTML", anotherDt.RootElement); Assert.Equal("PUBLIC", anotherDt.KindDoctype); Assert.Equal("-//W3C//DTD HTML 4.01 Transitional//EN", anotherDt.FPI); Assert.Equal("http://www.w3.org/TR/html4/loose.dtd", anotherDt.Uri); Assert.Equal(StandardDoctype.Html401Transitional, anotherDt.StandardType); Assert.Throws <ArgumentNullException>(() => new HDocumentType(null)); }
public void TestAdd() { var hDoc = new HDocument(); // Can't add CData ArgumentException aex = Assert.Throws <ArgumentException>(() => hDoc.Add(new HCData("Content"))); Assert.Equal("Can't add CData in a document", aex.Message); // Can't add document aex = Assert.Throws <ArgumentException>(() => hDoc.Add(new HDocument())); Assert.Equal("Can't add a document in a document", aex.Message); // Can't add non whitespace text hDoc.Add(" "); aex = Assert.Throws <ArgumentException>(() => hDoc.Add("Content")); Assert.Equal("Can't add non whitespace text in a document.", aex.Message); Assert.Null(hDoc.DocumentType); Assert.Null(hDoc.Root); var dt = new HDocumentType(); hDoc.Add(dt); Assert.Same(dt, hDoc.DocumentType); Assert.Null(hDoc.Root); hDoc.Add(" "); Assert.Null(hDoc.Root); // Can't add a document type when it's already defined aex = Assert.Throws <ArgumentException>(() => hDoc.Add(new HDocumentType())); Assert.Equal("Document type is alreay defined.", aex.Message); var root = new HElement("root"); hDoc.Add(root); Assert.Same(root, hDoc.Root); // Can't add element when Root is already defined aex = Assert.Throws <ArgumentException>(() => hDoc.Add(new HElement("other-root"))); Assert.Equal("Root is already defined.", aex.Message); // Can't add a document type after the root hDoc = new HDocument(new HElement("root")); aex = Assert.Throws <ArgumentException>(() => hDoc.Add(new HDocumentType())); Assert.Equal("Can't add a document type after the root node.", aex.Message); }
public void TestCreate() { // Create default => HTML5 var dt = new HDocumentType(); Assert.Equal("html", dt.RootElement); Assert.Equal(null, dt.KindDoctype); Assert.Equal(null, dt.FPI); Assert.Equal(null, dt.Uri); Assert.Equal(StandardDoctype.Html5, dt.StandardType); // Create an HTML5 by elements dt = new HDocumentType("HTML", null, null, null); Assert.Equal("HTML", dt.RootElement); Assert.Equal(null, dt.KindDoctype); Assert.Equal(null, dt.FPI); Assert.Equal(null, dt.Uri); Assert.Equal(StandardDoctype.Html5, dt.StandardType); // Create a standard by elements dt = new HDocumentType("html", "-//W3C//DTD HTML 4.01//EN", "http://www.w3.org/TR/html4/strict.dtd", "public"); Assert.Equal("html", dt.RootElement); Assert.Equal("public", dt.KindDoctype); Assert.Equal("-//W3C//DTD HTML 4.01//EN", dt.FPI); Assert.Equal("http://www.w3.org/TR/html4/strict.dtd", dt.Uri); Assert.Equal(StandardDoctype.Html401Strict, dt.StandardType); // Create a non standard by elements dt = new HDocumentType("html", "-//W3C//DTD HTML 4.01//EN", "Unknown", null); Assert.Equal("html", dt.RootElement); Assert.Equal(null, dt.KindDoctype); Assert.Equal("-//W3C//DTD HTML 4.01//EN", dt.FPI); Assert.Equal("Unknown", dt.Uri); Assert.Equal(null, dt.StandardType); // Create from standard dt = new HDocumentType(StandardDoctype.Html401Transitional); Assert.Equal("HTML", dt.RootElement); Assert.Equal("PUBLIC", dt.KindDoctype); Assert.Equal("-//W3C//DTD HTML 4.01 Transitional//EN", dt.FPI); Assert.Equal("http://www.w3.org/TR/html4/loose.dtd", dt.Uri); Assert.Equal(StandardDoctype.Html401Transitional, dt.StandardType); // Root element is required Assert.Throws <ArgumentNullException>(() => new HDocumentType(null, null, null, null)); }
public void TestDocumentType() { var hDoc = new HDocument(); Assert.Null(hDoc.DocumentType); hDoc.Add(" "); Assert.Null(hDoc.DocumentType); hDoc.Add(new HText(" ")); Assert.Null(hDoc.DocumentType); var dt = new HDocumentType(); hDoc.Add(dt); Assert.Same(dt, hDoc.DocumentType); }