Exemplo n.º 1
0
        public void AddIndividualBytes(string text)
        {
            var data = text.ToArraySegment();

            foreach (var value in data.Array.Skip(data.Offset).Take(data.Count))
            {
                var available = Baton.Available(1);
                available.Array[available.Offset] = value;
                Baton.Extend(1);
                CallConsume();
                if (Paused)
                {
                    throw new InvalidOperationException("Pause not implemented on this one yet");
                }
            }
        }
Exemplo n.º 2
0
        public void ExtendCausesArraySegmentToIncludeMoreBytesAtTheEnd()
        {
            // Arrange
            var baton = new Baton(new FakeMemoryPool())
            {
                Buffer = "xxhello worldxx".ToArraySegment()
            };

            baton.Buffer = new ArraySegment <byte>(baton.Buffer.Array, 2, 5);

            // Act
            var before = baton.Buffer.ToString(Encoding.Default);

            baton.Extend(5);
            var after = baton.Buffer.ToString(Encoding.Default);

            // Assert
            Assert.Equal("hello", before);
            Assert.Equal("hello worl", after);
            Assert.Equal(2, baton.Buffer.Offset);
            Assert.Equal(10, baton.Buffer.Count);
        }