Esempio n. 1
0
        public void WriteValue_should_use_cdata_if_required()
        {
            // arrange
            TextWriter writer    = new StringWriter();
            var        xmlWriter = XmlWriter.Create(writer);

            var expected =
                "<?xml version=\"1.0\" encoding=\"utf-16\" standalone=\"yes\"?>" +
                "<tag type=\"Compound\">" +
                "<alpha type=\"String\">" +
                "<![CDATA[<BAD>]]>" +
                "</alpha>" +
                "</tag>";

            var target = new XmlTagWriter(xmlWriter);

            target.WriteStartDocument();
            target.WriteStartTag(TagType.Compound);

            // act
            target.WriteTag("alpha", "<BAD>");

            // assert
            target.WriteEndTag();
            target.WriteEndDocument();
            var actual = writer.ToString();

            Assert.Equal(expected, actual);
        }
Esempio n. 2
0
        public void Constructor_allows_external_writer()
        {
            // arrange
            Tag actual;

            Tag expected = CreateComplexData();

            TextWriter textWriter = new StringWriter();
            var        writer     = XmlWriter.Create(textWriter, new XmlWriterSettings
            {
                Indent = true
            });

            TagWriter target = new XmlTagWriter(writer);

            // act
            target.WriteStartDocument();
            target.WriteTag(expected);
            target.WriteEndDocument();

            using (TextReader textReader = new StringReader(textWriter.ToString()))
            {
                using (var reader = XmlReader.Create(textReader))
                {
                    actual = new XmlTagReader(reader).ReadTag();
                }
            }

            // assert
            NbtAssert.Equal(expected, actual);
        }
Esempio n. 3
0
 public void WritePredefinedXmlDocument()
 {
     using (Stream stream = new MemoryStream())
     {
         TagWriter writer = new XmlTagWriter(stream);
         writer.WriteStartDocument();
         writer.WriteTag(_predefined);
         writer.WriteEndDocument();
     }
 }
    public void SaveTest()
    {
      // arrange
      XmlTagWriter writer;
      TagCompound target;

      target = this.GetComplexData();
      writer = new XmlTagWriter();

      // act
      writer.Write(target, this.OutputFileName);

      // assert
      FileAssert.AreEqual(this.ComplexXmlDataFileName, this.OutputFileName);
    }
Esempio n. 5
0
        public void Close_should_close_writer()
        {
            // arrange
            var stream = new MemoryStream();
            var writer = XmlWriter.Create(stream);

            TagWriter target = new XmlTagWriter(writer);

            var expected = WriteState.Closed;

            // act
            target.Dispose();

            // assert
            Assert.Equal(expected, writer.WriteState);
        }
Esempio n. 6
0
        public void Close_should_close_writer()
        {
            // arrange
            TagWriter    target;
            XmlWriter    writer;
            MemoryStream stream;
            WriteState   expected;

            stream = new MemoryStream();
            writer = XmlWriter.Create(stream);

            target = new XmlTagWriter(writer);

            expected = WriteState.Closed;

            // act
            target.Close();

            // assert
            Assert.AreEqual(expected, writer.WriteState);
        }