Represents a moderate-performance byte buffer with a maximum capacity.
Inheritance: IDisposable
コード例 #1
0
        public void AppendFill_Should_Throw_On_Null_Buffer()
        {
            var buffer = new BoundedBuffer();

            buffer.Invoking(b => b.AppendFill(null, 0, 0))
            .ShouldThrow <ArgumentNullException>();
        }
コード例 #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>();
        }
コード例 #3
0
        public void ExtractAndReset_Should_Throw_On_Negative_Capacity()
        {
            var buffer = new BoundedBuffer(32);

            buffer.Invoking(b => b.ExtractAndReset(-1))
            .ShouldThrow <ArgumentOutOfRangeException>();
        }
コード例 #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>();
        }
コード例 #5
0
        public void ExtractAndReset_With_Zero_Capacity_Should_Not_Throw()
        {
            var buffer = new BoundedBuffer(32);

            buffer.Invoking(b => b.ExtractAndReset(0))
            .ShouldNotThrow();
        }
コード例 #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>();
        }
コード例 #7
0
        public void ExtractAndReset_Should_Set_New_Capacity()
        {
            var buffer = new BoundedBuffer(100);

            buffer.ExtractAndReset(64);

            buffer.FreeSpace.Should().Be(64);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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;
        }
コード例 #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>();
        }
コード例 #14
0
        public void Double_Dispose_Should_Not_Throw()
        {
            var buffer = new BoundedBuffer(32);

            buffer.Dispose();

            buffer.Invoking(b => b.Dispose())
            .ShouldNotThrow();
        }
コード例 #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);
        }
コード例 #16
0
        public void Reset_Should_Throw_After_Disposal()
        {
            var buffer = new BoundedBuffer(32);

            buffer.Dispose();

            buffer.Invoking(b => b.Reset(0))
            .ShouldThrow <ObjectDisposedException>();
        }
コード例 #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>();
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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));
        }
コード例 #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));
        }
コード例 #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);
        }
コード例 #25
0
        public void Default_Constructor_Should_Create_Instance_With_Requested_Capacity()
        {
            var buffer = new BoundedBuffer(123);

            buffer.FreeSpace.Should().Be(123);
        }
コード例 #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>();
        }
コード例 #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>();
 }
コード例 #28
0
 public void Reset_With_Zero_Capacity_Should_Not_Throw()
 {
     var buffer = new BoundedBuffer(32);
     buffer.Invoking(b => b.Reset(0))
           .ShouldNotThrow();
 }
コード例 #29
0
        public void Reset_Should_Throw_On_Negative_Capacity()
        {
            var buffer = new BoundedBuffer(32);

            buffer.Invoking(b => b.Reset(-1))
                  .ShouldThrow<ArgumentOutOfRangeException>();
        }
コード例 #30
0
        public void Reset_Should_Throw_After_Disposal()
        {
            var buffer = new BoundedBuffer(32);
            buffer.Dispose();

            buffer.Invoking(b => b.Reset(0))
                  .ShouldThrow<ObjectDisposedException>();
        }
コード例 #31
0
        public void Reset_Should_Set_New_Capacity()
        {
            var buffer = new BoundedBuffer(100);

            buffer.Reset(64);

            buffer.FreeSpace.Should().Be(64);
        }
コード例 #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>();
        }
コード例 #33
0
        public void Double_Dispose_Should_Not_Throw()
        {
            var buffer = new BoundedBuffer(32);
            buffer.Dispose();

            buffer.Invoking(b => b.Dispose())
                  .ShouldNotThrow();
        }
コード例 #34
0
        public void Default_Constructor_Should_Create_Instance_With_Requested_Capacity()
        {
            var buffer = new BoundedBuffer(123);

            buffer.FreeSpace.Should().Be(123);
        }
コード例 #35
0
        public void AppendFill_Should_Throw_On_Null_Buffer()
        {
            var buffer = new BoundedBuffer();

            buffer.Invoking(b => b.AppendFill(null, 0, 0))
                  .ShouldThrow<ArgumentNullException>();
        }
コード例 #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>();
 }
コード例 #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>();
        }