Ejemplo n.º 1
0
        public void GetTypesImplementingType_PassTypeWithExistingImplementationWithFlagIsTrue_ReturnTypes()
        {
            var typeLoader = new Kusnadi.Utils.TypeLoader();

            typeLoader.LoadFromCurrentAppDomain();

            //implementing normal class, return also the type
            var types = typeLoader.GetTypesImplementingType <ClassA>(true);

            Assert.AreEqual(3, types.Count());
            Assert.IsTrue(types.Any(item => item.Name == "ConcreteConcreteClassA" || item.Name == "ConcreteClassA" || item.Name == "ClassA"));

            types = typeLoader.GetTypesImplementingType <ConcreteClassA>(true);
            Assert.AreEqual(2, types.Count());
            Assert.IsTrue(types.Any(item => item.Name == "ConcreteConcreteClassA" || item.Name == "ConcreteClassA"));

            types = typeLoader.GetTypesImplementingType <ConcreteConcreteClassA>(true);
            Assert.AreEqual(1, types.Count());
            Assert.IsTrue(types.First().Name == "ConcreteConcreteClassA");

            //implementing abtract, return only implementation type
            types = typeLoader.GetTypesImplementingType <AbstractA>(true);
            Assert.AreEqual(1, types.Count());
            Assert.IsTrue(types.First().Name == "ConcreteAbstractA");

            //implementing interface, return only implemtation type
            types = typeLoader.GetTypesImplementingType <InterfaceA>(true);
            Assert.AreEqual(1, types.Count());
            Assert.IsTrue(types.First().Name == "ConcreteInterfaceA");
        }
Ejemplo n.º 2
0
        public void GetTypesWithAttribute_ReturnAllInstantiableTypes()
        {
            var typeLoader = new Kusnadi.Utils.TypeLoader();

            typeLoader.LoadFromCurrentAppDomain();

            var types = typeLoader.GetTypesWithAttribute <DataAttribute>();

            Assert.AreEqual(5, types.Count());
            Assert.IsTrue(types.Any(item => item.Name == "ClassA"));
            Assert.IsTrue(types.Any(item => item.Name == "ConcreteClassA"));
            Assert.IsTrue(types.Any(item => item.Name == "ConcreteConcreteClassA"));
            Assert.IsTrue(types.Any(item => item.Name == "ConcreteAbstractA"));
            Assert.IsTrue(types.Any(item => item.Name == "ConcreteInterfaceA"));
        }