public void TypeBasedOverrideWithConstructorDefaultFromConfig() { ParameterOverride overrideParam = new ParameterOverride("value", 222); TypeBasedOverride overrideDecorator = new TypeBasedOverride(typeof(TypeToInject2ForTypeOverride), overrideParam); IUnityContainer container = ConfigurationFixtureBase.GetContainer(@"ConfigFiles\TypeOverride.config", "TypeOverrideContainer"); var defaultResult = container.Resolve<TypeToUndergoeTypeBasedInject1>("TestTypeOverrideDefaultInConfiguration"); var overrideResult = container.Resolve<TypeToUndergoeTypeBasedInject1>("TestTypeOverrideDefaultInConfiguration", overrideDecorator); Assert.AreEqual<int>(101, defaultResult.IForTypeToInject.Value); Assert.AreEqual<int>(222, overrideResult.IForTypeToInject.Value); }
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); }
public void TypeBasedOverrideWithConstructorExactTypeMatch() { TypeToInject2ForTypeOverride defaultValue = new TypeToInject2ForTypeOverride(111); TypeToInject2ForTypeOverride overrideValue = new TypeToInject2ForTypeOverride(222); ParameterOverride overrideParam = new ParameterOverride("injectedObject", overrideValue); TypeBasedOverride overrideDecorator = new TypeBasedOverride(typeof(TypeToToUndergoeTypeBasedInject2), overrideParam); IUnityContainer container = new UnityContainer(); container.RegisterType<IForToUndergoeInject, TypeToToUndergoeTypeBasedInject2>(new InjectionConstructor(defaultValue)); var result = container.Resolve<IForToUndergoeInject>(overrideDecorator); Assert.AreEqual<int>(222, result.IForTypeToInject.Value); }
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 TypeBasedOverrideWithResolveAll() { IForTypeToInject defaultValue = new TypeToInject1ForTypeOverride(111); IForTypeToInject overrideValue = new TypeToInject1ForTypeOverride(222); ParameterOverride overrideParam = new ParameterOverride("injectedObject", overrideValue); TypeBasedOverride overrideDecorator = new TypeBasedOverride(typeof(TypeToUndergoeTypeBasedInject1), overrideParam); IUnityContainer container = new UnityContainer(); container.RegisterType<IForToUndergoeInject, TypeToUndergoeTypeBasedInject1>(new InjectionConstructor(defaultValue)).RegisterType<IForToUndergoeInject, TypeToUndergoeTypeBasedInject1>("Named", new InjectionConstructor(defaultValue)); var resultList = container.ResolveAll<IForToUndergoeInject>(overrideDecorator); foreach (var result in resultList) { Assert.AreEqual<int>(222, result.IForTypeToInject.Value); } }
public void TypeBasedOverrideInjectsDependentTypeConstructor() { ParameterOverride overrideParam = new ParameterOverride("value", 222); TypeBasedOverride overrideDecorator = new TypeBasedOverride(typeof(TypeToInject2ForTypeOverride), overrideParam); IUnityContainer container = new UnityContainer(); container.RegisterType<TypeToToUndergoeTypeBasedInject2>().RegisterType<TypeToInject2ForTypeOverride>(new InjectionConstructor(111)); var result = container.Resolve<TypeToToUndergoeTypeBasedInject2>(overrideDecorator); Assert.AreEqual<int>(222, result.IForTypeToInject.Value); }