private ITestAdapter GetTestAdapter(ITestElement test) { Debug.Assert(test != null, "Internal error: test is null!"); // Get more metadata off the type. string id = test.HumanReadableId; int lastDot = id.LastIndexOf('.'); string typeName = id.Substring(0, lastDot); Type dynamicHostType = DynamicHostTypeAttribute.GetDynamicHostType(test.Name, typeName, test.Storage); string dynamicHostTypeName = dynamicHostType.FullName; ITestAdapter realTestAdapter = null; bool containsAdapter = m_adapters.TryGetValue(dynamicHostTypeName, out realTestAdapter); if (!containsAdapter) { realTestAdapter = (ITestAdapter)Activator.CreateInstance(dynamicHostType, new Object[] { }); // Iniitialize was delayed to be run from the Run method. realTestAdapter.Initialize(m_runContext); m_adapters.Add(dynamicHostTypeName, realTestAdapter); } return(realTestAdapter); }
public static Type GetDynamicHostType(string testName, string targetClassName, string targetClassCodebase) { Type attributeType = typeof(DynamicHostTypeAttribute); Assembly targetAssembly = Assembly.LoadFrom(targetClassCodebase); Type targetLoadedType = targetAssembly.GetType(targetClassName); MethodInfo targetMethod = targetLoadedType.GetMethod(testName); object[] attributes = targetMethod.GetCustomAttributes(attributeType, false); if (attributes.Length != 1) { throw new InvalidOperationException("Unable to find single DynamicHostType attribute"); } DynamicHostTypeAttribute attribute = attributes[0] as DynamicHostTypeAttribute; Debug.Assert(attribute != null, "DynamicHostType is not expected type"); Type hostType = attribute.HostType; return(hostType); }