當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。