Represents a moderate-performance byte buffer with a maximum capacity.
Inheritance: IDisposable
Ejemplo n.º 1
0
        public void AppendFill_Should_Throw_On_Null_Buffer()
        {
            var buffer = new BoundedBuffer();

            buffer.Invoking(b => b.AppendFill(null, 0, 0))
            .ShouldThrow <ArgumentNullException>();
        }
Ejemplo n.º 2
0
        public void AppendFill_Should_Throw_On_Non_Positive_Count(int count)
        {
            var buffer = new BoundedBuffer();

            buffer.Invoking(b => b.AppendFill(Helpers.EmptyBuffer, 0, count))
            .ShouldThrow <ArgumentOutOfRangeException>();
        }
Ejemplo n.º 3
0
        public void ExtractAndReset_Should_Throw_On_Negative_Capacity()
        {
            var buffer = new BoundedBuffer(32);

            buffer.Invoking(b => b.ExtractAndReset(-1))
            .ShouldThrow <ArgumentOutOfRangeException>();
        }
Ejemplo n.º 4
0
        public void AppendFill_Should_Throw_On_Bad_Segment_Length()
        {
            var buffer = new BoundedBuffer();

            buffer.Invoking(b => b.AppendFill(Helpers.EmptyBuffer, 0, 1))
            .ShouldThrow <ArraySegmentException>();
        }
Ejemplo n.º 5
0
        public void ExtractAndReset_With_Zero_Capacity_Should_Not_Throw()
        {
            var buffer = new BoundedBuffer(32);

            buffer.Invoking(b => b.ExtractAndReset(0))
            .ShouldNotThrow();
        }
Ejemplo n.º 6
0
        public void AppendFill_Should_Throw_On_Negative_Offset()
        {
            var buffer = new BoundedBuffer();

            buffer.Invoking(b => b.AppendFill(Helpers.EmptyBuffer, -1, 0))
            .ShouldThrow <ArgumentOutOfRangeException>();
        }
Ejemplo n.º 7
0
        public void ExtractAndReset_Should_Set_New_Capacity()
        {
            var buffer = new BoundedBuffer(100);

            buffer.ExtractAndReset(64);

            buffer.FreeSpace.Should().Be(64);
        }
Ejemplo n.º 8
0
        public void AppendFill_Should_Return_Written_Bytes_When_FreeSpace_Insufficient()
        {
            var buffer = new BoundedBuffer(9);
            var bytes  = Helpers.GetRandomBytes(10);

            var written = buffer.AppendFill(bytes, 0, 10);

            written.Should().Be(9);
        }
Ejemplo n.º 9
0
        public void AppendFill_Should_Return_Written_Bytes()
        {
            var buffer = new BoundedBuffer(30);
            var bytes  = Helpers.GetRandomBytes(10);

            var written = buffer.AppendFill(bytes, 0, 10);

            written.Should().Be(10);
        }
Ejemplo n.º 10
0
        public void AppendFill_Should_Decrease_FreeSpace_Until_Zero()
        {
            var buffer = new BoundedBuffer(16);
            var bytes  = Helpers.GetRandomBytes(32);

            buffer.AppendFill(bytes, 0, 32);

            buffer.FreeSpace.Should().Be(0);
        }
Ejemplo n.º 11
0
        public void AppendFill_Should_Decrease_FreeSpace()
        {
            var buffer = new BoundedBuffer(30);
            var bytes  = Helpers.GetRandomBytes(10);

            buffer.AppendFill(bytes, 0, 10);

            buffer.FreeSpace.Should().Be(20);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EncryptedNetworkSession"/> class with no specified socket.
        /// </summary>
        /// <remarks>
        /// Call <see cref="AttachSocket(Socket)"/> before starting the network operations.
        /// </remarks>
        protected EncryptedNetworkSession()
        {
            this.packetBuffer = new BoundedBuffer();
            this.headerBuffer = new BoundedBuffer(4);

            this.baseSession = this.CreateInnerSession();

            this.isDisposed = false;
        }
Ejemplo n.º 13
0
        public void FreeSpace_Access_Should_Throw_After_Disposal()
        {
            var buffer = new BoundedBuffer(32);

            buffer.Dispose();

            buffer.Invoking(b => b.FreeSpace.Whatever())
            .ShouldThrow <ObjectDisposedException>();
        }
Ejemplo n.º 14
0
        public void Double_Dispose_Should_Not_Throw()
        {
            var buffer = new BoundedBuffer(32);

            buffer.Dispose();

            buffer.Invoking(b => b.Dispose())
            .ShouldNotThrow();
        }
Ejemplo n.º 15
0
        public void AppendFill_Should_Decrease_FreeSpace_Until_Zero()
        {
            var buffer = new BoundedBuffer(16);
            var bytes = Helpers.GetRandomBytes(32);

            buffer.AppendFill(bytes, 0, 32);

            buffer.FreeSpace.Should().Be(0);
        }
Ejemplo n.º 16
0
        public void Reset_Should_Throw_After_Disposal()
        {
            var buffer = new BoundedBuffer(32);

            buffer.Dispose();

            buffer.Invoking(b => b.Reset(0))
            .ShouldThrow <ObjectDisposedException>();
        }
Ejemplo n.º 17
0
        public void AppendFill_Should_Throw_After_Disposal()
        {
            var buffer = new BoundedBuffer(32);

            buffer.Dispose();

            buffer.Invoking(b => b.AppendFill(Helpers.EmptyBuffer, 0, 0))
            .ShouldThrow <ObjectDisposedException>();
        }
Ejemplo n.º 18
0
        public void AppendFill_Should_Return_Written_Bytes()
        {
            var buffer = new BoundedBuffer(30);
            var bytes = Helpers.GetRandomBytes(10);

            var written = buffer.AppendFill(bytes, 0, 10);

            written.Should().Be(10);
        }
Ejemplo n.º 19
0
        public void AppendFill_Should_Decrease_FreeSpace()
        {
            var buffer = new BoundedBuffer(30);
            var bytes = Helpers.GetRandomBytes(10);

            buffer.AppendFill(bytes, 0, 10);

            buffer.FreeSpace.Should().Be(20);
        }
Ejemplo n.º 20
0
        public void AppendFill_Should_Return_Written_Bytes_When_FreeSpace_Insufficient()
        {
            var buffer = new BoundedBuffer(9);
            var bytes = Helpers.GetRandomBytes(10);

            var written = buffer.AppendFill(bytes, 0, 10);

            written.Should().Be(9);
        }
Ejemplo n.º 21
0
        public void AppendFill_Should_Append_Whole_Array()
        {
            var buffer = new BoundedBuffer(128);

            var bytes = Helpers.GetRandomBytes(90);
            buffer.AppendFill(bytes, 0, 90);
            var extracted = buffer.ExtractAndReset(0);

            extracted.Take(90).Should().ContainInOrder(bytes);
        }
Ejemplo n.º 22
0
        public void AppendFill_Should_Fill_Buffer_When_FreeSpace_Insufficient()
        {
            var buffer = new BoundedBuffer(100);
            var bytes = Helpers.GetRandomBytes(127);
            buffer.AppendFill(bytes, 0, 100);

            var extracted = buffer.ExtractAndReset(0);

            extracted.Should().ContainInOrder(bytes.Take(100));
        }
Ejemplo n.º 23
0
        public void AppendFill_Should_Fill_Buffer_When_FreeSpace_Insufficient()
        {
            var buffer = new BoundedBuffer(100);
            var bytes  = Helpers.GetRandomBytes(127);

            buffer.AppendFill(bytes, 0, 100);

            var extracted = buffer.ExtractAndReset(0);

            extracted.Should().ContainInOrder(bytes.Take(100));
        }
Ejemplo n.º 24
0
        public void AppendFill_Should_Append_Whole_Array()
        {
            var buffer = new BoundedBuffer(128);

            var bytes = Helpers.GetRandomBytes(90);

            buffer.AppendFill(bytes, 0, 90);
            var extracted = buffer.ExtractAndReset(0);

            extracted.Take(90).Should().ContainInOrder(bytes);
        }
Ejemplo n.º 25
0
        public void Default_Constructor_Should_Create_Instance_With_Requested_Capacity()
        {
            var buffer = new BoundedBuffer(123);

            buffer.FreeSpace.Should().Be(123);
        }
Ejemplo n.º 26
0
        public void AppendFill_Should_Throw_On_Negative_Offset()
        {
            var buffer = new BoundedBuffer();

            buffer.Invoking(b => b.AppendFill(Helpers.EmptyBuffer, -1, 0))
                  .ShouldThrow<ArgumentOutOfRangeException>();
        }
Ejemplo n.º 27
0
 public void AppendFill_Should_Throw_On_Non_Positive_Count(int count)
 {
     var buffer = new BoundedBuffer();
     buffer.Invoking(b => b.AppendFill(Helpers.EmptyBuffer, 0, count))
           .ShouldThrow<ArgumentOutOfRangeException>();
 }
Ejemplo n.º 28
0
 public void Reset_With_Zero_Capacity_Should_Not_Throw()
 {
     var buffer = new BoundedBuffer(32);
     buffer.Invoking(b => b.Reset(0))
           .ShouldNotThrow();
 }
Ejemplo n.º 29
0
        public void Reset_Should_Throw_On_Negative_Capacity()
        {
            var buffer = new BoundedBuffer(32);

            buffer.Invoking(b => b.Reset(-1))
                  .ShouldThrow<ArgumentOutOfRangeException>();
        }
Ejemplo n.º 30
0
        public void Reset_Should_Throw_After_Disposal()
        {
            var buffer = new BoundedBuffer(32);
            buffer.Dispose();

            buffer.Invoking(b => b.Reset(0))
                  .ShouldThrow<ObjectDisposedException>();
        }
Ejemplo n.º 31
0
        public void Reset_Should_Set_New_Capacity()
        {
            var buffer = new BoundedBuffer(100);

            buffer.Reset(64);

            buffer.FreeSpace.Should().Be(64);
        }
Ejemplo n.º 32
0
        public void AppendFill_Should_Throw_After_Disposal()
        {
            var buffer = new BoundedBuffer(32);
            buffer.Dispose();

            buffer.Invoking(b => b.AppendFill(Helpers.EmptyBuffer, 0, 0))
                  .ShouldThrow<ObjectDisposedException>();
        }
Ejemplo n.º 33
0
        public void Double_Dispose_Should_Not_Throw()
        {
            var buffer = new BoundedBuffer(32);
            buffer.Dispose();

            buffer.Invoking(b => b.Dispose())
                  .ShouldNotThrow();
        }
Ejemplo n.º 34
0
        public void Default_Constructor_Should_Create_Instance_With_Requested_Capacity()
        {
            var buffer = new BoundedBuffer(123);

            buffer.FreeSpace.Should().Be(123);
        }
Ejemplo n.º 35
0
        public void AppendFill_Should_Throw_On_Null_Buffer()
        {
            var buffer = new BoundedBuffer();

            buffer.Invoking(b => b.AppendFill(null, 0, 0))
                  .ShouldThrow<ArgumentNullException>();
        }
Ejemplo n.º 36
0
 public void AppendFill_Should_Throw_On_Bad_Segment_Length()
 {
     var buffer = new BoundedBuffer();
     buffer.Invoking(b => b.AppendFill(Helpers.EmptyBuffer, 0, 1))
           .ShouldThrow<ArraySegmentException>();
 }
Ejemplo n.º 37
0
        public void FreeSpace_Access_Should_Throw_After_Disposal()
        {
            var buffer = new BoundedBuffer(32);
            buffer.Dispose();

            buffer.Invoking(b => b.FreeSpace.Whatever())
                  .ShouldThrow<ObjectDisposedException>();
        }