Пример #1
0
        public void Test_MultiLevel_Variable_Names()
        {
            IParameterDic dic = new ParameterDic();
            IParameterDic subDic1, subDic2;
            int dictionaryCount, subDic1Count, subDic2Count, 
                property1Value, property3Value, property5Value;

            dic.Set("{SubDic1.Property1}", 1);
            dic.Set("{SubDic1.SubDic2.Property3}", 3);
            dic.Set("{SubDic1.SubDic2.Property5}", 3);
            dic.Add("{SubDic1.SubDic2.Property5}", 2);

            subDic1 = dic.Get<ParameterDic>("{SubDic1}");
            property1Value = dic.Get("{SubDic1.Property1}", -1);
            subDic2 = dic.Get<ParameterDic>("{SubDic1.SubDic2}");
            property3Value = dic.Get("{SubDic1.SubDic2.Property3}", -1);
            property5Value = dic.Get("{SubDic1.SubDic2.Property5}", -1);

            dictionaryCount = dic.List().Count();
            subDic1Count = subDic1.List().Count();
            subDic2Count = subDic2.List().Count();

            Assert.AreEqual(1, dictionaryCount, "dictionaryCount");
            Assert.IsNotNull(subDic1, "subDic1");
            Assert.IsNotNull(subDic2, "subDic2");
            Assert.AreEqual(2, subDic1Count, "subDic1Count");
            Assert.AreEqual(2, subDic2Count, "subDic2Count");

            Assert.AreEqual(1, property1Value, "property1Value");
            Assert.AreEqual(3, property3Value, "property3Value");
            Assert.AreEqual(5, property5Value, "property5Value");



        }
Пример #2
0
        public void Test_ExecuteFunc()
        {
            IParameterDic pm = new ParameterDic();

            Assert.IsTrue(runCommand(
                              ScriptCommands.Assign("{utcNow}", DateTime.UtcNow,
                                                    ScriptCommands.ExecuteFunc("{utcNow}", "AddDays",
                                                                               new object[] { 10 }, "{utcNow10}")), pm));
            Assert.AreNotEqual(pm.Get("{utcNow.Day}"), pm.Get("{utcNow10.Day}"));
        }
Пример #3
0
        public void Test_SubString()
        {
            IParameterDic pm  = new ParameterDic();
            string        str = "onceuponatime";

            Assert.IsTrue(runCommand(
                              ScriptCommands.Assign("{str}", str,
                                                    ScriptCommands.Substring("{str}", 4, "{outputStr}",
                                                                             ScriptCommands.Substring("{str}", 4, 4, "{outputStr2}"))), pm));
            Assert.AreEqual("uponatime", pm.Get("{outputStr}"));
            Assert.AreEqual("upon", pm.Get("{outputStr2}"));
        }
Пример #4
0
        public void Test_GetArrayItem()
        {
            IParameterDic pm = new ParameterDic();

            int[] array = new[] { 1, 3, 5 };
            Assert.IsTrue(runCommand(
                              ScriptCommands.Assign("{array}", array,
                                                    ScriptCommands.GetArrayItem("{array}", 1, "{item1}",
                                                                                ScriptCommands.Reassign("{array[1]}", null, "{item2}"))), pm));
            Assert.AreEqual(3, pm.Get("{item1}"));
            Assert.AreEqual(3, pm.Get("{item2}"));
        }
Пример #5
0
        public void Test_GetProperty()
        {
            IParameterDic pm = new ParameterDic();

            Assert.IsTrue(runCommand(
                              ScriptCommands.Assign("{utcNow}", DateTime.UtcNow,
                                                    ScriptCommands.GetProperty("{utcNow}", "Ticks", "{ticks1}",
                                                                               ScriptCommands.Reassign("{utcNow.Ticks}", null, "{ticks2}"))), pm));
            Assert.AreNotEqual(0, pm.Get("{ticks1}"));
            Assert.AreEqual(pm.Get <long>("{ticks1}"),
                            pm.Get <long>("{ticks2}"));
        }
Пример #6
0
        public void Test_ParameterDic_Not_Altered()
        {
            IParameterDic pm = new ParameterDic();

            pm.Set("{var1}", 1);
            ScriptRunner.RunScript(pm, false, //Not Cloned
                                   ScriptCommands.Assign("{var1}", 2));
            Assert.AreEqual(2, pm.Get <int>("{var1}", -1));

            pm.Set("{var1}", 1);
            ScriptRunner.RunScript(pm, true, //Cloned
                                   ScriptCommands.Assign("{var1}", 2));
            Assert.AreEqual(1, pm.Get <int>("{var1}", -1));
        }
Пример #7
0
        public void Test_SetProperty()
        {
            IParameterDic pm  = new ParameterDic();
            testClass     obj = new testClass()
            {
                val1 = 1, val2 = 2
            };

            Assert.IsTrue(runCommand(
                              ScriptCommands.Assign("{obj}", obj,
                                                    ScriptCommands.SetProperty("{obj}", "val1", "{obj.val2}",
                                                                               ScriptCommands.Assign("{obj.val2}", 1))), pm));
            Assert.AreEqual(2, pm.Get <int>("{obj.val1}"));
            Assert.AreEqual(1, pm.Get <int>("{obj.val2}"));
        }
Пример #8
0
        public void Test_Script_Assign()
        {
            IParameterDic pm = new ParameterDic();
            int           var1; bool resultValue;

            bool success = runCommand(ScriptCommands.Assign("{var1}", 1,
                                                            ScriptCommands.IfEquals("{var1}", 1,
                                                                                    ScriptCommands.Assign("{resultValue}", true),
                                                                                    ScriptCommands.Assign("{resultValue}", false))), pm);

            Assert.IsTrue(success);
            var1        = pm.Get("{var1}", -1);
            resultValue = pm.Get("{resultValue}", false);

            Assert.AreEqual(var1, 1);
            Assert.IsTrue(resultValue);
        }
Пример #9
0
        public void Test_Add_Int_And_String()
        {
            IParameterDic dic = new ParameterDic();
            int property1Value = -1;
            string property2Value;

            dic.Set("{Property1}", 10);
            dic.Set("{Property2}", "Once");

            dic.Add("{Property1}", 1, 2, 3);
            dic.Add("{Property2}", "upon", "a", "time");

            property1Value = dic.Get("{Property1}", -1);
            property2Value = dic.Get("{Property2}", "");

            Assert.AreEqual(16, property1Value);
            Assert.AreEqual("Onceuponatime", property2Value);
        }
Пример #10
0
        public void Test_Basic_Get_And_Set_Operation()
        {
            IParameterDic dic = new ParameterDic();
            int totalItems1, totalItems2;
            string property1Value;
            int property2Value;

            dic.Set("{Property1}", "Property1");
            dic.Set("{Property2}", 2);
            totalItems1 = dic.List().Count();

            property1Value = dic.Get("{Property1}") as string;
            property2Value = dic.Get<int>("{Property2}");
            dic.Remove("{Property2}");
            totalItems2 = dic.List().Count();

            Assert.AreEqual(2, totalItems1);
            Assert.AreEqual(1, totalItems2);
            Assert.AreEqual("Property1", property1Value);
            Assert.AreEqual(2, property2Value);
        }
Пример #11
0
        public void Test_AssignValueFunc()
        {
            IParameterDic pm = new ParameterDic();
            DateTime      utcNow;

            bool success = runCommand(ScriptCommands.AssignValueFunc("{utcNow}",
                                                                     () => DateTime.UtcNow), pm);

            Assert.IsTrue(success);
            utcNow = pm.Get("{utcNow}", DateTime.MinValue);

            Assert.AreNotEqual(DateTime.MinValue, utcNow);
        }
Пример #12
0
        public void Test_ForEach()
        {
            int[]         array = new int[] { 1, 3, 5 };
            IParameterDic pm    = new ParameterDic();
            int           sum;

            bool success = runCommand(
                ScriptCommands.Assign("{array}", array,
                                      ScriptCommands.ForEach("{array}", "{i}",
                                                             ScriptCommands.Add("{i}", "{sum}", "{sum}"))), pm);

            Assert.IsTrue(success);
            sum = pm.Get <int>("{sum}");

            Assert.AreEqual(9, sum);
        }
Пример #13
0
        public void Test_ArithmeticCommands()
        {
            IParameterDic pm = new ParameterDic();
            int           val1 = 1; int val2 = 2;

            //Assert.IsTrue(runCommand(
            //    ScriptCommands.Assign(val1,
            //        ScriptCommands.Assign(val2,
            //          ScriptCommands.Add("{val1}", "{val2}", "{outputVal}"))), pm));
            Assert.IsTrue(runCommand(
                              ScriptCommands.AssignMulti(
                                  ScriptCommands.Add("{val1}", "{val2}", "{outputVal}"),
                                  () => val1,
                                  () => val2), pm));
            Assert.AreEqual(3, pm.Get("{outputVal}"));
        }
Пример #14
0
        public void Test_FormatText()
        {
            string        fmtString = "{day}-{month}-{year}";
            int           day = 5; int month = 12; int year = 2015;
            string        outputStr;
            IParameterDic pm = new ParameterDic();

            bool success = runCommand(
                ScriptCommands.Assign("{day}", day,
                                      ScriptCommands.Assign("{month}", month,
                                                            ScriptCommands.Assign("{year}", year,
                                                                                  ScriptCommands.FormatText("{output}", fmtString)))), pm);

            Assert.IsTrue(success);
            outputStr = pm.Get <string>("{output}");

            Assert.AreEqual("5-12-2015", outputStr);
        }
Пример #15
0
        public void Test_FilterArray()
        {
            int[]         array = new int[] { 1, 3, 5 };
            IParameterDic pm    = new ParameterDic();

            int[] outputArray; int arraySize;

            bool success = runCommand(
                ScriptCommands.Assign("{array}", array,
                                      ScriptCommands.FilterArray("{array}", null,
                                                                 ComparsionOperator.GreaterThan, 2, "{outputArray}",
                                                                 ScriptCommands.PrintDebug("{outputArray.Length}"))), pm);

            Assert.IsTrue(success);
            outputArray = pm.Get <int[]>("{outputArray}");
            arraySize   = outputArray.Length;

            Assert.IsNotNull(outputArray);
            Assert.AreEqual(2, arraySize);
        }