Exemplo 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));
        }
Exemplo n.º 2
0
        public void Null_conditional_property()
        {
            var           target = new Interpreter().SetVariable("x", null, typeof(MyTestService));
            MyTestService x      = null;

            Assert.IsNull(target.Eval("x?.AProperty"));
        }
Exemplo n.º 3
0
        public void Indexer_Setter_MultiDimensional()
        {
            var target = new Interpreter();

            var x = new[, ] {
                { 11, 12, 13, 14 }, { 21, 22, 23, 24 }, { 31, 32, 33, 34 }
            };

            target.SetVariable("x", x);
            var y = new MyTestService();

            target.SetVariable("y", y);

            var span = TimeSpan.FromDays(3.5);

            target.SetVariable("span", span);

            target.Eval("x[1, 2] = 7");
            Assert.AreEqual(x, new[, ] {
                { 11, 12, 13, 14 }, { 21, 22, 7, 24 }, { 31, 32, 33, 34 }
            });
            target.Eval("y[y.Today, 2] = span");
            Assert.AreEqual(y.AField, y.Today.AddDays(2).Add(span));
            target.Eval("y[y.Today] = span");
            Assert.AreEqual(y.AField, y.Today.AddDays(3).Add(span));
        }
        public void Overload_paramsArray_methods_with_compatible_type_params()
        {
            var target = new Interpreter();
            var x      = new MyTestService();

            target.SetVariable("x", x);
            Assert.AreEqual(3, target.Eval("x.OverloadMethodWithParamsArray(2, 3, 1)"));
        }
Exemplo n.º 5
0
Arquivo: test.cs Projeto: mono/gert
	static int Main ()
	{
		MyTestService svc = new MyTestService ();
		if (svc.SayHello ("Mono") != "Hello Mono")
			return 1;

		return 0;
	}
Exemplo n.º 6
0
        public void ToString_Method_on_a_custom_type()
        {
            var service = new MyTestService();
            var target  = new Interpreter()
                          .SetVariable("service", service);

            Assert.AreEqual("DynamicExpresso.UnitTest.MemberInvocationTest+MyTestService", target.Eval("service.ToString()"));
        }
Exemplo n.º 7
0
        public void GetType_Method_on_a_custom_type()
        {
            var service = new MyTestService();
            var target  = new Interpreter()
                          .SetVariable("service", service);

            Assert.AreEqual(typeof(MyTestService), target.Eval("service.GetType()"));
        }
Exemplo n.º 8
0
        public void Static_Properties_And_Methods_Of_Custom_Types()
        {
            var target = new Interpreter()
                         .Reference(typeof(Uri))
                         .Reference(typeof(MyTestService));

            Assert.AreEqual(Uri.UriSchemeHttp, target.Eval("Uri.UriSchemeHttp"));
            Assert.AreEqual(MyTestService.MyStaticMethod(), target.Eval("MyTestService.MyStaticMethod()"));
        }
Exemplo n.º 9
0
        public void Chaining_Methods()
        {
            var x = new MyTestService();

            var target = new Interpreter();

            target.SetVariable("x", x);

            Assert.AreEqual(x.HelloWorld().ToUpper(), target.Eval("x.HelloWorld().ToUpper()"));
        }
Exemplo n.º 10
0
        public void Method_Property_Field_basic_test()
        {
            var x = new MyTestService();

            var target = new Interpreter().SetVariable("x", x);

            Assert.AreEqual(x.HelloWorld(), target.Eval("x.HelloWorld()"));
            Assert.AreEqual(x.AProperty, target.Eval("x.AProperty"));
            Assert.AreEqual(x.AField, target.Eval("x.AField"));
        }
Exemplo n.º 11
0
Arquivo: test.cs Projeto: mono/gert
	static int Main ()
	{
		MyTestService svc = new MyTestService ();
		DateTime date = svc.SayHello ("Mono");
		if (date != DateTime.MinValue) {
			Console.WriteLine (date.ToLongDateString ());
			return 1;
		}

		return 0;
	}
        public void ServicePublishTwoMessage()
        {
            var service = new MyTestService(MessageBus);

            Start();

            service.DoStuffAndPublishMessage(2);

            MessageBroker.Published.Should().Contain(m => m.Topic == "MyPublishTopic");
            MessageBroker.Published.Count().Should().Be(2);
        }
Exemplo n.º 13
0
        public void Void_Method()
        {
            var service = new MyTestService();
            var target  = new Interpreter()
                          .SetVariable("service", service);

            Assert.AreEqual(0, service.VoidMethodCalls);
            target.Eval("service.VoidMethod()");
            Assert.AreEqual(1, service.VoidMethodCalls);

            Assert.AreEqual(typeof(void), target.Parse("service.VoidMethod()").ReturnType);
        }
Exemplo n.º 14
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);
        }
Exemplo n.º 15
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);
		}
        public void RequestResponseFromService()
        {
            var service = new MyTestService(MessageBus);

            MessageBus.RequestHandler <MyRequestDto, MyResponseDto>(MyTestServiceConfig.MyTestRequest, service.MyTestRequestHandler);

            Start();

            var response = MessageBroker.Request <MyRequestDto, MyResponseDto>(MyTestServiceConfig.MyTestRequest, new MyRequestDto {
                Name = "MyRequest", Count = 1
            });

            response.Name.Should().Be("MyRequest");
            response.Count.Should().Be(1);
        }
        public void RegisterTwoSubscriberToSameTopicAndSendOneMessage()
        {
            var service = new MyTestService(MessageBus);

            MessageBus.SubscribeHandler <MySubscribeDto>(MyTestServiceConfig.MyTestSubscribe, service.MyTestSubscribeHandler);
            MessageBus.SubscribeHandler <MySubscribeDto>(MyTestServiceConfig.MyTestSubscribe, service.MyTestSubscribeHandler);

            Start();

            MessageBroker.Publish(MyTestServiceConfig.MyTestSubscribe, new MySubscribeDto {
                Name = "A"
            });

            MessageBroker.Published.Count().Should().Be(2);
        }
Exemplo n.º 18
0
        public void Indexer()
        {
            var target = new Interpreter();

            var x = "ciao";

            target.SetVariable("x", x);
            var y = new MyTestService();

            target.SetVariable("y", y);

            Assert.AreEqual(x[2], target.Eval("x[2]"));
            Assert.AreEqual(y[2], target.Eval("y[2]"));
            Assert.AreEqual(y[2].ToString(), target.Eval("y[2].ToString()"));
        }
        public void RegisterOneSubscriberAndSendOneMessageThatFailsTheSubscriber()
        {
            var service = new MyTestService(MessageBus);

            MessageBus.SubscribeHandler <MySubscribeDto>(MyTestServiceConfig.MyTestSubscribe, service.MyTestSubscribeHandler);

            Start();

            MessageBroker.Publish(MyTestServiceConfig.MyTestSubscribe, new MySubscribeDto {
                Name = "Exception"
            });

            MessageBroker.Published.Count().Should().Be(0);
            MessageBroker.SubscriberHandlerFailed.Count().Should().Be(1);
            MessageBroker.SubscriberHandlerCompleted.Count().Should().Be(0);
        }
Exemplo n.º 20
0
        public void ParamsArray_methods_are_not_called_when_there_is_an_exact_method_match()
        {
            var target = new Interpreter();

            var x = new MyTestService();

            target.SetVariable("x", x);

            target.Eval("x.AmbiguousMethod(DateTime.Now, 2, 3)");
            Assert.AreEqual(1, x.AmbiguousMethod_NormalCalls);
            Assert.AreEqual(0, x.AmbiguousMethod_ParamsArrayCalls);

            target.Eval("x.AmbiguousMethod(DateTime.Now, 2, 3, 4)");
            Assert.AreEqual(1, x.AmbiguousMethod_NormalCalls);
            Assert.AreEqual(1, x.AmbiguousMethod_ParamsArrayCalls);
        }
Exemplo n.º 21
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));
        }
Exemplo n.º 22
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));
        }
Exemplo n.º 23
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));
        }
Exemplo n.º 24
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));
        }
Exemplo n.º 25
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));
        }
Exemplo n.º 26
0
        public void Indexer_Getter_MultiDimensional()
        {
            var target = new Interpreter();

            var x = new[, ] {
                { 11, 12, 13, 14 }, { 21, 22, 23, 24 }, { 31, 32, 33, 34 }
            };

            target.SetVariable("x", x);
            var y = new MyTestService();

            target.SetVariable("y", y);

            Assert.AreEqual(x[1, 2], target.Eval("x[1, 2]"));
            Assert.AreEqual(y[y.Today, 2], target.Eval("y[y.Today, 2]"));
            Assert.AreEqual(y[y.Today], target.Eval("y[y.Today]"));
        }
Exemplo n.º 27
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));
        }
Exemplo n.º 28
0
        public void Method_with_params_array()
        {
            var target = new Interpreter();

            var x = new MyTestService();

            target.SetVariable("x", x);

            Assert.AreEqual(0, x.MethodWithParamsArrayCalls);

            Assert.AreEqual(x.MethodWithParamsArray(DateTime.Now, 2, 1, 34), target.Eval("x.MethodWithParamsArray(DateTime.Now, 2, 1, 34)"));
            Assert.AreEqual(2, x.MethodWithParamsArrayCalls);

            var myParamArray = new int[] { 2, 1, 34 };

            target.SetVariable("myParamArray", myParamArray);

            Assert.AreEqual(x.MethodWithParamsArray(DateTime.Now, myParamArray), target.Eval("x.MethodWithParamsArray(DateTime.Now, myParamArray)"));
            Assert.AreEqual(4, x.MethodWithParamsArrayCalls);
        }
Exemplo n.º 29
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));
        }
        public void ServiceCallRequestAsyncGetMockResponse()
        {
            var service = new MyTestService(MessageBus);

            MessageBroker.MockResponse <MyRequestDto, MyResponseDto>(MyTestServiceConfig.MyTestRequest, r => r.Name == "YourName", new MyResponseDto {
                Name = "MyResponse1"
            });
            MessageBroker.MockResponse <MyRequestDto, MyResponseDto>(MyTestServiceConfig.MyTestRequest, r => r.Name == "MyName", new MyResponseDto {
                Name = "MyResponse2"
            });
            MessageBroker.MockResponse(MyTestServiceConfig.MyTestRequest, new MyResponseDto {
                Name = "MyResponse3"
            });

            Start();

            service.DoStuffAndRequestAsyncData();

            service.Name.Should().Be("MyResponse2");
        }
Exemplo n.º 31
0
        public void Indexer_Getter()
        {
            var target = new Interpreter();

            var x = "ciao";

            target.SetVariable("x", x);
            var y = new MyTestService();

            target.SetVariable("y", y);
            var z = new[] { 7, 8, 9, 10 };

            target.SetVariable("z", z);

            Assert.AreEqual(x[2], target.Eval("x[2]"));
            Assert.AreEqual(y[2], target.Eval("y[2]"));
            Assert.AreEqual(y[2].ToString(), target.Eval("y[2].ToString()"));
            Assert.AreEqual(y[(short)2], target.Eval("y[(Int16)2]"));
            Assert.AreEqual(z[2], target.Eval("z[2]"));
        }
Exemplo n.º 32
0
        public void Indexer_Setter()
        {
            var target = new Interpreter();

            var x = new System.Text.StringBuilder("time");

            target.SetVariable("x", x);
            var y = new MyTestService();

            target.SetVariable("y", y);
            var z = new[] { 7, 8, 9, 10 };

            target.SetVariable("z", z);

            target.Eval("x[2] = 'r'");
            Assert.AreEqual(x.ToString(), "tire");
            target.Eval("y[(Int16)9] = y.Today");
            Assert.AreEqual(y.AField, y.Today.AddYears(9));
            target.Eval("y[(Int64)7] = y.Today");
            Assert.AreEqual(y.AField, y.Today.AddSeconds(7));
            target.Eval("z[2] = 4");
            Assert.AreEqual(z, new[] { 7, 8, 4, 10 });
        }
Exemplo n.º 33
0
		public void Parse_An_Expression_And_Invoke_It_With_Different_Parameters()
		{
			var service = new MyTestService();

			var target = new Interpreter()
													.SetVariable("service", service);

			var func = target.Parse("x > 4 ? service.VoidMethod() : service.VoidMethod2()",
															new Parameter("x", typeof(int)));

			Assert.AreEqual(typeof(void), func.ReturnType);

			Assert.AreEqual(0, service.VoidMethodCalled);
			Assert.AreEqual(0, service.VoidMethod2Called);

			func.Invoke(new Parameter("x", 5));
			Assert.AreEqual(1, service.VoidMethodCalled);
			Assert.AreEqual(0, service.VoidMethod2Called);

			func.Invoke(new Parameter("x", 2));
			Assert.AreEqual(1, service.VoidMethodCalled);
			Assert.AreEqual(1, service.VoidMethod2Called);
		}
Exemplo n.º 34
0
        public void Parse_An_Expression_And_Invoke_It_With_Different_Parameters()
        {
            var service = new MyTestService();

            var target = new Interpreter()
                         .SetVariable("service", service);

            var func = target.Parse("x > 4 ? service.VoidMethod() : service.VoidMethod2()",
                                    new Parameter("x", typeof(int)));

            Assert.AreEqual(typeof(void), func.ReturnType);

            Assert.AreEqual(0, service.VoidMethodCalled);
            Assert.AreEqual(0, service.VoidMethod2Called);

            func.Invoke(new Parameter("x", 5));
            Assert.AreEqual(1, service.VoidMethodCalled);
            Assert.AreEqual(0, service.VoidMethod2Called);

            func.Invoke(new Parameter("x", 2));
            Assert.AreEqual(1, service.VoidMethodCalled);
            Assert.AreEqual(1, service.VoidMethod2Called);
        }
Exemplo n.º 35
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));
        }
Exemplo n.º 36
-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));
        }