当前位置: 首页>>代码示例>>C#>>正文


C# ReflectedHttpActionDescriptor.ExecuteAsync方法代码示例

本文整理汇总了C#中ReflectedHttpActionDescriptor.ExecuteAsync方法的典型用法代码示例。如果您正苦于以下问题:C# ReflectedHttpActionDescriptor.ExecuteAsync方法的具体用法?C# ReflectedHttpActionDescriptor.ExecuteAsync怎么用?C# ReflectedHttpActionDescriptor.ExecuteAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ReflectedHttpActionDescriptor的用法示例。


在下文中一共展示了ReflectedHttpActionDescriptor.ExecuteAsync方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExecuteAsync_IfTaskReturningMethod_ReturnsWrappedTaskInstance_Throws

        public void ExecuteAsync_IfTaskReturningMethod_ReturnsWrappedTaskInstance_Throws()
        {
            Func<Task> method = _controller.WrappedTaskReturningMethod;
            ReflectedHttpActionDescriptor actionDescriptor = new ReflectedHttpActionDescriptor { MethodInfo = method.Method };

            var exception = Assert.Throws<InvalidOperationException>(
                 () => actionDescriptor.ExecuteAsync(_context, _arguments, CancellationToken.None).RethrowFaultedTaskException(),
                 "The method 'WrappedTaskReturningMethod' on type 'UsersRpcController' returned an instance of 'System.Threading.Tasks.Task`1[[System.Threading.Tasks.Task, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]'. Make sure to call Unwrap on the returned value to avoid unobserved faulted Task.");
        }
开发者ID:reza899,项目名称:aspnetwebstack,代码行数:9,代码来源:ReflectedHttpActionDescriptorTest.cs

示例2: ExecuteAsync_IfObjectReturningMethod_ReturnsTaskInstance_Throws

        public void ExecuteAsync_IfObjectReturningMethod_ReturnsTaskInstance_Throws()
        {
            Func<object> method = _controller.TaskAsObjectReturningMethod;
            ReflectedHttpActionDescriptor actionDescriptor = new ReflectedHttpActionDescriptor { MethodInfo = method.Method };

            var exception = Assert.Throws<InvalidOperationException>(
                 () => actionDescriptor.ExecuteAsync(_context, _arguments, CancellationToken.None).RethrowFaultedTaskException(),
                 "The method 'TaskAsObjectReturningMethod' on type 'UsersRpcController' returned a Task instance even though it is not an asynchronous method.");
        }
开发者ID:reza899,项目名称:aspnetwebstack,代码行数:9,代码来源:ReflectedHttpActionDescriptorTest.cs

示例3: ExecuteAsync_Throws_IfArgumentNameIsWrong

        public void ExecuteAsync_Throws_IfArgumentNameIsWrong()
        {
            Func<int, User> retrieveUserMethod = _controller.RetriveUser;
            ReflectedHttpActionDescriptor actionDescriptor = new ReflectedHttpActionDescriptor { MethodInfo = retrieveUserMethod.Method };
            _arguments["otherId"] = 6;

            var exception = Assert.Throws<HttpResponseException>(
                () => actionDescriptor.ExecuteAsync(_context, _arguments, CancellationToken.None).RethrowFaultedTaskException());

            Assert.Equal(HttpStatusCode.BadRequest, exception.Response.StatusCode);
            var content = Assert.IsType<ObjectContent<HttpError>>(exception.Response.Content);
            Assert.Equal("The parameters dictionary does not contain an entry for parameter 'id' of type 'System.Int32' " +
                "for method 'System.Web.Http.User RetriveUser(Int32)' in 'System.Web.Http.UsersRpcController'. " +
                "The dictionary must contain an entry for each parameter, including parameters that have null values.",
                ((HttpError)content.Value)["MessageDetail"]);
        }
开发者ID:reza899,项目名称:aspnetwebstack,代码行数:16,代码来源:ReflectedHttpActionDescriptorTest.cs

示例4: ExecuteAsync_Throws_IfArgumentTypeIsWrong

        public void ExecuteAsync_Throws_IfArgumentTypeIsWrong()
        {
            Func<int, User> retrieveUserMethod = _controller.RetriveUser;
            ReflectedHttpActionDescriptor actionDescriptor = new ReflectedHttpActionDescriptor { MethodInfo = retrieveUserMethod.Method };
            _arguments["id"] = new DateTime();

            var exception = Assert.Throws<HttpResponseException>(
                 () => actionDescriptor.ExecuteAsync(_context, _arguments, CancellationToken.None).RethrowFaultedTaskException());

            Assert.Equal(HttpStatusCode.BadRequest, exception.Response.StatusCode);
            var content = Assert.IsType<ObjectContent<HttpError>>(exception.Response.Content);
            Assert.Equal("The parameters dictionary contains an invalid entry for parameter 'id' for method " +
                "'System.Web.Http.User RetriveUser(Int32)' in 'System.Web.Http.UsersRpcController'. " +
                "The dictionary contains a value of type 'System.DateTime', but the parameter requires a value " +
                "of type 'System.Int32'.",
                ((HttpError)content.Value)["MessageDetail"]);
        }
开发者ID:reza899,项目名称:aspnetwebstack,代码行数:17,代码来源:ReflectedHttpActionDescriptorTest.cs

示例5: ExecuteAsync_Throws_IfArgumentsIsNull

        public void ExecuteAsync_Throws_IfArgumentsIsNull()
        {
            Func<string, string, User> echoUserMethod = _controller.EchoUser;
            ReflectedHttpActionDescriptor actionDescriptor = new ReflectedHttpActionDescriptor { MethodInfo = echoUserMethod.Method };

            Assert.ThrowsArgumentNull(
                () => actionDescriptor.ExecuteAsync(_context, null, CancellationToken.None).RethrowFaultedTaskException(),
                "arguments");
        }
开发者ID:reza899,项目名称:aspnetwebstack,代码行数:9,代码来源:ReflectedHttpActionDescriptorTest.cs

示例6: ExecuteAsync_Throws_IfValueTypeArgumentsIsNull

        public void ExecuteAsync_Throws_IfValueTypeArgumentsIsNull()
        {
            Func<int, User> retrieveUserMethod = _controller.RetriveUser;
            ReflectedHttpActionDescriptor actionDescriptor = new ReflectedHttpActionDescriptor { MethodInfo = retrieveUserMethod.Method };
            _arguments["id"] = null;

            var exception = Assert.Throws<HttpResponseException>(
                 () => actionDescriptor.ExecuteAsync(_context, _arguments, CancellationToken.None).RethrowFaultedTaskException());

            Assert.Equal(HttpStatusCode.BadRequest, exception.Response.StatusCode);
            var content = Assert.IsType<ObjectContent<HttpError>>(exception.Response.Content);
            Assert.Equal("The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' " +
                "for method 'System.Web.Http.User RetriveUser(Int32)' in 'System.Web.Http.UsersRpcController'. An optional parameter " +
                "must be a reference type, a nullable type, or be declared as an optional parameter.",
                ((HttpError)content.Value)["MessageDetail"]);
        }
开发者ID:reza899,项目名称:aspnetwebstack,代码行数:16,代码来源:ReflectedHttpActionDescriptorTest.cs

示例7: ExecuteAsync_Throws_IfContextIsNull

        public void ExecuteAsync_Throws_IfContextIsNull()
        {
            Func<string, string, User> echoUserMethod = _controller.EchoUser;
            ReflectedHttpActionDescriptor actionDescriptor = new ReflectedHttpActionDescriptor { MethodInfo = echoUserMethod.Method };

            Assert.ThrowsArgumentNull(
                () => actionDescriptor.ExecuteAsync(null, _arguments, CancellationToken.None),
                "controllerContext");
        }
开发者ID:reza899,项目名称:aspnetwebstack,代码行数:9,代码来源:ReflectedHttpActionDescriptorTest.cs

示例8: ExecuteAsync_Returns_Results_ForTaskOfTAction

        public void ExecuteAsync_Returns_Results_ForTaskOfTAction()
        {
            Func<string, string, Task<User>> echoUserMethod = _controller.EchoUserAsync;
            ReflectedHttpActionDescriptor actionDescriptor = new ReflectedHttpActionDescriptor { MethodInfo = echoUserMethod.Method };
            _arguments["firstName"] = "test";
            _arguments["lastName"] = "unit";

            Task<object> result = actionDescriptor.ExecuteAsync(_context, _arguments, CancellationToken.None);

            result.WaitUntilCompleted();
            var returnValue = Assert.IsType<User>(result.Result);
            Assert.Equal("test", returnValue.FirstName);
            Assert.Equal("unit", returnValue.LastName);
        }
开发者ID:reza899,项目名称:aspnetwebstack,代码行数:14,代码来源:ReflectedHttpActionDescriptorTest.cs

示例9: ExecuteAsync_Returns_TaskOfNull_ForTaskAction

        public void ExecuteAsync_Returns_TaskOfNull_ForTaskAction()
        {
            Func<Task> deleteAllUsersMethod = _controller.DeleteAllUsersAsync;
            ReflectedHttpActionDescriptor actionDescriptor = new ReflectedHttpActionDescriptor { MethodInfo = deleteAllUsersMethod.Method };

            Task<object> returnValue = actionDescriptor.ExecuteAsync(_context, _arguments, CancellationToken.None);

            returnValue.WaitUntilCompleted();
            Assert.Null(returnValue.Result);
        }
开发者ID:reza899,项目名称:aspnetwebstack,代码行数:10,代码来源:ReflectedHttpActionDescriptorTest.cs

示例10: ExecuteAsync_DoesNotCallActionWhenCancelled

        public void ExecuteAsync_DoesNotCallActionWhenCancelled()
        {
            var cts = new CancellationTokenSource();
            cts.Cancel();
            Action action = () => { throw new NotImplementedException(); };
            ReflectedHttpActionDescriptor actionDescriptor = new ReflectedHttpActionDescriptor { MethodInfo = action.Method };

            Task<object> result = actionDescriptor.ExecuteAsync(_context, _arguments, cts.Token);

            result.WaitUntilCompleted();
            Assert.True(result.IsCanceled);
        }
开发者ID:reza899,项目名称:aspnetwebstack,代码行数:12,代码来源:ReflectedHttpActionDescriptorTest.cs

示例11: ExecuteAsync_Returns_TaskOfNull_ForVoidAction

        public void ExecuteAsync_Returns_TaskOfNull_ForVoidAction()
        {
            Action deleteAllUsersMethod = _controller.DeleteAllUsers;
            ReflectedHttpActionDescriptor actionDescriptor = new ReflectedHttpActionDescriptor { MethodInfo = deleteAllUsersMethod.Method };

            Task<object> returnValue = actionDescriptor.ExecuteAsync(_context, _arguments);

            returnValue.WaitUntilCompleted();
            Assert.Null(returnValue.Result);
        }
开发者ID:haoduotnt,项目名称:aspnetwebstack,代码行数:10,代码来源:ReflectedHttpActionDescriptorTest.cs


注:本文中的ReflectedHttpActionDescriptor.ExecuteAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。