本文整理汇总了C#中BSONDocument.Set方法的典型用法代码示例。如果您正苦于以下问题:C# BSONDocument.Set方法的具体用法?C# BSONDocument.Set怎么用?C# BSONDocument.Set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BSONDocument
的用法示例。
在下文中一共展示了BSONDocument.Set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InferSchema
public void InferSchema()
{
var doc = new BSONDocument();
doc.Set( new BSONStringElement("FullName", "Alex Bobby") );
doc.Set( new BSONInt32Element("Age", 123) );
doc.Set( new BSONBooleanElement("IsGood", true) );
var c = new RowConverter();
var schema = c.InferSchemaFromBSONDocument(doc);
Assert.AreEqual(3, schema.FieldCount);
Assert.AreEqual(0, schema["FullName"].Order);
Assert.AreEqual(1, schema["Age"].Order);
Assert.AreEqual(2, schema["IsGood"].Order);
Assert.AreEqual(typeof(object), schema["FullName"].NonNullableType);
Assert.AreEqual(typeof(object), schema["Age"].NonNullableType);
Assert.AreEqual(typeof(object), schema["IsGood"].NonNullableType);
var row = new DynamicRow(schema);
c.BSONDocumentToRow(doc, row, null);
Assert.AreEqual("Alex Bobby", row[0]);
Assert.AreEqual(123, row[1]);
Assert.AreEqual(true, row[2]);
Assert.AreEqual("Alex Bobby", row["FullName"]);
Assert.AreEqual(123, row["Age"]);
Assert.AreEqual(true, row["IsGood"]);
}
示例2: WriteBigIntegers
public void WriteBigIntegers(Stream stream)
{
stream.Position = 0;
var root = new BSONDocument();
root.Set(new BSONInt32Element("intMin", int.MinValue));
root.Set(new BSONInt32Element("intMax", int.MaxValue));
root.Set(new BSONInt64Element("longMin", long.MinValue));
root.Set(new BSONInt64Element("longMax", long.MaxValue));
root.WriteAsBSON(stream);
}
示例3: CollectionDrop
public void CollectionDrop()
{
using(var client= new MongoClient("My Test"))
{
var collection = client.DefaultLocalServer["db1"]["ToDrop"];
var doc1 = new BSONDocument();
doc1.Set( new BSONStringElement("_id", "id1"))
.Set( new BSONStringElement("val", "My value"))
.Set( new BSONInt32Element("age", 125));
var r = collection.Insert(doc1);
Assert.AreEqual(1, r.TotalDocumentsAffected);
collection.Drop();
Assert.IsTrue( collection.Disposed );
}
}
示例4: DoConvertCLRtoBSON
/// <summary>
/// override to perform the conversion. the data is never null here, and ref cycles a ruled out
/// </summary>
protected virtual BSONElement DoConvertCLRtoBSON(string name, object data, Type dataType, string targetName)
{
//1 Primitive/direct types
Func<string, object, BSONElement> func;
if (m_CLRtoBSON.TryGetValue(dataType, out func)) return func(name, data);
//2 Enums
if (dataType.IsEnum)
return name != null ? new BSONStringElement(name, data.ToString()) : new BSONStringElement(data.ToString());
//3 Complex Types
if (data is Row)
return this.RowToBSONDocumentElement((Row)data, targetName, name: name);
//IDictionary //must be before IEnumerable
if (data is IDictionary)
{
var dict = (IDictionary)data;
var result = new BSONDocument();
foreach( var key in dict.Keys)
{
var fldName = key.ToString();
var el = ConvertCLRtoBSON(fldName, dict[key], targetName);
result.Set(el);
}
return name != null ? new BSONDocumentElement(name, result) : new BSONDocumentElement(result);
}
//IEnumerable
if (data is IEnumerable)
{
var list = (IEnumerable)data;
List<BSONElement> elements = new List<BSONElement>();
foreach( var obj in list)
{
var el = ConvertCLRtoBSON(null, obj, targetName);
elements.Add(el);
}
var result = name != null ? new BSONArrayElement(name, elements.ToArray()) : new BSONArrayElement(elements.ToArray());
return result;
}
throw new BSONException(StringConsts.CLR_BSON_CONVERSION_TYPE_NOT_SUPPORTED_ERROR.Args(dataType.FullName));
}
示例5: docFromMessage
private BSONDocument docFromMessage(Message msg)
{
var doc = new BSONDocument();
var rc = new RowConverter();
doc.Set(new BSONStringElement("Guid", msg.Guid.ToString("N")));
doc.Set(new BSONStringElement("RelatedTo", msg.RelatedTo.ToString("N")));
doc.Set(new BSONStringElement("Type", msg.Type.ToString()));
doc.Set(new BSONInt32Element("Source", msg.Source));
doc.Set(new BSONInt64Element("TimeStamp", msg.TimeStamp.Ticks));
doc.Set(new BSONStringElement("Host", msg.Host));
doc.Set(new BSONStringElement("From", msg.From));
doc.Set(new BSONStringElement("Topic", msg.Topic));
doc.Set(new BSONStringElement("Text", msg.Text));
doc.Set(new BSONStringElement("Parameters", msg.Parameters));
doc.Set(new BSONStringElement("Exception", msg.Exception.ToMessageWithType()));
doc.Set(new BSONInt32Element("ThreadID", msg.ThreadID));
return doc;
}
示例6: WriteStringInt32DoubleMixedArray
public void WriteStringInt32DoubleMixedArray()
{
using (var stream = new MemoryStream())
using (var reader = new BinaryReader(stream))
{
var root = new BSONDocument();
var array = new BSONElement[] { new BSONStringElement("apple"), new BSONInt32Element(3), new BSONDoubleElement(2.14D) };
root.Set(new BSONArrayElement("stuff", array));
root.WriteAsBSON(stream);
Assert.AreEqual(stream.Position, 48); // ensure document length is 48 bytes
stream.Seek(0, SeekOrigin.Begin);
CollectionAssert.AreEqual(reader.ReadBytes(4), BitConverter.GetBytes(48)); // document's content length is 48
Assert.AreEqual(reader.ReadByte(), (byte)BSONElementType.Array); // element type is array 0x04
CollectionAssert.AreEqual(reader.ReadBytes(5), Encoding.UTF8.GetBytes("stuff")); // element name is 'stuff'
Assert.AreEqual(reader.ReadByte(), (byte)0x00); // string name terminator 0x00 is present
CollectionAssert.AreEqual(reader.ReadBytes(4), BitConverter.GetBytes(36)); // array's content length is 36
Assert.AreEqual(reader.ReadByte(), (byte)BSONElementType.String); // element type is string 0x02
CollectionAssert.AreEqual(reader.ReadBytes(1), Encoding.UTF8.GetBytes("0")); // element name is '0'
Assert.AreEqual(reader.ReadByte(), (byte)0x00); // last byte is terminator 0x00
CollectionAssert.AreEqual(reader.ReadBytes(4), BitConverter.GetBytes(6)); // string content length is 6
CollectionAssert.AreEqual(reader.ReadBytes(5),Encoding.UTF8.GetBytes("apple")); // string content length is 'apple'
Assert.AreEqual(reader.ReadByte(), (byte)0x00); // last byte is terminator 0x00
Assert.AreEqual(reader.ReadByte(), (byte)BSONElementType.Int32); // element type is int32 0x10
CollectionAssert.AreEqual(reader.ReadBytes(1), Encoding.UTF8.GetBytes("1")); // element name is '1'
Assert.AreEqual(reader.ReadByte(), (byte)0x00); // last byte is terminator 0x00
CollectionAssert.AreEqual(reader.ReadBytes(4), BitConverter.GetBytes(3)); // value is 3
Assert.AreEqual(reader.ReadByte(), (byte)BSONElementType.Double); // element type is double 0x01
CollectionAssert.AreEqual(reader.ReadBytes(1), Encoding.UTF8.GetBytes("2")); // element name is '2'
Assert.AreEqual(reader.ReadByte(), (byte)0x00); // last byte is terminator 0x00
CollectionAssert.AreEqual(reader.ReadBytes(8), BitConverter.GetBytes(2.14D)); // value is 2.14
Assert.AreEqual(reader.ReadByte(), (byte)0x00); // ensure last byte is terminator 0x00
Assert.AreEqual(reader.ReadByte(), (byte)0x00); // ensure last byte is terminator 0x00
Assert.AreEqual(stream.Position, 48); // ensure whole document readed
}
}
示例7: WriteStringAndInt32Pair
public void WriteStringAndInt32Pair()
{
using (var stream = new MemoryStream())
using (var reader = new BinaryReader(stream))
{
var root = new BSONDocument();
root.Set(new BSONStringElement("name", "Gagarin"));
root.Set(new BSONInt32Element("birth", 1934));
root.WriteAsBSON(stream);
Assert.AreEqual(stream.Position, 34); // ensure document length is 38 bytes
stream.Seek(0, SeekOrigin.Begin);
CollectionAssert.AreEqual(reader.ReadBytes(sizeof(int)), BitConverter.GetBytes(34)); // ensure content length is 34
Assert.AreEqual(reader.ReadByte(), (byte)BSONElementType.String); // ensure element type is string 0x02
CollectionAssert.AreEqual(reader.ReadBytes(4), Encoding.UTF8.GetBytes("name")); // ensure element name is 'name'
Assert.AreEqual(reader.ReadByte(), (byte)0x00); // ensure string name terminator 0x00 is present
CollectionAssert.AreEqual(reader.ReadBytes(sizeof(int)), BitConverter.GetBytes(8)); // ensure string content length is 8
CollectionAssert.AreEqual(reader.ReadBytes(7), Encoding.UTF8.GetBytes("Gagarin")); // ensure element value is 'Gagarin'
Assert.AreEqual(reader.ReadByte(), (byte)0x00); // ensure string value terminator 0x00 is present
Assert.AreEqual(reader.ReadByte(), (byte)BSONElementType.Int32); // ensure element type is int 0x10
CollectionAssert.AreEqual(reader.ReadBytes(5), Encoding.UTF8.GetBytes("birth")); // ensure element name is 'birth'
Assert.AreEqual(reader.ReadByte(), (byte)0x00); // ensure string name terminator 0x00 is present
CollectionAssert.AreEqual(reader.ReadBytes(4), BitConverter.GetBytes(1934)); // ensure element value is int 1934
Assert.AreEqual(reader.ReadByte(), (byte)0x00); // ensure last byte is terminator 0x00
Assert.AreEqual(stream.Position, 34); // ensure whole document readed
}
}
示例8: WriteSingleString
public void WriteSingleString()
{
using (var stream = new MemoryStream())
using (var reader = new BinaryReader(stream))
{
var root = new BSONDocument();
root.Set(new BSONStringElement("greetings", "Hello World!"));
root.WriteAsBSON(stream);
Assert.AreEqual(stream.Position, 33); // ensure document length is 33 bytes
stream.Seek(0, SeekOrigin.Begin);
CollectionAssert.AreEqual(reader.ReadBytes(sizeof(int)), BitConverter.GetBytes(33)); // ensure content length is 33
Assert.AreEqual(reader.ReadByte(), (byte)BSONElementType.String); // ensure element type is string 0x02
CollectionAssert.AreEqual(reader.ReadBytes(9), Encoding.UTF8.GetBytes("greetings")); // ensure element name is 'greetings'
Assert.AreEqual(reader.ReadByte(), (byte)0x00); // ensure string name terminator 0x00 is present
CollectionAssert.AreEqual(reader.ReadBytes(sizeof(int)), BitConverter.GetBytes(13)); // ensure string content length is 13
CollectionAssert.AreEqual(reader.ReadBytes(12), Encoding.UTF8.GetBytes("Hello World!")); // ensure element value is 'Hello World!'
Assert.AreEqual(reader.ReadByte(), (byte)0x00); // ensure string value terminator 0x00 is present
Assert.AreEqual(reader.ReadByte(), (byte)0x00); // ensure last byte is terminator 0x00
Assert.AreEqual(stream.Position, 33); // ensure whole document readed
}
}
示例9: WriteSingleObjectId
public void WriteSingleObjectId()
{
using (var stream = new MemoryStream())
using (var reader = new BinaryReader(stream))
{
var hex = "507f1f77bcf86cd799439011";
var data = Enumerable.Range(0, hex.Length)
.Where(x => x % 2 == 0)
.Select(x => Convert.ToByte(hex.Substring(x, 2), 16))
.ToArray();
var root = new BSONDocument();
var objectId = new BSONObjectID(data);
root.Set(new BSONObjectIDElement("objectId", objectId));
root.WriteAsBSON(stream);
Assert.AreEqual(stream.Position, 27); // ensure document length is 27 bytes
stream.Seek(0, SeekOrigin.Begin);
CollectionAssert.AreEqual(reader.ReadBytes(4), BitConverter.GetBytes(27)); // content length is 27
Assert.AreEqual(reader.ReadByte(), (byte)BSONElementType.ObjectID); // element type is objectID 0x07
CollectionAssert.AreEqual(reader.ReadBytes(8), Encoding.UTF8.GetBytes("objectId")); // element name is 'objectId'
Assert.AreEqual(reader.ReadByte(), (byte)0x00); // string name terminator 0x00 is present
CollectionAssert.AreEqual(reader.ReadBytes(12), data); // byte content is correct
Assert.AreEqual(reader.ReadByte(), (byte)0x00); // ensure last byte is terminator 0x00
Assert.AreEqual(stream.Position, 27); // ensure whole document readed
}
}
示例10: WriteSingleBinaryData
public void WriteSingleBinaryData()
{
using (var stream = new MemoryStream())
using (var reader = new BinaryReader(stream))
{
var data = Encoding.UTF8.GetBytes("This is binary data");
var root = new BSONDocument();
var binary = new BSONBinary(BSONBinaryType.BinaryOld, data);
root.Set(new BSONBinaryElement("binary", binary));
root.WriteAsBSON(stream);
Assert.AreEqual(stream.Position, 37); // ensure document length is 37 bytes
stream.Seek(0, SeekOrigin.Begin);
CollectionAssert.AreEqual(reader.ReadBytes(4), BitConverter.GetBytes(37)); // content length is 37
Assert.AreEqual(reader.ReadByte(), (byte)BSONElementType.Binary); // element type is binary 0x05
CollectionAssert.AreEqual(reader.ReadBytes(6), Encoding.UTF8.GetBytes("binary")); // element name is 'binary'
Assert.AreEqual(reader.ReadByte(), (byte)0x00); // string name terminator 0x00 is present
CollectionAssert.AreEqual(reader.ReadBytes(4), BitConverter.GetBytes(19)); // byte length is 19
Assert.AreEqual(reader.ReadByte(), (byte)BSONBinaryType.BinaryOld); // binary type is BinaryOld 0x02
CollectionAssert.AreEqual(reader.ReadBytes(19), data); // byte content is correct
Assert.AreEqual(reader.ReadByte(), (byte)0x00); // ensure last byte is terminator 0x00
Assert.AreEqual(stream.Position, 37); // ensure whole document readed
}
}
示例11: WriteReadStringsWithDifferentLengths
public void WriteReadStringsWithDifferentLengths()
{
Parallel.For(0, 10*1024, i =>
{
using (var stream = new MemoryStream())
using (var reader = new BinaryReader(stream))
{
// Write
var root = new BSONDocument();
var value = new string('a', i);
root.Set(new BSONStringElement("vary", value));
root.WriteAsBSON(stream);
Assert.AreEqual(stream.Position, 16 + i); // ensure document length is 16+i bytes
stream.Seek(0, SeekOrigin.Begin);
CollectionAssert.AreEqual(reader.ReadBytes(4), BitConverter.GetBytes(16 + i)); // content length is 16+i
Assert.AreEqual(reader.ReadByte(), (byte) BSONElementType.String); // element type is string 0x02
CollectionAssert.AreEqual(reader.ReadBytes(4), Encoding.UTF8.GetBytes("vary")); // element name is 'vary'
Assert.AreEqual(reader.ReadByte(), (byte) 0x00); // string name terminator 0x00 is present
CollectionAssert.AreEqual(reader.ReadBytes(4), BitConverter.GetBytes(i + 1)); // string content length is 13
CollectionAssert.AreEqual(reader.ReadBytes(i), Encoding.UTF8.GetBytes(value)); // element value is value
Assert.AreEqual(reader.ReadByte(), (byte) 0x00); // string value terminator 0x00 is present
Assert.AreEqual(reader.ReadByte(), (byte) 0x00); // last byte is terminator 0x00
Assert.AreEqual(stream.Position, 16 + i); // ensure whole document readed
stream.Position = 0;
// Read
var deser = new BSONDocument(stream);
Assert.AreEqual(deser.ByteSize, 16 + i);
Assert.AreEqual(deser.Count, 1);
var element = deser["vary"] as BSONStringElement;
Assert.IsNotNull(element);
Assert.AreEqual(element.ElementType, BSONElementType.String);
Assert.AreEqual(element.Name, "vary");
Assert.AreEqual(element.Value, value);
Assert.AreEqual(stream.Position, 16 + i); // ensure whole document readed
stream.Position = 0;
}
});
}
示例12: WriteReadSingleDateTime
public void WriteReadSingleDateTime()
{
using (var stream = new MemoryStream())
{
var now = new DateTime(2015, 08, 26, 14, 23, 56);
var bson1 = new BSONDocument();
bson1.Set(new BSONDateTimeElement("now", now));
bson1.WriteAsBSON(stream);
stream.Position = 0;
var bson2 = new BSONDocument(stream);
var now1 = ((BSONDateTimeElement)bson1["now"]).Value;
var now2 = ((BSONDateTimeElement)bson2["now"]).Value;
Console.WriteLine("{0} {1}", now1, now1.Kind);
Console.WriteLine("{0} {1}", now2, now2.Kind);
Assert.AreEqual(now1.ToUniversalTime(), now2);
}
}
示例13: WriteNestedDocument
public void WriteNestedDocument()
{
using (var stream = new MemoryStream())
using (var reader = new BinaryReader(stream))
{
var root = new BSONDocument();
var nested = new BSONDocument();
nested.Set(new BSONStringElement("capital", "Moscow"));
root.Set(new BSONDocumentElement("nested", nested));
root.WriteAsBSON(stream);
Assert.AreEqual(stream.Position, 38); // ensure document length is 38 bytes
stream.Seek(0, SeekOrigin.Begin);
CollectionAssert.AreEqual(reader.ReadBytes(sizeof(int)), BitConverter.GetBytes(38)); // content length is 38
Assert.AreEqual(reader.ReadByte(), (byte)BSONElementType.Document); // element type is document 0x03
CollectionAssert.AreEqual(reader.ReadBytes(6), Encoding.UTF8.GetBytes("nested")); // element name is 'nested'
Assert.AreEqual(reader.ReadByte(), (byte)0x00); // string name terminator 0x00 is present
CollectionAssert.AreEqual(reader.ReadBytes(4), BitConverter.GetBytes(25)); // nested document length is 25
Assert.AreEqual(reader.ReadByte(), (byte)BSONElementType.String); // element type is string 0x02
CollectionAssert.AreEqual(reader.ReadBytes(7), Encoding.UTF8.GetBytes("capital")); // element name is 'capital'
Assert.AreEqual(reader.ReadByte(), (byte)0x00); // string name terminator 0x00 is present
CollectionAssert.AreEqual(reader.ReadBytes(4), BitConverter.GetBytes(7)); // string length is 7
CollectionAssert.AreEqual(reader.ReadBytes(6), Encoding.UTF8.GetBytes("Moscow")); // element value is 'Moscow'
Assert.AreEqual(reader.ReadByte(), (byte)0x00); // last byte is terminator 0x00
Assert.AreEqual(reader.ReadByte(), (byte)0x00); // last byte is terminator 0x00
Assert.AreEqual(reader.ReadByte(), (byte)0x00); // last byte is terminator 0x00
Assert.AreEqual(stream.Position, 38); // ensure whole document readed
}
}
示例14: WriteInt32Array
public void WriteInt32Array()
{
using (var stream = new MemoryStream())
using (var reader = new BinaryReader(stream))
{
var root = new BSONDocument();
var array = new[] { new BSONInt32Element(1963), new BSONInt32Element(1984), new BSONInt32Element(2015) };
root.Set(new BSONArrayElement("years", array));
root.WriteAsBSON(stream);
Assert.AreEqual(stream.Position, 38); // ensure document length is 38 bytes
stream.Seek(0, SeekOrigin.Begin);
CollectionAssert.AreEqual(reader.ReadBytes(4), BitConverter.GetBytes(38)); // document's content length is 38
Assert.AreEqual(reader.ReadByte(), (byte)BSONElementType.Array); // element type is array 0x04
CollectionAssert.AreEqual(reader.ReadBytes(5), Encoding.UTF8.GetBytes("years")); // element name is 'years'
Assert.AreEqual(reader.ReadByte(), (byte)0x00); // string name terminator 0x00 is present
CollectionAssert.AreEqual(reader.ReadBytes(4), BitConverter.GetBytes(26)); // array's content length is 26
Assert.AreEqual(reader.ReadByte(), (byte)BSONElementType.Int32); // element type is int32 0x10
CollectionAssert.AreEqual(reader.ReadBytes(1), Encoding.UTF8.GetBytes("0")); // element name is '0'
Assert.AreEqual(reader.ReadByte(), (byte)0x00); // last byte is terminator 0x00
CollectionAssert.AreEqual(reader.ReadBytes(4), BitConverter.GetBytes(1963)); // value is 1963
Assert.AreEqual(reader.ReadByte(), (byte)BSONElementType.Int32); // element type is int32 0x10
CollectionAssert.AreEqual(reader.ReadBytes(1), Encoding.UTF8.GetBytes("1")); // element name is '1'
Assert.AreEqual(reader.ReadByte(), (byte)0x00); // last byte is terminator 0x00
CollectionAssert.AreEqual(reader.ReadBytes(4), BitConverter.GetBytes(1984)); // value is 1984
Assert.AreEqual(reader.ReadByte(), (byte)BSONElementType.Int32); // element type is int32 0x10
CollectionAssert.AreEqual(reader.ReadBytes(1), Encoding.UTF8.GetBytes("2")); // element name is '2'
Assert.AreEqual(reader.ReadByte(), (byte)0x00); // last byte is terminator 0x00
CollectionAssert.AreEqual(reader.ReadBytes(4), BitConverter.GetBytes(2015)); // value is 2015
Assert.AreEqual(reader.ReadByte(), (byte)0x00); // ensure last byte is terminator 0x00
Assert.AreEqual(reader.ReadByte(), (byte)0x00); // ensure last byte is terminator 0x00
Assert.AreEqual(stream.Position, 38); // ensure whole document readed
}
}
示例15: WriteBigIntegers
public void WriteBigIntegers()
{
using (var stream = new MemoryStream())
using (var reader = new BinaryReader(stream))
{
var root = new BSONDocument();
root.Set(new BSONInt32Element("intMin", int.MinValue));
root.Set(new BSONInt32Element("intMax", int.MaxValue));
root.Set(new BSONInt64Element("longMin", long.MinValue));
root.Set(new BSONInt64Element("longMax", long.MaxValue));
root.WriteAsBSON(stream);
Assert.AreEqual(stream.Position, 63); // ensure document length is 63 bytes
stream.Seek(0, SeekOrigin.Begin);
CollectionAssert.AreEqual(reader.ReadBytes(4), BitConverter.GetBytes(63)); // content length is 63
Assert.AreEqual(reader.ReadByte(), (byte)BSONElementType.Int32); // element type is int32 0x10
CollectionAssert.AreEqual(reader.ReadBytes(6), Encoding.UTF8.GetBytes("intMin")); // element name is 'intMin'
Assert.AreEqual(reader.ReadByte(), (byte)0x00); // string name terminator 0x00 is present
CollectionAssert.AreEqual(reader.ReadBytes(4), BitConverter.GetBytes(int.MinValue)); // element value is int.MinValue
Assert.AreEqual(reader.ReadByte(), (byte)BSONElementType.Int32); // element type is int32 0x10
CollectionAssert.AreEqual(reader.ReadBytes(6), Encoding.UTF8.GetBytes("intMax")); // element name is 'intMax'
Assert.AreEqual(reader.ReadByte(), (byte)0x00); // string name terminator 0x00 is present
CollectionAssert.AreEqual(reader.ReadBytes(4), BitConverter.GetBytes(int.MaxValue)); // element value is int.MaxValue
Assert.AreEqual(reader.ReadByte(), (byte)BSONElementType.Int64); // element type is int64 0x12
CollectionAssert.AreEqual(reader.ReadBytes(7), Encoding.UTF8.GetBytes("longMin")); // element name is 'longMin'
Assert.AreEqual(reader.ReadByte(), (byte)0x00); // string name terminator 0x00 is present
CollectionAssert.AreEqual(reader.ReadBytes(8), BitConverter.GetBytes(long.MinValue)); // element value is long.MinValue
Assert.AreEqual(reader.ReadByte(), (byte)BSONElementType.Int64); // element type is int64 0x12
CollectionAssert.AreEqual(reader.ReadBytes(7), Encoding.UTF8.GetBytes("longMax")); // element name is 'longMax'
Assert.AreEqual(reader.ReadByte(), (byte)0x00); // string name terminator 0x00 is present
CollectionAssert.AreEqual(reader.ReadBytes(8), BitConverter.GetBytes(long.MaxValue)); // element value is long.MaxValue
Assert.AreEqual(reader.ReadByte(), (byte)0x00); // ensure last byte is terminator 0x00
Assert.AreEqual(stream.Position, 63); // ensure whole document readed
}
}