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 TestJsonPathArray() { var f = IntrinsicFunction.Parse("States.JsonToString($.a)"); var res = _registry.CallFunction(f, JObject.Parse("{'a':[1,2,3,4]}"), new JObject()); Assert.Equal("[1,2,3,4]", res); }
public void TestWithoutArgument() { var f = IntrinsicFunction.Parse("States.Format('value')"); var r = _registry.CallFunction(f, "test", new JObject()); Assert.Equal("value", r); }
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()); }
public static JToken Array(IntrinsicFunction function, JToken input, JObject context, IntrinsicFunctionRegistry registry) { Ensure.IsNotNull <ArgumentNullException>(function); Ensure.IsNotNull <ArgumentNullException>(registry); var result = new JArray(); foreach (var p in function.Parameters) { result.Add(p switch { NullIntrinsicParam _ => null, StringIntrinsicParam s => s.Value, NumberIntrinsicParam n => n.Number, PathIntrinsicParam pa => GetPathValue(pa, input, context), IntrinsicFunction func => registry.CallFunction(func, input, context), _ => throw new InvalidIntrinsicFunctionException("Invalid Parameter type") });