public async Task PopulateKarmaSpecs() { if (IsValid && _karmaSpecs == null) { Globals.IsTest = true; var karmaSpecs = new List <Spec>(); var settings = new KarmaSettings(Name, KarmaConfig, f => File.Exists(f), BaseDirectory, Logger); if (settings.AreValid) { try { var server = new KarmaServer(settings, Logger); server.OutputReceived += line => _karmaOutput.Add(line); server.ErrorReceived += line => _karmaOutput.Add(line); var port = await server.StartServer(60000); var stopCommand = new StopCommand(port); var discoverCommand = new DiscoverCommand(port); await discoverCommand.Run(spec => karmaSpecs.Add(spec)); await stopCommand.Run(); await server.Finished; _karmaSpecs = karmaSpecs; Logger.Info("{0} specs discovered", _karmaSpecs.Count()); } catch (AggregateException ex) { _validator.Validate(false, ex.InnerExceptions.First().Message); } catch (Exception ex) { _validator.Validate(false, ex.Message); } } else { _validator.Validate(false, settings.InvalidReason); } } }