public static List <AutomatedTestMethod> DiscoverAutomatedTests(FileInfo assemblyFile) { if (!assemblyFile.Exists || assemblyFile == null) { throw new FileNotFoundException($"Assembly file not found"); } List <AutomatedTestMethod> foundTests = new List <AutomatedTestMethod>(); Assembly testAssembly = Assembly.LoadFrom(assemblyFile.FullName); foreach (Type type in testAssembly.GetTypes()) { if (type.IsClass) { foreach (MethodInfo methodInfo in type.GetMethods()) { var automatedTestAttribute = Attribute.GetCustomAttribute(methodInfo, typeof(AutomatedTestIDAttribute)); if (automatedTestAttribute != null) { AutomatedTestMethod t = new AutomatedTestMethod(methodInfo.Name, methodInfo.DeclaringType.FullName + "." + methodInfo.Name, assemblyFile.Name); t.TestID = ((AutomatedTestIDAttribute)automatedTestAttribute).WorkItemID; foundTests.Add(t); Trace.TraceInformation($"Found TEST method: {t}"); } } } } return(foundTests); }
public static bool AssociateTestCase(ITestManagementTeamProject project, AutomatedTestMethod testMethod) { try { var automatedTest = project.TestCases.Find(testMethod.TestID); if (automatedTest != null) { automatedTest.SetAssociatedAutomation(project, testMethod); automatedTest.Save(); testMethod.Associated = true; Trace.TraceInformation($"Automated test method {testMethod.FullName} associated to {testMethod.TestID} | {automatedTest.Title}"); return(true); } Trace.TraceWarning($"Test with ID {testMethod.TestID} not found"); return(false); } catch (DeniedOrNotExistException ex) { Trace.TraceWarning(ex.Message); return(false); } catch (Exception ex) { Trace.TraceError(ex.Message); return(false); } }
public static void SetAssociatedAutomation(this ITestCase testCase, ITestManagementTeamProject project, AutomatedTestMethod testMethod) { if (testCase == null) { return; } //create a GUID ID var cryptoServiceProvider = new SHA1CryptoServiceProvider(); var hash = cryptoServiceProvider.ComputeHash(Encoding.Unicode.GetBytes(testMethod.Name)); var bytes = new byte[16]; Array.Copy(hash, bytes, 16); var automationGuid = new Guid(bytes); testCase.Implementation = project.CreateTmiTestImplementation(testMethod.FullName, testMethod.Type, testMethod.Assembly, automationGuid); }