Пример #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);
        }