Example #1
0
        public void BuildVoidMethod_Arguments()
        {
            MethodInfo method = GetMethod(nameof(IDummyInterface.VoidMethod_Arguments), typeof(int), typeof(string));

            var lambda = MethodInvokerBuilder.Build(typeof(IDummyInterface), method);

            Moq.Mock <IDummyInterface> target = new Moq.Mock <IDummyInterface>();
            target.Setup(v => v.VoidMethod_Arguments(10, "val"));
            Assert.Null(lambda(target.Object, new object[] { 10, "val" }));
        }
Example #2
0
        public void BuildFunc_NoArguments()
        {
            MethodInfo method = GetMethod(nameof(IDummyInterface.Func_NoArguments));

            var lambda = MethodInvokerBuilder.Build(typeof(IDummyInterface), method);

            Moq.Mock <IDummyInterface> target = new Moq.Mock <IDummyInterface>();
            target.Setup(v => v.Func_NoArguments()).Returns(10);
            Assert.Equal(10, lambda(target.Object, null));
        }
Example #3
0
 public ActionDescriptor(ActionMetadata metadata)
 {
     Parameters      = metadata.Action.GetParameters().ToList();
     ParametersTypes = Parameters.Select(p => p.ParameterType).ToArray();
     _compiledLambda = MethodInvokerBuilder.Build(metadata.Action.DeclaringType, metadata.Action);
     _isTaskResult   = typeof(Task).IsAssignableFrom(metadata.Action.ReturnType);
     if (_isTaskResult && metadata.Action.ReturnType.GetTypeInfo().IsGenericType)
     {
         _taskResultProvider = MethodInvokerBuilder.BuildTaskResultProvider(metadata.ResultType);
     }
 }
Example #4
0
        public void BuildVoidMethod_NoArguments()
        {
            MethodInfo method = GetMethod(nameof(IDummyInterface.VoidMethod_NoArguments));

            var lambda = MethodInvokerBuilder.Build(typeof(IDummyInterface), method);

            Moq.Mock <IDummyInterface> target = new Moq.Mock <IDummyInterface>();
            target.Setup(v => v.VoidMethod_NoArguments()).Verifiable();

            lambda(target.Object, null);

            target.Verify();
        }
Example #5
0
            protected override MethodMetadata Create(MethodInfo key, object context)
            {
                ActionMetadata             metadata = BoltFramework.ActionMetadata.Resolve(key);
                Func <Task <object>, Task> provider = null;

                if (metadata.IsAsynchronous && metadata.HasResult)
                {
                    provider = MethodInvokerBuilder.Build(metadata.ResultType);
                }

                MethodInfo method = _proxyBase.GetRuntimeMethod(key.Name, key.GetParameters().Select(p => p.ParameterType).ToArray());

                return(new MethodMetadata(metadata, provider, method));
            }