本文整理汇总了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);
}
示例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);
}
示例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");
}
示例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);
}
示例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");
}
示例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);
}
}
示例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);
}
示例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);
}
示例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);
}
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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>();
}