Example #1
0
        public void ExpressionPropertyTests_ArrayExpressionObject()
        {
            var data = new
            {
                test = new ArrFoo()
                {
                    Objects = new List <Foo>()
                    {
                        new Foo()
                        {
                            Age  = 13,
                            Name = "joe"
                        }
                    }
                }
            };

            var val = new ArrayExpression <Foo>("test.Objects");

            Assert.NotNull(val.ExpressionText);
            Assert.Null(val.Value);
            var(result, error) = val.TryGetValue(data);
            Assert.Equal(data.test.Objects, result);

            val = new ArrayExpression <Foo>("=test.Objects");
            Assert.NotNull(val.ExpressionText);
            Assert.Null(val.Value);
            (result, error) = val.TryGetValue(data);
            Assert.Equal(data.test.Objects, result);

            val = new ArrayExpression <Foo>(data.test.Objects);
            Assert.Null(val.ExpressionText);
            Assert.NotNull(val.Value);
            (result, error) = val.TryGetValue(data);
            Assert.Equal(JsonConvert.SerializeObject(data.test.Objects, settings), JsonConvert.SerializeObject(result, settings));

            val = new ArrayExpression <Foo>(JArray.FromObject(data.test.Objects));
            Assert.Null(val.ExpressionText);
            Assert.NotNull(val.Value);
            (result, error) = val.TryGetValue(data);
            Assert.Equal(JsonConvert.SerializeObject(data.test.Objects, settings), JsonConvert.SerializeObject(result, settings));
        }
Example #2
0
        public void ExpressionPropertyTests_ArrayExpressionString()
        {
            var data = new
            {
                test = new ArrFoo()
                {
                    Strings = new List <string>()
                    {
                        "a", "b", "c"
                    }
                }
            };

            var val = new ArrayExpression <string>("test.Strings");

            Assert.NotNull(val.ExpressionText);
            Assert.Null(val.Value);
            var(result, error) = val.TryGetValue(data);
            Assert.Equal(JsonConvert.SerializeObject(data.test.Strings, settings), JsonConvert.SerializeObject(result, settings: settings));
            Assert.Equal(data.test.Strings, result);

            val = new ArrayExpression <string>("=test.Strings");
            Assert.NotNull(val.ExpressionText);
            Assert.Null(val.Value);
            (result, error) = val.TryGetValue(data);
            Assert.Equal(JsonConvert.SerializeObject(data.test.Strings, settings), JsonConvert.SerializeObject(result, settings: settings));
            Assert.Equal(data.test.Strings, result);

            val = new ArrayExpression <string>(data.test.Strings);
            Assert.Null(val.ExpressionText);
            Assert.NotNull(val.Value);
            (result, error) = val.TryGetValue(data);
            Assert.Equal(JsonConvert.SerializeObject(data.test.Strings, settings), JsonConvert.SerializeObject(result, settings: settings));
            Assert.Equal(data.test.Strings, result);

            val = new ArrayExpression <string>(data.test.Strings);
            Assert.Null(val.ExpressionText);
            Assert.NotNull(val.Value);
            (result, error) = val.TryGetValue(data);
            Assert.Equal(JsonConvert.SerializeObject(data.test.Strings, settings), JsonConvert.SerializeObject(result, settings: settings));
            Assert.Equal(data.test.Strings, result);
        }