Exemplo n.º 1
0
        public void ExpressionPropertyTests_ValueExpression()
        {
            var data = new
            {
                test = new { x = 13 }
            };

            var val = new ValueExpression("test");

            Assert.Equal("=`test`", val.ExpressionText);
            Assert.Null(val.Value);
            Assert.Equal(val.ToString(), JsonConvert.DeserializeObject <ValueExpression>(JsonConvert.SerializeObject(val, settings: settings), settings: settings).ToString());
            var(result, error) = val.TryGetValue(data);
            Assert.Equal("test", result);
            Assert.Null(error);

            val = new ValueExpression("=test");
            Assert.Equal("=test", val.ExpressionText);
            Assert.Null(val.Value);
            Assert.Equal(val.ToString(), JsonConvert.DeserializeObject <ValueExpression>(JsonConvert.SerializeObject(val, settings: settings), settings: settings).ToString());
            (result, error) = val.TryGetValue(data);
            Assert.Equal(JsonConvert.SerializeObject(data.test), JsonConvert.SerializeObject(result));
            Assert.Null(error);

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

            val = new ValueExpression("Hello ${test.x}");
            Assert.Equal("=`Hello ${test.x}`", val.ExpressionText);
            Assert.Null(val.Value);
            Assert.Equal(val.ToString(), JsonConvert.DeserializeObject <ValueExpression>(JsonConvert.SerializeObject(val, settings: settings), settings: settings).ToString());
            (result, error) = val.TryGetValue(data);
            Assert.Equal("Hello 13", result);
            Assert.Null(error);

            // slashes are the chars
            val             = new ValueExpression("c:\\test\\test\\test");
            (result, error) = val.TryGetValue(data);
            Assert.Equal("c:\\test\\test\\test", result);
            Assert.Null(error);

            // tabs are the chars
            val             = new ValueExpression("c:\test\test\test");
            (result, error) = val.TryGetValue(data);
            Assert.Equal("c:\test\test\test", result);
            Assert.Null(error);
        }
Exemplo n.º 2
0
        public void ExpressionPropertyTests_ValueExpression()
        {
            var data = new
            {
                test = new { x = 13 }
            };

            var val = new ValueExpression("test");

            Assert.IsNull(val.Expression);
            Assert.IsNotNull(val.Value);
            Assert.AreEqual(val.ToString(), JsonConvert.DeserializeObject <ValueExpression>(JsonConvert.SerializeObject(val, settings: settings), settings: settings).ToString());
            var(result, error) = val.TryGetValue(data);
            Assert.AreEqual("test", result);
            Assert.IsNull(error);

            val = new ValueExpression("=test");
            Assert.IsNotNull(val.Expression);
            Assert.IsNull(val.Value);
            Assert.AreEqual(val.ToString(), JsonConvert.DeserializeObject <ValueExpression>(JsonConvert.SerializeObject(val, settings: settings), settings: settings).ToString());
            (result, error) = val.TryGetValue(data);
            Assert.AreEqual(JsonConvert.SerializeObject(data.test), JsonConvert.SerializeObject(result));
            Assert.IsNull(error);

            val = new ValueExpression(data.test);
            Assert.IsNull(val.Expression);
            Assert.IsNotNull(val.Value);
            Assert.AreEqual(JsonConvert.SerializeObject(data.test, settings), JsonConvert.DeserializeObject <ValueExpression>(JsonConvert.SerializeObject(val, settings: settings), settings: settings).ToString());
            (result, error) = val.TryGetValue(data);
            Assert.AreEqual(JsonConvert.SerializeObject(data.test), JsonConvert.SerializeObject(result));
            Assert.IsNull(error);

            val = new ValueExpression("Hello @{test.x}");
            Assert.IsNull(val.Expression);
            Assert.IsNotNull(val.Value);
            Assert.AreEqual(val.ToString(), JsonConvert.DeserializeObject <ValueExpression>(JsonConvert.SerializeObject(val, settings: settings), settings: settings).ToString());
            (result, error) = val.TryGetValue(data);
            Assert.AreEqual("Hello 13", result);
            Assert.IsNull(error);
        }