Exemplo n.º 1
0
        public void CanDistinguishDerivedTypesThatImplementAnInterface()
        {
            // Test root interface
            var allTypesOfAThatImplementILetter = new List <A>();

            allTypesOfAThatImplementILetter.AddRange(ReflectionTools.GetAllInstancesOfTypeWithInterface <A, ILetter>());

            Assert.AreEqual(4, allTypesOfAThatImplementILetter.Count);
            for (var i = 0; i < allAssignableFromA.Count; i++)
            {
                Assert.IsTrue(allAssignableFromA.Exists(x => x.GetType() == allAssignableFromA[i].GetType()));
            }

            // Test nested interface
            var allSubclassesOfAWithInterfaceIFavoriteLetter = new List <A>
            {
                new C(), new D()
            };

            var reflectionDerivedTypesOfAWithInterfaceIFavoriteLetter = new List <A>();

            reflectionDerivedTypesOfAWithInterfaceIFavoriteLetter.AddRange(
                ReflectionTools
                .GetAllInstancesOfTypeWithInterface <A, IFavoriteLetter>());

            Assert.AreEqual(2, reflectionDerivedTypesOfAWithInterfaceIFavoriteLetter.Count);
            for (var i = 0; i < allSubclassesOfAWithInterfaceIFavoriteLetter.Count; i++)
            {
                Assert.IsTrue(
                    reflectionDerivedTypesOfAWithInterfaceIFavoriteLetter.Exists(
                        x =>
                        x.GetType() == allSubclassesOfAWithInterfaceIFavoriteLetter[i].GetType()));
            }
        }