Exemplo n.º 1
0
        public void Activate_SetsPropertyValue()
        {
            // Arrange
            var instance = new TestClass();
            var typeInfo = instance.GetType().GetTypeInfo();
            var property = typeInfo.GetDeclaredProperty("IntProperty");
            var activator = new PropertyActivator<int>(property, valueAccessor: (val) => val + 1);

            // Act
            activator.Activate(instance, 123);

            // Assert
            Assert.Equal(124, instance.IntProperty);
        }
Exemplo n.º 2
0
    public void Activate_SetsPropertyValue()
    {
        // Arrange
        var instance  = new TestClass();
        var typeInfo  = instance.GetType().GetTypeInfo();
        var property  = typeInfo.GetDeclaredProperty("IntProperty");
        var activator = new PropertyActivator <int>(property, valueAccessor: (val) => val + 1);

        // Act
        activator.Activate(instance, 123);

        // Assert
        Assert.Equal(124, instance.IntProperty);
    }
Exemplo n.º 3
0
    /// <inheritdoc />
    public override void Init(TagHelperContext context)
    {
        if (PropertyActivator == null)
        {
            var serviceProvider = ViewContext.HttpContext.RequestServices;
            PropertyActivator = serviceProvider.GetRequiredService <ITagHelperComponentPropertyActivator>();
        }

        foreach (var component in _components)
        {
            PropertyActivator.Activate(ViewContext, component);
            component.Init(context);
            if (_logger.IsEnabled(LogLevel.Debug))
            {
                _logger.TagHelperComponentInitialized(component.GetType().FullName !);
            }
        }
    }
Exemplo n.º 4
0
        public void Activate_InvokesValueAccessorWithExpectedValue()
        {
            // Arrange
            var instance = new TestClass();
            var typeInfo = instance.GetType().GetTypeInfo();
            var property = typeInfo.GetDeclaredProperty("IntProperty");
            var invokedWith = -1;
            var activator = new PropertyActivator<int>(
                property,
                valueAccessor: (val) =>
                {
                    invokedWith = val;
                    return val;
                });

            // Act
            activator.Activate(instance, 123);

            // Assert
            Assert.Equal(123, invokedWith);
        }
Exemplo n.º 5
0
    public void Activate_InvokesValueAccessorWithExpectedValue()
    {
        // Arrange
        var instance    = new TestClass();
        var typeInfo    = instance.GetType().GetTypeInfo();
        var property    = typeInfo.GetDeclaredProperty("IntProperty");
        var invokedWith = -1;
        var activator   = new PropertyActivator <int>(
            property,
            valueAccessor: (val) =>
        {
            invokedWith = val;
            return(val);
        });

        // Act
        activator.Activate(instance, 123);

        // Assert
        Assert.Equal(123, invokedWith);
    }