コード例 #1
0
        public void InstantiateComponent_AssignsPropertiesWithInjectAttributeOnBaseType()
        {
            // Arrange
            var componentType = typeof(DerivedComponent);
            var factory       = new ComponentFactory(new CustomComponentActivator <DerivedComponent>());

            // Act
            var instance = factory.InstantiateComponent(GetServiceProvider(), componentType);

            // Assert
            Assert.NotNull(instance);
            var component = Assert.IsType <DerivedComponent>(instance);

            Assert.NotNull(component.Property1);
            Assert.NotNull(component.GetProperty2());
            Assert.NotNull(component.Property3);

            // Property on derived type without [Inject] should not be assigned
            Assert.Null(component.Property4);
            // Property on the base type with the [Inject] attribute should
            Assert.NotNull(((ComponentWithInjectProperties)component).Property4);
        }