Ejemplo n.º 1
0
        private static TestServerAction GetTestServerAction <TController>(Expression <Func <TController, object> > actionSelector)
        {
            if (actionSelector.NodeType != ExpressionType.Lambda)
            {
                throw new InvalidOperationException($"The action selector is not a valid lambda expression");
            }

            var methodCall = (MethodCallExpression)actionSelector.Body;

            var  action = new TestServerAction(methodCall.Method);
            bool haveAttributeApiController = typeof(TController).GetTypeInfo().GetCustomAttribute(typeof(ApiControllerAttribute)) != null;
            bool isGetOrDelete = action.MethodInfo.GetCustomAttributes().FirstOrDefault(attr => attr.GetType() == typeof(HttpGetAttribute) ||
                                                                                        attr.GetType() == typeof(HttpDeleteAttribute)) != null;

            var index = 0;

            foreach (var item in methodCall.Arguments)
            {
                action.AddArgument(index, item, haveAttributeApiController && !isGetOrDelete);

                ++index;
            }

            return(action);
        }
        private static TestServerAction GetTestServerAction <TController>(Expression <Func <TController, object> > actionSelector)
        {
            if (actionSelector.NodeType != ExpressionType.Lambda)
            {
                throw new InvalidOperationException($"The action selector is not a valid lambda expression");
            }

            var methodCall = (MethodCallExpression)actionSelector.Body;

            var action = new TestServerAction(methodCall.Method);

            int index = 0;

            foreach (var item in methodCall.Arguments)
            {
                action.AddArgument(index, item);

                ++index;
            }

            return(action);
        }