public void ShouldInstantiateArrayOfStrings() { CollectionComponentParameter ccp = new CollectionComponentParameter(); Mock componentAdapterMock = new DynamicMock(typeof(IComponentAdapter)); componentAdapterMock.ExpectAndReturn("ComponentKey", "x", null); componentAdapterMock.ExpectAndReturn("ComponentKey", "x", null); Mock containerMock = new DynamicMock(typeof(IPicoContainer)); containerMock.ExpectAndReturn("ComponentAdapters", new Hashtable(), null); IComponentAdapter[] adapters = new IComponentAdapter[] { new InstanceComponentAdapter("y", "Hello"), new InstanceComponentAdapter("z", "World") }; containerMock.ExpectAndReturn("GetComponentAdaptersOfType", adapters, new IsEqual(typeof(string))); containerMock.ExpectAndReturn("GetComponentInstance", "Hello", new IsEqual("y")); containerMock.ExpectAndReturn("GetComponentInstance", "World", new IsEqual("z")); containerMock.ExpectAndReturn("Parent", null, null); ArrayList expected = new ArrayList(new string[] { "Hello", "World" }); expected.Sort(); object[] array = (object[])ccp.ResolveInstance((IPicoContainer)containerMock.MockInstance, (IComponentAdapter)componentAdapterMock.MockInstance, typeof(string[])); ArrayList actual = new ArrayList(array); actual.Sort(); Assert.AreEqual(expected.ToArray(), actual.ToArray()); // Verify mocks componentAdapterMock.Verify(); containerMock.Verify(); }
public void Verify() { IMutablePicoContainer pico = new DefaultPicoContainer(); CollectionComponentParameter parameterNonEmpty = CollectionComponentParameter.ARRAY; pico.RegisterComponentImplementation(typeof(Shark)); parameterNonEmpty.Verify(pico, null, typeof(Fish[])); try { parameterNonEmpty.Verify(pico, null, typeof(Cod[])); Assert.Fail("PicoIntrospectionException expected"); } catch (PicoIntrospectionException e) { Assert.IsTrue(e.Message.IndexOf(typeof(Cod).Name) > -1); } CollectionComponentParameter parameterEmpty = CollectionComponentParameter.ARRAY_ALLOW_EMPTY; parameterEmpty.Verify(pico, null, typeof(Fish[])); parameterEmpty.Verify(pico, null, typeof(Cod[])); }
public void ShouldInstantiateArrayOfStrings() { CollectionComponentParameter ccp = new CollectionComponentParameter(); Mock componentAdapterMock = new DynamicMock(typeof (IComponentAdapter)); componentAdapterMock.ExpectAndReturn("ComponentKey", "x", null); componentAdapterMock.ExpectAndReturn("ComponentKey", "x", null); Mock containerMock = new DynamicMock(typeof (IPicoContainer)); containerMock.ExpectAndReturn("ComponentAdapters", new Hashtable(), null); IComponentAdapter[] adapters = new IComponentAdapter[] { new InstanceComponentAdapter("y", "Hello"), new InstanceComponentAdapter("z", "World") }; containerMock.ExpectAndReturn("GetComponentAdaptersOfType", adapters, new IsEqual(typeof (string))); containerMock.ExpectAndReturn("GetComponentInstance", "World", new IsEqual("z")); containerMock.ExpectAndReturn("GetComponentInstance", "Hello", new IsEqual("y")); containerMock.ExpectAndReturn("Parent", null, null); ArrayList expected = new ArrayList(new string[] {"Hello", "World"}); expected.Sort(); object[] array = (object[]) ccp.ResolveInstance((IPicoContainer) containerMock.MockInstance, (IComponentAdapter) componentAdapterMock.MockInstance, typeof (string[])); ArrayList actual = new ArrayList(array); actual.Sort(); Assert.AreEqual(expected.ToArray(), actual.ToArray()); // Verify mocks componentAdapterMock.Verify(); containerMock.Verify(); }