예제 #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");
                }
            }
        }
예제 #2
0
        public void AvailableBufferBringsOffsetBackToZeroIfOccupiedSegmentIsZeroLength()
        {
            // Arrange
            var baton = new Baton(new FakeMemoryPool())
            {
                Buffer = "xxhello worldxx".ToArraySegment()
            };

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

            // Act
            var buffer = baton.Available(0);

            // Assert
            Assert.Equal(15, buffer.Count);
            Assert.Equal("xxhello worldxx", buffer.ToString(Encoding.Default));
        }
예제 #3
0
        public void AvailableBufferReturnsAreaThatIsUnused()
        {
            // Arrange
            var baton = new Baton(new FakeMemoryPool())
            {
                Buffer = "xxhello worldxx".ToArraySegment()
            };

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

            // Act
            var buffer = baton.Available(0);

            // Assert
            Assert.Equal(8, buffer.Count);
            Assert.Equal(" worldxx", buffer.ToString(Encoding.Default));
        }
예제 #4
0
        public void Add(string text)
        {
            if (Paused)
            {
                throw new InvalidOperationException("FakeInput.Add cannot be called when Paused is true");
            }

            Baton.Available(Encoding.GetByteCount(text));
            var count = Encoding.GetBytes(
                text, 0, text.Length, Baton.Buffer.Array, Baton.Buffer.Offset + Baton.Buffer.Count);

            Assert.Equal(text.Length, count);
            Baton.Buffer = new ArraySegment <byte>(
                Baton.Buffer.Array,
                Baton.Buffer.Offset,
                Baton.Buffer.Count + count);

            CallConsume();
        }