Ejemplo n.º 1
0
        public void Write(Action<Stream> output)
        {
            var stream = new MemoryStream();
            output(stream);

            stream.Position = 0;
            _writer.WriteLine(stream.ReadAllText());
        }
Ejemplo n.º 2
0
        public void TestReadAllText()
        {
            var inputText = "Testing1234";
            var bytes = Encoding.UTF8.GetBytes(inputText);

            var stream = new MemoryStream(bytes);
            var outputText = stream.ReadAllText(Encoding.UTF8);

            Assert.AreEqual(inputText, outputText);
        }
Ejemplo n.º 3
0
        public void can_read_all_text_synchronously()
        {
            var helloWorld = "Hello world.";

            var stream = new MemoryStream();
            var writer = new StreamWriter(stream, Encoding.Unicode);
            writer.WriteLine(helloWorld);
            writer.Flush();

            stream.Position = 0;
            stream.ReadAllText().Trim()
                .ShouldBe(helloWorld);
        }
        private void injectContent(IDictionary<string, object> environment, MemoryStream recordedStream, OwinHttpResponse response)
        {
            var html = recordedStream.ReadAllText();
            var builder = new StringBuilder(html);
            var position = html.IndexOf("</head>", 0, StringComparison.OrdinalIgnoreCase);

            if (position >= 0)
            {
                builder.Insert(position, _options.Content(environment));
            }

            response.Write(builder.ToString());
            response.Flush();
        }
Ejemplo n.º 5
0
        public void ReadAllText_should_return_the_correct_string()
        {
            const string expectedValue = "hello";

            var stream = new MemoryStream();
            var writer = new StreamWriter(stream)
            {
                AutoFlush = true
            };

            writer.Write(expectedValue);
            stream.Position = 0;

            stream.ReadAllText().Should().Be(expectedValue);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Convert document to text
        /// </summary>
        public static string ToText(this XmlNode xmlNode, Encoding encoding)
        {
            if (xmlNode == null)
            {
                throw new ArgumentNullException("xmlNode");
            }

            using (var ms = new MemoryStream())
            {
                using (var writer = CreateXmlWriter(xmlNode, ms, encoding))
                {
                    xmlNode.WriteTo(writer);
                    writer.Flush();

                    return ms.ReadAllText(encoding);
                }
            }
        }
Ejemplo n.º 7
0
        public async Task Write(Func<Stream, Task> output)
        {
            var stream = new MemoryStream();
            await output(stream).ConfigureAwait(false);

            stream.Position = 0;
            _writer.WriteLine(stream.ReadAllText());

        }
 /// <summary>
 /// Gets the content with the specified data format.
 /// </summary>
 /// <param name="dataFormat">The data format.</param>
 /// <returns>The content with the specified data format.</returns>
 private string GetContent(string dataFormat)
 {
     TextRange textRange = new TextRange(this.Document.ContentStart, this.Document.ContentEnd);
     using (MemoryStream memoryStream = new MemoryStream())
     {
         textRange.Save(memoryStream, dataFormat);
         memoryStream.Position = 0;
         return memoryStream.ReadAllText();
     }
 }