Пример #1
0
        private void Compare(string expected, XmlNode node)
        {
            var stream = new XmlNodePlainTextReadonlyByteStream(node);

            using (var reader = new StreamReader(stream)) {
                var read = reader.ReadToEnd();
                Assert.AreEqual(expected, read);
            }
        }
Пример #2
0
        public void Reading_in_tiny_buffer_sizes_can_roundtrip()
        {
            var doc = new XDoc("code")
                      .Value("public ")
                      .Elem("b", "void")
                      .Value(" ")
                      .Start("i").Value("Foo( ").Elem("b", "int bar ").Value(");").End();
            var expected = "public void Foo( int bar );";
            var actual   = new StringBuilder();
            var stream   = new XmlNodePlainTextReadonlyByteStream(doc.AsXmlNode);
            var buffer   = new byte[8];
            var read     = stream.Read(buffer, 0, buffer.Length);

            while (read > 0)
            {
                actual.Append(Encoding.UTF8.GetString(buffer, 0, read));
                read = stream.Read(buffer, 0, buffer.Length);
            }
            Assert.AreEqual(expected, actual.ToString());
        }
Пример #3
0
        public void Can_read_large_blocks_from_doc_with_large_text_nodes()
        {
            var builder = new StringBuilder();

            for (var i = 0; i < 10000; i++)
            {
                builder.AppendFormat("{0:000000}abcdef", i);
            }
            var doc      = new XDoc("doc").Elem("a", builder.ToString()).Elem("b", builder.ToString());
            var expected = doc.AsXmlNode.InnerText;
            var actual   = new StringBuilder();
            var stream   = new XmlNodePlainTextReadonlyByteStream(doc.AsXmlNode);
            var buffer   = new byte[32 * 1024];
            var read     = stream.Read(buffer, 0, buffer.Length);

            while (read > 0)
            {
                actual.Append(Encoding.UTF8.GetString(buffer, 0, read));
                read = stream.Read(buffer, 0, buffer.Length);
            }
            Assert.AreEqual(expected, actual.ToString());
        }
 public void Reading_in_tiny_buffer_sizes_can_roundtrip() {
     var doc = new XDoc("code")
          .Value("public ")
          .Elem("b", "void")
          .Value(" ")
          .Start("i").Value("Foo( ").Elem("b", "int bar ").Value(");").End();
     var expected = "public void Foo( int bar );";
     var actual = new StringBuilder();
     var stream = new XmlNodePlainTextReadonlyByteStream(doc.AsXmlNode);
     var buffer = new byte[8];
     var read = stream.Read(buffer, 0, buffer.Length);
     while(read > 0) {
         actual.Append(Encoding.UTF8.GetString(buffer, 0, read));
         read = stream.Read(buffer, 0, buffer.Length);
     }
     Assert.AreEqual(expected, actual.ToString());
 }
 private void Compare(string expected, XmlNode node) {
     var stream = new XmlNodePlainTextReadonlyByteStream(node);
     using(var reader = new StreamReader(stream)) {
         var read = reader.ReadToEnd();
         Assert.AreEqual(expected, read);
     }
 }
 public void Can_read_large_blocks_from_doc_with_large_text_nodes() {
     var builder = new StringBuilder();
     for(var i = 0; i < 10000; i++) {
         builder.AppendFormat("{0:000000}abcdef", i);
     }
     var doc = new XDoc("doc").Elem("a", builder.ToString()).Elem("b", builder.ToString());
     var expected = doc.AsXmlNode.InnerText;
     var actual = new StringBuilder();
     var stream = new XmlNodePlainTextReadonlyByteStream(doc.AsXmlNode);
     var buffer = new byte[32 * 1024];
     var read = stream.Read(buffer, 0, buffer.Length);
     while(read > 0) {
         actual.Append(Encoding.UTF8.GetString(buffer, 0, read));
         read = stream.Read(buffer, 0, buffer.Length);
     }
     Assert.AreEqual(expected, actual.ToString());
 }