Пример #1
0
        public void TypeBasedOverrideWithBuildUp()
        {
            MySimpleType instance = new MySimpleType();
            instance.X = 111;

            PropertyOverride overrideParam = new PropertyOverride("X", 222);
            TypeBasedOverride overrideDecorator = new TypeBasedOverride(typeof(MySimpleType), overrideParam);

            UnityContainer container = new UnityContainer();

            var result = container.BuildUp<MySimpleType>(instance, overrideDecorator);
            Assert.AreEqual<int>(222, result.X);
        }
Пример #2
0
        public void TypeBasedOverrideInjectsDependentTypeProperty()
        {
            ParameterOverride overrideParam = new ParameterOverride("value", 222);
            PropertyOverride overrideProp = new PropertyOverride("PropertyToInject", "TestOverrideProp");
            TypeBasedOverride typeOverrideConstructor = new TypeBasedOverride(typeof(TypeToInject3ForTypeOverride), overrideParam);
            TypeBasedOverride typeOverrideProp = new TypeBasedOverride(typeof(TypeToInject3ForTypeOverride), overrideProp);

            IUnityContainer container = new UnityContainer();

            container.RegisterType<TypeToUndergoeTypeBasedInject1>().RegisterType<IForTypeToInject, TypeToInject3ForTypeOverride>(new InjectionConstructor(111), new InjectionProperty("PropertyToInject", "DefaultValue"));
            var result = container.Resolve<TypeToUndergoeTypeBasedInject1>(typeOverrideConstructor, typeOverrideProp);
            TypeToInject3ForTypeOverride overriddenProperty = (TypeToInject3ForTypeOverride)result.IForTypeToInject;

            Assert.AreEqual<int>(222, overriddenProperty.Value);
            Assert.AreEqual<string>("TestOverrideProp", overriddenProperty.PropertyToInject);
        }
        public void PropertyOverrideWithBuildUp()
        {
            MySimpleTypeForPropertyOverride instance = new MySimpleTypeForPropertyOverride();
            instance.X = 111;

            PropertyOverride overrideParam = new PropertyOverride("X", 222);

            IUnityContainer container = new UnityContainer();

            var result = container.BuildUp<MySimpleTypeForPropertyOverride>(instance, overrideParam);

            Assert.AreEqual<int>(222, result.X);
        }