public void AddEventHandlerToPerson()
        {
            NameListener listener = new NameListener();
            Person person = new Person() { FirstName = "Adam" };
            FunctionWrapper<string, int, MyEvent> wrapper = new FunctionWrapper<string, int, MyEvent>(listener, null);
            typeof(Person).GetEvent("NameEvent").AddEventHandler(person, wrapper.CreateFunctionDelegate());
            person.GetName();

            Assert.AreEqual(4, listener.Length);
            Assert.AreEqual("Adam", listener.Name);
        }
        public void AddEventHandlerToCalculator()
        {
            Listener listener = new Listener();
            Calculator calculator = new Calculator();
            FunctionWrapper<int, int, int, Action<int, int>> wrapper = new FunctionWrapper<int, int, int, Action<int, int>>(listener, null);
            typeof(Calculator).GetEvent("MyEvent").AddEventHandler(calculator, wrapper.CreateActionDelegate());
            calculator.Add(1, 2);

            Assert.AreEqual(1, listener.X);
            Assert.AreEqual(2, listener.Y);

            MethodInfo invoke = typeof(Calculator).GetEvent("MyEvent").EventHandlerType.GetMethod("Invoke");
            MethodInfo add = typeof(Calculator).GetEvent("MyEvent").GetAddMethod();
            Assert.IsNotNull(add);
            Assert.AreEqual(1, add.GetParameters().Count());
            Assert.IsNotNull(invoke);
            var parameters = invoke.GetParameters();
            var returnparameter = invoke.ReturnParameter;
            Assert.IsNotNull(returnparameter);
            Assert.AreEqual("System.Void", returnparameter.ParameterType.FullName);

            Assert.AreEqual(typeof(MyEvent), typeof(Person).GetEvent("NameEvent").EventHandlerType);
        }
        public void InvokeFunctionWrapper()
        {
            FunctionWrapper<int, int, int, Func<int, int, int>> wrapper = new FunctionWrapper<int, int, int, Func<int, int, int>>(new Adder(), null);

            var result = wrapper.CreateFunctionDelegate().DynamicInvoke(2, 3);

            Assert.IsNotNull(result);
            Assert.AreEqual(5, result);
        }
 public void CreateThreadStart()
 {
     BindingEnvironment environment = new BindingEnvironment();
     Runner function = new Runner();
     FunctionWrapper wrapper = new FunctionWrapper(function, environment);
     Thread th = new Thread(wrapper.CreateThreadStart());
     th.Start();
     th.Join();
     Assert.IsTrue(function.WasInvoked);
 }