コード例 #1
0
        public void Bytes_get_should_throw_when_subject_is_disposed()
        {
            var subject = new ByteArrayChunk(1);
            subject.Dispose();

            Action action = () => { var _ = subject.Bytes; };

            action.ShouldThrow<ObjectDisposedException>().And.ObjectName.Should().Be("ByteArrayChunk");
        }
コード例 #2
0
        public void constructor_with_size_should_initialize_subject(
            [Values(1, 2, 16)]
            int size)
        {
            var subject = new ByteArrayChunk(size);

            var segment = subject.Bytes;
            segment.Array.Should().NotBeNull();
            segment.Offset.Should().Be(0);
            segment.Count.Should().Be(size);
        }
コード例 #3
0
        public void Bytes_get_should_return_expected_result()
        {
            var size = 1;
            var bytes = new byte[size];
            var subject = new ByteArrayChunk(bytes);

            var result = subject.Bytes;

            result.Array.Should().BeSameAs(bytes);
            result.Offset.Should().Be(0);
            result.Count.Should().Be(size);
        }
コード例 #4
0
        public void constructor_with_bytes_should_initialize_subject(
            [Values(1, 2, 16)]
            int size)
        {
            var bytes = new byte[size];

            var subject = new ByteArrayChunk(bytes);

            var segment = subject.Bytes;
            segment.Array.Should().BeSameAs(bytes);
            segment.Offset.Should().Be(0);
            segment.Count.Should().Be(size);
        }
コード例 #5
0
        /// <inheritdoc/>
        public IBsonChunk GetChunk(int requestedSize)
        {
            if (requestedSize <= 0)
            {
                throw new ArgumentOutOfRangeException("requestedSize");
            }
            ThrowIfDisposed();

            IBsonChunk chunk;

            if (_previousChunkSize == 0 && _initialUnpooledChunkSize != 0)
            {
                chunk = new ByteArrayChunk(_initialUnpooledChunkSize);
            }
            else
            {
                var powerOf2Size = PowerOf2.RoundUpToPowerOf2(_previousChunkSize + 1);
                var chunkSize    = Math.Max(Math.Min(powerOf2Size, _maxChunkSize), _minChunkSize);
                chunk = _baseSource.GetChunk(chunkSize);
            }

            _previousChunkSize = chunk.Bytes.Count;
            return(chunk);
        }
コード例 #6
0
        public void Disposed_can_be_called_more_than_once()
        {
            var subject = new ByteArrayChunk(1);

            subject.Dispose();
            subject.Dispose();
        }
コード例 #7
0
 public Reflector(ByteArrayChunk instance)
 {
     _instance = instance;
 }
コード例 #8
0
        public void Fork_should_return_a_new_handle()
        {
            var subject = new ByteArrayChunk(1);

            var result = subject.Fork();

            result.Should().NotBeSameAs(subject);
            var subjectSegment = subject.Bytes;
            var resultSegment = result.Bytes;
            resultSegment.Array.Should().BeSameAs(subjectSegment.Array);
            resultSegment.Offset.Should().Be(subjectSegment.Offset);
            resultSegment.Count.Should().Be(subjectSegment.Count);
        }
コード例 #9
0
        public void Dispose_should_not_dispose_forked_handle()
        {
            var subject = new ByteArrayChunk(1);
            var forked = subject.Fork();

            subject.Dispose();

            var reflector = new Reflector((ByteArrayChunk)forked);
            reflector._disposed.Should().BeFalse();
        }
コード例 #10
0
        public void Dispose_should_dispose_subject()
        {
            var subject = new ByteArrayChunk(1);

            subject.Dispose();

            var reflector = new Reflector(subject);
            reflector._disposed.Should().BeTrue();
        }
コード例 #11
0
 private IEnumerable<IBsonChunk> CreateChunks(byte[] bytes, IEnumerable<int> chunkSizes)
 {
     var offset = 0;
     foreach (var size in chunkSizes)
     {
         if (size > 0)
         {
             var chunk = new ByteArrayChunk(size);
             Buffer.BlockCopy(bytes, offset, chunk.Bytes.Array, chunk.Bytes.Offset, size);
             yield return chunk;
             offset += size;
         }
     }
 }
コード例 #12
0
 private MultiChunkBuffer CreateSubject(int size = 0, int? length = null, bool isReadOnly = false)
 {
     var chunk = new ByteArrayChunk(size);
     return new MultiChunkBuffer(new[] { chunk }, length ?? size, isReadOnly);
 }
コード例 #13
0
 private SingleChunkBuffer CreateSubject(int size = 0, int? length = null, bool isReadOnly = false)
 {
     var chunk = new ByteArrayChunk(size);
     return new SingleChunkBuffer(chunk, length ?? size, isReadOnly);
 }
コード例 #14
0
 private SingleChunkBuffer CreateSubject(byte[] bytes, int? length = null, bool isReadOnly = false)
 {
     var chunk = new ByteArrayChunk(bytes);
     return new SingleChunkBuffer(chunk, length ?? bytes.Length, isReadOnly);
 }
コード例 #15
0
        /// <inheritdoc/>
        public IBsonChunk GetChunk(int requestedSize)
        {
            if (requestedSize <= 0)
            {
                throw new ArgumentOutOfRangeException("requestedSize");
            }
            ThrowIfDisposed();

            IBsonChunk chunk;
            if (_previousChunkSize == 0 && _initialUnpooledChunkSize != 0)
            {
                chunk = new ByteArrayChunk(_initialUnpooledChunkSize);
            }
            else
            {
                var powerOf2Size = PowerOf2.RoundUpToPowerOf2(_previousChunkSize + 1);
                var chunkSize = Math.Max(Math.Min(powerOf2Size, _maxChunkSize), _minChunkSize);
                chunk = _baseSource.GetChunk(chunkSize);
            }

            _previousChunkSize = chunk.Bytes.Count;
            return chunk;
        }