Beispiel #1
0
        public void TypeBasedOverrideCollectionInCompositeOverrideInjectionTest()
        {
            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);
            CompositeResolverOverride compositeOverride       = new CompositeResolverOverride();

            compositeOverride.Add(typeOverrideConstructor);
            compositeOverride.Add(typeOverrideProp);

            IUnityContainer container = new UnityContainer();

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

            Assert.AreEqual <int>(222, overriddenProperty.Value);
            Assert.AreEqual <string>("TestOverrideProp", overriddenProperty.PropertyToInject);
        }
Beispiel #2
0
 public IFactory <TOut> And <T>(T dependency)
 {
     _resolverOverrides.Add(new DependencyOverride <T>(new InjectionParameter <T>(dependency)));
     return(this);
 }
        public void TypeBasedOverrideCollectionInCompositeOverrideInjectionTest()
        {
            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);
            CompositeResolverOverride compositeOverride = new CompositeResolverOverride();
            compositeOverride.Add(typeOverrideConstructor);
            compositeOverride.Add(typeOverrideProp);

            IUnityContainer container = new UnityContainer();

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

            Assert.AreEqual<int>(222, overriddenProperty.Value);
            Assert.AreEqual<string>("TestOverrideProp", overriddenProperty.PropertyToInject);
        }