public TestLibraryContainer GetTestLibraryContainer(string assemblyPath) { var testLibraryContainer = new TestLibraryContainer(); var assemblyDefinition = AssemblyDefinition.ReadAssembly(assemblyPath); var typeDefinitions = GetTypeDefinitions(assemblyDefinition.Modules.FirstOrDefault()); var typesThatAreTestFixtures = GetTypesThatAreTestFixtures(typeDefinitions); testLibraryContainer.TestClasses.AddRange(BuildTestClassesFromTestTypes(typesThatAreTestFixtures)); foreach (var testClass in testLibraryContainer.TestClasses) { testClass.TestMethods = GetMethodsForTestClass(testClass, typesThatAreTestFixtures); } return(testLibraryContainer); }
public List <TestToRun> GetTestsToRun(TestLibraryContainer testLibraryContainer, string assemblyLocation, string projectName, List <string> namespaces) { var testToRuns = new List <TestToRun>(); if (namespaces != null) { foreach (var testClass in testLibraryContainer.TestClasses) { foreach (var ns in namespaces) { if (testClass.Name.Contains(ns)) { foreach (var testMethod in testClass.TestMethods) { var testToRun = new TestToRun(); var testRecord = new TestRecord { AssertCount = testMethod.AssertCount, DateOfTest = DateTime.Now, Description = testMethod.Name, Executed = false, FullName = string.Format("{0}.{1}", testClass.Name, testMethod.Name), HasResults = false, IsError = false, IsFailure = false, IsSuccess = false, Message = "", Time = 0, Name = testMethod.Name, Project = projectName, StackTrace = "", }; testToRun.TestRecord = testRecord; var fixture = string.Format("/fixture:{0}", testClass.Name); string[] arg = { fixture, assemblyLocation }; testToRun.Arguments = arg; testToRuns.Add(testToRun); } } } } } else { foreach (var testClass in testLibraryContainer.TestClasses) { foreach (var testMethod in testClass.TestMethods) { var testToRun = new TestToRun(); var testRecord = new TestRecord { AssertCount = testMethod.AssertCount, DateOfTest = DateTime.Now, Description = testMethod.Name, Executed = false, FullName = string.Format("{0}.{1}", testClass.Name, testMethod.Name), HasResults = false, IsError = false, IsFailure = false, IsSuccess = false, Message = "", Time = 0, Name = testMethod.Name, Project = projectName, StackTrace = "", }; testToRun.TestRecord = testRecord; var fixture = string.Format("/fixture:{0}", testClass.Name); string[] arg = { fixture, assemblyLocation }; testToRun.Arguments = arg; testToRuns.Add(testToRun); } } } var elements = new HashSet <string>(); // Type of property testToRuns.RemoveAll(i => !elements.Add(i.Arguments[0])); return(testToRuns); }