public async Task NoRequestModel_Fails() { var modelProvider = new Mock <IRequestModelProvider>(); var configurationProvider = new Mock <IListConfigurationProvider>(); var actionFilter = new TransferValuesActionFilter(modelProvider.Object, configurationProvider.Object); var httpContext = new Mock <HttpContext>(); var actionContext = new ActionContext(httpContext.Object, new RouteData(), new ControllerActionDescriptor()); var controller = new Mock <Controller>(); var httpRequest = new Mock <HttpRequest>(); var actionExecutionDelegate = new Mock <ActionExecutionDelegate>(); var result = new JsonResult(new TestResult()); var actionExecutedContext = new ActionExecutedContext(actionContext, new List <IFilterMetadata>(), controller.Object) { Result = result }; actionExecutionDelegate.Setup(x => x.Invoke()).ReturnsAsync(() => actionExecutedContext); httpContext.SetupGet(x => x.Request).Returns(httpRequest.Object); var actionExecutingContext = new ActionExecutingContext(actionContext, new List <IFilterMetadata>(), new RouteValueDictionary(), controller.Object); await actionFilter.OnActionExecutionAsync(actionExecutingContext, actionExecutionDelegate.Object); actionExecutingContext.Result.Should().BeNull(); configurationProvider.Verify(x => x.GetConfiguration(It.IsAny <Type>()), Times.Never); }
public async Task Disabled_Fails() { var requestModel = new TestRequest(); var modelProvider = new Mock <IRequestModelProvider>(); modelProvider.Setup(x => x.GetCurrentRequestModel()).Returns(requestModel); var transferValuesConfiguration = new Mock <ITransferValuesConfiguration>(); transferValuesConfiguration.SetupGet(x => x.ActionName).Returns("Index"); transferValuesConfiguration.SetupGet(x => x.Enabled).Returns(false); var listConfiguration = new Mock <IListConfiguration>(); listConfiguration.SetupGet(x => x.ResultType).Returns(typeof(TestResult)); listConfiguration.SetupGet(x => x.TransferValuesConfiguration).Returns(transferValuesConfiguration.Object); var configurationProvider = new Mock <IListConfigurationProvider>(); configurationProvider.Setup(x => x.GetConfiguration(It.IsAny <Type>())).Returns(listConfiguration.Object); var actionFilter = new TransferValuesActionFilter(modelProvider.Object, configurationProvider.Object); var httpContext = new Mock <HttpContext>(); var actionContext = new ActionContext(httpContext.Object, new RouteData(), new ControllerActionDescriptor() { ActionName = "Index", RouteValues = new Dictionary <string, string>() { ["action"] = "Index" } }); var controller = new Mock <Controller>(); var httpRequest = new Mock <HttpRequest>(); var actionExecutionDelegate = new Mock <ActionExecutionDelegate>(); var result = new JsonResult(new TestResult()); var actionExecutedContext = new ActionExecutedContext(actionContext, new List <IFilterMetadata>(), controller.Object) { Result = result }; actionExecutionDelegate.Setup(x => x.Invoke()).ReturnsAsync(() => actionExecutedContext); httpContext.SetupGet(x => x.Request).Returns(httpRequest.Object); var actionExecutingContext = new ActionExecutingContext(actionContext, new List <IFilterMetadata>(), new RouteValueDictionary(), controller.Object); await actionFilter.OnActionExecutionAsync(actionExecutingContext, actionExecutionDelegate.Object); actionExecutingContext.Result.Should().BeNull(); }
public async Task Succeeds() { var requestModel = new TestRequest(); var resultModel = new TestResult(); var modelProvider = new Mock <IRequestModelProvider>(); modelProvider.Setup(x => x.GetCurrentRequestModel()).Returns(requestModel); var transferValuesConfiguration = new Mock <ITransferValuesConfiguration>(); transferValuesConfiguration.SetupGet(x => x.ActionName).Returns("Index"); transferValuesConfiguration.SetupGet(x => x.Enabled).Returns(true); var searchConfiguration = new SearchConfiguration(typeof(TestRequest).GetProperty(nameof(TestRequest.Text))) { ResultProperty = typeof(TestResult).GetProperty(nameof(TestResult.Text)) }; var searchConfigurations = new List <ISearchConfiguration> { searchConfiguration }; var propertyConfiguration = new PropertyConfiguration(RequestType.GetProperty("Foo"), ResultType.GetProperty("Foo"), "Bar", false); var propertyConfigurations = new List <IPropertyConfiguration>() { propertyConfiguration }; var pageConfiguration = new PageConfiguration(RequestType.GetProperty("Page"), ResultType.GetProperty("Page"), 1); var rowsConfiguration = new RowsConfiguration(RequestType.GetProperty("Rows"), ResultType.GetProperty("Rows"), 200); var sortColumnConfiguration = new SortColumnConfiguration(RequestType.GetProperty("Ordx"), ResultType.GetProperty("Ordx"), ""); var sortDirectionConfiguration = new SortDirectionConfiguration(RequestType.GetProperty("Ordd"), ResultType.GetProperty("Ordd"), Direction.Ascending); var listConfiguration = new Mock <IListConfiguration>(); listConfiguration.SetupGet(x => x.ResultType).Returns(typeof(TestResult)); listConfiguration.SetupGet(x => x.TransferValuesConfiguration).Returns(transferValuesConfiguration.Object); listConfiguration.SetupGet(x => x.SearchConfigurations).Returns(searchConfigurations); listConfiguration.SetupGet(x => x.PropertyConfigurations).Returns(propertyConfigurations); listConfiguration.SetupGet(x => x.PageConfiguration).Returns(pageConfiguration); listConfiguration.SetupGet(x => x.RowsConfiguration).Returns(rowsConfiguration); listConfiguration.SetupGet(x => x.SortColumnConfiguration).Returns(sortColumnConfiguration); listConfiguration.SetupGet(x => x.SortDirectionConfiguration).Returns(sortDirectionConfiguration); var configurationProvider = new Mock <IListConfigurationProvider>(); configurationProvider.Setup(x => x.GetConfiguration(It.IsAny <Type>())).Returns(listConfiguration.Object); var actionFilter = new TransferValuesActionFilter(modelProvider.Object, configurationProvider.Object); var httpContext = new Mock <HttpContext>(); var actionContext = new ActionContext(httpContext.Object, new RouteData(), new ControllerActionDescriptor() { ActionName = "Index", RouteValues = new Dictionary <string, string>() { ["action"] = "Index" } }); var controller = new Mock <Controller>(); var httpRequest = new Mock <HttpRequest>(); var actionExecutionDelegate = new Mock <ActionExecutionDelegate>(); var result = new JsonResult(resultModel); var actionExecutedContext = new ActionExecutedContext(actionContext, new List <IFilterMetadata>(), controller.Object) { Result = result }; actionExecutionDelegate.Setup(x => x.Invoke()).ReturnsAsync(() => actionExecutedContext); httpContext.SetupGet(x => x.Request).Returns(httpRequest.Object); var actionExecutingContext = new ActionExecutingContext(actionContext, new List <IFilterMetadata>(), new RouteValueDictionary(), controller.Object); await actionFilter.OnActionExecutionAsync(actionExecutingContext, actionExecutionDelegate.Object); resultModel.Text.Should().BeOfType <TextSearch>(); }