本文整理汇总了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.");
}
示例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.");
}
示例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"]);
}
示例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"]);
}
示例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");
}
示例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"]);
}
示例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");
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}