public void TestIntrinsicFunction()
        {
            var f   = IntrinsicFunction.Parse("States.StringToJson(States.JsonToString($.a))");
            var res = _registry.CallFunction(f, JObject.Parse("{'a':[1,2,3,4]}"), new JObject());

            Assert.Equal(JArray.Parse("[1,2,3,4]"), res);
        }
Exemplo n.º 2
0
        public void InvalidStatesFormat(string function, string input, string context)
        {
            var f = IntrinsicFunction.Parse(function);

            Assert.Throws <InvalidIntrinsicFunctionException>(() =>
                                                              _registry.CallFunction(f, JToken.Parse(input), JObject.Parse(context)));
        }
        public void TestStringToJsonError(string function, string input)
        {
            var f = IntrinsicFunction.Parse(function);

            Assert.Throws <InvalidIntrinsicFunctionException>(() =>
                                                              _registry.CallFunction(f, JToken.Parse(input), new JObject()));
        }
        public void TestRawJson()
        {
            var f   = IntrinsicFunction.Parse("States.StringToJson('{\"number\": 20}')");
            var res = _registry.CallFunction(f, "'a'", new JObject());

            Assert.Equal(JObject.Parse("{'number': 20}"), res);
        }
        public void TestJsonPathObject()
        {
            var f   = IntrinsicFunction.Parse("States.JsonToString($.a)");
            var res = _registry.CallFunction(f, JObject.Parse("{'a':{'b':1,'c':'test'}}"), new JObject());

            Assert.Equal("{\"b\":1,\"c\":\"test\"}", res.Value <string>());
        }
Exemplo n.º 6
0
        public void OneParameterIntrinsicFunction()
        {
            var f = IntrinsicFunction.Parse("Test('hello')");

            Assert.Equal("Test", f.Name);
            Assert.Single(f.Parameters);
            Assert.IsType <StringIntrinsicParam>(f.Parameters[0]);
            Assert.Equal("hello", ((StringIntrinsicParam)f.Parameters[0]).Value);

            f = IntrinsicFunction.Parse("Test($.hello)");
            Assert.Equal("Test", f.Name);
            Assert.Single(f.Parameters);
            Assert.IsType <PathIntrinsicParam>(f.Parameters[0]);
            Assert.Equal("$.hello", ((PathIntrinsicParam)f.Parameters[0]).Path);

            f = IntrinsicFunction.Parse("Test(33.45)");
            Assert.Equal("Test", f.Name);
            Assert.Single(f.Parameters);
            Assert.IsType <NumberIntrinsicParam>(f.Parameters[0]);
            Assert.Equal(33.45m, ((NumberIntrinsicParam)f.Parameters[0]).Number);

            f = IntrinsicFunction.Parse("Test(null)");
            Assert.Equal("Test", f.Name);
            Assert.Single(f.Parameters);
            Assert.IsType <NullIntrinsicParam>(f.Parameters[0]);
        }
Exemplo n.º 7
0
        public void TestFunctionArgument()
        {
            var f = IntrinsicFunction.Parse("States.Format('hello {}', States.Format('world'))");

            var r = _registry.CallFunction(f, "test", new JObject());

            Assert.Equal("hello world", r.Value <string>());
        }
        public void TestObjectArrayItem()
        {
            var f = IntrinsicFunction.Parse("States.Array($.a)");
            var r = _registry.CallFunction(f, JObject.Parse("{'a':{'b':33}}"), new JObject());

            Assert.True(r is JArray);
            Assert.Equal(JToken.Parse("{'b':33}"), r.First);
        }
Exemplo n.º 9
0
        public void TestWithNumberArgument()
        {
            var f = IntrinsicFunction.Parse("States.Format('hello {}',12.34)");

            var r = _registry.CallFunction(f, "test", new JObject());

            Assert.Equal("hello 12.34", r.Value <string>());
        }
Exemplo n.º 10
0
        public void TestWithoutArgumentFromPath()
        {
            var f = IntrinsicFunction.Parse("States.Format($.p)");

            var r = _registry.CallFunction(f, JToken.Parse("{'p':'value'}"), new JObject());

            Assert.Equal("value", r.Value <string>());
        }
Exemplo n.º 11
0
        public void TestWithoutArgument()
        {
            var f = IntrinsicFunction.Parse("States.Format('value')");

            var r = _registry.CallFunction(f, "test", new JObject());

            Assert.Equal("value", r);
        }
Exemplo n.º 12
0
        public void HelloWorldTest(string function, string input, string context)
        {
            var f = IntrinsicFunction.Parse(function);

            var r = _registry.CallFunction(f, JToken.Parse(input), JObject.Parse(context));

            Assert.Equal("hello world", r.Value <string>());
        }
        public void TestJsonPath()
        {
            var f   = IntrinsicFunction.Parse("States.StringToJson($.someString)");
            var res = _registry.CallFunction(f,
                                             JObject.Parse("{'someString': '{\\\"number\\\": 20}','zebra': 'stripe'}"), new JObject());

            Assert.Equal(JObject.Parse("{'number': 20}"), res);
        }
Exemplo n.º 14
0
        public void TestEscapeCharsFunctionArgument()
        {
            var f = IntrinsicFunction.Parse("States.Format('hello \\\\{\\\\}')");

            var r = _registry.CallFunction(f, "test", new JObject());

            Assert.Equal("hello {}", r.Value <string>());
        }
Exemplo n.º 15
0
        public void TestPathArgument()
        {
            var f = IntrinsicFunction.Parse("States.Format('hello {}', $.p)");

            var r = _registry.CallFunction(f, JToken.Parse("{'p':'world'}"), new JObject());

            Assert.Equal("hello world", r.Value <string>());
        }
        public void TestArrayParameterCount(string definition, int count)
        {
            var f = IntrinsicFunction.Parse(definition);
            var r = _registry.CallFunction(f, "'a'", new JObject());

            Assert.True(r is JArray);
            Assert.Equal(count, r.Count());
        }
Exemplo n.º 17
0
        public void IgnoreWhiteSpacesAroundQuoteStringParam(string test)
        {
            var f = IntrinsicFunction.Parse(test);

            Assert.Equal("Test", f.Name);
            Assert.Single(f.Parameters);
            Assert.IsType <StringIntrinsicParam>(f.Parameters[0]);
            Assert.Equal("hello", ((StringIntrinsicParam)f.Parameters[0]).Value);
        }
Exemplo n.º 18
0
        public void IgnoreWhiteSpacesAroundUnquotePathParam(string test)
        {
            var f = IntrinsicFunction.Parse(test);

            Assert.Equal("Test", f.Name);
            Assert.Single(f.Parameters);
            Assert.IsType <PathIntrinsicParam>(f.Parameters[0]);
            Assert.Equal("$.test", ((PathIntrinsicParam)f.Parameters[0]).Path);
        }
Exemplo n.º 19
0
        public void OneParameterIntrinsicFunctionWithDotAndUnder()
        {
            var f = IntrinsicFunction.Parse("Tes.t_('hello')");

            Assert.Equal("Tes.t_", f.Name);
            Assert.Single(f.Parameters);
            Assert.IsType <StringIntrinsicParam>(f.Parameters[0]);
            Assert.Equal("hello", ((StringIntrinsicParam)f.Parameters[0]).Value);
        }
Exemplo n.º 20
0
        public void SubIntrinsicFunctiontest()
        {
            var f = IntrinsicFunction.Parse("Test(Test($.test))");

            Assert.Equal("Test", f.Name);
            Assert.Single(f.Parameters);
            Assert.IsType <IntrinsicFunction>(f.Parameters[0]);
            Assert.Equal("Test", ((IntrinsicFunction)f.Parameters[0]).Name);
            Assert.IsType <PathIntrinsicParam>(((IntrinsicFunction)f.Parameters[0]).Parameters[0]);
            Assert.Equal("$.test", ((PathIntrinsicParam)((IntrinsicFunction)f.Parameters[0]).Parameters[0]).Path);
        }
Exemplo n.º 21
0
        public void TwoParametersIntrinsicFunction()
        {
            var f = IntrinsicFunction.Parse("Test('hello',33)");

            Assert.Equal("Test", f.Name);
            Assert.Equal(2, f.Parameters.Length);
            Assert.IsType <StringIntrinsicParam>(f.Parameters[0]);
            Assert.Equal("hello", ((StringIntrinsicParam)f.Parameters[0]).Value);
            Assert.IsType <NumberIntrinsicParam>(f.Parameters[1]);
            Assert.Equal(33, ((NumberIntrinsicParam)f.Parameters[1]).Number);
        }
Exemplo n.º 22
0
        public void FourParametersIntrinsicFunction()
        {
            var f = IntrinsicFunction.Parse("Test('hello',33,null,$.test)");

            Assert.Equal("Test", f.Name);
            Assert.Equal(4, f.Parameters.Length);
            Assert.IsType <StringIntrinsicParam>(f.Parameters[0]);
            Assert.Equal("hello", ((StringIntrinsicParam)f.Parameters[0]).Value);
            Assert.IsType <NumberIntrinsicParam>(f.Parameters[1]);
            Assert.Equal(33, ((NumberIntrinsicParam)f.Parameters[1]).Number);
            Assert.IsType <NullIntrinsicParam>(f.Parameters[2]);
            Assert.IsType <PathIntrinsicParam>(f.Parameters[3]);
            Assert.Equal("$.test", ((PathIntrinsicParam)f.Parameters[3]).Path);
        }
Exemplo n.º 23
0
        public void IgnoreWhiteSpacesAroundComplex()
        {
            var f = IntrinsicFunction.Parse("test(   1    ,  'a'  , a(  $p  , 'test'  )  )  ");

            Assert.Equal("test", f.Name);
            Assert.Equal(3, f.Parameters.Length);
            Assert.IsType <NumberIntrinsicParam>(f.Parameters[0]);
            Assert.Equal(1, ((NumberIntrinsicParam)f.Parameters[0]).Number);
            Assert.IsType <StringIntrinsicParam>(f.Parameters[1]);
            Assert.Equal("a", ((StringIntrinsicParam)f.Parameters[1]).Value);
            Assert.IsType <IntrinsicFunction>(f.Parameters[2]);

            var f2 = (IntrinsicFunction)f.Parameters[2];

            Assert.Equal("a", f2.Name);
            Assert.Equal(2, f2.Parameters.Length);
            Assert.IsType <PathIntrinsicParam>(f2.Parameters[0]);
            Assert.Equal("$p", ((PathIntrinsicParam)f2.Parameters[0]).Path);
            Assert.IsType <StringIntrinsicParam>(f2.Parameters[1]);
            Assert.Equal("test", ((StringIntrinsicParam)f2.Parameters[1]).Value);
        }
Exemplo n.º 24
0
 public void IntrinsicFunctionParserError(string functionDefinition)
 {
     Assert.Throws <InvalidIntrinsicFunctionException>(() => IntrinsicFunction.Parse(functionDefinition));
 }