Ejemplo n.º 1
0
        public void Method_with_generic_param()
        {
            var target = new Interpreter();

            var    x          = new MyTestService();
            var    y          = "davide";
            double z          = 5;
            int?   w          = null;
            var    parameters = new[] {
                new Parameter("x", x.GetType(), x),
                new Parameter("y", y.GetType(), y),
                new Parameter("z", z.GetType(), z),
                new Parameter("w", typeof(int?), w)
            };

            Assert.AreEqual(x.MethodWithGenericParam(x), target.Eval("x.MethodWithGenericParam(x)", parameters));
            Assert.AreEqual(x.MethodWithGenericParam(y), target.Eval("x.MethodWithGenericParam(y)", parameters));
            Assert.AreEqual(x.MethodWithGenericParam(z), target.Eval("x.MethodWithGenericParam(z)", parameters));
            Assert.AreEqual(x.MethodWithGenericParam(w), target.Eval("x.MethodWithGenericParam(w)", parameters));

            Assert.AreEqual(x.MethodWithGenericParam(y, x), target.Eval("x.MethodWithGenericParam(y, x)", parameters));
            Assert.AreEqual(x.MethodWithGenericParam(y, y), target.Eval("x.MethodWithGenericParam(y, y)", parameters));
            Assert.AreEqual(x.MethodWithGenericParam(y, z), target.Eval("x.MethodWithGenericParam(y, z)", parameters));
            Assert.AreEqual(x.MethodWithGenericParam(y, w), target.Eval("x.MethodWithGenericParam(y, w)", parameters));
        }
Ejemplo n.º 2
0
		public void Should_Understand_ReturnType_Of_expressions()
		{
			var target = new Interpreter();

			var x = new MyTestService();
			var y = 5;
			var parameters = new[] {
                            new Parameter("x", x.GetType(), x),
                            new Parameter("y", y.GetType(), y),
                            };

			Assert.AreEqual(typeof(bool), target.Parse("x.AProperty > y && x.HelloWorld().Length == 10", parameters).ReturnType);
			Assert.AreEqual(typeof(int), target.Parse("x.AProperty * (4 + 65) / x.AProperty", parameters).ReturnType);
		}
Ejemplo n.º 3
0
        public void Should_Understand_ReturnType_Of_expressions()
        {
            var target = new Interpreter();

            var x          = new MyTestService();
            var y          = 5;
            var parameters = new[] {
                new Parameter("x", x.GetType(), x),
                new Parameter("y", y.GetType(), y),
            };

            Assert.AreEqual(typeof(bool), target.Parse("x.AProperty > y && x.HelloWorld().Length == 10", parameters).ReturnType);
            Assert.AreEqual(typeof(int), target.Parse("x.AProperty * (4 + 65) / x.AProperty", parameters).ReturnType);
        }
Ejemplo n.º 4
0
        public void Methods_Fields_And_Properties_By_Default_Are_Case_Sensitive()
        {
            var target = new Interpreter();

            var x          = new MyTestService();
            var parameters = new[] {
                new Parameter("x", x.GetType(), x)
            };

            Assert.AreEqual(x.HelloWorld(), target.Eval("x.HelloWorld()", parameters));
            Assert.AreEqual(x.HELLOWORLD(), target.Eval("x.HELLOWORLD()", parameters));
            Assert.AreEqual(x.AProperty, target.Eval("x.AProperty", parameters));
            Assert.AreEqual(x.APROPERTY, target.Eval("x.APROPERTY", parameters));
            Assert.AreEqual(x.AField, target.Eval("x.AField", parameters));
            Assert.AreEqual(x.AFIELD, target.Eval("x.AFIELD", parameters));
        }
Ejemplo n.º 5
0
        public void Method_with_optional_null_param()
        {
            var target = new Interpreter();

            var x          = new MyTestService();
            var y          = "1";
            var z          = "2";
            var parameters = new[] {
                new Parameter("x", x.GetType(), x),
                new Parameter("y", y.GetType(), y),
                new Parameter("z", z.GetType(), z),
            };

            Assert.AreEqual(x.MethodWithOptionalNullParam(y), target.Eval("x.MethodWithOptionalNullParam(y)", parameters));
            Assert.AreEqual(x.MethodWithOptionalNullParam(y, z), target.Eval("x.MethodWithOptionalNullParam(y, z)", parameters));
        }
Ejemplo n.º 6
0
        public void Complex_expression()
        {
            var target = new Interpreter();

            var x          = new MyTestService();
            var y          = 5;
            var parameters = new[] {
                new Parameter("x", x.GetType(), x),
                new Parameter("y", y.GetType(), y),
            };

            Assert.AreEqual(x.AProperty > y && x.HelloWorld().Length == 10, target.Eval("x.AProperty      >\t y && \r\n x.HelloWorld().Length == 10", parameters));
            Assert.AreEqual(x.AProperty * (4 + 65) / x.AProperty, target.Eval("x.AProperty * (4 + 65) / x.AProperty", parameters));

            Assert.AreEqual(Convert.ToString(x.AProperty * (4 + 65) / x.AProperty), target.Eval("Convert.ToString(x.AProperty * (4 + 65) / x.AProperty)", parameters));
        }
Ejemplo n.º 7
0
        public void Complex_parameters()
        {
            var target = new Interpreter();

            var x          = new MyTestService();
            var y          = new Uri("http://www.google.com");
            var z          = CultureInfo.GetCultureInfo("en-US");
            var parameters = new[] {
                new Parameter("x", x.GetType(), x),
                new Parameter("y", y.GetType(), y),
                new Parameter("z", z.GetType(), z)
            };

            Assert.AreEqual(x, target.Eval("x", parameters));
            Assert.AreEqual(y, target.Eval("y", parameters));
            Assert.AreEqual(z, target.Eval("z", parameters));
        }
Ejemplo n.º 8
0
        public void Complex_parameters()
        {
            var target = new Interpreter();

            var x = new MyTestService();
            var y = new Uri("http://www.google.com");
            var z = CultureInfo.GetCultureInfo("en-US");
            var parameters = new[] {
                            new Parameter("x", x.GetType(), x),
                            new Parameter("y", y.GetType(), y),
                            new Parameter("z", z.GetType(), z)
                            };

            Assert.AreEqual(x, target.Eval("x", parameters));
            Assert.AreEqual(y, target.Eval("y", parameters));
            Assert.AreEqual(z, target.Eval("z", parameters));
        }
Ejemplo n.º 9
0
        public void Method_with_nullable_param()
        {
            var target = new Interpreter();

            var x          = new MyTestService();
            var y          = "davide";
            var z          = 5;
            int?w          = null;
            var parameters = new[] {
                new Parameter("x", x.GetType(), x),
                new Parameter("y", y.GetType(), y),
                new Parameter("z", z.GetType(), z),
                new Parameter("w", typeof(int?), w)
            };

            Assert.AreEqual(x.MethodWithNullableParam(y, z), target.Eval("x.MethodWithNullableParam(y, z)", parameters));
            Assert.AreEqual(x.MethodWithNullableParam(y, w), target.Eval("x.MethodWithNullableParam(y, w)", parameters));
            Assert.AreEqual(x.MethodWithNullableParam(y, 30), target.Eval("x.MethodWithNullableParam(y, 30)", parameters));
            Assert.AreEqual(x.MethodWithNullableParam(y, null), target.Eval("x.MethodWithNullableParam(y, null)", parameters));
        }
Ejemplo n.º 10
0
        public void Methods_Fields_and_Properties_On_Parameters()
        {
            var target = new Interpreter();

            var x          = new MyTestService();
            var y          = "davide";
            var z          = 5;
            var w          = DateTime.Today;
            var parameters = new[] {
                new Parameter("x", x.GetType(), x),
                new Parameter("y", y.GetType(), y),
                new Parameter("z", z.GetType(), z),
                new Parameter("w", w.GetType(), w)
            };

            Assert.AreEqual(x.HelloWorld(), target.Eval("x.HelloWorld()", parameters));
            Assert.AreEqual(x.CallMethod(y, z, w), target.Eval("x.CallMethod( y, z,w)", parameters));
            Assert.AreEqual(x.AProperty + 1, target.Eval("x.AProperty + 1", parameters));
            Assert.AreEqual(x.AField, target.Eval("x.AField", parameters));
        }
Ejemplo n.º 11
0
        public void Methods_Fields_and_Properties_On_Parameters()
        {
            var target = new Interpreter();

            var x = new MyTestService();
            var y = "davide";
            var z = 5;
            var w = DateTime.Today;
            var parameters = new[] {
                            new Parameter("x", x.GetType(), x),
                            new Parameter("y", y.GetType(), y),
                            new Parameter("z", z.GetType(), z),
                            new Parameter("w", w.GetType(), w)
                            };

            Assert.AreEqual(x.HelloWorld(), target.Eval("x.HelloWorld()", parameters));
            Assert.AreEqual(x.CallMethod(y, z, w), target.Eval("x.CallMethod( y, z,w)", parameters));
            Assert.AreEqual(x.AProperty + 1, target.Eval("x.AProperty + 1", parameters));
            Assert.AreEqual(x.AField, target.Eval("x.AField", parameters));
        }
Ejemplo n.º 12
-1
        public void Complex_expression()
        {
            var target = new Interpreter();

            var x = new MyTestService();
            var y = 5;
            var parameters = new[] {
                            new Parameter("x", x.GetType(), x),
                            new Parameter("y", y.GetType(), y),
                            };

            Assert.AreEqual(x.AProperty > y && x.HelloWorld().Length == 10, target.Eval("x.AProperty      >\t y && \r\n x.HelloWorld().Length == 10", parameters));
            Assert.AreEqual(x.AProperty * (4 + 65) / x.AProperty, target.Eval("x.AProperty * (4 + 65) / x.AProperty", parameters));

            Assert.AreEqual(Convert.ToString(x.AProperty * (4 + 65) / x.AProperty), target.Eval("Convert.ToString(x.AProperty * (4 + 65) / x.AProperty)", parameters));
        }