public async Task <TestRunnerResponse> RunTestCase(TestId testId) { Type classType = null; MethodInfo testMethod = null; MethodInfo preTestMethod = null; MethodInfo postTestMethod = null; TestRunnerResponse response = null; //not using cancellation token. As, this testing service will be short lived and will be killed and respawned multiple times during countinous delivery //var tokenSource = new CancellationTokenSource(); //var cancellationtoken = tokenSource.Token; Dictionary <string, MethodInfo> methodsInClass = new Dictionary <string, MethodInfo>(); try { Assembly mscorlib = Assembly.GetExecutingAssembly(); foreach (Type type in mscorlib.GetTypes())//find all classes in assembly { //find class first if (type.FullName == testId.NamespaceNameDotClassName)//if class matches the class name of required test case { //commented below code as "TestClass" tag is redundant here /*TestClassAttribute testClassAttribute; * foreach (Object attributes in type.GetCustomAttributes(false))//find all attributes on class * { * testClassAttribute = attributes as TestClassAttribute; * * if (testClassAttribute != null)//if class has 'TestClass' attribute and matches the class name of required test case * { * classType = type; * break; * } * }*/ classType = type; } //find method now if (classType != null) { foreach (MethodInfo m in classType.GetMethods()) { methodsInClass.Add(m.Name, m); } if (methodsInClass.ContainsKey(testId.MethodName)) { foreach (Attribute attr in methodsInClass[testId.MethodName].GetCustomAttributes(true)) { if (attr is TestMethodServiceFabricAttribute testMethodAttr) { testMethod = methodsInClass[testId.MethodName]; response = new TestRunnerResponse(testMethodAttr.ExpectedExecutionTimeOfTestInMillisecondsIncludingPreTestAndPostTest); if (methodsInClass.ContainsKey(testMethodAttr.PreTestMethod)) { preTestMethod = methodsInClass[testMethodAttr.PreTestMethod]; } if (methodsInClass.ContainsKey(testMethodAttr.PostTestMethod)) { postTestMethod = methodsInClass[testMethodAttr.PostTestMethod]; } } } } break; } } if (classType != null && testMethod != null) { //run test case here in a thread var testCaseTask = Task.Run(() => RunTestCaseInternal(testId, response.TestRunInstanceGuid, classType, testMethod, preTestMethod, postTestMethod)); } } catch (Exception ex) { response = new TestRunnerResponse(0); response.TestRunnerErrorDescription = ex.Message; response.TestRunnerStackTrace = ex.StackTrace; } return(response); }