Ejemplo n.º 1
0
        public void TestMethod_01()
        {
            Inventor tesla = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian");

            tesla.PlaceOfBirth.City = "Smiljan";

            string evaluatedName = (string)ExpressionEvaluator.GetValue(tesla, "Name");

            Assert.AreEqual("Nikola Tesla", evaluatedName);

            string evaluatedCity = (string)ExpressionEvaluator.GetValue(tesla, "PlaceOfBirth.City");

            Assert.AreEqual("Smiljan", evaluatedCity);


            int year = (int)ExpressionEvaluator.GetValue(tesla, "DOB.Year");  // 1856

            Assert.AreEqual(1856, year);

            ExpressionEvaluator.SetValue(tesla, "PlaceOfBirth.City", "Novi Sad");


            evaluatedCity = (string)ExpressionEvaluator.GetValue(tesla, "PlaceOfBirth.City");

            Assert.AreEqual("Novi Sad", evaluatedCity);
        }
Ejemplo n.º 2
0
        public void TestMethod_20()
        {
            Inventor ieee = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian");
            // sets the name of the president and returns its instance
            var a1 = ExpressionEvaluator.GetValue(ieee, "Officers['president'].( #this.Name = 'Nikola Tesla'; #this )");


            var a2 = ExpressionEvaluator.GetValue(ieee, "Officers['president'].( #root.Officers.Remove('president'); #this )");
        }
Ejemplo n.º 3
0
        public void TestMethod_14()
        {
            Inventor ieee = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian");

            String pupin = (String)ExpressionEvaluator.GetValue(ieee.Members, "([1].Place.City = 'Beograd'; [1].Place.Name = 'Serbia'; [1].Name)");



        }
Ejemplo n.º 4
0
        public void TestMethod_16()
        {
            Inventor tesla = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian");
            Type dateType = (Type)ExpressionEvaluator.GetValue(null, "T(System.DateTime)");

            Type evalType =
                (Type)ExpressionEvaluator.GetValue(null, "T(Spring.Expressions.ExpressionEvaluator, Spring.EL)");

            bool trueValue = (bool)ExpressionEvaluator.GetValue(tesla, "T(System.DateTime) == DOB.GetType()");

        }
Ejemplo n.º 5
0
        public void TestMethod_13()
        {
            Inventor inventor = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian");

            String aleks = (String)ExpressionEvaluator.GetValue(inventor, "Name = 'Aleksandar Seovic'");

            DateTime dt = (DateTime)ExpressionEvaluator.GetValue(inventor, "DOB = date('1974-08-24')");



        }
Ejemplo n.º 6
0
        public void TestMethod_03()
        {
            Inventor tesla = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian");

            tesla.PlaceOfBirth.City = "Smiljan";
            string invention = (string)ExpressionEvaluator.GetValue(tesla, "Inventions[2]"); // "Induction motor"

            string name = (string)ExpressionEvaluator.GetValue(tesla, "Members[0].Name"); // "Nikola Tesla"


            string invention1 = (string)ExpressionEvaluator.GetValue(tesla, "Members[0].Inventions[2]"); // "Wireless communication"
        }
Ejemplo n.º 7
0
        public void TestMethod_22()
        {
            Inventor ieee = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian");
            ExpressionEvaluator.SetValue(ieee, "Name", "IEEE");
            Dictionary<string, object> vars = new Dictionary<string, object>();
            vars["queryName"] = "Nikola Tesla";

            string expression = @"IsMember(#queryName)
                      ? #queryName + ' is a member of the ' + Name + ' Society'
                      : #queryName + ' is not a member of the ' + Name + ' Society'";

            String queryResultString = (String)ExpressionEvaluator.GetValue(ieee, expression, vars);
        }
Ejemplo n.º 8
0
        public void TestMethod_17()
        {
            Inventor2 tesla = new Inventor2("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian");
            DateTime dt = (DateTime)ExpressionEvaluator.GetValue(null, "new DateTime(1974, 8, 24)");

            // Register Inventor type then create new inventor instance within Add method inside an expression list.
            // Then return the new count of the Members collection.

            TypeRegistry.RegisterType(typeof(PlaceOfBirth));
            int three = (int)ExpressionEvaluator.GetValue(tesla.Members, "( Add(new PlaceOfBirth('Aleksandar Seovic')); Count)");

            TypeRegistry.RegisterType(typeof(Inventor));
            Inventor aleks = (Inventor)ExpressionEvaluator.GetValue(null, "new Inventor('Aleksandar Seovic', date('1974-08-24'), 'Serbian', Inventions = new string[]{'SPELL'})");
        }
Ejemplo n.º 9
0
        public void TestMethod_06()
        {
            Inventor tesla = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian");
            //string literal
            char[] chars = (char[])ExpressionEvaluator.GetValue(null, "'test'.ToCharArray(1, 2)");  // 't','e'

            //date literal
            int year = (int)ExpressionEvaluator.GetValue(null, "date('1974/08/24').AddYears(31).Year"); // 2005

            // object usage, calculate age of tesla navigating from the IEEE society.

            int age = (int)ExpressionEvaluator.GetValue(tesla, "Members[0].GetAge(date('2005-01-01'))"); // 149 (eww..a big anniversary is coming up ;)

        }
Ejemplo n.º 10
0
        public void TestMethod_19()
        {
            Inventor tesla = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian");
            Dictionary<string, object> vars = new Dictionary<string, object>();
            vars["newName"] = "Mike Tesla2";
            var a = ExpressionEvaluator.GetValue(tesla, "Name = #newName", vars);


            ExpressionEvaluator.GetValue(tesla, "( #oldName = Name; Name = 'Nikola Tesla' )", vars);
            String oldName = (String)vars["oldName"]; // Mike Tesla


            vars["prez"] = "president";
            Inventor2 pupin = (Inventor2)ExpressionEvaluator.GetValue(tesla, "Officers[#prez]", vars);

        }
Ejemplo n.º 11
0
        public void TestMethod_23()
        {
            Inventor ieee = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian");
            IList placesOfBirth = (IList)ExpressionEvaluator.GetValue(ieee, "Members.!{Name}"); // { 'Smiljan', 'Idvor' }


            IList serbianInventors = (IList)ExpressionEvaluator.GetValue(ieee, "Members.?{Name == '1'}"); // { tesla, pupin }


            IList sonarInventors = (IList)ExpressionEvaluator.GetValue(ieee, "Members.?{'1' in Inventions}"); // { pupin }


            IList sonarInventorsNames = (IList)ExpressionEvaluator.GetValue(ieee, "Members.?{'1' in Inventions}.!{Name}"); // { 'Mihajlo Pupin' }


            var a1 = ExpressionEvaluator.GetValue(ieee, "Members.^{Name == '1'}.Name");  // 'Nikola Tesla'
            var a3 = ExpressionEvaluator.GetValue(ieee, "Members.${Name == '3'}.Name"); // 'Mihajlo Pupin'

        }
Ejemplo n.º 12
0
        public void TestMethod_10()
        {
            Inventor ieee = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian");
            // AND
            bool falseValue = (bool)ExpressionEvaluator.GetValue(null, "true and false"); //false

            string expression = @"IsMember('Nikola Tesla') and IsMember('Mihajlo Pupin')";
            bool trueValue = (bool)ExpressionEvaluator.GetValue(ieee, expression);  //true

            // OR
            trueValue = (bool)ExpressionEvaluator.GetValue(null, "true or false");  //true

            expression = @"IsMember('Nikola Tesla') or IsMember('Albert Einstien')";
            trueValue = (bool)ExpressionEvaluator.GetValue(ieee, expression); // true

            // NOT
            falseValue = (bool)ExpressionEvaluator.GetValue(null, "!true");

            // AND and NOT
            expression = @"IsMember('Nikola Tesla') and !IsMember('Mihajlo Pupin')";
            falseValue = (bool)ExpressionEvaluator.GetValue(ieee, expression);

        }