當前位置: 首頁>>代碼示例>>C#>>正文


C# Test.ToBson方法代碼示例

本文整理匯總了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()));
        }
開發者ID:modesto,項目名稱:mongo-csharp-driver,代碼行數:29,代碼來源:CSharp104Tests.cs

示例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]);
        }
開發者ID:nickgervasi,項目名稱:mongo-csharp-driver,代碼行數:14,代碼來源:CSharp479Tests.cs

示例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()));
        }
開發者ID:ebix,項目名稱:mongo-csharp-driver,代碼行數:16,代碼來源:CSharp102Tests.cs


注:本文中的System.Test.ToBson方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。