Ejemplo n.º 1
0
 /// <summary>
 /// Writes the value in this instance of <see cref="HtmlString"/> to the target <paramref name="targetWriter"/>.
 /// </summary>
 /// <param name="targetWriter">The <see cref="TextWriter"/> to write contents to.</param>
 public void WriteTo(TextWriter targetWriter)
 {
     if (_writer != null)
     {
         _writer.CopyTo(targetWriter);
     }
     else
     {
         targetWriter.Write(_input);
     }
 }
        public void Copy_WritesContent_IfTargetTextWriterIsNotAStringCollectionTextWriter()
        {
            // Arrange
            var source   = new StringCollectionTextWriter(Encoding.UTF8);
            var target   = new StringWriter();
            var expected = @"Hello world" + Environment.NewLine + "abc";

            // Act
            source.WriteLine("Hello world");
            source.Write(new[] { 'x', 'a', 'b', 'c' }, 1, 3);
            source.CopyTo(target);

            // Assert
            Assert.Equal(expected, target.ToString());
        }
        public void Copy_CopiesContent_IfTargetTextWriterIsAStringCollectionTextWriter()
        {
            // Arrange
            var source = new StringCollectionTextWriter(Encoding.UTF8);
            var target = new StringCollectionTextWriter(Encoding.UTF8);

            // Act
            source.Write("Hello world");
            source.Write(new char[1], 0, 1);
            source.CopyTo(target);

            // Assert
            // Make sure content was written to the source.
            Assert.Equal(2, source.Buffer.BufferEntries.Count);
            Assert.Equal(1, target.Buffer.BufferEntries.Count);
            Assert.Same(source.Buffer.BufferEntries, target.Buffer.BufferEntries[0]);
        }
Ejemplo n.º 4
0
        public void Copy_CopiesContent_IfTargetTextWriterIsAStringCollectionTextWriter()
        {
            // Arrange
            var source = new StringCollectionTextWriter(Encoding.UTF8);
            var target = new StringCollectionTextWriter(Encoding.UTF8);

            // Act
            source.Write("Hello world");
            source.Write(new char[1], 0, 1);
            source.CopyTo(target, new CommonTestEncoder());

            // Assert
            // Make sure content was written to the source.
            Assert.Equal(2, source.Content.Entries.Count);
            Assert.Equal(1, target.Content.Entries.Count);
            var result = Assert.Single(target.Content.Entries);
            var bufferedHtmlContent = Assert.IsType <BufferedHtmlContent>(result);

            Assert.Same(source.Content.Entries, bufferedHtmlContent.Entries);
        }
        public void Copy_WritesContent_IfTargetTextWriterIsNotAStringCollectionTextWriter()
        {
            // Arrange
            var source = new StringCollectionTextWriter(Encoding.UTF8);
            var target = new StringWriter();
            var expected = @"Hello world" + Environment.NewLine + "abc";

            // Act
            source.WriteLine("Hello world");
            source.Write(new[] { 'x', 'a', 'b', 'c' }, 1, 3);
            source.CopyTo(target);

            // Assert
            Assert.Equal(expected, target.ToString());
        }
        public void Copy_CopiesContent_IfTargetTextWriterIsAStringCollectionTextWriter()
        {
            // Arrange
            var source = new StringCollectionTextWriter(Encoding.UTF8);
            var target = new StringCollectionTextWriter(Encoding.UTF8);

            // Act
            source.Write("Hello world");
            source.Write(new char[1], 0, 1);
            source.CopyTo(target);

            // Assert
            // Make sure content was written to the source.
            Assert.Equal(2, source.Buffer.BufferEntries.Count);
            Assert.Equal(1, target.Buffer.BufferEntries.Count);
            Assert.Same(source.Buffer.BufferEntries, target.Buffer.BufferEntries[0]);
        }
Ejemplo n.º 7
0
        public void Copy_CopiesContent_IfTargetTextWriterIsAStringCollectionTextWriter()
        {
            // Arrange
            var source = new StringCollectionTextWriter(Encoding.UTF8);
            var target = new StringCollectionTextWriter(Encoding.UTF8);

            // Act
            source.Write("Hello world");
            source.Write(new char[1], 0, 1);
            source.CopyTo(target, new CommonTestEncoder());

            // Assert
            // Make sure content was written to the source.
            Assert.Equal(2, source.Content.Entries.Count);
            Assert.Equal(1, target.Content.Entries.Count);
            var result = Assert.Single(target.Content.Entries);
            var bufferedHtmlContent = Assert.IsType<BufferedHtmlContent>(result);
            Assert.Same(source.Content.Entries, bufferedHtmlContent.Entries);
        }