public void CreateExecutor_ThrowsIfTypeIsNotAValidReturnType(string methodName) { // Arrange var methodInfo = typeof(TestPageModel).GetMethod(methodName); var handler = new HandlerMethodDescriptor() { MethodInfo = methodInfo, Parameters = CreateParameters(methodInfo), }; // Act & Assert var ex = Assert.Throws <InvalidOperationException>(() => ExecutorFactory.CreateExecutor(handler)); Assert.Equal($"Unsupported handler method return type '{methodInfo.ReturnType}'.", ex.Message); }
private static PageHandlerExecutorDelegate[] GetHandlerExecutors(CompiledPageActionDescriptor actionDescriptor) { if (actionDescriptor.HandlerMethods == null || actionDescriptor.HandlerMethods.Count == 0) { return(Array.Empty <PageHandlerExecutorDelegate>()); } var results = new PageHandlerExecutorDelegate[actionDescriptor.HandlerMethods.Count]; for (var i = 0; i < actionDescriptor.HandlerMethods.Count; i++) { results[i] = ExecutorFactory.CreateExecutor(actionDescriptor.HandlerMethods[i]); } return(results); }
public async Task CreateExecutor_ForMethodReturningConcreteSubtypeOfIActionResult() { // Arrange var handler = new HandlerMethodDescriptor() { MethodInfo = typeof(TestPage).GetMethod(nameof(TestPage.ConcreteActionResult)), Parameters = new HandlerParameterDescriptor[0], }; // Act var executor = ExecutorFactory.CreateExecutor(handler); // Assert Assert.NotNull(executor); var actionResultTask = executor(new TestPage(), null); var actionResult = await actionResultTask; Assert.IsType <ViewResult>(actionResult); }
public async Task CreateExecutor_ForTaskOfIActionResultReturningMethod() { // Arrange var methodInfo = typeof(TestPage).GetMethod(nameof(TestPage.GenericTaskHandler)); var handler = new HandlerMethodDescriptor() { MethodInfo = methodInfo, Parameters = CreateParameters(methodInfo), }; // Act var executor = ExecutorFactory.CreateExecutor(handler); // Assert Assert.NotNull(executor); var actionResultTask = executor(new TestPage(), null); var actionResult = await actionResultTask; Assert.IsType <EmptyResult>(actionResult); }
public async Task CreateExecutor_ForActionResultReturningMethod_WithParameters() { // Arrange var methodInfo = typeof(TestPage).GetMethod(nameof(TestPage.ActionResultReturnHandlerWithParameters)); var handler = new HandlerMethodDescriptor() { MethodInfo = methodInfo, Parameters = CreateParameters(methodInfo), }; // Act var executor = ExecutorFactory.CreateExecutor(handler); // Assert Assert.NotNull(executor); var actionResultTask = executor(new TestPage(), CreateArguments(methodInfo)); var actionResult = await actionResultTask; var contentResult = Assert.IsType <ContentResult>(actionResult); Assert.Equal("Hello 0", contentResult.Content); }
public async Task CreateExecutor_ForVoidReturningMethod() { // Arrange var handler = new HandlerMethodDescriptor() { MethodInfo = typeof(TestPage).GetMethod(nameof(TestPage.VoidReturningHandler)), Parameters = new HandlerParameterDescriptor[0], }; var page = new TestPage(); // Act var executor = ExecutorFactory.CreateExecutor(handler); // Assert Assert.NotNull(executor); var actionResultTask = executor(page, null); var actionResult = await actionResultTask; Assert.Null(actionResult); Assert.True(page.SideEffects); }