当前位置: 首页>>代码示例>>C#>>正文


C# TestClass.ToBson方法代码示例

本文整理汇总了C#中TestClass.ToBson方法的典型用法代码示例。如果您正苦于以下问题:C# TestClass.ToBson方法的具体用法?C# TestClass.ToBson怎么用?C# TestClass.ToBson使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TestClass的用法示例。


在下文中一共展示了TestClass.ToBson方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestNull

        public void TestNull()
        {
            var obj = new TestClass { Addresses = null };
            var json = obj.ToJson();
            var expected = "{ 'Addresses' : null }".Replace("'", "\"");
            Assert.AreEqual(expected, json);

            var bson = obj.ToBson();
            var rehydrated = BsonSerializer.Deserialize<TestClass>(bson);
            Assert.IsTrue(bson.SequenceEqual(rehydrated.ToBson()));
        }
开发者ID:niemyjski,项目名称:mongo-csharp-driver,代码行数:11,代码来源:GenericEnumerableSerializerTests.cs

示例2: TestNotEmpty

        public void TestNotEmpty()
        {
            var obj = new TestClass(new BsonArray { 1, 2 });
            var json = obj.ToJson();
            var expected = "{ 'B' : #, 'V' : # }".Replace("#", "[1, 2]").Replace("'", "\"");
            Assert.Equal(expected, json);

            var bson = obj.ToBson();
            var rehydrated = BsonSerializer.Deserialize<TestClass>(bson);
            Assert.True(bson.SequenceEqual(rehydrated.ToBson()));
        }
开发者ID:RavenZZ,项目名称:MDRelation,代码行数:11,代码来源:BsonValueSerializerTests.cs

示例3: TestNull

        public void TestNull()
        {
            var obj = new TestClass(null);
            var json = obj.ToJson();
            var expected = "{ 'B' : #, 'V' : # }".Replace("#", "{ '_csharpnull' : true }").Replace("'", "\"");
            Assert.Equal(expected, json);

            var bson = obj.ToBson();
            var rehydrated = BsonSerializer.Deserialize<TestClass>(bson);
            Assert.Equal(null, rehydrated.B);
            Assert.Equal(null, rehydrated.V);
            Assert.True(bson.SequenceEqual(rehydrated.ToBson()));
        }
开发者ID:RavenZZ,项目名称:MDRelation,代码行数:13,代码来源:BsonValueSerializerTests.cs

示例4: TestTrue

        public void TestTrue()
        {
            var obj = new TestClass
            {
                N = true, B = true, D128 = true, D = true, I = true, L = true, S = true
            };
            var json = obj.ToJson();
            var expected = "{ 'N' : true, 'B' : true, 'D128' : NumberDecimal('1'), 'D' : 1.0, 'I' : 1, 'L' : NumberLong(1), 'S' : 'true' }".Replace("'", "\"");
            Assert.Equal(expected, json);

            var bson = obj.ToBson();
            var rehydrated = BsonSerializer.Deserialize<TestClass>(bson);
            Assert.True(bson.SequenceEqual(rehydrated.ToBson()));
        }
开发者ID:mfidemraizer,项目名称:mongo-csharp-driver,代码行数:14,代码来源:BsonPrimitiveSerializerTests.cs

示例5: TestFalse

        public void TestFalse()
        {
            var obj = new TestClass
            {
                N = false, B = false, D128 = false, D = false, I = false, L = false, S = false
            };
            var json = obj.ToJson();
            var expected = "{ 'N' : false, 'B' : false, 'D128' : NumberDecimal('0'), 'D' : 0.0, 'I' : 0, 'L' : NumberLong(0), 'S' : 'false' }".Replace("'", "\"");
            Assert.Equal(expected, json);

            var bson = obj.ToBson();
            var rehydrated = BsonSerializer.Deserialize<TestClass>(bson);
            Assert.True(bson.SequenceEqual(rehydrated.ToBson()));
        }
开发者ID:mfidemraizer,项目名称:mongo-csharp-driver,代码行数:14,代码来源:BsonPrimitiveSerializerTests.cs

示例6: TestLength0

        public void TestLength0()
        {
            var obj = new TestClass
            {
                B = new BitArray(new bool[0]),
                S = new BitArray(new bool[0])
            };
            var json = obj.ToJson();
            var expected = "{ 'B' : new BinData(0, ''), 'S' : '' }".Replace("'", "\"");
            Assert.Equal(expected, json);

            var bson = obj.ToBson();
            var rehydrated = BsonSerializer.Deserialize<TestClass>(bson);
            Assert.True(bson.SequenceEqual(rehydrated.ToBson()));
        }
开发者ID:RavenZZ,项目名称:MDRelation,代码行数:15,代码来源:NetPrimitiveSerializerTests.cs

示例7: TestLength1

        public void TestLength1()
        {
            var obj = new TestClass
            {
                B = new BitArray(new[] { true }),
                S = new BitArray(new[] { true })
            };
            var json = obj.ToJson();
            var expected = "{ 'B' : { 'Length' : 1, 'Bytes' : new BinData(0, 'AQ==') }, 'S' : '1' }".Replace("'", "\"");
            Assert.Equal(expected, json);

            var bson = obj.ToBson();
            var rehydrated = BsonSerializer.Deserialize<TestClass>(bson);
            Assert.True(rehydrated.B[0]);
            Assert.True(bson.SequenceEqual(rehydrated.ToBson()));
        }
开发者ID:RavenZZ,项目名称:MDRelation,代码行数:16,代码来源:NetPrimitiveSerializerTests.cs

示例8: TestSerialization

        public void TestSerialization()
        {
            var obj = new TestClass
            {
                Addresses = new HashSet<Address>
                {
                    new Address { Street = "123 Main", City = "Smithtown", State = "PA", Zip = 12345 },
                    new Address { Street = "456 First", City = "Johnstown", State = "MD", Zip = 45678 }
                }
            };
            var json = obj.ToJson();
            var expected = "{ 'Addresses' : [#A1, #A2] }";
            expected = expected.Replace("#A1", "{ 'Street' : '123 Main', 'City' : 'Smithtown', 'State' : 'PA', 'Zip' : 12345 }");
            expected = expected.Replace("#A2", "{ 'Street' : '456 First', 'City' : 'Johnstown', 'State' : 'MD', 'Zip' : 45678 }");
            expected = expected.Replace("'", "\"");
            Assert.AreEqual(expected, json);

            var bson = obj.ToBson();
            var rehydrated = BsonSerializer.Deserialize<TestClass>(bson);
            Assert.IsInstanceOf<HashSet<Address>>(rehydrated.Addresses);
            Assert.IsTrue(bson.SequenceEqual(rehydrated.ToBson()));
        }
开发者ID:niemyjski,项目名称:mongo-csharp-driver,代码行数:22,代码来源:GenericEnumerableSerializerTests.cs

示例9: TestIPv4

        public void TestIPv4()
        {
            var obj = new TestClass
            {
                EndPoint = new IPEndPoint(new IPAddress(new byte[] { 1, 2, 3, 4 }), 1234)
            };
            var json = obj.ToJson();
            var expected = "{ 'EndPoint' : '1.2.3.4:1234' }".Replace("'", "\"");
            Assert.Equal(expected, json);

            var bson = obj.ToBson();
            var rehydrated = BsonSerializer.Deserialize<TestClass>(bson);
            Assert.True(bson.SequenceEqual(rehydrated.ToBson()));
        }
开发者ID:RavenZZ,项目名称:MDRelation,代码行数:14,代码来源:NetPrimitiveSerializerTests.cs

示例10: TestOne

        public void TestOne()
        {
            var obj = new TestClass
            {
                D = 1,
                I = 1,
                L = 1,
                S = 1
            };
            var json = obj.ToJson();
            var expected = ("{ 'D' : 1.0, 'I' : 1, 'L' : NumberLong(1), 'S' : '1' }").Replace("'", "\"");
            Assert.Equal(expected, json);

            var bson = obj.ToBson();
            var rehydrated = BsonSerializer.Deserialize<TestClass>(bson);
            Assert.True(bson.SequenceEqual(rehydrated.ToBson()));
        }
开发者ID:RavenZZ,项目名称:MDRelation,代码行数:17,代码来源:NetPrimitiveSerializerTests.cs

示例11: TestMax

        public void TestMax()
        {
            var obj = new TestClass
            {
                D = short.MaxValue,
                I = short.MaxValue,
                L = short.MaxValue,
                S = short.MaxValue
            };
            var json = obj.ToJson();
            var expected = ("{ 'D' : 32767.0, 'I' : 32767, 'L' : NumberLong(32767), 'S' : '32767' }").Replace("'", "\"");
            Assert.Equal(expected, json);

            var bson = obj.ToBson();
            var rehydrated = BsonSerializer.Deserialize<TestClass>(bson);
            Assert.True(bson.SequenceEqual(rehydrated.ToBson()));
        }
开发者ID:RavenZZ,项目名称:MDRelation,代码行数:17,代码来源:NetPrimitiveSerializerTests.cs

示例12: TestZero

        public void TestZero()
        {
            var obj = new TestClass
            {
                D = 0,
                I = 0,
                L = 0,
                S = 0
            };
            var json = obj.ToJson();
            var expected = ("{ 'D' : 0.0, 'I' : 0, 'L' : NumberLong(0), 'S' : '0' }").Replace("'", "\"");
            Assert.Equal(expected, json);

            var bson = obj.ToBson();
            var rehydrated = BsonSerializer.Deserialize<TestClass>(bson);
            Assert.True(bson.SequenceEqual(rehydrated.ToBson()));
        }
开发者ID:RavenZZ,项目名称:MDRelation,代码行数:17,代码来源:NetPrimitiveSerializerTests.cs

示例13: TestEmpty

        public void TestEmpty()
        {
            var obj = new TestClass
            {
                Addresses = new List<Address>()
            };
            var json = obj.ToJson();
            var expected = "{ 'Addresses' : [] }".Replace("'", "\"");
            Assert.AreEqual(expected, json);

            var bson = obj.ToBson();
            var rehydrated = BsonSerializer.Deserialize<TestClass>(bson);
            Assert.IsInstanceOf<List<Address>>(rehydrated.Addresses);
            Assert.IsTrue(bson.SequenceEqual(rehydrated.ToBson()));
        }
开发者ID:niemyjski,项目名称:mongo-csharp-driver,代码行数:15,代码来源:GenericEnumerableSerializerTests.cs

示例14: TestHttp

        public void TestHttp()
        {
            var obj = new TestClass
            {
                V = new Uri("http://www.cnn.com")
            };
            var json = obj.ToJson();
            var expected = "{ 'V' : 'http://www.cnn.com' }".Replace("'", "\"");
            Assert.Equal(expected, json);

            var bson = obj.ToBson();
            var rehydrated = BsonSerializer.Deserialize<TestClass>(bson);
            Assert.True(bson.SequenceEqual(rehydrated.ToBson()));
        }
开发者ID:RavenZZ,项目名称:MDRelation,代码行数:14,代码来源:NetPrimitiveSerializerTests.cs

示例15: TestMongoDB

        public void TestMongoDB()
        {
            var obj = new TestClass
            {
                V = new Uri("mongodb://localhost/?w=1")
            };
            var json = obj.ToJson();
            var expected = "{ 'V' : 'mongodb://localhost/?w=1' }".Replace("'", "\"");
            Assert.Equal(expected, json);

            var bson = obj.ToBson();
            var rehydrated = BsonSerializer.Deserialize<TestClass>(bson);
            Assert.True(bson.SequenceEqual(rehydrated.ToBson()));
        }
开发者ID:RavenZZ,项目名称:MDRelation,代码行数:14,代码来源:NetPrimitiveSerializerTests.cs


注:本文中的TestClass.ToBson方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。