Exemple #1
0
    public void CreateInstance_CreatesFilter()
    {
        // Arrange
        var properties = new LifecycleProperty[]
        {
            new LifecycleProperty(),
            new LifecycleProperty(),
        };
        var filterFactory = new ControllerViewDataAttributeFilterFactory(properties);

        // Act
        var result = filterFactory.CreateInstance(Mock.Of <IServiceProvider>());

        // Assert
        var filter = Assert.IsType <ControllerViewDataAttributeFilter>(result);

        Assert.Same(properties, filter.Properties);
    }
Exemple #2
0
    /// <inheritdoc />
    public void OnProvidersExecuting(ApplicationModelProviderContext context)
    {
        if (context == null)
        {
            throw new ArgumentNullException(nameof(context));
        }

        foreach (var controllerModel in context.Result.Controllers)
        {
            var controllerType = controllerModel.ControllerType.AsType();

            var viewDataProperties = ViewDataAttributePropertyProvider.GetViewDataProperties(controllerType);
            if (viewDataProperties == null)
            {
                continue;
            }

            var filter = new ControllerViewDataAttributeFilterFactory(viewDataProperties);
            controllerModel.Filters.Add(filter);
        }
    }