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 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); }
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()); }