public override List <Module> GetData() { List <Module> modules = new List <Module>(); Module module; string fileName = GetDataFilePath(); XDocument xDoc = XDocument.Load(fileName); IEnumerable <XElement> modulesSection = xDoc.Descendants(TestDataInfrastructure.GetTestInputData("ModuleSectionName")); XAttribute startupLoaded; if (null != modulesSection) { foreach (XElement moduleElement in modulesSection) { module = new Module(moduleElement.Attribute(TestDataInfrastructure.GetTestInputData("ModuleNameAttribute")).Value); startupLoaded = moduleElement.Attribute(TestDataInfrastructure.GetTestInputData("StartupLoadingAttributeConfigDriven")); module.AllowsDelayLoading = (null == startupLoaded) ? false : startupLoaded.Value.Equals("false"); foreach (XElement dependency in moduleElement.Descendants(TestDataInfrastructure.GetTestInputData("DependenciesNode")) .Descendants(TestDataInfrastructure.GetTestInputData("DependencyNode"))) { module.Dependencies.Add(dependency.Attribute(TestDataInfrastructure.GetTestInputData("ModuleNameAttribute")).Value); } modules.Add(module); } return(modules ?? null); } else { return(null); } }
public override List <Module> GetData() { List <Module> modules = new List <Module>(); Module module = null; string thisAssemblyLocation = Assembly.GetExecutingAssembly().Location; //from the assembly location knock-off the assembly file name along with ".dll" extension string path = thisAssemblyLocation.Substring(0, thisAssemblyLocation.Length - Assembly.GetExecutingAssembly().GetName().Name.Length - ".dll".Length); path += TestDataInfrastructure.GetTestInputData("ModulesFolder"); DirectoryInfo directory = new DirectoryInfo(path); string fileName; foreach (FileInfo file in directory.GetFiles("*.dll")) { fileName = file.Name.Substring(0, file.Name.Length - ".dll".Length); module = new Module(fileName); //reflect and find the value of the StartupLoaded property from the custom attributes //assumption: the module file (implementing IModule interface) is named after the module and so is the namespace Type moduleType = Assembly.LoadFrom(file.FullName) .GetType(fileName + "." + fileName); if (moduleType != null) { object[] attributes = moduleType.GetCustomAttributes(true); foreach (var customAttribute in attributes) { Type type = customAttribute.GetType(); switch (type.Name) { case "ModuleAttribute": object startupLoaded = type.InvokeMember( TestDataInfrastructure.GetTestInputData("StartupLoadingAttributeDirLookup") , BindingFlags.GetProperty , null , customAttribute , null , CultureInfo.InvariantCulture); module.AllowsDelayLoading = !bool.Parse(startupLoaded.ToString()); break; case "ModuleDependencyAttribute": object moduleDependencyName = type.InvokeMember( TestDataInfrastructure.GetTestInputData("DependencyAttributeDirLookup") , BindingFlags.GetProperty , null , customAttribute , null , CultureInfo.InvariantCulture); module.Dependencies.Add(moduleDependencyName.ToString()); break; } } } } return(modules); }