| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268 |
- //
- // System.Xml.XmlTextWriterTests
- //
- // Authors:
- // Kral Ferch <[email protected]>
- // Martin Willemoes Hansen <[email protected]>
- //
- // (C) 2002 Kral Ferch
- // (C) 2003 Martin Willemoes Hansen
- //
- using System;
- using System.IO;
- using System.Text;
- using System.Xml;
- using NUnit.Framework;
- namespace MonoTests.System.Xml
- {
- [TestFixture]
- public class XmlTextWriterTests : Assertion
- {
- StringWriter sw;
- XmlTextWriter xtw;
- [SetUp]
- public void GetReady ()
- {
- sw = new StringWriter ();
- xtw = new XmlTextWriter (sw);
- xtw.QuoteChar = '\'';
- }
- private string StringWriterText
- {
- get { return sw.GetStringBuilder ().ToString (); }
- }
- [Test]
- public void AttributeNamespacesNonNamespaceAttributeBefore ()
- {
- xtw.WriteStartElement ("foo");
- xtw.WriteAttributeString("bar", "baz");
- xtw.WriteAttributeString ("xmlns", "abc", null, "http://abc.def");
- AssertEquals ("<foo bar='baz' xmlns:abc='http://abc.def'", StringWriterText);
- }
- [Test]
- public void AttributeNamespacesNonNamespaceAttributeAfter ()
- {
- xtw.WriteStartElement ("foo");
- xtw.WriteAttributeString ("xmlns", "abc", null, "http://abc.def");
- xtw.WriteAttributeString("bar", "baz");
- AssertEquals ("<foo xmlns:abc='http://abc.def' bar='baz'", StringWriterText);
- }
- [Test]
- public void AttributeNamespacesThreeParamWithNullInNamespaceParam ()
- {
- xtw.WriteAttributeString ("xmlns", null, "http://abc.def");
- AssertEquals ("xmlns='http://abc.def'", StringWriterText);
- }
- [Test]
- public void AttributeNamespacesThreeParamWithTextInNamespaceParam ()
- {
- try
- {
- xtw.WriteAttributeString ("xmlns", "http://somenamespace.com", "http://abc.def");
- }
- catch (ArgumentException) {}
- }
- [Test]
- public void AttributeNamespacesWithNullInNamespaceParam ()
- {
- xtw.WriteAttributeString ("xmlns", "abc", null, "http://abc.def");
- AssertEquals ("xmlns:abc='http://abc.def'", StringWriterText);
- }
- [Test]
- public void AttributeNamespacesWithTextInNamespaceParam ()
- {
- try {
- xtw.WriteAttributeString ("xmlns", "abc", "http://somenamespace.com", "http://abc.def");
- } catch (ArgumentException) {}
- }
- [Test]
- public void AttributeNamespacesXmlnsXmlns ()
- {
- xtw.WriteStartElement ("foo");
- try {
- xtw.WriteAttributeString ("xmlns", "xmlns", null, "http://abc.def");
- // This should not be allowed, even though MS.NET doesn't treat as an error.
- // See http://www.w3.org/TR/REC-xml-names/ Namespace Constraint: Prefix Declared
- Fail ("any prefix which name starts from \"xml\" must not be allowed.");
- }
- catch (ArgumentException) {}
- xtw.WriteAttributeString ("", "xmlns", null, "http://abc.def");
- }
- [Test]
- public void AttributeWriteAttributeString ()
- {
- xtw.WriteStartElement ("foo");
- xtw.WriteAttributeString ("foo", "bar");
- AssertEquals ("<foo foo='bar'", StringWriterText);
- xtw.WriteAttributeString ("bar", "");
- AssertEquals ("<foo foo='bar' bar=''", StringWriterText);
- xtw.WriteAttributeString ("baz", null);
- AssertEquals ("<foo foo='bar' bar='' baz=''", StringWriterText);
- xtw.WriteAttributeString ("hoge", "a\nb");
- AssertEquals ("<foo foo='bar' bar='' baz='' hoge='a
b'", StringWriterText);
- xtw.WriteAttributeString ("fuga", " a\t\r\nb\t");
- AssertEquals ("<foo foo='bar' bar='' baz='' hoge='a
b' fuga=' a\t
b\t'", StringWriterText);
- try {
- // Why does this pass Microsoft?
- // Anyway, Mono should not allow such code.
- xtw.WriteAttributeString ("", "quux");
- // AssertEquals ("<foo foo='bar' bar='' baz='' ='quux'", StringWriterText);
- Fail ("empty name not allowed.");
- } catch (Exception) {
- }
- try {
- // Why does this pass Microsoft?
- // Anyway, Mono should not allow such code.
- xtw.WriteAttributeString (null, "quuux");
- // AssertEquals ("<foo foo='bar' bar='' baz='' ='quux' ='quuux'", StringWriterText);
- Fail ("null name not allowed.");
- } catch (Exception) {
- }
- }
- [Test]
- [ExpectedException (typeof (InvalidOperationException))]
- public void AttributeWriteAttributeStringNotInsideOpenStartElement ()
- {
- xtw.WriteStartElement ("foo");
- xtw.WriteString ("bar");
-
- xtw.WriteAttributeString ("baz", "quux");
- }
- [Test]
- public void AttributeWriteAttributeStringWithoutParentElement ()
- {
- xtw.WriteAttributeString ("foo", "bar");
- AssertEquals ("foo='bar'", StringWriterText);
- xtw.WriteAttributeString ("baz", "quux");
- AssertEquals ("foo='bar' baz='quux'", StringWriterText);
- }
- [Test]
- public void CDataValid ()
- {
- xtw.WriteCData ("foo");
- AssertEquals ("WriteCData had incorrect output.", "<![CDATA[foo]]>", StringWriterText);
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void CDataInvalid ()
- {
- xtw.WriteCData("foo]]>bar");
- }
-
- [Test]
- public void CloseOpenElements ()
- {
- xtw.WriteStartElement("foo");
- xtw.WriteStartElement("bar");
- xtw.WriteStartElement("baz");
- xtw.Close();
- AssertEquals ("Close didn't write out end elements properly.", "<foo><bar><baz /></bar></foo>", StringWriterText);
- }
- [Test]
- public void CloseWriteAfter ()
- {
- xtw.WriteElementString ("foo", "bar");
- xtw.Close ();
- // WriteEndElement and WriteStartDocument aren't tested here because
- // they will always throw different exceptions besides 'The Writer is closed.'
- // and there are already tests for those exceptions.
- try {
- xtw.WriteCData ("foo");
- Fail ("WriteCData after Close Should have thrown an InvalidOperationException.");
- }
- catch (InvalidOperationException) {
- // Don't rely on English message assertion.
- // It is enough to check an exception occurs.
- // AssertEquals ("Exception message is incorrect.", "The Writer is closed.", e.Message);
- }
- try {
- xtw.WriteComment ("foo");
- Fail ("WriteComment after Close Should have thrown an InvalidOperationException.");
- }
- catch (InvalidOperationException) {
- // AssertEquals ("Exception message is incorrect.", "The Writer is closed.", e.Message);
- }
- try {
- xtw.WriteProcessingInstruction ("foo", "bar");
- Fail ("WriteProcessingInstruction after Close Should have thrown an InvalidOperationException.");
- }
- catch (InvalidOperationException) {
- // AssertEquals ("Exception message is incorrect.", "The Writer is closed.", e.Message);
- }
- try {
- xtw.WriteStartElement ("foo", "bar", "baz");
- Fail ("WriteStartElement after Close Should have thrown an InvalidOperationException.");
- }
- catch (InvalidOperationException) {
- // AssertEquals ("Exception message is incorrect.", "The Writer is closed.", e.Message);
- }
- try
- {
- xtw.WriteAttributeString ("foo", "bar");
- Fail ("WriteAttributeString after Close Should have thrown an InvalidOperationException.");
- }
- catch (InvalidOperationException)
- {
- // AssertEquals ("Exception message is incorrect.", "The Writer is closed.", e.Message);
- }
- try {
- xtw.WriteString ("foo");
- Fail ("WriteString after Close Should have thrown an InvalidOperationException.");
- }
- catch (InvalidOperationException) {
- // AssertEquals ("Exception message is incorrect.", "The Writer is closed.", e.Message);
- }
- }
- [Test]
- public void CommentValid ()
- {
- xtw.WriteComment ("foo");
- AssertEquals ("WriteComment had incorrect output.", "<!--foo-->", StringWriterText);
- }
- [Test]
- public void CommentInvalid ()
- {
- try {
- xtw.WriteComment("foo-");
- Fail("Should have thrown an ArgumentException.");
- }
- catch (ArgumentException) { }
- try {
- xtw.WriteComment("foo-->bar");
- Fail("Should have thrown an ArgumentException.");
- }
- catch (ArgumentException) { }
- }
- [Test]
- public void ConstructorsAndBaseStream ()
- {
- Assert ("BaseStream property returned wrong value.", Object.ReferenceEquals (null, this.xtw.BaseStream));
- MemoryStream ms;
- StreamReader sr;
- XmlTextWriter xtw;
- ms = new MemoryStream ();
- xtw = new XmlTextWriter (ms, new UnicodeEncoding ());
- xtw.WriteStartDocument ();
- xtw.Flush ();
- ms.Seek (0, SeekOrigin.Begin);
- sr = new StreamReader (ms, Encoding.Unicode);
- string expectedXmlDeclaration = "<?xml version=\"1.0\" encoding=\"utf-16\"?>";
- string actualXmlDeclaration = sr.ReadToEnd();
- AssertEquals (expectedXmlDeclaration, actualXmlDeclaration);
- Assert ("BaseStream property returned wrong value.", Object.ReferenceEquals (ms, xtw.BaseStream));
- ms = new MemoryStream ();
- xtw = new XmlTextWriter (ms, new UnicodeEncoding ());
- xtw.WriteStartDocument (true);
- xtw.Flush ();
- ms.Seek (0, SeekOrigin.Begin);
- sr = new StreamReader (ms, Encoding.Unicode);
- AssertEquals ("<?xml version=\"1.0\" encoding=\"utf-16\" standalone=\"yes\"?>", sr.ReadToEnd ());
- ms = new MemoryStream ();
- xtw = new XmlTextWriter (ms, new UTF8Encoding ());
- xtw.WriteStartDocument ();
- xtw.Flush ();
- ms.Seek (0, SeekOrigin.Begin);
- sr = new StreamReader (ms, Encoding.UTF8);
- AssertEquals ("<?xml version=\"1.0\" encoding=\"utf-8\"?>", sr.ReadToEnd ());
- ms = new MemoryStream ();
- xtw = new XmlTextWriter (ms, null);
- xtw.WriteStartDocument ();
- xtw.Flush ();
- ms.Seek (0, SeekOrigin.Begin);
- sr = new StreamReader (ms, Encoding.UTF8);
- AssertEquals ("<?xml version=\"1.0\"?>", sr.ReadToEnd ());
- ms = new MemoryStream ();
- xtw = new XmlTextWriter (ms, null);
- xtw.WriteStartDocument (true);
- xtw.Flush ();
- ms.Seek (0, SeekOrigin.Begin);
- sr = new StreamReader (ms, Encoding.UTF8);
- AssertEquals ("<?xml version=\"1.0\" standalone=\"yes\"?>", sr.ReadToEnd ());
- Assert ("BaseStream property returned wrong value.", Object.ReferenceEquals (ms, xtw.BaseStream));
- }
- [Test]
- public void DocumentStart ()
- {
- xtw.WriteStartDocument ();
- AssertEquals ("XmlDeclaration is incorrect.", "<?xml version='1.0' encoding='utf-16'?>", StringWriterText);
- try
- {
- xtw.WriteStartDocument ();
- Fail("Should have thrown an InvalidOperationException.");
- }
- catch (InvalidOperationException) {
- // Don't rely on English message assertion.
- // It is enough to check an exception occurs.
- // AssertEquals ("Exception message is incorrect.",
- // "WriteStartDocument should be the first call.", e.Message);
- }
- xtw = new XmlTextWriter (sw = new StringWriter ());
- xtw.QuoteChar = '\'';
- xtw.WriteStartDocument (true);
- AssertEquals ("<?xml version='1.0' encoding='utf-16' standalone='yes'?>", StringWriterText);
- xtw = new XmlTextWriter (sw = new StringWriter ());
- xtw.QuoteChar = '\'';
- xtw.WriteStartDocument (false);
- AssertEquals ("<?xml version='1.0' encoding='utf-16' standalone='no'?>", StringWriterText);
- }
- [Test]
- public void ElementAndAttributeSameXmlns ()
- {
- xtw.WriteStartElement ("ped", "foo", "urn:foo");
- xtw.WriteStartAttribute ("ped", "foo", "urn:foo");
- xtw.WriteEndElement ();
- AssertEquals ("<ped:foo ped:foo='' xmlns:ped='urn:foo' />", StringWriterText);
- }
- [Test]
- public void ElementXmlnsNeedEscape ()
- {
- xtw.WriteStartElement ("test", "foo", "'");
- xtw.WriteEndElement ();
- // MS.NET fails this case.
- AssertEquals ("<test:foo xmlns:test=''' />", StringWriterText);
- }
- [Test]
- public void ElementEmpty ()
- {
- xtw.WriteStartElement ("foo");
- xtw.WriteEndElement ();
- AssertEquals ("Incorrect output.", "<foo />", StringWriterText);
- }
- [Test]
- public void ElementWriteElementString ()
- {
- xtw.WriteElementString ("foo", "bar");
- AssertEquals ("WriteElementString has incorrect output.", "<foo>bar</foo>", StringWriterText);
- xtw.WriteElementString ("baz", "");
- AssertEquals ("<foo>bar</foo><baz />", StringWriterText);
- xtw.WriteElementString ("quux", null);
- AssertEquals ("<foo>bar</foo><baz /><quux />", StringWriterText);
- xtw.WriteElementString ("", "quuux");
- AssertEquals ("<foo>bar</foo><baz /><quux /><>quuux</>", StringWriterText);
- xtw.WriteElementString (null, "quuuux");
- AssertEquals ("<foo>bar</foo><baz /><quux /><>quuux</><>quuuux</>", StringWriterText);
- }
- [Test]
- public void FormattingTest ()
- {
- xtw.Formatting = Formatting.Indented;
- xtw.WriteStartDocument ();
- xtw.WriteStartElement ("foo");
- xtw.WriteElementString ("bar", "");
- xtw.Close ();
- AssertEquals (String.Format ("<?xml version='1.0' encoding='utf-16'?>{0}<foo>{0} <bar />{0}</foo>", Environment.NewLine), StringWriterText);
- }
- [Test]
- public void FormattingInvalidXmlForFun ()
- {
- xtw.Formatting = Formatting.Indented;
- xtw.IndentChar = 'x';
- xtw.WriteStartDocument ();
- xtw.WriteStartElement ("foo");
- xtw.WriteStartElement ("bar");
- xtw.WriteElementString ("baz", "");
- xtw.Close ();
- AssertEquals (String.Format ("<?xml version='1.0' encoding='utf-16'?>{0}<foo>{0}xx<bar>{0}xxxx<baz />{0}xx</bar>{0}</foo>", Environment.NewLine), StringWriterText);
- }
- [Test]
- public void FormattingFromRemarks ()
- {
- // Remarks section of on-line help for XmlTextWriter.Formatting suggests this test.
- xtw.Formatting = Formatting.Indented;
- xtw.WriteStartElement ("ol");
- xtw.WriteStartElement ("li");
- xtw.WriteString ("The big "); // This means "li" now has a mixed content model.
- xtw.WriteElementString ("b", "E");
- xtw.WriteElementString ("i", "lephant");
- xtw.WriteString (" walks slowly.");
- xtw.WriteEndElement ();
- xtw.WriteEndElement ();
- AssertEquals (String.Format ("<ol>{0} <li>The big <b>E</b><i>lephant</i> walks slowly.</li>{0}</ol>", Environment.NewLine), StringWriterText);
- }
- [Test]
- public void LookupPrefix ()
- {
- xtw.WriteStartElement ("root");
- xtw.WriteStartElement ("one");
- xtw.WriteAttributeString ("xmlns", "foo", null, "http://abc.def");
- xtw.WriteAttributeString ("xmlns", "bar", null, "http://ghi.jkl");
- AssertEquals ("foo", xtw.LookupPrefix ("http://abc.def"));
- AssertEquals ("bar", xtw.LookupPrefix ("http://ghi.jkl"));
- xtw.WriteEndElement ();
- xtw.WriteStartElement ("two");
- xtw.WriteAttributeString ("xmlns", "baz", null, "http://mno.pqr");
- xtw.WriteString("quux");
- AssertEquals ("baz", xtw.LookupPrefix ("http://mno.pqr"));
- AssertNull (xtw.LookupPrefix ("http://abc.def"));
- AssertNull (xtw.LookupPrefix ("http://ghi.jkl"));
- AssertNull (xtw.LookupPrefix ("http://bogus"));
- }
- [Test]
- public void NamespacesAttributesPassingInNamespaces ()
- {
- xtw.Namespaces = false;
- xtw.WriteStartElement ("foo");
- // These shouldn't throw any exceptions since they don't pass in
- // a namespace.
- xtw.WriteAttributeString ("bar", "baz");
- xtw.WriteAttributeString ("", "a", "", "b");
- xtw.WriteAttributeString (null, "c", "", "d");
- xtw.WriteAttributeString ("", "e", null, "f");
- xtw.WriteAttributeString (null, "g", null, "h");
- AssertEquals ("<foo bar='baz' a='b' c='d' e='f' g='h'", StringWriterText);
- // These should throw ArgumentException because they pass in a
- // namespace when Namespaces = false.
- }
- [Test]
- public void NamespacesElementsPassingInNamespaces ()
- {
- xtw.Namespaces = false;
- // These shouldn't throw any exceptions since they don't pass in
- // a namespace.
- xtw.WriteElementString ("foo", "bar");
- xtw.WriteStartElement ("baz");
- xtw.WriteStartElement ("quux", "");
- xtw.WriteStartElement ("quuux", null);
- xtw.WriteStartElement (null, "a", null);
- xtw.WriteStartElement (null, "b", "");
- xtw.WriteStartElement ("", "c", null);
- xtw.WriteStartElement ("", "d", "");
- AssertEquals ("<foo>bar</foo><baz><quux><quuux><a><b><c><d", StringWriterText);
- // These should throw ArgumentException because they pass in a
- // namespace when Namespaces = false.
- try {
- xtw.WriteElementString ("qux", "http://netsack.com/", String.Empty);
- Fail ("Expected an ArgumentException.");
- } catch (ArgumentException) {}
- try {
- xtw.WriteStartElement ("foo", "http://netsack.com/");
- Fail ("Expected an ArgumentException.");
- } catch (ArgumentException) {}
- try {
- xtw.WriteStartElement ("foo", "bar", "http://netsack.com/");
- Fail ("Expected an ArgumentException.");
- } catch (ArgumentException) {}
- try {
- xtw.WriteStartElement ("foo", "bar", null);
- Fail ("Expected an ArgumentException.");
- } catch (ArgumentException) {}
- try {
- xtw.WriteStartElement ("foo", "bar", "");
- Fail ("Expected an ArgumentException.");
- } catch (ArgumentException) {}
- try {
- xtw.WriteStartElement ("foo", "", "");
- Fail ("Expected an ArgumentException.");
- } catch (ArgumentException) {}
- }
- [Test]
- public void NamespacesNoNamespaceClearsDefaultNamespace ()
- {
- xtw.WriteStartElement(String.Empty, "foo", "http://netsack.com/");
- xtw.WriteStartElement(String.Empty, "bar", String.Empty);
- xtw.WriteElementString("baz", String.Empty, String.Empty);
- xtw.WriteEndElement();
- xtw.WriteEndElement();
- AssertEquals ("XmlTextWriter is incorrectly outputting namespaces.",
- "<foo xmlns='http://netsack.com/'><bar xmlns=''><baz /></bar></foo>", StringWriterText);
- }
- [Test]
- public void NamespacesPrefix ()
- {
- xtw.WriteStartElement ("foo", "bar", "http://netsack.com/");
- xtw.WriteStartElement ("foo", "baz", "http://netsack.com/");
- xtw.WriteElementString ("qux", "http://netsack.com/", String.Empty);
- xtw.WriteEndElement ();
- xtw.WriteEndElement ();
- AssertEquals ("XmlTextWriter is incorrectly outputting prefixes.",
- "<foo:bar xmlns:foo='http://netsack.com/'><foo:baz><foo:qux /></foo:baz></foo:bar>", StringWriterText);
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void NamespacesPrefixWithEmptyAndNullNamespaceEmpty ()
- {
- xtw.WriteStartElement ("foo", "bar", "");
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void NamespacesPrefixWithEmptyAndNullNamespaceNull ()
- {
- xtw.WriteStartElement ("foo", "bar", null);
- }
- [Test]
- public void NamespacesSettingWhenWriteStateNotStart ()
- {
- xtw.WriteStartElement ("foo");
- try
- {
- xtw.Namespaces = false;
- Fail ("Expected an InvalidOperationException.");
- }
- catch (InvalidOperationException) {}
- AssertEquals (true, xtw.Namespaces);
- }
- [Test]
- public void ProcessingInstructionValid ()
- {
- xtw.WriteProcessingInstruction("foo", "bar");
- AssertEquals ("WriteProcessingInstruction had incorrect output.", "<?foo bar?>", StringWriterText);
- }
- [Test]
- public void ProcessingInstructionInvalid ()
- {
- try
- {
- xtw.WriteProcessingInstruction("fo?>o", "bar");
- Fail("Should have thrown an ArgumentException.");
- }
- catch (ArgumentException) { }
- try
- {
- xtw.WriteProcessingInstruction("foo", "ba?>r");
- Fail("Should have thrown an ArgumentException.");
- }
- catch (ArgumentException) { }
- try
- {
- xtw.WriteProcessingInstruction("", "bar");
- Fail("Should have thrown an ArgumentException.");
- }
- catch (ArgumentException) { }
- try
- {
- xtw.WriteProcessingInstruction(null, "bar");
- Fail("Should have thrown an ArgumentException.");
- }
- catch (ArgumentException) { }
- }
- [Test]
- public void QuoteCharDoubleQuote ()
- {
- xtw.QuoteChar = '"';
- // version, encoding, standalone
- xtw.WriteStartDocument (true);
-
- // namespace declaration
- xtw.WriteElementString ("foo", "http://netsack.com", "bar");
- AssertEquals ("<?xml version=\"1.0\" encoding=\"utf-16\" standalone=\"yes\"?><foo xmlns=\"http://netsack.com\">bar</foo>", StringWriterText);
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void QuoteCharInvalid ()
- {
- xtw.QuoteChar = 'x';
- }
- [Test]
- public void WriteBase64 ()
- {
- UTF8Encoding encoding = new UTF8Encoding();
- byte[] fooBar = encoding.GetBytes("foobar");
- xtw.WriteBase64 (fooBar, 0, 6);
- AssertEquals("Zm9vYmFy", StringWriterText);
- try {
- xtw.WriteBase64 (fooBar, 3, 6);
- Fail ("Expected an Argument Exception to be thrown.");
- } catch (ArgumentException) {}
- try {
- xtw.WriteBase64 (fooBar, -1, 6);
- Fail ("Expected an Argument Exception to be thrown.");
- } catch (ArgumentOutOfRangeException) {}
- try {
- xtw.WriteBase64 (fooBar, 3, -1);
- Fail ("Expected an Argument Exception to be thrown.");
- } catch (ArgumentOutOfRangeException) {}
- try {
- xtw.WriteBase64 (null, 0, 6);
- Fail ("Expected an Argument Exception to be thrown.");
- } catch (ArgumentNullException) {}
- }
- [Test]
- public void WriteBinHex ()
- {
- byte [] bytes = new byte [] {4,14,34, 54,94,114, 134,194,255, 0,5};
- xtw.WriteBinHex (bytes, 0, 11);
- AssertEquals ("040E22365E7286C2FF0005", StringWriterText);
- }
- [Test]
- public void WriteCharEntity ()
- {
- xtw.WriteCharEntity ('a');
- AssertEquals ("a", StringWriterText);
- xtw.WriteCharEntity ('A');
- AssertEquals ("aA", StringWriterText);
- xtw.WriteCharEntity ('1');
- AssertEquals ("aA1", StringWriterText);
- xtw.WriteCharEntity ('K');
- AssertEquals ("aA1K", StringWriterText);
- try {
- xtw.WriteCharEntity ((char)0xd800);
- } catch (ArgumentException) {}
- }
- [Test]
- [ExpectedException (typeof (InvalidOperationException))]
- public void WriteEndAttribute ()
- {
- xtw.WriteEndAttribute ();
- }
- [Test]
- public void WriteEndDocument ()
- {
- try {
- xtw.WriteEndDocument ();
- Fail ("Expected an ArgumentException.");
- } catch (ArgumentException) {}
- xtw.WriteStartDocument ();
- try
- {
- xtw.WriteEndDocument ();
- Fail ("Expected an ArgumentException.");
- }
- catch (ArgumentException) {}
- xtw.WriteStartElement ("foo");
- xtw.WriteStartAttribute ("bar", null);
- AssertEquals ("<?xml version='1.0' encoding='utf-16'?><foo bar='", StringWriterText);
- xtw.WriteEndDocument ();
- AssertEquals ("<?xml version='1.0' encoding='utf-16'?><foo bar='' />", StringWriterText);
- AssertEquals (WriteState.Start, xtw.WriteState);
- }
- [Test]
- public void WriteEndElement ()
- {
- try {
- xtw.WriteEndElement ();
- Fail ("Should have thrown an InvalidOperationException.");
- } catch (InvalidOperationException) {
- // Don't rely on English message assertion.
- // It is enough to check an exception occurs.
- // AssertEquals ("Exception message is incorrect.", "There was no XML start tag open.", e.Message);
- }
- xtw.WriteStartElement ("foo");
- xtw.WriteEndElement ();
- AssertEquals ("<foo />", StringWriterText);
- xtw.WriteStartElement ("bar");
- xtw.WriteStartAttribute ("baz", null);
- xtw.WriteEndElement ();
- AssertEquals ("<foo /><bar baz='' />", StringWriterText);
- }
- [Test]
- public void FullEndElement ()
- {
- xtw.WriteStartElement ("foo");
- xtw.WriteFullEndElement ();
- AssertEquals ("<foo></foo>", StringWriterText);
- xtw.WriteStartElement ("bar");
- xtw.WriteAttributeString ("foo", "bar");
- xtw.WriteFullEndElement ();
- AssertEquals ("<foo></foo><bar foo='bar'></bar>", StringWriterText);
- xtw.WriteStartElement ("baz");
- xtw.WriteStartAttribute ("bar", null);
- xtw.WriteFullEndElement ();
- AssertEquals ("<foo></foo><bar foo='bar'></bar><baz bar=''></baz>", StringWriterText);
- }
- [Test]
- public void WriteQualifiedName ()
- {
- xtw.WriteStartElement (null, "test", null);
- xtw.WriteAttributeString ("xmlns", "me", null, "http://localhost/");
- xtw.WriteQualifiedName ("bob", "http://localhost/");
- xtw.WriteEndElement ();
- AssertEquals ("<test xmlns:me='http://localhost/'>me:bob</test>", StringWriterText);
- }
- [Test]
- public void WriteRaw ()
- {
- xtw.WriteRaw("&<>\"'");
- AssertEquals ("&<>\"'", StringWriterText);
- xtw.WriteRaw(null);
- AssertEquals ("&<>\"'", StringWriterText);
- xtw.WriteRaw("");
- AssertEquals ("&<>\"'", StringWriterText);
- }
- [Test]
- public void WriteRawInvalidInAttribute ()
- {
- xtw.WriteStartElement ("foo");
- xtw.WriteStartAttribute ("bar", null);
- xtw.WriteRaw ("&<>\"'");
- xtw.WriteEndAttribute ();
- xtw.WriteEndElement ();
- AssertEquals ("<foo bar='&<>\"'' />", StringWriterText);
- }
- [Test]
- public void WriteStateTest ()
- {
- AssertEquals (WriteState.Start, xtw.WriteState);
- xtw.WriteStartDocument ();
- AssertEquals (WriteState.Prolog, xtw.WriteState);
- xtw.WriteStartElement ("root");
- AssertEquals (WriteState.Element, xtw.WriteState);
- xtw.WriteElementString ("foo", "bar");
- AssertEquals (WriteState.Content, xtw.WriteState);
- xtw.Close ();
- AssertEquals (WriteState.Closed, xtw.WriteState);
- }
- [Test]
- public void WriteString ()
- {
- xtw.WriteStartDocument ();
- try {
- xtw.WriteString("foo");
- } catch (InvalidOperationException) {}
- // Testing attribute values
- xtw.WriteStartElement ("foo");
- xtw.WriteAttributeString ("bar", "&<>");
- AssertEquals ("<?xml version='1.0' encoding='utf-16'?><foo bar='&<>'", StringWriterText);
- }
- [Test]
- public void WriteAttributeStringSingleQuoteChar()
- {
- // When QuoteChar is single quote then replaces single quotes within attributes
- // but not double quotes.
- xtw.WriteStartElement ("foo");
- xtw.WriteAttributeString ("bar", "\"baz\"");
- xtw.WriteAttributeString ("quux", "'baz'");
- AssertEquals ("<foo bar='\"baz\"' quux=''baz''", StringWriterText);
- }
- [Test]
- public void WriteAttributeStringDoubleQuoteChar()
- {
- // When QuoteChar is double quote then replaces double quotes within attributes
- // but not single quotes.
- xtw.QuoteChar = '"';
- xtw.WriteStartElement ("foo");
- xtw.WriteAttributeString ("bar", "\"baz\"");
- xtw.WriteAttributeString ("quux", "'baz'");
- AssertEquals ("<foo bar=\""baz"\" quux=\"'baz'\"", StringWriterText);
- }
- [Test]
- public void WriteStringWithEntities()
- {
- // Testing element values
- xtw.QuoteChar = '\'';
- xtw.WriteElementString ("foo", "&<>\"'");
- AssertEquals ("<foo>&<>\"'</foo>", StringWriterText);
- }
- [Test]
- public void XmlLang ()
- {
- AssertNull (xtw.XmlLang);
-
- xtw.WriteStartElement ("foo");
- xtw.WriteAttributeString ("xml", "lang", null, "langfoo");
- AssertEquals ("langfoo", xtw.XmlLang);
- AssertEquals ("<foo xml:lang='langfoo'", StringWriterText);
- xtw.WriteAttributeString ("boo", "yah");
- AssertEquals ("langfoo", xtw.XmlLang);
- AssertEquals ("<foo xml:lang='langfoo' boo='yah'", StringWriterText);
-
- xtw.WriteElementString("bar", "baz");
- AssertEquals ("langfoo", xtw.XmlLang);
- AssertEquals ("<foo xml:lang='langfoo' boo='yah'><bar>baz</bar>", StringWriterText);
-
- xtw.WriteString("baz");
- AssertEquals ("langfoo", xtw.XmlLang);
- AssertEquals ("<foo xml:lang='langfoo' boo='yah'><bar>baz</bar>baz", StringWriterText);
-
- xtw.WriteStartElement ("quux");
- xtw.WriteStartAttribute ("xml", "lang", null);
- AssertEquals ("langfoo", xtw.XmlLang);
- AssertEquals ("<foo xml:lang='langfoo' boo='yah'><bar>baz</bar>baz<quux xml:lang='", StringWriterText);
-
- xtw.WriteString("langbar");
- AssertEquals ("langfoo", xtw.XmlLang);
- AssertEquals ("<foo xml:lang='langfoo' boo='yah'><bar>baz</bar>baz<quux xml:lang='", StringWriterText);
-
- xtw.WriteEndAttribute ();
- AssertEquals ("langbar", xtw.XmlLang);
- AssertEquals ("<foo xml:lang='langfoo' boo='yah'><bar>baz</bar>baz<quux xml:lang='langbar'", StringWriterText);
- // check if xml:lang repeats output even if same as current scope.
- xtw.WriteStartElement ("joe");
- xtw.WriteAttributeString ("xml", "lang", null, "langbar");
- AssertEquals ("<foo xml:lang='langfoo' boo='yah'><bar>baz</bar>baz<quux xml:lang='langbar'><joe xml:lang='langbar'", StringWriterText);
-
- xtw.WriteElementString ("quuux", "squonk");
- AssertEquals ("langbar", xtw.XmlLang);
- AssertEquals ("<foo xml:lang='langfoo' boo='yah'><bar>baz</bar>baz<quux xml:lang='langbar'><joe xml:lang='langbar'><quuux>squonk</quuux>", StringWriterText);
- xtw.WriteEndElement ();
- xtw.WriteEndElement ();
- AssertEquals ("langfoo", xtw.XmlLang);
- AssertEquals ("<foo xml:lang='langfoo' boo='yah'><bar>baz</bar>baz<quux xml:lang='langbar'><joe xml:lang='langbar'><quuux>squonk</quuux></joe></quux>", StringWriterText);
-
- xtw.WriteEndElement ();
- AssertNull (xtw.XmlLang);
- AssertEquals ("<foo xml:lang='langfoo' boo='yah'><bar>baz</bar>baz<quux xml:lang='langbar'><joe xml:lang='langbar'><quuux>squonk</quuux></joe></quux></foo>", StringWriterText);
-
- xtw.Close ();
- AssertNull (xtw.XmlLang);
- }
- // TODO: test operational aspects
- [Test]
- public void XmlSpaceTest ()
- {
- xtw.WriteStartElement ("foo");
- AssertEquals (XmlSpace.None, xtw.XmlSpace);
- xtw.WriteStartElement ("bar");
- xtw.WriteAttributeString ("xml", "space", null, "preserve");
- AssertEquals (XmlSpace.Preserve, xtw.XmlSpace);
- AssertEquals ("<foo><bar xml:space='preserve'", StringWriterText);
- xtw.WriteStartElement ("baz");
- xtw.WriteAttributeString ("xml", "space", null, "preserve");
- AssertEquals (XmlSpace.Preserve, xtw.XmlSpace);
- AssertEquals ("<foo><bar xml:space='preserve'><baz xml:space='preserve'", StringWriterText);
- xtw.WriteStartElement ("quux");
- xtw.WriteStartAttribute ("xml", "space", null);
- AssertEquals (XmlSpace.Preserve, xtw.XmlSpace);
- AssertEquals ("<foo><bar xml:space='preserve'><baz xml:space='preserve'><quux xml:space='", StringWriterText);
- xtw.WriteString ("default");
- AssertEquals (XmlSpace.Preserve, xtw.XmlSpace);
- AssertEquals ("<foo><bar xml:space='preserve'><baz xml:space='preserve'><quux xml:space='", StringWriterText);
-
- xtw.WriteEndAttribute ();
- AssertEquals (XmlSpace.Default, xtw.XmlSpace);
- AssertEquals ("<foo><bar xml:space='preserve'><baz xml:space='preserve'><quux xml:space='default'", StringWriterText);
- xtw.WriteEndElement ();
- AssertEquals (XmlSpace.Preserve, xtw.XmlSpace);
- xtw.WriteEndElement ();
- AssertEquals (XmlSpace.Preserve, xtw.XmlSpace);
- xtw.WriteEndElement ();
- AssertEquals (XmlSpace.None, xtw.XmlSpace);
- xtw.WriteStartElement ("quux");
- try {
- xtw.WriteAttributeString ("xml", "space", null, "bubba");
- } catch (ArgumentException) {}
- try {
- xtw.WriteAttributeString ("xml", "space", null, "PRESERVE");
- } catch (ArgumentException) {}
- try {
- xtw.WriteAttributeString ("xml", "space", null, "Preserve");
- } catch (ArgumentException) {}
- try {
- xtw.WriteAttributeString ("xml", "space", null, "Default");
- } catch (ArgumentException) {}
- try {
- xtw.WriteWhitespace ("x");
- } catch (ArgumentException) { }
- }
- [Test]
- public void XmlSpaceRaw ()
- {
- xtw.WriteStartElement ("foo");
- xtw.WriteStartAttribute ("xml", "space", null);
- AssertEquals (XmlSpace.None, xtw.XmlSpace);
- AssertEquals ("<foo xml:space='", StringWriterText);
- xtw.WriteString ("default");
- AssertEquals (XmlSpace.None, xtw.XmlSpace);
- AssertEquals ("<foo xml:space='", StringWriterText);
- xtw.WriteEndAttribute ();
- AssertEquals (XmlSpace.Default, xtw.XmlSpace);
- AssertEquals ("<foo xml:space='default'", StringWriterText);
- }
- [Test]
- public void WriteAttributes ()
- {
- XmlDocument doc = new XmlDocument();
- StringWriter sw = new StringWriter();
- XmlWriter wr = new XmlTextWriter(sw);
- StringBuilder sb = sw.GetStringBuilder();
- XmlParserContext ctx = new XmlParserContext(doc.NameTable, new XmlNamespaceManager(doc.NameTable), "", XmlSpace.Default);
- XmlTextReader xtr = new XmlTextReader("<?xml version='1.0' encoding='utf-8' standalone='no'?><root a1='A' b2='B' c3='C'><foo><bar /></foo></root>", XmlNodeType.Document, ctx);
- xtr.Read(); // read XMLDecl
- wr.WriteAttributes(xtr, false);
- // This method don't always have to take this double-quoted style...
- AssertEquals("#WriteAttributes.XmlDecl.1", "version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"", sw.ToString().Trim());
- sb.Remove(0, sb.Length); // init
- ctx = new XmlParserContext(doc.NameTable, new XmlNamespaceManager(doc.NameTable), "", XmlSpace.Default);
- xtr = new XmlTextReader("<?xml version='1.0' standalone='no'?><root a1='A' b2='B' c3='C'><foo><bar /></foo></root>", XmlNodeType.Document, ctx);
- xtr.Read(); // read XMLDecl
- AssertEquals (XmlNodeType.XmlDeclaration, xtr.NodeType);
- sw = new StringWriter ();
- wr = new XmlTextWriter (sw);
- // This block raises an error on MS.NET 1.0.
- wr.WriteAttributes(xtr, false);
- // This method don't always have to take this double-quoted style...
- AssertEquals("#WriteAttributes.XmlDecl.2", "version=\"1.0\" standalone=\"no\"", sw.ToString().Trim());
- sw = new StringWriter ();
- wr = new XmlTextWriter (sw);
- sb.Remove(0, sb.Length); // init
- xtr.Read(); // read root
- AssertEquals (XmlNodeType.Element, xtr.NodeType);
- wr.WriteStartElement(xtr.LocalName, xtr.NamespaceURI);
- wr.WriteAttributes(xtr, false);
- wr.WriteEndElement();
- wr.Close();
- // This method don't always have to take this double-quoted style...
- AssertEquals("#WriteAttributes.Element", "<root a1=\"A\" b2=\"B\" c3=\"C\" />", sw.ToString().Trim());
- xtr.Close ();
- }
- [Test]
- public void WriteWhitespace ()
- {
- xtw.WriteStartElement ("a");
- xtw.WriteWhitespace ("\n\t");
- xtw.WriteStartElement ("b");
- xtw.WriteWhitespace ("\n\t");
- xtw.WriteEndElement ();
- xtw.WriteWhitespace ("\n");
- xtw.WriteEndElement ();
- xtw.WriteWhitespace ("\n");
- xtw.Flush ();
- AssertEquals ("<a>\n\t<b>\n\t</b>\n</a>\n", StringWriterText);
- }
- [Test]
- public void FlushDoesntCloseTag ()
- {
- xtw.WriteStartElement ("foo");
- xtw.WriteAttributeString ("bar", "baz");
- xtw.Flush ();
- AssertEquals ("<foo bar='baz'", StringWriterText);
- }
- [Test]
- public void WriteWhitespaceClosesTag ()
- {
- xtw.WriteStartElement ("foo");
- xtw.WriteAttributeString ("bar", "baz");
- xtw.WriteWhitespace (" ");
- AssertEquals ("<foo bar='baz'> ", StringWriterText);
- }
- [Test]
- public void DontOutputMultipleXmlns ()
- {
- XmlDocument doc = new XmlDocument();
- doc.LoadXml("<a xmlns:dt=\"b\" dt:dt=\"c\"/>");
- XmlDocument doc2 = new XmlDocument();
- doc2.LoadXml(doc.InnerXml);
- AssertEquals ("<a xmlns:dt=\"b\" dt:dt=\"c\" />",
- doc2.OuterXml);
- }
- [Test]
- public void DontOutputNonDeclaredXmlns ()
- {
- string xml = "<x:a foo='foo' xmlns:x='urn:foo'><b /></x:a>";
- XmlDocument doc = new XmlDocument();
- doc.LoadXml(xml);
- XmlDocument doc2 = new XmlDocument();
- doc2.LoadXml(doc.InnerXml);
- AssertEquals (xml.Replace ('\'', '"'), doc2.OuterXml);
- }
- [Test]
- public void DontOutputRemovalDefaultNSDeclaration ()
- {
- xtw.WriteStartDocument ();
- xtw.WriteStartElement ("foo");
- xtw.WriteAttributeString ("xmlns", "probe");
- AssertEquals (String.Empty, xtw.LookupPrefix ("probe"));
- xtw.WriteStartElement ("b");
- AssertEquals (String.Empty, xtw.LookupPrefix ("probe"));
- xtw.WriteStartElement (null, "b2", null); // *Don't* output xmlns=""
- xtw.WriteEndElement (); // b2
- xtw.WriteStartElement (null, "b2", ""); // *Do* output xmlns=""
- xtw.WriteEndElement (); // b2
- xtw.WriteEndElement (); // b
- xtw.WriteEndElement (); // foo
- xtw.WriteEndDocument ();
- xtw.Close ();
- AssertEquals ("<?xml version='1.0' encoding='utf-16'?><foo xmlns='probe'><b><b2 /><b2 xmlns='' /></b></foo>", StringWriterText);
- }
- [Test]
- public void DontOutputRemovalDefaultNSDeclaration2 ()
- {
- xtw.WriteStartDocument ();
- // IMPORTANT DIFFERENCE!! ns = "", not null
- xtw.WriteStartElement ("foo", "");
- xtw.WriteAttributeString ("xmlns", "probe");
- AssertNull (xtw.LookupPrefix ("probe"));
- xtw.WriteStartElement ("b");
- AssertNull (xtw.LookupPrefix ("probe"));
- xtw.WriteStartElement (null, "b2", null); // *Don't* output xmlns=""
- xtw.WriteEndElement (); // b2
- xtw.WriteStartElement (null, "b2", ""); // *Do* output xmlns=""
- xtw.WriteEndElement (); // b2
- xtw.WriteEndElement (); // b
- xtw.WriteEndElement (); // foo
- xtw.WriteEndDocument ();
- xtw.Close ();
- AssertEquals ("<?xml version='1.0' encoding='utf-16'?><foo xmlns='probe'><b><b2 /><b2 /></b></foo>", StringWriterText);
- }
- [Test]
- public void DoOutputRemovalDefaultNSDeclaration ()
- {
- xtw.WriteStartElement ("docelem", "a-namespace");
-
- XmlDocument doc = new XmlDocument ();
- doc.CreateElement ("hola").WriteTo (xtw);
- // This means, WriteTo never passes null NamespaceURI argument to XmlWriter.
- xtw.WriteEndElement ();
- xtw.Close ();
- AssertEquals ("<docelem xmlns='a-namespace'><hola xmlns='' /></docelem>", StringWriterText);
- }
- [Test]
- public void WriteAttributeTakePrecedenceOnXmlns ()
- {
- xtw.WriteStartElement ("root", "urn:foo");
- xtw.WriteAttributeString ("xmlns", "urn:bar");
- xtw.WriteEndElement ();
- xtw.Close ();
- AssertEquals ("<root xmlns='urn:bar' />", StringWriterText);
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void LookupPrefixNull ()
- {
- xtw.LookupPrefix (null);
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void LookupPrefixEmpty ()
- {
- xtw.LookupPrefix (String.Empty);
- }
- [Test]
- public void LookupPrefixIgnoresXmlnsAttribute ()
- {
- AssertNull (xtw.LookupPrefix ("urn:foo"));
- xtw.WriteStartElement ("root");
- AssertNull (xtw.LookupPrefix ("urn:foo"));
- xtw.WriteAttributeString ("xmlns", "urn:foo");
- // Surprisingly to say, it is ignored!!
- AssertEquals (String.Empty, xtw.LookupPrefix ("urn:foo"));
- xtw.WriteStartElement ("hoge");
- // (still after flushing previous start element.)
- AssertEquals (String.Empty, xtw.LookupPrefix ("urn:foo"));
- xtw.WriteStartElement ("fuga", "urn:foo");
- // Is this testing on the correct way? Yes, here it is.
- AssertEquals (String.Empty, xtw.LookupPrefix ("urn:foo"));
- }
- [Test]
- public void WriteInvalidNames ()
- {
- xtw.WriteStartElement ("foo<>");
- xtw.WriteAttributeString ("ho<>ge", "value");
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void AttributeWriteStartAttributePrefixWithoutNS ()
- {
- xtw.WriteStartAttribute ("some", "foo", null);
- }
- [Test]
- public void AttributeWriteStartAttributeXmlnsNullNS ()
- {
- xtw.WriteStartAttribute ("xmlns", "foo", null);
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void AttributeWriteEndAttributeXmlnsNullNs ()
- {
- // Compare with the test AttributeWriteStartAttributeXmlnsNullNS().
- xtw.WriteStartAttribute ("xmlns", "foo", null);
- xtw.WriteEndAttribute ();
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void AttributeWriteStartAttributePrefixXmlnsNonW3CNS ()
- {
- xtw.WriteStartAttribute ("xmlns", "foo", "urn:foo");
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void AttributeWriteStartAttributeLocalXmlnsNonW3CNS ()
- {
- xtw.WriteStartAttribute ("", "xmlns", "urn:foo");
- }
- [Test]
- public void WriteRawProceedToProlog ()
- {
- XmlTextWriter xtw = new XmlTextWriter (new StringWriter ());
- xtw.WriteRaw ("");
- AssertEquals (WriteState.Prolog, xtw.WriteState);
- }
- [Test]
- public void Indent ()
- {
- XmlDocument doc = new XmlDocument ();
- doc.LoadXml ("<root><test>test<foo></foo>string</test><test>string</test></root>");
- StringWriter sw = new StringWriter ();
- sw.NewLine = "_";
- XmlTextWriter xtw = new XmlTextWriter (sw);
- xtw.Formatting = Formatting.Indented;
- doc.WriteContentTo (xtw);
- AssertEquals (@"<root>_ <test>test<foo></foo>string</test>_ <test>string</test>_</root>", sw.ToString ());
- }
- }
- }
|