コード例 #1
0
        public void GetChunk_should_throw_when_subject_is_disposed()
        {
            var baseSource = Substitute.For<IBsonChunkSource>();
            var subject = new OutputBufferChunkSource(baseSource);
            subject.Dispose();

            Action action = () => subject.GetChunk(1);
 
            action.ShouldThrow<ObjectDisposedException>().And.ObjectName.Should().Be("OutputBufferChunkSource");
       }
コード例 #2
0
        public void GetChunk_should_return_expected_result_when_initialUnpooledChunkSize_is_zero(int numberOfCalls, int[] expectedRequestSizes)
        {
            var baseSource = Substitute.For<IBsonChunkSource>();
            baseSource.GetChunk(Arg.Any<int>()).Returns(x =>
            {
                var requestedSize = (int)x[0];
                return new ByteArrayChunk(requestedSize);
            });
            var subject = new OutputBufferChunkSource(baseSource, initialUnpooledChunkSize: 0, minChunkSize: 4, maxChunkSize: 32);

            for (var n = 0; n < numberOfCalls; n++)
            {
                var result = subject.GetChunk(1);
                result.Bytes.Count.Should().Be(expectedRequestSizes[n]);
            }

            baseSource.Received(numberOfCalls).GetChunk(Arg.Any<int>());
            foreach (var expectedRequestSize in expectedRequestSizes)
            {
                var requiredNumberOfCalls = expectedRequestSizes.Count(s => s == expectedRequestSize);
                baseSource.Received(requiredNumberOfCalls).GetChunk(expectedRequestSize);
            }
        }
コード例 #3
0
        public void GetChunk_should_throw_when_requestedSize_is_less_than_or_equal_to_zero(
            [Values(-1, 0)]
            int requestedSize)
        {
            var baseSource = Substitute.For<IBsonChunkSource>();
            var subject = new OutputBufferChunkSource(baseSource);

            Action action = () => subject.GetChunk(requestedSize);

            action.ShouldThrow<ArgumentOutOfRangeException>().And.ParamName.Should().Be("requestedSize");
        }
コード例 #4
0
        public void GetChunk_should_return_expected_result_when_initialUnpooledChunkSize_is_zero(int numberOfCalls, int[] expectedRequestSizes)
        {
            var mockBaseSource = new Mock<IBsonChunkSource>();
            mockBaseSource.Setup(s => s.GetChunk(It.IsAny<int>())).Returns((int requestedSize) => new ByteArrayChunk(requestedSize));
            var subject = new OutputBufferChunkSource(mockBaseSource.Object, initialUnpooledChunkSize: 0, minChunkSize: 4, maxChunkSize: 32);

            for (var n = 0; n < numberOfCalls; n++)
            {
                var result = subject.GetChunk(1);
                result.Bytes.Count.Should().Be(expectedRequestSizes[n]);
            }

            mockBaseSource.Verify(s => s.GetChunk(It.IsAny<int>()), Times.Exactly(numberOfCalls));
            foreach (var expectedRequestSize in expectedRequestSizes)
            {
                var requiredNumberOfCalls = expectedRequestSizes.Count(s => s == expectedRequestSize);
                mockBaseSource.Verify(s => s.GetChunk(expectedRequestSize), Times.Exactly(requiredNumberOfCalls));
            }
        }