Exemplo n.º 1
0
        protected TypeDefinition GetType(string filepath, string classname)
        {
            if (typesCash.ContainsKey(classname))
            {
                return(typesCash[classname]);
            }


            if (!moduleCash.ContainsKey(filepath))
            {
                var fullpath         = Path.Combine(Path.GetDirectoryName(this.GetType().Module.Assembly.Location), filepath);
                var resolver         = new DotnetCoreAssemblyResolver();
                var testAssemblyPath = Path.GetDirectoryName(this.GetType().Module.Assembly.Location);
                resolver.AddSearchDirectory(testAssemblyPath);

                ReaderParameters p = new ReaderParameters()
                {
                    AssemblyResolver = resolver
                };


                var readModule = ModuleDefinition.ReadModule(fullpath, p);
                moduleCash.Add(filepath, readModule);
            }

            var module    = moduleCash[filepath];
            var types     = module.GetTypes();
            var testclass = types
                            .SingleOrDefault(t => t.FullName == classname);

            if (testclass == null)
            {
                throw new Exception($"Test was unable to find type {classname}");
            }

            var typeDef = DocUtils.FixUnnamedParameters(testclass.Resolve());

            typesCash.Add(classname, typeDef);
            return(typeDef);
        }