Example #1
0
        public async Task SerializeSubCollections()
        {
            var obj1 = new Obj1
            {
                Obj2s = new List <Obj2>
                {
                    new Obj2
                    {
                        Id   = 1,
                        Name = "1"
                    },
                    new Obj2
                    {
                        Id   = 2,
                        Name = "2"
                    }
                }
            };

            var selection = new Selection <Obj1>(new List <Obj1> {
                obj1
            }, 1);
            var fields = new ExpressionParser().ParseTree <Obj1>("obj2s[id,name]");
            var json   = await SerializeAsync(selection, fields);

            Assert.Equal(ExpectedInput(@"{""items"":[{""obj2s"":[{""id"":1,""name"":""1""},{""id"":2,""name"":""2""}]}]}"), json);
        }
Example #2
0
        public async Task TwoLevelSelection()
        {
            var obj1 = new Obj1
            {
                Id   = 1,
                Name = "1",
                Obj2 = new Obj2
                {
                    Id        = 2,
                    Name      = "2",
                    Something = "something",
                    Else      = "else",
                    Obj3      = new Obj3
                    {
                        Id        = 3,
                        Name      = "3",
                        Something = "A",
                        Else      = "B"
                    }
                }
            };
            ISelection <Obj1> selection = new Selection <Obj1>(new List <Obj1> {
                obj1
            }, 1);

            var fields = new ExpressionParser().ParseTree <Obj1>("Obj2[Id,Name,Obj3[Something,Else],Else]");

            var json = await SerializeAsync(selection, fields);

            Assert.Equal(ExpectedInput(@"{""items"":[{""obj2"":{""id"":2,""name"":""2"",""obj3"":{""something"":""A"",""else"":""B""},""else"":""else""}}]}"), json);
        }
Example #3
0
        public async Task EmptyFieldsSingleObject()
        {
            var obj1 = new Obj1
            {
                Id   = 1,
                Name = "1"
            };

            var fields = new ExpressionParser().ParseTree <Obj1>("");

            var json = await SerializeAsync(obj1, fields);

            Assert.Equal(ExpectedInput(@"{""id"":1,""name"":""1"",""url"":""http://www.example.org/""}"), json);
        }
Example #4
0
        public async Task EmptyFieldsSelection()
        {
            var obj1 = new Obj1
            {
                Id   = 1,
                Name = "1"
            };
            ISelection <Obj1> selection = new Selection <Obj1>(new List <Obj1> {
                obj1
            }, 1);

            var fields = new ExpressionParser().ParseTree <Obj1>("");

            var json = await SerializeAsync(selection, fields);

            Assert.Equal(ExpectedInput(@"{""items"":[{""id"":1,""name"":""1"",""url"":""http://www.example.org/""}]}"), json);
        }