Example #1
0
        public void ExecuteTaskWithTimeout()
        {
            // Arrange
            TaskAsyncActionDescriptor actionDescriptor = GetActionDescriptor(
                GetExecuteControllerMethodInfo("TaskTimeout")
                );

            Dictionary <string, object> token = new Dictionary <string, object>()
            {
                { "cancellationToken", new CancellationToken() }
            };

            // Act & assert
            Assert.Throws <TimeoutException>(
                () =>
                actionDescriptor.EndExecute(
                    actionDescriptor.BeginExecute(
                        GetControllerContext(2000),
                        parameters: token,
                        callback: null,
                        state: null
                        )
                    ),
                "The operation has timed out."
                );
        }
Example #2
0
        public void ExecuteTaskGenericPreservesStackTraceOnException()
        {
            // Arrange
            TaskAsyncActionDescriptor actionDescriptor = GetActionDescriptor(
                GetExecuteControllerMethodInfo("GenericTaskException")
                );

            Dictionary <string, object> parameters = new Dictionary <string, object>()
            {
                { "taskId", "foo" },
                { "throwException", true }
            };

            // Act
            IAsyncResult result = actionDescriptor.BeginExecute(
                GetControllerContext(),
                parameters,
                null,
                null
                );

            // Assert
            InvalidOperationException ex = Assert.Throws <InvalidOperationException>(
                () => actionDescriptor.EndExecute(result),
                "Test exception from action"
                );

            Assert.Contains(
                "System.Web.Mvc.Async.Test.TaskAsyncActionDescriptorTest.ExecuteController.",
                ex.StackTrace
                );
        }
Example #3
0
        public static object ExecuteHelper(TaskAsyncActionDescriptor actionDescriptor, Dictionary <string, object> parameters, ControllerContext controllerContext = null)
        {
            SignalContainer <object> resultContainer = new SignalContainer <object>();
            AsyncCallback            callback        = ar =>
            {
                object o = actionDescriptor.EndExecute(ar);
                resultContainer.Signal(o);
            };

            actionDescriptor.BeginExecute(controllerContext ?? GetControllerContext(), parameters, callback, state: null);
            return(resultContainer.Wait());
        }
        public static object ExecuteHelper(TaskAsyncActionDescriptor actionDescriptor, Dictionary<string, object> parameters, ControllerContext controllerContext = null)
        {
            SignalContainer<object> resultContainer = new SignalContainer<object>();
            AsyncCallback callback = ar =>
            {
                object o = actionDescriptor.EndExecute(ar);
                resultContainer.Signal(o);
            };

            actionDescriptor.BeginExecute(controllerContext ?? GetControllerContext(), parameters, callback, state: null);
            return resultContainer.Wait();
        }