コード例 #1
0
ファイル: ActionExecutorTests.cs プロジェクト: gmmateev/Mvc
        public async Task AsyncAction_WithVoidReturnType()
        {
            var methodWithVoidReturnType = new MethodWithVoidReturnType(TestController.VoidAction);
            var result = await ReflectedActionExecutor.ExecuteAsync(
                methodWithVoidReturnType.GetMethodInfo(),
                null,
                (IDictionary <string, object>) null);

            Assert.Same(null, result);
        }
コード例 #2
0
ファイル: ActionExecutorTests.cs プロジェクト: gmmateev/Mvc
        public async Task SyncAction()
        {
            string inputString = "hello";
            var    syncMethod  = new SyncMethod(_controller.Echo);
            var    result      = await ReflectedActionExecutor.ExecuteAsync(
                syncMethod.GetMethodInfo(),
                _controller,
                new Dictionary <string, object>() { { "input", inputString } });

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

            var methodWithTaskOfTaskOfIntReturnType = new MethodWithTaskOfTaskOfIntReturnType(_controller.TaskOfTaskAction);
            var result = await(Task <int>)(await ReflectedActionExecutor.ExecuteAsync(
                                               methodWithTaskOfTaskOfIntReturnType.GetMethodInfo(),
                                               _controller,
                                               actionParameters));

            Assert.Equal(inputParam1, result);
        }
コード例 #4
0
ファイル: ActionExecutorTests.cs プロジェクト: gmmateev/Mvc
        public async Task SyncAction_WithException()
        {
            string inputString       = "hello";
            var    syncMethod        = new SyncMethod(_controller.EchoWithException);
            var    expectedException = "The method or operation is not implemented.";

            await AssertThrowsAsync <NotImplementedException>(
                async() =>
                await ReflectedActionExecutor.ExecuteAsync(
                    syncMethod.GetMethodInfo(),
                    _controller,
                    new Dictionary <string, object>()
            {
                { "input", inputString }
            }),
                expectedException);
        }
コード例 #5
0
ファイル: ActionExecutorTests.cs プロジェクト: gmmateev/Mvc
        public async Task AsyncAction_WithAsyncKeywordThrows()
        {
            int    inputParam1      = 1;
            string inputParam2      = "Second Parameter";
            var    actionParameters = new Dictionary <string, object> {
                { "i", inputParam1 }, { "s", inputParam2 }
            };

            var methodWithTaskOfIntReturnType = new MethodWithTaskOfIntReturnType(_controller.TaskActionWithException);

            await AssertThrowsAsync <NotImplementedException>(
                async() =>
                await ReflectedActionExecutor.ExecuteAsync(
                    methodWithTaskOfIntReturnType.GetMethodInfo(),
                    _controller,
                    actionParameters),
                "Not Implemented Exception");
        }
コード例 #6
0
ファイル: ActionExecutorTests.cs プロジェクト: gmmateev/Mvc
        public async Task ParametersInRandomOrder()
        {
            int    inputParam1 = 1;
            string inputParam2 = "Second Parameter";

            // Note that the order of parameters is reversed
            var actionParameters = new Dictionary <string, object> {
                { "s", inputParam2 }, { "i", inputParam1 }
            };
            var methodWithTaskOfIntReturnType = new MethodWithTaskOfIntReturnType(_controller.TaskValueTypeAction);

            var result = await ReflectedActionExecutor.ExecuteAsync(
                methodWithTaskOfIntReturnType.GetMethodInfo(),
                _controller,
                actionParameters);

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

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

            await AssertThrowsAsync <InvalidOperationException>(
                async() =>
                await ReflectedActionExecutor.ExecuteAsync(
                    dynamicTaskMethod.GetMethodInfo(),
                    _controller,
                    actionParameters),
                expectedException);
        }
コード例 #8
0
ファイル: ActionExecutorTests.cs プロジェクト: gmmateev/Mvc
        public async Task AsyncAction_ReturningUnwrappedTaskThrows()
        {
            int    inputParam1      = 1;
            string inputParam2      = "Second Parameter";
            var    actionParameters = new Dictionary <string, object> {
                { "i", inputParam1 }, { "s", inputParam2 }
            };

            var methodWithUnwrappedTask = new MethodWithTaskReturnType(_controller.UnwrappedTask);

            await AssertThrowsAsync <InvalidOperationException>(
                async() =>
                await ReflectedActionExecutor.ExecuteAsync(
                    methodWithUnwrappedTask.GetMethodInfo(),
                    _controller,
                    actionParameters),
                string.Format(CultureInfo.CurrentCulture,
                              "The method 'UnwrappedTask' on type '{0}' returned an instance of '{1}'. Make sure to call Unwrap on the returned value to avoid unobserved faulted Task.",
                              typeof(TestController),
                              typeof(Task <Task>).FullName
                              ));
        }
コード例 #9
0
ファイル: ActionExecutorTests.cs プロジェクト: gmmateev/Mvc
        public async Task InvalidParameterValueThrows()
        {
            string inputParam2 = "Second Parameter";

            var actionParameters = new Dictionary <string, object> {
                { "i", "Some Invalid Value" }, { "s", inputParam2 }
            };
            var methodWithTaskOfIntReturnType = new MethodWithTaskOfIntReturnType(_controller.TaskValueTypeAction);
            var expectedException             = string.Format(
                CultureInfo.CurrentCulture,
                "Object of type '{0}' cannot be converted to type '{1}'.",
                typeof(string),
                typeof(int));

            // If it is an unrecognized derived type we throw an InvalidOperationException.
            await AssertThrowsAsync <ArgumentException>(
                async() =>
                await ReflectedActionExecutor.ExecuteAsync(
                    methodWithTaskOfIntReturnType.GetMethodInfo(),
                    _controller,
                    actionParameters),
                expectedException);
        }
コード例 #10
0
ファイル: ActionExecutorTests.cs プロジェクト: gmmateev/Mvc
        public async Task AsyncAction_WithCustomTaskReturnTypeThrows()
        {
            int    inputParam1      = 1;
            string inputParam2      = "Second Parameter";
            var    actionParameters = new Dictionary <string, object> {
                { "i", inputParam1 }, { "s", inputParam2 }
            };

            // If it is an unrecognized derived type we throw an InvalidOperationException.
            var methodWithCutomTaskReturnType = new MethodWithCustomTaskReturnType(_controller.TaskActionWithCustomTaskReturnType);

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

            await AssertThrowsAsync <InvalidOperationException>(
                async() =>
                await ReflectedActionExecutor.ExecuteAsync(
                    methodWithCutomTaskReturnType.GetMethodInfo(),
                    _controller,
                    actionParameters),
                expectedException);
        }