Пример #1
0
 public void ConstantParameter()
 {
     Object value = new Object();
     ConstantParameter parameter = new ConstantParameter(value);
     IMutablePicoContainer picoContainer = new DefaultPicoContainer();
     Assert.AreSame(value, parameter.ResolveInstance(picoContainer, null, typeof (object)));
 }
        protected virtual IPicoContainer WrapComponentInstances(Type decoratingComponentAdapterClass,
                                                                IPicoContainer picoContainer,
                                                                object[] wrapperDependencies)
        {
            Assert.IsTrue(typeof (DecoratingComponentAdapter).IsAssignableFrom(decoratingComponentAdapterClass));
            IMutablePicoContainer mutablePicoContainer = new DefaultPicoContainer();
            int size = (wrapperDependencies != null ? wrapperDependencies.Length : 0) + 1;
            ICollection allComponentAdapters = picoContainer.ComponentAdapters;

            foreach (object adapter in allComponentAdapters)
            {
                IParameter[] parameters = new IParameter[size];
                parameters[0] = new ConstantParameter(adapter);
                for (int i = 1; i < parameters.Length; i++)
                {
                    parameters[i] = new ConstantParameter(wrapperDependencies[i - 1]);
                }
                IMutablePicoContainer instantiatingPicoContainer =
                    new DefaultPicoContainer(new ConstructorInjectionComponentAdapterFactory());
                instantiatingPicoContainer.RegisterComponentImplementation("decorator", decoratingComponentAdapterClass,
                                                                           parameters);
                mutablePicoContainer.RegisterComponent(
                    (IComponentAdapter) instantiatingPicoContainer.GetComponentInstance("decorator"));
            }
            return mutablePicoContainer;
        }
Пример #3
0
		public void ConstantParameterRespectsExpectedType()
		{
			IMutablePicoContainer picoContainer = new DefaultPicoContainer();
			IParameter parameter = new ConstantParameter(new SimpleTouchable());
			IComponentAdapter adapter = picoContainer.RegisterComponentImplementation(typeof (ITouchable), typeof (SimpleTouchable));
			Assert.IsFalse(parameter.IsResolvable(picoContainer, adapter, typeof (TestFixtureAttribute)));
		}
Пример #4
0
        public void ConstantParameter()
        {
            Object                value         = new Object();
            ConstantParameter     parameter     = new ConstantParameter(value);
            IMutablePicoContainer picoContainer = new DefaultPicoContainer();

            Assert.AreSame(value, parameter.ResolveInstance(picoContainer, null, typeof(object)));
        }
Пример #5
0
        public void ConstantParameterRespectsExpectedType()
        {
            IMutablePicoContainer picoContainer = new DefaultPicoContainer();
            IParameter            parameter     = new ConstantParameter(new SimpleTouchable());
            IComponentAdapter     adapter       =
                picoContainer.RegisterComponentImplementation(typeof(ITouchable), typeof(SimpleTouchable));

            Assert.IsFalse(parameter.IsResolvable(picoContainer, adapter, typeof(TestFixtureAttribute)));
        }
		private IComponentAdapter RegisterComponentImplementation(String[] parameterTypesAsString, String[] parameterValuesAsString, Object key, Type componentImplementation)
		{
			IParameter[] parameters = new IParameter[parameterTypesAsString.Length];
			for (int i = 0; i < parameters.Length; i++)
			{
				Type paramTypeClass = TypeLoader.GetType(parameterTypesAsString[i]);
				object value = Convert.ChangeType(parameterValuesAsString[i], paramTypeClass);
				parameters[i] = new ConstantParameter(value);
			}
			return picoContainer.RegisterComponentImplementation(key, componentImplementation, parameters);
		}