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"); }
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); }
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); }
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); }
/// <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); }
public void Disposed_can_be_called_more_than_once() { var subject = new ByteArrayChunk(1); subject.Dispose(); subject.Dispose(); }
public Reflector(ByteArrayChunk instance) { _instance = instance; }
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); }
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(); }
public void Dispose_should_dispose_subject() { var subject = new ByteArrayChunk(1); subject.Dispose(); var reflector = new Reflector(subject); reflector._disposed.Should().BeTrue(); }
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; } } }
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); }
private SingleChunkBuffer CreateSubject(int size = 0, int? length = null, bool isReadOnly = false) { var chunk = new ByteArrayChunk(size); return new SingleChunkBuffer(chunk, length ?? size, isReadOnly); }
private SingleChunkBuffer CreateSubject(byte[] bytes, int? length = null, bool isReadOnly = false) { var chunk = new ByteArrayChunk(bytes); return new SingleChunkBuffer(chunk, length ?? bytes.Length, isReadOnly); }
/// <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; }