• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# IO.BsonStreamAdapter类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: ReadString_should_throw_when_subject_is_disposed

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

            Action action = () => subject.ReadString(Utf8Encodings.Strict);

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


示例17: ReadTimeout_get_should_call_wrapped_stream

        public void ReadTimeout_get_should_call_wrapped_stream(
            [Values(0, 1, 2)]
            int readTimeout)
        {
            var stream = Substitute.For<Stream>();
            var subject = new BsonStreamAdapter(stream);
            stream.ReadTimeout.Returns(readTimeout);

            var result = subject.ReadTimeout;

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


示例18: ReadString_should_return_expected_result

        public void ReadString_should_return_expected_result(byte[] bytes, string expectedResult)
        {
            var stream = new MemoryStream(bytes);
            var subject = new BsonStreamAdapter(stream);

            var result = subject.ReadString(Utf8Encodings.Strict);

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


示例19: ReadObjectId_should_return_expected_result

        public void ReadObjectId_should_return_expected_result()
        {
            var objectId = ObjectId.GenerateNewId();
            var bytes = objectId.ToByteArray();
            var stream = new MemoryStream(bytes);
            var subject = new BsonStreamAdapter(stream);

            var result = subject.ReadObjectId();

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


示例20: Read_should_call_wrapped_stream

        public void Read_should_call_wrapped_stream()
        {
            var stream = Substitute.For<Stream>();
            var subject = new BsonStreamAdapter(stream);
            var buffer = new byte[3];
            var offset = 1;
            var count = 2;
            var numberOfBytesRead = 1;
            stream.Read(buffer, offset, count).Returns(numberOfBytesRead);

            var result = subject.Read(buffer, offset, count);

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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# IO.BsonWriter类代码示例发布时间:2022-05-26
下一篇:
C# IO.BsonReader类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap