public void CommonFunctions_atomtoString_GivenJsonAppend_ExpectCorrectJson()
        {
            //------------Setup for test--------------------------
            var eEnv = new ExecutionEnvironment();

            eEnv.AssignJson(new AssignValue("[[@a]]", "{\"aa\":1}"), 0);
            eEnv.AssignJson(new AssignValue("[[@a.b]]", "{\"bb\":2}"), 0);
            eEnv.AssignJson(new AssignValue("[[@a.c]]", "[[@a]]"), 0);
            eEnv.AssignJson(new AssignValue("[[@a2(1)]]", "{\"indexNested\": 3}"), 0);
            eEnv.AssignJson(new AssignValue("[[@a.d]]", "[[@a2]]"), 0);
            eEnv.AssignJson(new AssignValue("[[@a.e()]]", "{\"ee\":4}"), 0);
            var env = ExtractEnvironment(eEnv);

            var result = EvaluationFunctions.eval(env, 0, false, "[[@a]]");
            var a      = CommonFunctions.evalResultToString(result);
            var json   = (JObject)JsonConvert.DeserializeObject(a);

            Assert.AreEqual(1, json["aa"]);
            Assert.AreEqual(2, json["b"]["bb"]);
            Assert.AreEqual(1, json["c"]["aa"]);
            Assert.AreEqual(2, json["c"]["b"]["bb"]);
            Assert.AreEqual(1, ((JArray)json["d"]).Count);
            Assert.AreEqual(3, json["d"][0]["indexNested"]);
            Assert.AreEqual(1, ((JArray)json["e"]).Count);
            Assert.AreEqual(4, json["e"][0]["ee"]);
        }
        public void CommonFunctions_EvalResultToJsonCompatable()
        {
            var env = CreateEnvironmentWithData();
            var a   = CommonFunctions.evalResultToString(EvaluationFunctions.eval(env, 0, false, "[[x]]"));

            Assert.AreEqual(a, "1");
        }
        public void CommonFunctions_atomtoString_GivenCircularJson_ExpectCorrectJson()
        {
            //------------Setup for test--------------------------
            var eEnv = new ExecutionEnvironment();

            eEnv.AssignJson(new AssignValue("[[@a]]", "{\"aa\":1}"), 0);
            eEnv.AssignJson(new AssignValue("[[@a.b()]]", "{\"bb\":2}"), 0);
            eEnv.AssignJson(new AssignValue("[[@a.c(1).a1]]", "[[@a]]"), 0);
            eEnv.AssignJson(new AssignValue("[[@a.c(1).a1.aa]]", "55"), 0);
            var env = ExtractEnvironment(eEnv);

            var result = EvaluationFunctions.eval(env, 0, false, "[[@a]]");
            var a      = CommonFunctions.evalResultToString(result);

            var json = (JObject)JsonConvert.DeserializeObject(a);

            Assert.AreEqual(1, json["aa"]);
            Assert.AreEqual(1, ((JArray)json["b"]).Count);
            Assert.AreEqual(2, json["b"][0]["bb"]);
            var c1 = ((JArray)json["c"])[0];

            Assert.AreEqual(55, c1["a1"]["aa"]);
            Assert.AreEqual(2, c1["a1"]["b"][0]["bb"]);
            Assert.IsFalse(((JObject)c1["a1"]).ContainsKey("c"));
            //Assert.AreEqual(1, ((JArray)c1["a1"]["c"]).Count); // this should not exist, it is an artifact of the assign in progress when c(1).a1 is being assigned its parent @a
        }
Esempio n. 4
0
        public void CreateJSONAndEvalEntireObject()
        {
            //------------Setup for test--------------------------
            var createDataSet = WarewolfTestData.CreateTestEnvWithData;
            var j             = JObject.FromObject(new Person()
            {
                Name = "n", Children = new List <Person>()
            });
            var added = WarewolfDataEvaluationCommon.addToJsonObjects(createDataSet, "bob", j);

            //------------Execute Test---------------------------

            //------------Assert Results-------------------------
            Assert.IsTrue(added.JsonObjects.ContainsKey("bob"));
            Assert.AreEqual((added.JsonObjects["bob"] as JObject).GetValue("Name").ToString(), "n");
            var evalled = EvaluationFunctions.eval(added, 0, false, "[[@bob]]");

            Assert.IsTrue(evalled.IsWarewolfAtomResult);
            var res = (evalled as CommonFunctions.WarewolfEvalResult.WarewolfAtomResult).Item;

            if (res is DataStorage.WarewolfAtom.JsonObject jsonObject)
            {
                var str = jsonObject.ToString();
                Assert.AreEqual(j.ToString(), str);
            }
            else
            {
                Assert.Fail("expected JsonObject");
            }
        }
Esempio n. 5
0
        public void CreateJSONAndEvalPartialObjectNestedIndex()
        {
            //------------Setup for test--------------------------
            var createDataSet = WarewolfTestData.CreateTestEnvWithData;
            var j             = JObject.FromObject(new Person()
            {
                Name = "n", Children = new List <Person> {
                    new Person()
                    {
                        Name = "p", Children = new List <Person>()
                    }
                }, Spouse = new Person()
                {
                    Name = "o", Children = new List <Person>()
                }
            });
            var added = WarewolfDataEvaluationCommon.addToJsonObjects(createDataSet, "bob", j);

            //------------Execute Test---------------------------

            //------------Assert Results-------------------------
            Assert.IsTrue(added.JsonObjects.ContainsKey("bob"));

            var evalled = CommonFunctions.evalResultToString(EvaluationFunctions.eval(added, 0, false, "[[@bob.Children(1).Name]]"));

            Assert.AreEqual(evalled, "p");
        }
        public void Eval_Json_Root()
        {
            //------------Setup for test--------------------------
            var          env      = CreateEnvironmentWithData();
            const string expected = "{" +
                                    "\"Name\": \"bob\"," +
                                    "\"Age\": \"22\"," +
                                    "\"Spouse\": {" +
                                    "\"Name\": \"dora\"" +
                                    "}," +
                                    "\"Children\": [" +
                                    "{" +
                                    "\"Name\": \"Mary\"" +
                                    "}," +
                                    "{" +
                                    "\"Name\": \"Jane\"" +
                                    "}" +
                                    "]," +
                                    "\"Score\": [" +
                                    "\"2\"," +
                                    "\"3\"" +
                                    "]" +
                                    "}";
            //------------Execute Test---------------------------
            var res = EvaluationFunctions.eval(env, 0, false, "[[@Person]]");

            //------------Assert Results-------------------------
            Assert.AreEqual(expected.Replace(" ", ""), CommonFunctions.evalResultToString(res).Replace(Environment.NewLine, "").Replace(" ", ""));
        }
Esempio n. 7
0
        public void Eval_RecSet_RecsetResult()
        {
            //------------Setup for test--------------------------
            var env = CreateEnvironmentWithData();
            //------------Execute Test---------------------------
            var res = EvaluationFunctions.eval(env, 0, false, " [[Rec()]]");

            //------------Assert Results-------------------------
            Assert.AreEqual(" 3, c", CommonFunctions.evalResultToString(res));
        }
Esempio n. 8
0
        public void Eval_JsonArrayComplexLast()
        {
            //------------Setup for test--------------------------
            var env = CreateEnvironmentWithData();
            //------------Execute Test---------------------------
            var res = EvaluationFunctions.eval(env, 0, false, "[[@arrayObj().Name]]");

            //------------Assert Results-------------------------
            Assert.AreEqual("bobe", CommonFunctions.evalResultToString(res));
        }
Esempio n. 9
0
        public void Eval_JsonNested()
        {
            //------------Setup for test--------------------------
            var env = CreateEnvironmentWithData();
            //------------Execute Test---------------------------
            var res = EvaluationFunctions.eval(env, 0, false, "[[@Person.Spouse.Name]]");

            //------------Assert Results-------------------------
            Assert.AreEqual("dora", CommonFunctions.evalResultToString(res));
        }
Esempio n. 10
0
        public void Eval_JsonNestedArrayOfObjects()
        {
            //------------Setup for test--------------------------
            var env = CreateEnvironmentWithData();
            //------------Execute Test---------------------------
            var res = EvaluationFunctions.eval(env, 0, false, "[[@Person.Children(*).Name]]");

            //------------Assert Results-------------------------
            Assert.AreEqual("Mary,Jane", CommonFunctions.evalResultToString(res));
        }
Esempio n. 11
0
        public void EvaluationFunctions_Eval_WithEscapeCharsEscapeFalse_ShouldReturnUnEscapedString()
        {
            //------------Setup for test--------------------------

            var env = CreateEnvironmentWithData();
            //------------Execute Test---------------------------
            var val = EvaluationFunctions.eval(env, 0, false, "[[escapeValue]]");

            //------------Assert Results-------------------------
            Assert.AreEqual("C:\test", CommonFunctions.evalResultToString(val));
        }
Esempio n. 12
0
        public void EvaluationFunctions_Eval_WithEscapeCharsEscapeTrue_ShouldReturnEscapedString()
        {
            //------------Setup for test--------------------------

            var env = CreateEnvironmentWithData();
            //------------Execute Test---------------------------
            var val = EvaluationFunctions.eval(env, 0, true, "[[escapeValue]]");

            //------------Assert Results-------------------------
            Assert.AreEqual("some\\ test\\ with\\ a\\ tab\\ character\\tin\\ it", CommonFunctions.evalResultToString(val));
        }
Esempio n. 13
0
        public void UpdateInPlace_Update_ApplyLambda_Atom()
        {
            //------------Setup for test--------------------------
            var env = CreateEnvironmentWithData();

            //------------Execute Test---------------------------
            var updated = PublicFunctions.EvalUpdate("12", env, 0, a => DataStorage.WarewolfAtom.NewDataString("1x"));
            //------------Assert Results-------------------------
            var res = CommonFunctions.evalResultToString(EvaluationFunctions.eval(updated, 0, false, "[[x]]"));

            Assert.AreEqual(res, "1x");
        }
Esempio n. 14
0
        public void Eval_RecSetWithIndexExpression()
        {
            //------------Setup for test--------------------------
            var env = CreateEnvironmentWithData();



            //------------Execute Test---------------------------
            var res = EvaluationFunctions.eval(env, 0, false, "[[Rec([[x]]).a]]");

            //------------Assert Results-------------------------
            Assert.AreEqual(CommonFunctions.evalResultToString(res), "1");
        }
Esempio n. 15
0
        public void Eval_RecSet_Complete_WithUpdate_Recset_Mixed()
        {
            //------------Setup for test--------------------------
            var env = CreateEnvironmentWithData();



            //------------Execute Test---------------------------
            var res = EvaluationFunctions.eval(env, 1, false, "[[Rec(*).a]][[Rec(3).a]]");

            //------------Assert Results-------------------------
            Assert.AreEqual(CommonFunctions.evalResultToString(res), "13");
        }
Esempio n. 16
0
        public void Eval_RecSet_Index_NonExistent()
        {
            //------------Setup for test--------------------------
            var env = CreateEnvironmentWithData();



            //------------Execute Test---------------------------
            var res = EvaluationFunctions.eval(env, 0, false, "[[eeerRec(1).a]]");

            //------------Assert Results-------------------------
            Assert.AreEqual(CommonFunctions.evalResultToString(res), "1");
        }
Esempio n. 17
0
        public void Eval_RecSet_Json_Array_star()
        {
            //------------Setup for test--------------------------
            var env = CreateEnvironmentWithData();



            //------------Execute Test---------------------------
            var res = EvaluationFunctions.eval(env, 0, false, "[[@Person.Score(*)]]");

            //------------Assert Results-------------------------
            Assert.AreEqual(CommonFunctions.evalResultToString(res), "2,3");
        }
Esempio n. 18
0
        public void Eval_RecSet_Atom()
        {
            //------------Setup for test--------------------------
            var env = CreateEnvironmentWithData();



            //------------Execute Test---------------------------
            var res = EvaluationFunctions.eval(env, 0, false, " 1 2 3");

            //------------Assert Results-------------------------
            Assert.AreEqual(CommonFunctions.evalResultToString(res), " 1 2 3");
        }
Esempio n. 19
0
        public void EvaluationFunctions_Eval_WithEscapeCharsEscapeFalseRecordSet_ShouldReturnUnEscapedString()
        {
            //------------Setup for test--------------------------

            var env = CreateEnvironmentWithData();
            //------------Execute Test---------------------------
            var val  = EvaluationFunctions.eval(env, 0, false, "[[esc(1).val]]");
            var val2 = EvaluationFunctions.eval(env, 0, false, "[[esc(2).val]]");

            //------------Assert Results-------------------------
            Assert.AreEqual("some\tstring", CommonFunctions.evalResultToString(val));
            Assert.AreEqual("another\tstring", CommonFunctions.evalResultToString(val2));
        }
Esempio n. 20
0
        public void EvaluationFunctions_Eval_WithEscapeCharsEscapeTrueRecordSet_ShouldReturnEscapedString()
        {
            //------------Setup for test--------------------------

            var env = CreateEnvironmentWithData();
            //------------Execute Test---------------------------
            var val  = EvaluationFunctions.eval(env, 0, true, "[[esc(1).val]]");
            var val2 = EvaluationFunctions.eval(env, 0, true, "[[esc(2).val]]");

            //------------Assert Results-------------------------
            Assert.AreEqual("C:\\temp", CommonFunctions.evalResultToString(val));
            Assert.AreEqual("C:\\tval", CommonFunctions.evalResultToString(val2));
        }
Esempio n. 21
0
        public void Sort_SortRecset_ExpectSortedRecset_desc()
        {
            //------------Setup for test--------------------------
            var env = CreateEnvironmentWithData();

            //------------Execute Test---------------------------
            var env2 = Sort.sortRecset("[[Rec(*).a]]", true, 0, env);
            //------------Assert Results-------------------------

            var res = CommonFunctions.evalResultToString(EvaluationFunctions.eval(env2, 0, false, "[[Rec(*).a]]"));

            Assert.AreEqual("3,2,2,1", res);
        }
Esempio n. 22
0
        public void Eval_RecSet_Complete_WithUpdate_Mixed()
        {
            //------------Setup for test--------------------------
            var env = CreateEnvironmentWithData();



            //------------Execute Test---------------------------
            var res = EvaluationFunctions.eval(env, 1, false, "[[Rec(*)]][[Rec(3)]]");

            //------------Assert Results-------------------------
            // note this is currently undefined behaviour
            Assert.AreEqual("13,1c,a3,ac", CommonFunctions.evalResultToString(res));
        }
Esempio n. 23
0
        public void UpdateInPlace_Update_ApplyLambda_ExpectError_Complex()
        {
            //------------Setup for test--------------------------
            var env = CreateEnvironmentWithData();

            //------------Execute Test---------------------------
            // ReSharper disable once RedundantAssignment
            var updated = PublicFunctions.EvalUpdate("[[s]]", env, 0, a => DataStorage.WarewolfAtom.NewDataString("[[s]]"));

            updated = PublicFunctions.EvalUpdate("[[[[s]]]]", updated, 0, a => DataStorage.WarewolfAtom.NewDataString("e"));
            //------------Assert Results-------------------------
            var res = CommonFunctions.evalResultToString(EvaluationFunctions.eval(updated, 0, false, "[[s]]"));

            Assert.AreEqual(res, "e");
        }
Esempio n. 24
0
        public void CreateJSONAndEvalPartialObject()
        {
            //------------Setup for test--------------------------
            var     createDataSet = WarewolfTestData.CreateTestEnvWithData;
            JObject j             = JObject.FromObject(new Person()
            {
                Name = "n", Children = new List <Person>()
            });
            var added = WarewolfDataEvaluationCommon.addToJsonObjects(createDataSet, "bob", j);

            //------------Execute Test---------------------------

            //------------Assert Results-------------------------
            Assert.IsTrue(added.JsonObjects.ContainsKey("bob"));
            Assert.AreEqual((added.JsonObjects["bob"] as JObject).GetValue("Name").ToString(), "n");
            var evalled = CommonFunctions.evalResultToString(EvaluationFunctions.eval(added, 0, false, "[[@bob.Name]]"));

            Assert.AreEqual(evalled, "n");
        }
Esempio n. 25
0
        public void Distinct_EvalDistinct_HappyPath_Last_ExpectDistinctResults()
        {
            //------------Setup for test--------------------------
            var env = CreateEnvironmentWithData();

            //------------Execute Test---------------------------
            var modified = Distinct.evalDistinct(env, new List <string>()
            {
                "[[Rec(*).a]]"
            }, new List <string> {
                "[[Rec(*).a]]"
            }, 0, new List <string> {
                "[[Bec().a]]"
            });

            //------------Assert Results-------------------------
            var res = CommonFunctions.evalResultToString(EvaluationFunctions.eval(modified, 0, false, "[[Bec(*).a]]"));

            Assert.AreEqual(res, "1,2,3");
        }
Esempio n. 26
0
 public void CommonFunctions_EvalResultToJsonCompatableJson()
 {
     var env = CreateEnvironmentWithData();
     var a   = CommonFunctions.evalResultToJsonCompatibleObject(EvaluationFunctions.eval(env, 0, false, "[[Rec(*)]]"));
 }