public void SuccessOnValidMutipleArgs() { TFSOperate tfstest = new TFSOperate(); Uri tfsUri = new Uri("https://tfs-alm.intel.com:8088/tfs/"); tfstest.TfsConnect(tfsUri); string testPlan = "CentralTestPlan"; tfstest.GetTeamProject(testPlan); string[] validTfsPaths = { "CentralTestPlan\\ISH", "CentralTestPlan\\ISH\\Linux (Ubuntu)" }; for (int i = 0; i < validTfsPaths.Length; i++) { string sql = string.Format("select * from WorkItems where [System.TeamProject] = '{0}' and [System.WorkItemType] = 'Test Case' and [System.State] <> 'Removed' and [System.AreaPath] under '{1}'", testPlan, validTfsPaths[i]); int success = 0; try { var testcases = tfstest.GetTestCaseFromSql(sql); success = 1; Assert.IsNotNull(testcases);//"Expected exception was not thrown"); Console.WriteLine("args[{0}] {1} is a correct args!", i, validTfsPaths[i]); } catch (Exception ex) { Assert.IsTrue(success == 0); Console.WriteLine("args[{0}] {1} is an error args!", i, validTfsPaths[i]); } } }
public void SuccessOnValidArgs() { TFSOperate tfstest = new TFSOperate(); Uri tfsUri = new Uri("https://tfs-alm.intel.com:8088/tfs/"); tfstest.TfsConnect(tfsUri); string testPlan = "CentralTestPlan"; string valideTfsPath = "CentralTestPlan\\ISH\\Linux (Ubuntu)"; //string invalideTfsPath = "ISH\\Bat)"; tfstest.GetTeamProject(testPlan); string sql = string.Format("select * from WorkItems where [System.TeamProject] = '{0}' and [System.WorkItemType] = 'Test Case' and [System.State] <> 'Removed' and [System.AreaPath] under '{1}'", testPlan, valideTfsPath); int success = 0; try { var testcases = tfstest.GetTestCaseFromSql(sql); success = 1; Assert.IsNotNull(testcases);//"Expected exception was not thrown"); } catch (Exception ex) { Assert.IsTrue(success == 0); Console.WriteLine("Exception is thrown"); } }
public void ErrorsOnInvalidUrl() { TFSOperate tfstest = new TFSOperate(); Uri tfsUri = new Uri("https://www.baidu.com/"); string testPlan = "CentralTestPlan"; int success = 0; try { tfstest.TfsConnect(tfsUri); tfstest.GetTeamProject(testPlan); success = 1; Console.WriteLine("URL: {0} is a correct TFS URL", tfsUri.ToString()); } catch (Exception ex) { Assert.IsTrue(success == 0); Console.WriteLine("URL: {0} is a error TFS URL Info: {1}", tfsUri.ToString(), ex.Message); } }
private static void Main(string[] args) { string testDllName, testCaseName; ArrayList testCaseCollection = new ArrayList(); string logpath = Directory.GetCurrentDirectory(); // judges if current directory have old log file ,if hava ,delete it. string logfile = Path.Combine(logpath, "log-file.txt"); if (File.Exists(logfile)) { File.Delete(logfile); } ILog log = LogManager.GetLogger("testApp.Logging"); //Uri tfsUri = new Uri("https://tfs-alm.intel.com:8088/tfs/"); Uri tfsUri = new Uri(ConfigurationManager.AppSettings["TfsUri"]); log.InfoFormat("Connecting to Team Foundation Server {0}...", tfsUri); TFSOperate tfsOper = new TFSOperate(); // connected to TFS tfsOper.TfsConnect(tfsUri); // get teamproject from TFS tfsOper.GetTeamProject("CentralTestPlan"); for (int index = 0; index < args.Length; index++) { try { string tfsPath = args[index]; // print the case path in tfs log.InfoFormat("PATH[[{0}]:{1}", index, tfsPath); log.Info("************************************"); /* * string sql1 * = "select * from WorkItems where [System.TeamProject] = 'CentralTestPlan' and [System.WorkItemType] = 'Test Case' and [System.State] <> 'Removed' and [System.AreaPath] under " + "'" + tfsPath + "'";*/ string sql = string.Format("select * from WorkItems where [System.TeamProject] = 'CentralTestPlan' and [System.WorkItemType] = 'Test Case' and [System.State] <> 'Removed' and [System.AreaPath] under '{0}'", tfsPath); // Get testcase collection from sql var testcases = tfsOper.GetTestCaseFromSql(sql); int count = 0; foreach (ITestCase testcase in testcases) { count++; if ((testcase.CustomFields["Is Automated"].Value.ToString() == "Full" || testcase.CustomFields["Is Automated"].Value.ToString() == "Partial") && testcase.CustomFields["Automation Test Name"].Value.ToString() != null) { string autoTestName = testcase.CustomFields["Automation Test Name"].Value.ToString(); if (autoTestName.IndexOf("/run=") == -1) { Flag = false; log.Info("ID: " + testcase.Id); log.Info("Title: " + testcase.Title); log.Info("Tfs Path: " + testcase.Area); log.Info("Is Automated: " + testcase.CustomFields["Is Automated"].Value.ToString()); log.Info("Automation Test Name: " + testcase.CustomFields["Automation Test Name"].Value.ToString()); log.Info("FAIL: No Run Parameters."); log.Info(""); continue; } } else { continue; } testDllName = GetDllName(testcase); string path = ConfigurationManager.AppSettings["dllPath"] + @"Tests\" + testDllName; testCaseCollection.Clear(); if (File.Exists(path)) { NUnitOperate nunitOper = new NUnitOperate(); var testTypes = nunitOper.GetMethodsFromAssemblyFile(path); foreach (var type in testTypes) { // get test method in class. foreach (var method in type.GetMethods()) { if (nunitOper.CanBulidForm(method)) { // judge a test case have a certain attribute if (nunitOper.HasTestCaseAttributeFor(method)) { testCaseCollection.AddRange(nunitOper.GetTestCasesWithTestCaseAttribute(method)); } else if (nunitOper.HasTestSourceCaseAttributeFor(method)) { testCaseCollection.AddRange(nunitOper.GetTestCaseWithTestSourceCaseAttribute(method)); } else if (nunitOper.HasValueAttributeFor(method)) { testCaseCollection.AddRange(nunitOper.GetTestCasesWithParameter(method)); } else { testCaseCollection.Add(nunitOper.BuildTestMethod(method)); } } } } testCaseCollection.Sort(); // Get Testcase Name testCaseName = GetTestCaseName(testcase.CustomFields["Automation Test Name"].Value.ToString()); // judge whether tests folder hava test case, if not , print these test case and its propety. if (!testCaseCollection.Contains(testCaseName)) { Flag = false; log.Info("ID: " + testcase.Id); log.Info("Title: " + testcase.Title); log.Info("Tfs Path: " + testcase.Area); log.Info("Is Automated: " + testcase.CustomFields["Is Automated"].Value.ToString()); log.Info("Automation Test Name: " + testcase.CustomFields["Automation Test Name"].Value.ToString()); log.Info("FAIL: Test Name is not correct."); log.Info(""); } } else { Flag = false; log.Info("ID: " + testcase.Id); log.Info("Title: " + testcase.Title); log.Info("Tfs Path: " + testcase.Area); log.Info("Is Automated: " + testcase.CustomFields["Is Automated"].Value.ToString()); log.Info("Automation Test Name: " + testcase.CustomFields["Automation Test Name"].Value.ToString()); log.InfoFormat("Not find the Dll file name: {0}", testDllName); log.Info("FAIL: dll not found"); log.Info(""); } } if (Flag) { log.Info("PASS: no errors."); log.Info(""); } log.Info("------------------------------------"); } catch (Exception e) { log.Info(e.Message); log.Info("------------------------------------"); continue; } } }