本文整理汇总了C#中BsonDocument.ToDictionary方法的典型用法代码示例。如果您正苦于以下问题:C# BsonDocument.ToDictionary方法的具体用法?C# BsonDocument.ToDictionary怎么用?C# BsonDocument.ToDictionary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BsonDocument
的用法示例。
在下文中一共展示了BsonDocument.ToDictionary方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestToDictionaryOneBinary
public void TestToDictionaryOneBinary()
{
var document = new BsonDocument("x", new BsonBinaryData(new byte[] { 1, 2, 3 }, BsonBinarySubType.Binary));
var dictionary = document.ToDictionary();
Assert.AreEqual(1, dictionary.Count);
Assert.IsInstanceOf<byte[]>(dictionary["x"]);
Assert.IsTrue(new byte[] { 1, 2, 3 }.SequenceEqual((byte[])dictionary["x"]));
}
示例2: TestToDictionaryOneBoolean
public void TestToDictionaryOneBoolean()
{
var document = new BsonDocument("x", true);
var dictionary = document.ToDictionary();
Assert.AreEqual(1, dictionary.Count);
Assert.IsInstanceOf<bool>(dictionary["x"]);
Assert.AreEqual(true, dictionary["x"]);
}
示例3: TestToDictionaryNestedArray
public void TestToDictionaryNestedArray()
{
var document = new BsonDocument
{
{ "x", 1 },
{ "array", new BsonArray { 1, "abc" } }
};
var dictionary = document.ToDictionary();
Assert.AreEqual(2, dictionary.Count);
Assert.IsInstanceOf<int>(dictionary["x"]);
Assert.AreEqual(1, dictionary["x"]);
Assert.IsInstanceOf<object[]>(dictionary["array"]);
var nested = (object[])dictionary["array"];
Assert.IsInstanceOf<int>(nested[0]);
Assert.IsInstanceOf<string>(nested[1]);
Assert.AreEqual(1, nested[0]);
Assert.AreEqual("abc", nested[1]);
}
示例4: TestToDictionaryNestedDocument
public void TestToDictionaryNestedDocument()
{
var document = new BsonDocument
{
{ "x", 1 },
{ "nested", new BsonDocument { { "a", 1 }, { "b", 2 } } }
};
var dictionary = document.ToDictionary();
Assert.AreEqual(2, dictionary.Count);
Assert.IsInstanceOf<int>(dictionary["x"]);
Assert.AreEqual(1, dictionary["x"]);
Assert.IsInstanceOf<Dictionary<string, object>>(dictionary["nested"]);
var nested = (Dictionary<string, object>)dictionary["nested"];
Assert.IsInstanceOf<int>(nested["a"]);
Assert.IsInstanceOf<int>(nested["b"]);
Assert.AreEqual(1, nested["a"]);
Assert.AreEqual(2, nested["b"]);
}
示例5: TestToDictionaryOtherTypes
public void TestToDictionaryOtherTypes()
{
var document = new BsonDocument
{
{ "JavaScript", new BsonJavaScript("x = 1") },
{ "JavaScriptWithScope", new BsonJavaScriptWithScope("x = y", new BsonDocument("y", 1)) },
{ "MaxKey", BsonMaxKey.Value },
{ "MinKey", BsonMinKey.Value },
{ "Null", BsonNull.Value },
{ "RegularExpression", new BsonRegularExpression("abc") },
{ "Symbol", BsonSymbolTable.Lookup("name") },
{ "Timestamp", new BsonTimestamp(123L) },
{ "Undefined", BsonUndefined.Value },
};
var dictionary = document.ToDictionary();
Assert.AreEqual(9, dictionary.Count);
Assert.IsInstanceOf<BsonJavaScript>(dictionary["JavaScript"]);
Assert.IsInstanceOf<BsonJavaScriptWithScope>(dictionary["JavaScriptWithScope"]);
Assert.AreSame(BsonMaxKey.Value, dictionary["MaxKey"]);
Assert.AreSame(BsonMinKey.Value, dictionary["MinKey"]);
Assert.IsNull(dictionary["Null"]);
Assert.IsInstanceOf<BsonRegularExpression>(dictionary["RegularExpression"]);
Assert.IsInstanceOf<BsonSymbol>(dictionary["Symbol"]);
Assert.IsInstanceOf<BsonTimestamp>(dictionary["Timestamp"]);
Assert.AreSame(BsonUndefined.Value, dictionary["Undefined"]);
}
示例6: TestToDictionaryEmpty
public void TestToDictionaryEmpty()
{
var document = new BsonDocument();
var dictionary = document.ToDictionary();
Assert.AreEqual(0, dictionary.Count);
}
示例7: TestToDictionaryOneObjectId
public void TestToDictionaryOneObjectId()
{
var objectId = ObjectId.GenerateNewId();
var hashtable = new BsonDocument("x", objectId);
var dictionary = hashtable.ToDictionary();
Assert.AreEqual(1, dictionary.Count);
Assert.IsInstanceOf<ObjectId>(dictionary["x"]);
Assert.AreEqual(objectId, dictionary["x"]);
}
示例8: TestToDictionaryOneString
public void TestToDictionaryOneString()
{
var document = new BsonDocument("x", "abc");
var dictionary = document.ToDictionary();
Assert.AreEqual(1, dictionary.Count);
Assert.IsInstanceOf<string>(dictionary["x"]);
Assert.AreEqual("abc", dictionary["x"]);
}
示例9: TestToDictionaryOneGuidStandard
public void TestToDictionaryOneGuidStandard()
{
var guid = Guid.NewGuid();
var document = new BsonDocument("x", new BsonBinaryData(guid, GuidRepresentation.Standard));
var dictionary = document.ToDictionary();
Assert.AreEqual(1, dictionary.Count);
Assert.IsInstanceOf<Guid>(dictionary["x"]);
Assert.AreEqual(guid, dictionary["x"]);
}
示例10: TestToDictionaryOneInt64
public void TestToDictionaryOneInt64()
{
var document = new BsonDocument("x", 1L);
var dictionary = document.ToDictionary();
Assert.AreEqual(1, dictionary.Count);
Assert.IsInstanceOf<long>(dictionary["x"]);
Assert.AreEqual(1L, dictionary["x"]);
}
示例11: TestToDictionaryOneDouble
public void TestToDictionaryOneDouble()
{
var document = new BsonDocument("x", 1.0);
var dictionary = document.ToDictionary();
Assert.AreEqual(1, dictionary.Count);
Assert.IsInstanceOf<double>(dictionary["x"]);
Assert.AreEqual(1.0, dictionary["x"]);
}
示例12: TestToDictionaryOneDateTime
public void TestToDictionaryOneDateTime()
{
var utcNow = DateTime.UtcNow;
var utcNowTruncated = utcNow.AddTicks(-(utcNow.Ticks % 10000));
var document = new BsonDocument("x", utcNow);
var dictionary = document.ToDictionary();
Assert.AreEqual(1, dictionary.Count);
Assert.IsInstanceOf<DateTime>(dictionary["x"]);
Assert.AreEqual(DateTimeKind.Utc, ((DateTime)dictionary["x"]).Kind);
Assert.AreEqual(utcNowTruncated, dictionary["x"]);
}
示例13: TestToDictionaryUnsupportedTypes
public void TestToDictionaryUnsupportedTypes()
{
var document = new BsonDocument
{
{ "JavaScript", new BsonJavaScript("x = 1") },
{ "JavaScriptWithScope", new BsonJavaScriptWithScope("x = y", new BsonDocument("y", 1)) },
{ "MaxKey", BsonMaxKey.Value },
{ "MinKey", BsonMinKey.Value },
{ "Null", BsonNull.Value },
{ "RegularExpression", new BsonRegularExpression("abc") },
{ "Symbol", BsonSymbol.Create("name") },
{ "Timestamp", new BsonTimestamp(123L) },
{ "Undefined", BsonUndefined.Value },
};
var dictionary = document.ToDictionary();
Assert.AreEqual(9, dictionary.Count);
Assert.IsNull(dictionary["JavaScript"]);
Assert.IsNull(dictionary["JavaScriptWithScope"]);
Assert.IsNull(dictionary["MaxKey"]);
Assert.IsNull(dictionary["MinKey"]);
Assert.IsNull(dictionary["Null"]);
Assert.IsNull(dictionary["RegularExpression"]);
Assert.IsNull(dictionary["Symbol"]);
Assert.IsNull(dictionary["Timestamp"]);
Assert.IsNull(dictionary["Undefined"]);
}
示例14: TestToDictionaryOneInt32
public void TestToDictionaryOneInt32()
{
var document = new BsonDocument("x", 1);
var dictionary = document.ToDictionary();
Assert.Equal(1, dictionary.Count);
Assert.IsType<int>(dictionary["x"]);
Assert.Equal(1, dictionary["x"]);
}
示例15: TestToDictionaryOneGuidLegacy
public void TestToDictionaryOneGuidLegacy()
{
var guid = Guid.NewGuid();
var document = new BsonDocument("x", new BsonBinaryData(guid, GuidRepresentation.CSharpLegacy));
var dictionary = document.ToDictionary();
Assert.Equal(1, dictionary.Count);
Assert.IsType<Guid>(dictionary["x"]);
Assert.Equal(guid, dictionary["x"]);
}