public void Ensure_FastProperty_Creating_Returns_Action() { var value = FastPropertySetter.MakeFastPropertySetter(testPropertyInfo); Assert.NotNull(value); Assert.IsType <Action <object, object> >(value); }
public void Constructor_Initialized_Main_Properties() { var setter = new FastPropertySetter(testPropertyInfo); Assert.Equal(setter.Property, testPropertyInfo); Assert.Equal(setter.Name, testPropertyInfo.Name); }
public void Inject(ITemplatePage page) { if (page == null) { throw new ArgumentNullException(nameof(page)); } PropertyInfo[] properties = page.GetType().GetRuntimeProperties() .Where(p => { return (p.IsDefined(typeof(RazorInjectAttribute)) && p.GetIndexParameters().Length == 0 && !p.SetMethod.IsStatic); }).ToArray(); var scopeFactory = services.GetRequiredService <IServiceScopeFactory>(); using (IServiceScope scope = scopeFactory.CreateScope()) { IServiceProvider scopeServices = scope.ServiceProvider; foreach (var property in properties) { Type memberType = property.PropertyType; object instance = scopeServices.GetRequiredService(memberType); FastPropertySetter setter = _propertyCache.GetOrAdd(property, new FastPropertySetter(property)); setter.SetValue(page, instance); } } }
public void Ensure_ValueSetter_Initialized() { var setter = new FastPropertySetter(testPropertyInfo); setter.SetValue(testClass, "Go"); Assert.NotNull(setter.ValueSetter); }
public void Ensure_ValueSetter_Sets_Value() { var @class = new TestClass(); string expected = "Razor"; var setter = new FastPropertySetter(testPropertyInfo); setter.SetValue(@class, expected); Assert.Equal(expected, @class.RefProperty); }
public void Ensure_ValueSetter_Initialized() { var setter = new FastPropertySetter(testPropertyInfo); var test = new TestClass(); string value = "Go"; setter.SetValue(test, value); Assert.NotNull(setter.ValueSetter); Assert.Equal(test.RefProperty, value); }