/// <summary> /// This method figures out what tests, environments and sites are to be tested and runs them separately in their own threads /// </summary> protected void btnSubmitTests_Click(object sender, EventArgs e) { WebTestManager manager = new WebTestManager(this); IEnumerable <TestEnvironment> envs = from ListItem li in cblEnv.Items.Cast <ListItem>() where li.Selected select Environments[int.Parse(li.Value)]; IEnumerable <TestSite> sites = from ListItem li in cblSites.Items.Cast <ListItem>() where li.Selected select Sites[int.Parse(li.Value)]; foreach (ListItem li in cblTests.Items.Cast <ListItem>().Where(a => a.Selected)) { TestFixture tf = Fixtures[li.Value]; manager.RunTest(tf, envs, sites); } }
static void RunWebTest(string[] args) { //params 1 = test assembly string testAssembly = string.Empty; if (args.Length > 1) { testAssembly = args[1]; } else { Console.WriteLine("You need to specify an assembly."); return; } //params 2 = test name string testName = string.Empty; if (args.Length > 2) { testName = args[2]; } else { Console.WriteLine("You need to specify a test."); return; } //params 3 = environments Dictionary <int, TestEnvironment> Environments = new Dictionary <int, TestEnvironment>(); if (args.Length > 3) { IEnumerable <TestEnvironment> prEnv = EnvironmentProvider.GetEnvironments(); foreach (string s in GetStrings(args[3])) { foreach (TestEnvironment fenv in prEnv.Where(a => a.ID.Equals(int.Parse(s)))) { if (!Environments.ContainsKey(fenv.ID)) { Console.WriteLine(string.Format("Adding '{0}' Environment.", fenv.Name)); Environments.Add(fenv.ID, fenv); } } } } // params 4 = systems // params 5 = sites // will look for sites by system unless systems is an empty string then it looks for them by site Dictionary <int, TestSite> Sites = new Dictionary <int, TestSite>(); IEnumerable <TestSite> prSites = SiteProvider.GetEnabledSites(); if (args.Length > 4 && !string.IsNullOrEmpty(args[4])) { foreach (string s in GetStrings(args[4])) { foreach (TestSite fsite in prSites.Where(a => a.SystemID.Equals(int.Parse(s)))) { if (!Sites.ContainsKey(fsite.ID)) { Console.WriteLine(string.Format("Adding '{0}' Site.", fsite.Name)); Sites.Add(fsite.ID, fsite); } } } } if (args.Length > 5) { foreach (string s in GetStrings(args[5])) { foreach (TestSite fsite in prSites.Where(a => a.ID.Equals(int.Parse(s)))) { if (!Sites.ContainsKey(fsite.ID)) { Console.WriteLine(string.Format("Adding '{0}' Site.", fsite.Name)); Sites.Add(fsite.ID, fsite); } } } } //setup for testing CoreExtensions.Host.InitializeService(); //get the test suite TestSuite suite = TestUtility.GetTestSuite(testAssembly); IEnumerable <TestFixture> Fixtures = suite.GetFixtures().Where(a => a.ClassName.EndsWith(string.Format(".{0}", testName))); if (!Fixtures.Any()) { Console.WriteLine("There were no Test Fixtures found. Make sure the class has the [TestFixture] attribute."); return; } TestFixture tf = Fixtures.First(); WebTestManager manager = new WebTestManager(new WebConsoleTestHandler()); manager.RunTest(tf, Environments.Values, Sites.Values); }