コード例 #1
0
ファイル: ActionExecutorTests.cs プロジェクト: zinoviev/Mvc
        public async Task AsyncAction_WithCustomTaskOfTReturnTypeThrows()
        {
            int    inputParam1      = 1;
            string inputParam2      = "Second Parameter";
            var    actionParameters = new Dictionary <string, object> {
                { "i", inputParam1 }, { "s", inputParam2 }
            };

            var    methodWithCutomTaskOfTReturnType = new MethodWithCustomTaskOfTReturnType(_controller.TaskActionWithCustomTaskOfTReturnType);
            string expectedException = string.Format(
                CultureInfo.CurrentCulture,
                "The method 'TaskActionWithCustomTaskOfTReturnType' on type '{0}' returned a Task instance even though it is not an asynchronous method.",
                typeof(TestController));

            await AssertThrowsAsync <InvalidOperationException>(
                async() =>
                await ControllerActionExecutor.ExecuteAsync(
                    methodWithCutomTaskOfTReturnType.GetMethodInfo(),
                    _controller,
                    actionParameters),
                expectedException);
        }
コード例 #2
0
        public async Task AsyncAction_WithCustomTaskOfTReturnTypeThrows()
        {
            // Arrange
            var inputParam1      = 1;
            var inputParam2      = "Second Parameter";
            var actionParameters = new Dictionary <string, object> {
                { "i", inputParam1 }, { "s", inputParam2 }
            };

            var methodWithCutomTaskOfTReturnType = new MethodWithCustomTaskOfTReturnType(_controller.TaskActionWithCustomTaskOfTReturnType);
            var expectedException = string.Format(
                CultureInfo.CurrentCulture,
                "The method 'TaskActionWithCustomTaskOfTReturnType' on type '{0}' returned a Task instance even though it is not an asynchronous method.",
                typeof(TestController));

            // Act & Assert
            var ex = await Assert.ThrowsAsync <InvalidOperationException>(
                () => ExecuteAction(
                    methodWithCutomTaskOfTReturnType,
                    _controller,
                    actionParameters));

            Assert.Equal(expectedException, ex.Message);
        }
コード例 #3
0
        public async Task AsyncAction_WithCustomTaskOfTReturnTypeThrows()
        {
            // Arrange
            var inputParam1 = 1;
            var inputParam2 = "Second Parameter";
            var actionParameters = new Dictionary<string, object> { { "i", inputParam1 }, { "s", inputParam2 } };

            var methodWithCutomTaskOfTReturnType = new MethodWithCustomTaskOfTReturnType(_controller.TaskActionWithCustomTaskOfTReturnType);
            var expectedException = string.Format(
                CultureInfo.CurrentCulture,
                "The method 'TaskActionWithCustomTaskOfTReturnType' on type '{0}' returned a Task instance even though it is not an asynchronous method.",
                typeof(TestController));

            // Act & Assert
            var ex = await Assert.ThrowsAsync<InvalidOperationException>(
                () => ControllerActionExecutor.ExecuteAsync(
                    methodWithCutomTaskOfTReturnType.GetMethodInfo(),
                    _controller,
                    actionParameters));
            Assert.Equal(expectedException, ex.Message);
        }