public void ShouldThrowExceptionWhenAccessingNonInterfaceKeyedComponentInStrictMode() 
		{
			IComponentAdapter ca = new ConstructorInjectionComponentAdapter("ww", typeof(FooBar));
			ImplementationHidingComponentAdapter ihca = new ImplementationHidingComponentAdapter(ca, true);
			ihca.GetComponentInstance(null);
			Assert.Fail("Oh no.");
		} 
		public void NonInterfaceInArrayCantBeHidden()
		{
			IComponentAdapter ca = new ConstructorInjectionComponentAdapter(new Type[] {typeof (string)}, typeof (FooBar));
			ImplementationHidingComponentAdapter ihca = new ImplementationHidingComponentAdapter(ca, true);
			ihca.GetComponentInstance(null);
			Assert.Fail("Oh no.");
		}
		public void NonCachingComponentAdapterReturnsNewInstanceOnEachCallToGetComponentInstance()
		{
			ConstructorInjectionComponentAdapter componentAdapter = new ConstructorInjectionComponentAdapter("blah", typeof (object));
			object o1 = componentAdapter.GetComponentInstance(null);
			object o2 = componentAdapter.GetComponentInstance(null);
			Assert.IsNotNull(o1);
			Assert.IsFalse(o1.Equals(o2));
		}
        protected override IComponentAdapter prepRES_failingInstantiationWithCyclicDependencyException(
            IMutablePicoContainer picoContainer)
        {
            IComponentAdapter componentAdapter = new ConstructorInjectionComponentAdapter(typeof(C1));

            picoContainer.RegisterComponent(componentAdapter);
            picoContainer.RegisterComponentImplementation(typeof(C2), typeof(C2));
            return(componentAdapter);
        }
Exemple #5
0
        public void NonCachingComponentAdapterReturnsNewInstanceOnEachCallToGetComponentInstance()
        {
            ConstructorInjectionComponentAdapter componentAdapter =
                new ConstructorInjectionComponentAdapter("blah", typeof(object));
            object o1 = componentAdapter.GetComponentInstance(null);
            object o2 = componentAdapter.GetComponentInstance(null);

            Assert.IsNotNull(o1);
            Assert.IsFalse(o1.Equals(o2));
        }
		public void FailingVerificationWithUnsatisfiedDependencies()
		{
			IComponentAdapter componentAdapter = new ConstructorInjectionComponentAdapter("foo", typeof (B));
			componentAdapter.Container = new DefaultPicoContainer();
			try
			{
				componentAdapter.Verify(componentAdapter.Container);
				Assert.Fail();
			}
			catch (UnsatisfiableDependenciesException)
			{
			}
		}
Exemple #7
0
        public void FailingVerificationWithUnsatisfiedDependencies()
        {
            IComponentAdapter componentAdapter = new ConstructorInjectionComponentAdapter("foo", typeof(B));

            componentAdapter.Container = new DefaultPicoContainer();
            try
            {
                componentAdapter.Verify(componentAdapter.Container);
                Assert.Fail();
            }
            catch (UnsatisfiableDependenciesException)
            {
            }
        }
		public void MultipleInterfacesCanBeHidden()
		{
			Type[] interfaces = new Type[] {typeof (InterfaceOne), typeof (InterfaceTwo)};
			Type implementation = typeof (FooBar);

			IComponentAdapter componentAdapter = new ConstructorInjectionComponentAdapter(
				interfaces,
				implementation);

			ImplementationHidingComponentAdapter ihca = new ImplementationHidingComponentAdapter(componentAdapter, true);
			Object comp = ihca.GetComponentInstance(null);
			Assert.IsNotNull(comp);
			Assert.IsTrue(comp is InterfaceOne);
			Assert.IsTrue(comp is InterfaceTwo);

			// Lets makes sure the actual object is invoked through the proxy
			Assert.IsTrue(((InterfaceOne)comp).MethodOne());
			Assert.IsFalse(((InterfaceTwo)comp).MethodTwo());
		}
 public ConstructorInjectionGuard(ConstructorInjectionComponentAdapter cica, IPicoContainer container)
 {
     this.cica = cica;
     guardedContainer = container;
 }
        public void IComponentAdapterRegistrationOrderIsMaintained()
        {
            ConstructorInjectionComponentAdapter c1 = new ConstructorInjectionComponentAdapter("1", typeof (object));
            ConstructorInjectionComponentAdapter c2 = new ConstructorInjectionComponentAdapter("2", typeof (MyString));

            IMutablePicoContainer picoContainer = CreatePicoContainer();
            picoContainer.RegisterComponent(c1);
            picoContainer.RegisterComponent(c2);
            ArrayList l = new ArrayList();
            l.Add(c1);
            l.Add(c2);

            object[] org = new object[] {c1, c2};
            for (int x = 0; x < 2; x++)
            {
                Assert.AreEqual(org[x], new ArrayList(picoContainer.ComponentAdapters).ToArray()[x]);
            }

            Assert.IsNotNull(picoContainer.ComponentInstances); // create all the instances at once
            Assert.IsFalse(picoContainer.ComponentInstances[0] is MyString);
            Assert.IsTrue(picoContainer.ComponentInstances[1] is MyString);

            IMutablePicoContainer reversedPicoContainer = CreatePicoContainer();
            reversedPicoContainer.RegisterComponent(c2);
            reversedPicoContainer.RegisterComponent(c1);

            l.Clear();
            l.Add(c2);
            l.Add(c1);
            org = new object[] {c2, c1};
            for (int x = 0; x < 2; x++)
            {
                Assert.AreEqual(org[x], new ArrayList(reversedPicoContainer.ComponentAdapters).ToArray()[x]);
            }

            Assert.IsNotNull(reversedPicoContainer.ComponentInstances); // create all the instances at once
            Assert.IsTrue(reversedPicoContainer.ComponentInstances[0] is MyString);
            Assert.IsFalse(reversedPicoContainer.ComponentInstances[1] is MyString);
        }
		protected override IComponentAdapter prepRES_failingInstantiationWithCyclicDependencyException(IMutablePicoContainer picoContainer)
		{
			IComponentAdapter componentAdapter = new ConstructorInjectionComponentAdapter(typeof (C1), typeof (C1));
			picoContainer.RegisterComponent(componentAdapter);
			picoContainer.RegisterComponentImplementation(typeof (C2), typeof (C2));
			return componentAdapter;
		}
Exemple #12
0
        public void SuccessfulVerificationWithNoDependencies()
        {
            InstantiatingComponentAdapter componentAdapter = new ConstructorInjectionComponentAdapter("foo", typeof(A));

            componentAdapter.Verify(componentAdapter.Container);
        }
		public void SuccessfulVerificationWithNoDependencies()
		{
			InstantiatingComponentAdapter componentAdapter = new ConstructorInjectionComponentAdapter("foo", typeof (A));
			componentAdapter.Verify(componentAdapter.Container);
		}
Exemple #14
0
 public ConstructorInjectionGuard(ConstructorInjectionComponentAdapter cica, IPicoContainer container)
 {
     this.cica        = cica;
     guardedContainer = container;
 }