当前位置: 首页>>代码示例>>C#>>正文


C# IO.BsonStreamAdapter类代码示例

本文整理汇总了C#中MongoDB.Bson.IO.BsonStreamAdapter的典型用法代码示例。如果您正苦于以下问题:C# BsonStreamAdapter类的具体用法?C# BsonStreamAdapter怎么用?C# BsonStreamAdapter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


BsonStreamAdapter类属于MongoDB.Bson.IO命名空间,在下文中一共展示了BsonStreamAdapter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BaseStream_should_return_expected_resut

        public void BaseStream_should_return_expected_resut()
        {
            var stream = Substitute.For<Stream>();
            var subject = new BsonStreamAdapter(stream);

            var result = subject.BaseStream;

            result.Should().Be(stream);
        }
开发者ID:fir3pho3nixx,项目名称:mongo-csharp-driver,代码行数:9,代码来源:BsonStreamAdapterTests.cs

示例2: BaseStream_should_return_expected_resut

        public void BaseStream_should_return_expected_resut()
        {
            var mockStream = new Mock<Stream>();
            var subject = new BsonStreamAdapter(mockStream.Object);

            var result = subject.BaseStream;

            result.Should().Be(mockStream.Object);
        }
开发者ID:mfidemraizer,项目名称:mongo-csharp-driver,代码行数:9,代码来源:BsonStreamAdapterTests.cs

示例3: BaseStream_should_throw_when_subject_is_disposed

        public void BaseStream_should_throw_when_subject_is_disposed()
        {
            var stream = Substitute.For<Stream>();
            var subject = new BsonStreamAdapter(stream);
            subject.Dispose();

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

            action.ShouldThrow<ObjectDisposedException>().And.ObjectName.Should().Be("BsonStreamAdapter");
        }
开发者ID:fir3pho3nixx,项目名称:mongo-csharp-driver,代码行数:10,代码来源:BsonStreamAdapterTests.cs

示例4: CanRead_should_call_wrapped_stream

        public void CanRead_should_call_wrapped_stream(
            [Values(false, true)]
            bool canRead)
        {
            var mockStream = new Mock<Stream>();
            var subject = new BsonStreamAdapter(mockStream.Object);
            mockStream.SetupGet(s => s.CanRead).Returns(canRead);

            var result = subject.CanRead;

            result.Should().Be(canRead);
            mockStream.VerifyGet(s => s.CanRead, Times.Once);
        }
开发者ID:XiaoPingJiang,项目名称:mongo-csharp-driver,代码行数:13,代码来源:BsonStreamAdapterTests.cs

示例5: BeginRead_should_throw_when_subject_is_diposed

        public void BeginRead_should_throw_when_subject_is_diposed()
        {
            var stream = Substitute.For<Stream>();
            var subject = new BsonStreamAdapter(stream);
            var buffer = new byte[0];
            var offset = 1;
            var count = 2;
            var callback = Substitute.For<AsyncCallback>();
            var state = new object();
            subject.Dispose();

            Action action = () => subject.BeginRead(buffer, offset, count, callback, state);

            action.ShouldThrow<ObjectDisposedException>().And.ObjectName.Should().Be("BsonStreamAdapter");
        }
开发者ID:fir3pho3nixx,项目名称:mongo-csharp-driver,代码行数:15,代码来源:BsonStreamAdapterTests.cs

示例6: Assert

        private void Assert(BsonTrie<int> trie, string name)
        {
            var subject = new TrieNameDecoder<int>(trie);

            using (var memoryStream = new MemoryStream())
            using (var bsonStream = new BsonStreamAdapter(memoryStream))
            {
                bsonStream.WriteCString(name);
                bsonStream.WriteInt32(20);
                bsonStream.Position = 0;

                var result = subject.Decode(bsonStream, Utf8Encodings.Strict);

                result.Should().Be(name);
            }
        }
开发者ID:narutoswj,项目名称:mongo-csharp-driver,代码行数:16,代码来源:TrieNameDecoderTests.cs

示例7: BeginRead_should_call_wrapped_stream

        public void BeginRead_should_call_wrapped_stream()
        {
            var mockStream = new Mock<Stream>();
            var subject = new BsonStreamAdapter(mockStream.Object);
            var buffer = new byte[0];
            var offset = 1;
            var count = 2;
            var mockCallback = new Mock<AsyncCallback>();
            var state = new object();
            var mockAsyncResult = new Mock<IAsyncResult>();
            mockStream.Setup(s => s.BeginRead(buffer, offset, count, mockCallback.Object, state)).Returns(mockAsyncResult.Object);

            var result = subject.BeginRead(buffer, offset, count, mockCallback.Object, state);

            result.Should().BeSameAs(mockAsyncResult.Object);
            mockStream.Verify(s => s.BeginRead(buffer, offset, count, mockCallback.Object, state), Times.Once);
        }
开发者ID:mfidemraizer,项目名称:mongo-csharp-driver,代码行数:17,代码来源:BsonStreamAdapterTests.cs

示例8: BeginRead_should_call_wrapped_stream

        public void BeginRead_should_call_wrapped_stream()
        {
            var stream = Substitute.For<Stream>();
            var subject = new BsonStreamAdapter(stream);
            var buffer = new byte[0];
            var offset = 1;
            var count = 2;
            var callback = Substitute.For<AsyncCallback>();
            var state = new object();
            var asyncResult = Substitute.For<IAsyncResult>();
            stream.BeginRead(buffer, offset, count, callback, state).Returns(asyncResult);

            var result = subject.BeginRead(buffer, offset, count, callback, state);

            result.Should().Be(asyncResult);
            stream.Received(1).BeginRead(buffer, offset, count, callback, state);
        }
开发者ID:fir3pho3nixx,项目名称:mongo-csharp-driver,代码行数:17,代码来源:BsonStreamAdapterTests.cs

示例9: BackpatchSize_should_backpatch_the_size

        public void BackpatchSize_should_backpatch_the_size(
            [Values(0, 1, 5)]
            int startPosition)
        {
            var bytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            var length = bytes.Length - startPosition;
            var expectedBytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            Array.Copy(BitConverter.GetBytes(length), 0, expectedBytes, startPosition, 4);

            using (var memoryStream = new MemoryStream())
            using (var stream = new BsonStreamAdapter(memoryStream))
            {
                stream.WriteBytes(bytes, 0, bytes.Length);
                var position = stream.Position;

                stream.BackpatchSize(startPosition);

                memoryStream.ToArray().Should().Equal(expectedBytes);
                stream.Position.Should().Be(position);
            }
        }
开发者ID:amitapl,项目名称:mongo-csharp-driver,代码行数:21,代码来源:BsonStreamExtensionsTests.cs

示例10: ReadObjectId_should_be_big_endian

        public void ReadObjectId_should_be_big_endian()
        {
            var bytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
            var stream = new MemoryStream(bytes);
            var subject = new BsonStreamAdapter(stream);
            var expectedResult = new ObjectId(0x01020304, 0x050607, 0x0809, 0x0a0b0c);

            var result = subject.ReadObjectId();

            result.Should().Be(expectedResult);
        }
开发者ID:fir3pho3nixx,项目名称:mongo-csharp-driver,代码行数:11,代码来源:BsonStreamAdapterTests.cs

示例11: ReadInt64_should_return_expected_result

        public void ReadInt64_should_return_expected_result(
            [Values(-1, 0, 1, long.MaxValue, long.MinValue)]
            long value)
        {
            var bytes = BitConverter.GetBytes(value);
            var stream = new MemoryStream(bytes);
            var subject = new BsonStreamAdapter(stream);

            var result = subject.ReadInt64();

            result.Should().Be(value);
            subject.Position.Should().Be(8);
        }
开发者ID:fir3pho3nixx,项目名称:mongo-csharp-driver,代码行数:13,代码来源:BsonStreamAdapterTests.cs

示例12: ReadInt64_should_be_little_endian

        public void ReadInt64_should_be_little_endian()
        {
            var bytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
            var stream = new MemoryStream(bytes);
            var subject = new BsonStreamAdapter(stream);

            var result = subject.ReadInt64();

            result.Should().Be(0x0807060504030201);
        }
开发者ID:fir3pho3nixx,项目名称:mongo-csharp-driver,代码行数:10,代码来源:BsonStreamAdapterTests.cs

示例13: ReadDouble_should_return_expected_result

        public void ReadDouble_should_return_expected_result(
            [Values(-1.0, 0.0, 1.0, double.Epsilon, double.MaxValue, double.MinValue, double.NaN, double.NegativeInfinity, double.PositiveInfinity)]
            double value
            )
        {
            var bytes = BitConverter.GetBytes(value);
            var stream = new MemoryStream(bytes);
            var subject = new BsonStreamAdapter(stream);

            var result = subject.ReadDouble();

            result.Should().Be(value);
            subject.Position.Should().Be(8);
        }
开发者ID:fir3pho3nixx,项目名称:mongo-csharp-driver,代码行数:14,代码来源:BsonStreamAdapterTests.cs

示例14: Length_get_should_call_wrapped_stream

        public void Length_get_should_call_wrapped_stream(
            [Values(0L, 1L, 2L)]
            long length)
        {
            var stream = Substitute.For<Stream>();
            var subject = new BsonStreamAdapter(stream);
            stream.Length.Returns(length);

            var result = subject.Length;

            result.Should().Be(length);
            var temp = stream.Received(1).Length;
        }
开发者ID:fir3pho3nixx,项目名称:mongo-csharp-driver,代码行数:13,代码来源:BsonStreamAdapterTests.cs

示例15: ReadCStringBytes_should_throw_when_terminating_null_byte_is_missing

        public void ReadCStringBytes_should_throw_when_terminating_null_byte_is_missing()
        {
            var bytes = new byte[] { 0, 97, 98 };
            var stream = new MemoryStream(bytes);
            var subject = new BsonStreamAdapter(stream);
            subject.SetLength(3);
            subject.Position = 1;

            Action action = () => subject.ReadCStringBytes();

            action.ShouldThrow<EndOfStreamException>();
        }
开发者ID:fir3pho3nixx,项目名称:mongo-csharp-driver,代码行数:12,代码来源:BsonStreamAdapterTests.cs


注:本文中的MongoDB.Bson.IO.BsonStreamAdapter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。