コード例 #1
0
    public void AddsViewDataPropertyFilter_ForViewDataAttributeProperties()
    {
        // Arrange
        var type     = typeof(TestController_NullableNonPrimitiveViewDataProperty);
        var provider = new ViewDataAttributeApplicationModelProvider();
        var context  = GetContext(type);

        // Act
        provider.OnProvidersExecuting(context);

        // Assert
        var controller = Assert.Single(context.Result.Controllers);

        Assert.IsType <ControllerViewDataAttributeFilterFactory>(Assert.Single(controller.Filters));
    }
コード例 #2
0
    public void OnProvidersExecuting_DoesNotAddFilter_IfTypeHasNoViewDataProperties()
    {
        // Arrange
        var type     = typeof(TestController_NoViewDataProperties);
        var provider = new ViewDataAttributeApplicationModelProvider();
        var context  = GetContext(type);

        // Act
        provider.OnProvidersExecuting(context);

        // Assert
        var controller = Assert.Single(context.Result.Controllers);

        Assert.Empty(controller.Filters);
    }
コード例 #3
0
    public void InitializeFilterFactory_WithExpectedPropertyHelpers_ForViewDataAttributeProperties()
    {
        // Arrange
        var expected = typeof(TestController_OneViewDataProperty).GetProperty(nameof(TestController_OneViewDataProperty.Test2));
        var provider = new ViewDataAttributeApplicationModelProvider();
        var context  = GetContext(typeof(TestController_OneViewDataProperty));

        // Act
        provider.OnProvidersExecuting(context);
        var controller = context.Result.Controllers.SingleOrDefault();
        var filter     = Assert.IsType <ControllerViewDataAttributeFilterFactory>(Assert.Single(controller.Filters));

        // Assert
        Assert.NotNull(filter);
        var property = Assert.Single(filter.Properties);

        Assert.Same(expected, property.PropertyInfo);
        Assert.Equal("Test2", property.Key);
    }