示例#1
0
        public void ET_Json_Serialization_NoCamel()
        {
            var entity = new Favorate
            {
                Name = "name"
            };

            var serializer = new AggtSerializer();
            serializer.Indent = true;
            serializer.IgnoreDefault = true;
            serializer.UseCamelProperty = false;
            var json = serializer.Serialize(entity);

            Assert.AreEqual(json,
            @"{
              ""Name"": ""name""
            }");
        }
示例#2
0
        public void ET_Json_Serialization_Ref()
        {
            var entity = new Favorate
            {
                Name = "name",
                Book = new Book { Id = 100, Name = "book" }
            };

            var serializer = new AggtSerializer();
            serializer.Indent = true;
            serializer.IgnoreDefault = true;
            var json = serializer.Serialize(entity);

            Assert.AreEqual(json,
            @"{
              ""book"": {
            ""id"": 100,
            ""name"": ""book""
              },
              ""bookId"": 100,
              ""name"": ""name""
            }");
        }
示例#3
0
        public void ET_Json_Serialization_IgnoreDefault()
        {
            var entity = new Favorate
            {
                Name = "name"
            };

            var serializer = new AggtSerializer();
            serializer.Indent = true;
            serializer.IgnoreDefault = false;
            var json = serializer.Serialize(entity);

            Assert.AreEqual(json,
            @"{
              ""id"": 0,
              ""arrayValue"": null,
              ""bookId"": 0,
              ""bytesContent"": """",
              ""listValue"": null,
              ""name"": ""name""
            }");
        }
示例#4
0
        public void ET_Json_Serialization_EntityList()
        {
            var list = new FavorateList
            {
                new Favorate { Name = "f1" },
                new Favorate { Name = "f2" },
            };

            var serializer = new AggtSerializer();
            serializer.Indent = true;
            serializer.IgnoreDefault = true;
            var json = serializer.Serialize(list);

            Assert.AreEqual(json,
            @"[
              {
            ""name"": ""f1""
              },
              {
            ""name"": ""f2""
              }
            ]");
        }
示例#5
0
        public void ET_Json_Serialization_Bytes()
        {
            var entity = new Favorate
            {
                BytesContent = Encoding.UTF8.GetBytes("test content")
            };

            var serializer = new AggtSerializer();
            serializer.Indent = true;
            serializer.IgnoreDefault = true;
            var json = serializer.Serialize(entity);

            Assert.AreEqual(json,
            @"{
              ""bytesContent"": ""dGVzdCBjb250ZW50""
            }");
        }
示例#6
0
        public void ET_Json_Serialization_ArrayValue()
        {
            var entity = new Favorate
            {
                ListValue = new List<string> { "1", "2", "3" },
                ArrayValue = new int[] { 1, 2, 3 },
            };

            var serializer = new AggtSerializer();
            serializer.Indent = true;
            serializer.IgnoreDefault = true;
            var json = serializer.Serialize(entity);

            Assert.AreEqual(json,
            @"{
              ""arrayValue"": [
            1,
            2,
            3
              ],
              ""listValue"": [
            ""1"",
            ""2"",
            ""3""
              ]
            }");
        }
示例#7
0
 public void ET_Json_Serialization_Aggt()
 {
     var entity = new Book
     {
         Name = "book",
         ChapterList =
         {
             new Chapter
             {
                 Name = "chapter1"
             },
             new Chapter
             {
                 Name = "chapter2",
                 SectionList =
                 {
                     new Section
                     {
                         Name = "section"
                     }
                 }
             },
         }
     };
     var serializer = new AggtSerializer();
     serializer.Indent = true;
     serializer.IgnoreDefault = true;
     var json = serializer.Serialize(entity);
     Assert.AreEqual(json,
     @"{
       ""chapterList"": [
     {
       ""name"": ""chapter1""
     },
     {
       ""name"": ""chapter2"",
       ""sectionList"": [
     {
       ""name"": ""section""
     }
       ]
     }
       ],
       ""name"": ""book""
     }");
 }