Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EventSourceStreamReader"/> class.
        /// </summary>
        /// <param name="connection">The connection associated with this event source</param>
        /// <param name="stream">The stream to read event source payloads from.</param>
        public EventSourceStreamReader(IConnection connection, Stream stream)
            : base(stream)
        {
            _connection = connection;
            _buffer     = new ChunkBuffer();

            Data = ProcessBuffer;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="EventSourceStreamReader"/> class.
        /// </summary>
        /// <param name="connection">The connection associated with this event source</param>
        /// <param name="stream">The stream to read event source payloads from.</param>
        public EventSourceStreamReader(IConnection connection, Stream stream)
            : base(stream)
        {
            _connection = connection;
            _buffer = new ChunkBuffer();

            Data = ProcessBuffer;
        }
            public void ReturnsTextUpToNewLine()
            {
                // Arrange
                var buffer = new ChunkBuffer();
                byte[] data = Encoding.UTF8.GetBytes("hello world\noy");

                // Act
                buffer.Add(data, data.Length);

                // Assert
                Assert.Equal("hello world", buffer.ReadLine());
            }
            public void ReturnsNullIfNoNewLineIfBuffer()
            {
                // Arrange
                var buffer = new ChunkBuffer();
                byte[] data = Encoding.UTF8.GetBytes("hello world");

                // Act
                buffer.Add(data, data.Length);

                // Assert
                Assert.Null(buffer.ReadLine());
            }
            public void CanReadMultipleLines()
            {
                // Arrange
                var buffer = new ChunkBuffer();
                byte[] data = Encoding.UTF8.GetBytes("hel\nlo world\noy");

                // Act
                buffer.Add(data, data.Length);

                // Assert
                Assert.Equal("hel", buffer.ReadLine());
                Assert.Equal("lo world", buffer.ReadLine());
                Assert.Null(buffer.ReadLine());
            }
 public void WillCompleteNewLine()
 {
     // Arrange
     var buffer = new ChunkBuffer();
     byte[] data = Encoding.UTF8.GetBytes("hello");
     buffer.Add(data, data.Length);
     Assert.Null(buffer.ReadLine());
     data = Encoding.UTF8.GetBytes("\n");
     buffer.Add(data, data.Length);
     Assert.Equal("hello", buffer.ReadLine());
     data = Encoding.UTF8.GetBytes("Another line");
     buffer.Add(data, data.Length);
     Assert.Null(buffer.ReadLine());
     data = Encoding.UTF8.GetBytes("\nnext");
     buffer.Add(data, data.Length);
     Assert.Equal("Another line", buffer.ReadLine());
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="EventSourceStreamReader"/> class.
 /// </summary>
 /// <param name="stream">The stream to read event source payloads from.</param>
 public EventSourceStreamReader(Stream stream)
 {
     _stream = stream;
     _buffer = new ChunkBuffer();
 }
Exemple #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EventSourceStreamReader"/> class.
 /// </summary>
 /// <param name="stream">The stream to read event source payloads from.</param>
 public EventSourceStreamReader(Stream stream)
 {
     _stream = stream;
     _buffer = new ChunkBuffer();
 }