Exemplo n.º 1
0
 public async Task Begin(TestRun testRun)
 {
     //probably do something here with DI to set up the logger
     var logger = new ApiLogger();
     //we need these two lists later
     var testConfigurations = new List<TestConfiguration>();
     //deserialise our config
     testConfigurations.AddRange(testRun.TestConfigurations);
     //load the assembly and get test method, this needs to be dynamic
     Assembly assembly = Assembly.LoadFrom(testRun.DllThatContainsTestsPath);
     //get all the classes in the assembly
     Type[] types = assembly.GetTypes().Where(x => x.IsClass).ToArray();
     //get all the methods in the classes
     List<MethodInfo> methodInfos = (from type in types
         from methodInfo
             in type.GetMethods()
         from attribute
             in methodInfo.CustomAttributes
         where attribute.AttributeType == typeof (PerformanceTest)
         select methodInfo).ToList();
     //now we have all of the methods we need to find their configurations for this test run
     //this needs to look at a config file and match on namespace/method name or something
     //or we could pass the configs into as arguments
     List<TestContainer> testContainers = (from method in methodInfos
         from testConfiguration in testConfigurations
         where
             method.DeclaringType != null &&
             (testConfiguration.MethodName == method.Name &&
              testConfiguration.NameSpace == method.DeclaringType.UnderlyingSystemType.FullName)
         select new TestContainer(method, testConfiguration)).ToList();
     //execute the methods that were identified with their configs
     Task task = ExecuteTestMethods(types[0], testContainers, testRun.TestRunIdentifier, logger);
     await task.ContinueWith(x =>
     {
         Console.WriteLine(x.Status.ToString());
         Console.WriteLine("end");
     });
     task.Wait();
 }
 private async Task PostToAgent(string agent, TestRun testRun)
 {
     Log4NetLogger.LogEntry(GetType(), "PostToAgent", "posting testrun to agent", LoggerLevel.Info);
     string testRunJson = JsonConvert.SerializeObject(testRun);
     using (var httpClient = new HttpClient())
     {
         httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
         var content = new StringContent(testRunJson);
         content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
         HttpResponseMessage result =
             await httpClient.PostAsync(string.Format("http://{0}:9999", agent), content);
         result.EnsureSuccessStatusCode();
     }
     Log4NetLogger.LogEntry(GetType(), "PostToAgent", "finished posting testrun to agent", LoggerLevel.Info);
 }