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


C# TestClass.ToJson方法代码示例

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


在下文中一共展示了TestClass.ToJson方法的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.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

示例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:niemyjski,项目名称:mongo-csharp-driver,代码行数:11,代码来源:GenericEnumerableSerializerTests.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: ToJson_ReturnsString

        public void ToJson_ReturnsString()
        {
            var tClass = new TestClass
            {
                IntValue = 444,
                TestSubClasses = new[]
                {
                    new TestSubClass {IntValue = 0, StringArray = new[] {"a","b","c"} },
                    new TestSubClass {IntValue = 1, StringArray = new[] {"d","e","f"} },
                    new TestSubClass {IntValue = 2, StringArray = new[] {"g","h","i"} }
                }
            };

            var actual = tClass.ToJson();
            var expected = "{\"IntValue\":444,\"TestSubClasses\":[{\"IntValue\":0,\"StringArray\":[\"a\",\"b\",\"c\"]},{\"IntValue\":1,\"StringArray\":[\"d\",\"e\",\"f\"]},{\"IntValue\":2,\"StringArray\":[\"g\",\"h\",\"i\"]}]}";

            expected.ShouldEqual(actual);
        }
开发者ID:saturn72,项目名称:Saturn72.Extensions,代码行数:18,代码来源:ObjectExtensionTests.cs

示例9: 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

示例10: 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

示例11: 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

示例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: 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

示例14: TestRelative

        public void TestRelative()
        {
            var obj = new TestClass
            {
                V = new Uri("/relative/page.html", UriKind.RelativeOrAbsolute)
            };
            var json = obj.ToJson();
            var expected = "{ 'V' : '/relative/page.html' }".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: TestA

        public void TestA()
        {
            var obj = new TestClass
            {
                I = 'A',
                S = 'A'
            };
            var json = obj.ToJson();
            var expected = "{ 'I' : #, 'S' : 'A' }".Replace("#", ((int)'A').ToString()).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


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