Exemplo n.º 1
0
        public async Task InvalidParameterValueThrows()
        {
            // Arrange
            var inputParam2 = "Second Parameter";

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

            // Act & Assert
            // If it is an unrecognized derived type we throw an InvalidOperationException.
            var ex = await Assert.ThrowsAsync <ArgumentException>(
                () => ControllerActionExecutor.ExecuteAsync(
                    methodWithTaskOfIntReturnType.GetMethodInfo(),
                    _controller,
                    actionParameters));

            Assert.Equal(expectedException, ex.Message);
        }
Exemplo n.º 2
0
        public async Task AsyncAction_WithoutAsyncThrows()
        {
            int    inputParam1      = 1;
            string inputParam2      = "Second Parameter";
            var    actionParameters = new Dictionary <string, object> {
                { "i", inputParam1 }, { "s", inputParam2 }
            };

            var methodWithTaskOfIntReturnType = new MethodWithTaskOfIntReturnType(_controller.TaskActionWithExceptionWithoutAsync);
            await Assert.ThrowsAsync <NotImplementedException>(
                () => ControllerActionExecutor.ExecuteAsync(methodWithTaskOfIntReturnType.GetMethodInfo(),
                                                            _controller,
                                                            actionParameters));
        }
Exemplo n.º 3
0
        public async Task AsyncAction_TaskOfValueReturnType()
        {
            int    inputParam1      = 1;
            string inputParam2      = "Second Parameter";
            var    actionParameters = new Dictionary <string, object> {
                { "i", inputParam1 }, { "s", inputParam2 }
            };

            var methodWithTaskOfIntReturnType = new MethodWithTaskOfIntReturnType(_controller.TaskValueTypeAction);
            var result = await ControllerActionExecutor.ExecuteAsync(
                methodWithTaskOfIntReturnType.GetMethodInfo(),
                _controller,
                actionParameters);

            Assert.Equal(inputParam1, result);
        }
Exemplo n.º 4
0
        public async Task AsyncAction_TaskOfValueReturnType()
        {
            // Arrange
            var inputParam1 = 1;
            var inputParam2 = "Second Parameter";
            var actionParameters = new Dictionary<string, object> { { "i", inputParam1 }, { "s", inputParam2 } };

            var methodWithTaskOfIntReturnType = new MethodWithTaskOfIntReturnType(_controller.TaskValueTypeAction);

            // Act
            var result = await ControllerActionExecutor.ExecuteAsync(
                                                        methodWithTaskOfIntReturnType.GetMethodInfo(),
                                                        _controller,
                                                        actionParameters);

            // Assert
            Assert.Equal(inputParam1, result);
        }
Exemplo n.º 5
0
        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 ControllerActionExecutor.ExecuteAsync(
                methodWithTaskOfIntReturnType.GetMethodInfo(),
                _controller,
                actionParameters);

            Assert.Equal(inputParam1, result);
        }
Exemplo n.º 6
0
        public async Task AsyncAction_WithExceptionsAfterAwait()
        {
            int    inputParam1      = 1;
            string inputParam2      = "Second Parameter";
            var    actionParameters = new Dictionary <string, object> {
                { "i", inputParam1 }, { "s", inputParam2 }
            };

            var methodWithTaskOfIntReturnType = new MethodWithTaskOfIntReturnType(_controller.TaskActionThrowAfterAwait);

            await AssertThrowsAsync <ArgumentException>(
                async() =>
                await ControllerActionExecutor.ExecuteAsync(
                    methodWithTaskOfIntReturnType.GetMethodInfo(),
                    _controller,
                    actionParameters),
                "Argument Exception");
        }
        public async Task AsyncAction_WithAsyncKeywordThrows()
        {
            // Arrange
            var inputParam1      = 1;
            var inputParam2      = "Second Parameter";
            var actionParameters = new Dictionary <string, object> {
                { "i", inputParam1 }, { "s", inputParam2 }
            };

            var methodWithTaskOfIntReturnType = new MethodWithTaskOfIntReturnType(_controller.TaskActionWithException);

            // Act and Assert
            await Assert.ThrowsAsync <NotImplementedException>(
                () => ExecuteAction(
                    methodWithTaskOfIntReturnType,
                    _controller,
                    actionParameters));
        }
        public async Task InvalidParameterValueThrows()
        {
            // Arrange
            var inputParam2 = "Second Parameter";

            var actionParameters = new Dictionary <string, object> {
                { "i", "Some Invalid Value" }, { "s", inputParam2 }
            };
            var methodWithTaskOfIntReturnType = new MethodWithTaskOfIntReturnType(_controller.TaskValueTypeAction);

            // Act & Assert
            // If it is an unrecognized derived type we throw an InvalidOperationException.
            var ex = await Assert.ThrowsAsync <InvalidCastException>(
                () => ExecuteAction(
                    methodWithTaskOfIntReturnType,
                    _controller,
                    actionParameters));
        }
        public async Task AsyncAction_TaskOfValueReturnType()
        {
            // Arrange
            var inputParam1      = 1;
            var inputParam2      = "Second Parameter";
            var actionParameters = new Dictionary <string, object> {
                { "i", inputParam1 }, { "s", inputParam2 }
            };

            var methodWithTaskOfIntReturnType = new MethodWithTaskOfIntReturnType(_controller.TaskValueTypeAction);

            // Act
            var result = await ExecuteAction(
                methodWithTaskOfIntReturnType,
                _controller,
                actionParameters);

            // Assert
            Assert.Equal(inputParam1, result);
        }
Exemplo n.º 10
0
        public async Task AsyncAction_WithExceptionsAfterAwait()
        {
            // Arrange
            var inputParam1      = 1;
            var inputParam2      = "Second Parameter";
            var actionParameters = new Dictionary <string, object> {
                { "i", inputParam1 }, { "s", inputParam2 }
            };

            var methodWithTaskOfIntReturnType = new MethodWithTaskOfIntReturnType(_controller.TaskActionThrowAfterAwait);
            var expectedException             = "Argument Exception";

            // Act & Assert
            var ex = await Assert.ThrowsAsync <ArgumentException>(
                () => ControllerActionExecutor.ExecuteAsync(
                    methodWithTaskOfIntReturnType.GetMethodInfo(),
                    _controller,
                    actionParameters));

            Assert.Equal(expectedException, ex.Message);
        }
        public async Task ParametersInRandomOrder()
        {
            // Arrange
            var inputParam1 = 1;
            var 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);

            // Act
            var result = await ExecuteAction(
                methodWithTaskOfIntReturnType,
                _controller,
                actionParameters);

            // Assert
            Assert.Equal(inputParam1, result);
        }
Exemplo n.º 12
0
        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);
        }
Exemplo n.º 13
0
        public async Task InvalidParameterValueThrows()
        {
            // Arrange
            var inputParam2 = "Second Parameter";

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

            // Act & Assert
            // If it is an unrecognized derived type we throw an InvalidOperationException.
            var ex = await Assert.ThrowsAsync<ArgumentException>(
                () => ControllerActionExecutor.ExecuteAsync(
                        methodWithTaskOfIntReturnType.GetMethodInfo(),
                        _controller,
                        actionParameters));

            Assert.Equal(expectedException, ex.Message);
        }
Exemplo n.º 14
0
        public async Task ParametersInRandomOrder()
        {
            // Arrange
            var inputParam1 = 1;
            var 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);

            // Act
            var result = await ControllerActionExecutor.ExecuteAsync(
                                                        methodWithTaskOfIntReturnType.GetMethodInfo(),
                                                        _controller,
                                                        actionParameters);

            // Assert
            Assert.Equal(inputParam1, result);
        }
Exemplo n.º 15
0
        public async Task AsyncAction_WithExceptionsAfterAwait()
        {
            // Arrange
            var inputParam1 = 1;
            var inputParam2 = "Second Parameter";
            var actionParameters = new Dictionary<string, object> { { "i", inputParam1 }, { "s", inputParam2 } };

            var methodWithTaskOfIntReturnType = new MethodWithTaskOfIntReturnType(_controller.TaskActionThrowAfterAwait);
            var expectedException = "Argument Exception";

            // Act & Assert
            var ex = await Assert.ThrowsAsync<ArgumentException>(
                () => ControllerActionExecutor.ExecuteAsync(
                    methodWithTaskOfIntReturnType.GetMethodInfo(),
                    _controller,
                    actionParameters));
            Assert.Equal(expectedException, ex.Message);
        }
Exemplo n.º 16
0
        public async Task AsyncAction_WithoutAsyncThrows()
        {
            // Arrange
            var inputParam1 = 1;
            var inputParam2 = "Second Parameter";
            var actionParameters = new Dictionary<string, object> { { "i", inputParam1 }, { "s", inputParam2 } };

            var methodWithTaskOfIntReturnType = new MethodWithTaskOfIntReturnType(_controller.TaskActionWithExceptionWithoutAsync);

            // Act & Assert
            await Assert.ThrowsAsync<NotImplementedException>(
                        () => ControllerActionExecutor.ExecuteAsync(methodWithTaskOfIntReturnType.GetMethodInfo(),
                                                                   _controller,
                                                                   actionParameters));
        }