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


C# TestClass.ToBson方法代码示例

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


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

示例1: 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.AreEqual(expected, json);

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

示例2: 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:abolibibelot,项目名称:mongo-csharp-driver,代码行数:11,代码来源:GenericEnumerablePropertySerializerTests.cs

示例3: TestTrue

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

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

示例4: TestFalse

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

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

示例5: 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.AreEqual(expected, json);

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

示例6: TestNull

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

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

示例7: TestLength0

        public void TestLength0()
        {
            var obj = new TestClass {
                V = new BitArray(new bool[0])
            };
            var json = obj.ToJson();
            var expected = "{ 'V' : { '$binary' : '', '$type' : '00' } }".Replace("'", "\"");
            Assert.AreEqual(expected, json);

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

示例8: TestTrue

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

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

示例9: 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.AreEqual(expected, json);

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

示例10: TestLength2

        public void TestLength2()
        {
            var obj = new TestClass {
                V = new BitArray(new[] { true, true })
            };
            var json = obj.ToJson();
            var expected = "{ 'V' : { 'Length' : 2, 'Bytes' : { '$binary' : 'Aw==', '$type' : '00' } } }".Replace("'", "\"");
            Assert.AreEqual(expected, json);

            var bson = obj.ToBson();
            var rehydrated = BsonSerializer.Deserialize<TestClass>(bson);
            Assert.IsTrue(rehydrated.V[0]);
            Assert.IsTrue(rehydrated.V[1]);
            Assert.IsTrue(bson.SequenceEqual(rehydrated.ToBson()));
        }
开发者ID:kenegozi,项目名称:mongo-csharp-driver,代码行数:15,代码来源:NetPrimitiveSerializerTests.cs

示例11: TestOne

        public void TestOne()
        {
            var obj = new TestClass {
                C = 1,
                F = 1
            };
            var json = obj.ToJson();
            var expected = "{ 'C' : 1, 'F' : { '_t' : 'System.Byte', 'v' : 1 } }".Replace("'", "\"");
            Assert.AreEqual(expected, json);

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

示例12: 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:ncipollina,项目名称:mongo-csharp-driver,代码行数:22,代码来源:GenericEnumerableSerializerTests.cs

示例13: TestMinUtc

        public void TestMinUtc()
        {
            var obj = new TestClass {
                DateTime = DateTime.SpecifyKind(DateTime.MinValue, DateTimeKind.Utc)
            };
            long milliseconds = (long) (DateTime.MinValue - BsonConstants.UnixEpoch).TotalMilliseconds;
            var json = obj.ToJson();
            var expected = ("{ 'DateTime' : { '$date' : " + milliseconds.ToString() + " } }").Replace("'", "\"");
            Assert.AreEqual(expected, json);

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

示例14: TestMin

        public void TestMin()
        {
            var obj = new TestClass(long.MinValue);
            var json = obj.ToJson();
            var expected = "{ 'B' : #, 'V' : # }".Replace("#", "NumberLong('-9223372036854775808')").Replace("'", "\"");
            Assert.AreEqual(expected, json);

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

示例15: TestMinusOne

        public void TestMinusOne()
        {
            var obj = new TestClass {
                Double = -1.0
            };
            var json = obj.ToJson();
            var expected = "{ 'Double' : -1 }".Replace("'", "\"");
            Assert.AreEqual(expected, json);

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


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