/// <summary> /// Tests the WriteTo method on XTest. /// </summary> /// <param name="contextValue"></param> /// <returns></returns> //[Variation(Desc = "TextWriteTo")] public void TextWriteTo() { XCData c = new XCData("abcd"); // Null writer not allowed. try { c.WriteTo(null); Validate.ExpectedThrow(typeof(ArgumentNullException)); } catch (Exception ex) { Validate.Catch(ex, typeof(ArgumentNullException)); } // Test. StringBuilder stringBuilder = new StringBuilder(); XmlWriter xmlWriter = XmlWriter.Create(stringBuilder); xmlWriter.WriteStartElement("x"); c.WriteTo(xmlWriter); xmlWriter.WriteEndElement(); xmlWriter.Flush(); Validate.IsEqual( stringBuilder.ToString(), "<?xml version=\"1.0\" encoding=\"utf-16\"?><x><![CDATA[abcd]]></x>"); }
public void TextWriteTo() { XCData c = new XCData("abcd"); // Null writer not allowed. Assert.Throws <ArgumentNullException>(() => c.WriteTo(null)); // Test. StringBuilder stringBuilder = new StringBuilder(); XmlWriter xmlWriter = XmlWriter.Create(stringBuilder); xmlWriter.WriteStartElement("x"); c.WriteTo(xmlWriter); xmlWriter.WriteEndElement(); xmlWriter.Flush(); Assert.Equal("<?xml version=\"1.0\" encoding=\"utf-16\"?><x><![CDATA[abcd]]></x>", stringBuilder.ToString()); }