本文整理汇总了C#中System.Test.ToBson方法的典型用法代码示例。如果您正苦于以下问题:C# Test.ToBson方法的具体用法?C# Test.ToBson怎么用?C# Test.ToBson使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Test
的用法示例。
在下文中一共展示了Test.ToBson方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestClassMap
public void TestClassMap()
{
// this test passes normally when the Test class is automapped
// uncomment all or parts of the class map initialization code to test
// the exceptions thrown for each non-compliant field or property
if (firstTime) {
BsonClassMap.RegisterClassMap<Test>(cm => {
cm.AutoMap();
// cm.MapField("literal");
// cm.MapField("readOnly");
// cm.MapField("notfound");
// cm.MapProperty("GetOnly");
// cm.MapProperty("SetOnly");
// cm.MapProperty("notfound");
// cm.MapMember(null);
});
firstTime = false;
}
var test = new Test("x") { SetOnly = "y" };
var json = test.ToJson();
var expected = "{ '_id' : { '$oid' : '000000000000000000000000' } }".Replace("'", "\"");
// Assert.AreEqual(expected, json);
var bson = test.ToBson();
var rehydrated = BsonSerializer.Deserialize<Test>(bson);
Assert.IsTrue(bson.SequenceEqual(rehydrated.ToBson()));
}
示例2: TestRoundTripping
public void TestRoundTripping()
{
var id1 = ObjectId.GenerateNewId().ToString();
var id2 = ObjectId.GenerateNewId().ToString();
var test = new Test();
test.OtherIds = new string[] { id1, id2 };
var bson = test.ToBson();
var rehydrated = BsonSerializer.Deserialize<Test>(bson);
Assert.AreEqual(id1, test.OtherIds[0]);
Assert.AreEqual(id2, test.OtherIds[1]);
}
示例3: TestClassMap
public void TestClassMap() {
var classMap = BsonClassMap.LookupClassMap(typeof(Test));
Assert.AreEqual(2, classMap.MemberMaps.Count());
Assert.IsTrue(classMap.MemberMaps.Any(m => m.MemberName == "Id"));
Assert.IsTrue(classMap.MemberMaps.Any(m => m.MemberName == "Normal"));
Assert.AreEqual("Id", classMap.IdMemberMap.MemberName);
var test = new Test { Normal = "normal" };
var json = test.ToJson();
var expected = "{ '_id' : { '$oid' : '000000000000000000000000' }, 'Normal' : 'normal' }".Replace("'", "\"");
Assert.AreEqual(expected, json);
var bson = test.ToBson();
var rehydrated = BsonSerializer.Deserialize<Test>(bson);
Assert.IsTrue(bson.SequenceEqual(rehydrated.ToBson()));
}