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); }
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); }
/// <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 !); } } }
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); }
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); }