示例#1
0
        public void Ensure_FastProperty_Creating_Returns_Action()
        {
            var value = FastPropertySetter.MakeFastPropertySetter(testPropertyInfo);

            Assert.NotNull(value);
            Assert.IsType <Action <object, object> >(value);
        }
示例#2
0
        public void Constructor_Initialized_Main_Properties()
        {
            var setter = new FastPropertySetter(testPropertyInfo);

            Assert.Equal(setter.Property, testPropertyInfo);
            Assert.Equal(setter.Name, testPropertyInfo.Name);
        }
示例#3
0
        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);
                }
            }
        }
示例#4
0
        public void Ensure_ValueSetter_Initialized()
        {
            var setter = new FastPropertySetter(testPropertyInfo);

            setter.SetValue(testClass, "Go");

            Assert.NotNull(setter.ValueSetter);
        }
示例#5
0
        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);
        }
示例#6
0
        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);
        }