internal void CreateOrUpdateTestCases(IEnumerable <ImportTestCase> tests) { var test_project = GetTestProject(); // get the test cases from the project var allTestCasesOfProject = test_project.TestCases.Query("SELECT [Title] FROM WorkItems"); List <ITestCase> testCases = new List <ITestCase>(); foreach (ITestCase tc in allTestCasesOfProject) { testCases.Add(tc); } // http://blogs.msdn.com/b/densto/archive/2010/03/04/the-test-management-api-part-2-creating-modifying-test-plans.aspx foreach (var t in tests) { var newTestCase = test_project.TestCases.Create(); newTestCase.Title = t.MethodName; newTestCase.WorkItem.Fields["Tags"].Value = string.Join(",", t.Tags.Select(x => x.Substring(1))); newTestCase.Description = ""; foreach (var s in t.Description) { newTestCase.Description += HttpUtility.HtmlEncode(s) + "<br/>"; } newTestCase.Description += "<br/>"; var tab = "<table class=w3-table-all><tbody>"; var row = "<tr>"; var rowHeadCell = "<th>"; var rowHeadCellEnd = "</th>"; var rowEnd = "</tr>"; var rowCell = "<td>"; var rowCellEnd = "</td>"; var tabEnd = "</tbody></table>"; string h = null; if (t.Examples != null) { newTestCase.Description += tab + row; foreach (var e in t.Examples) { if (h == null) { foreach (var eh in e) { h += rowHeadCell + HttpUtility.HtmlEncode(eh) + rowHeadCellEnd; } newTestCase.Description += h + rowEnd; } else { newTestCase.Description += row; foreach (var ed in e) { newTestCase.Description += rowCell + HttpUtility.HtmlEncode(ed) + rowCellEnd; } newTestCase.Description += rowEnd; } } newTestCase.Description += tabEnd; } ITmiTestImplementation imp = new TetsImplementation { Storage = SpecFlow2TFSConfig.LIB, TestId = Guid.NewGuid(), TestName = t.NameSpace + t.MethodName, TestType = "Unit Test" }; newTestCase.Implementation = imp; newTestCase.WorkItem.Fields["Microsoft.VSTS.TCM.AutomationStatus"].Value = "Automated"; newTestCase.WorkItem.Fields["Microsoft.VSTS.TCM.AutomatedTestName"].Value = imp.TestName; newTestCase.WorkItem.Fields["Microsoft.VSTS.TCM.AutomatedTestStorage"].Value = imp.Storage; newTestCase.WorkItem.Fields["Microsoft.VSTS.TCM.AutomatedTestId"].Value = imp.TestId.ToString(); newTestCase.WorkItem.Fields["Microsoft.VSTS.TCM.AutomatedTestType"].Value = imp.TestType; ArrayList ValidationResult = newTestCase.WorkItem.Validate(); newTestCase.Save(); } }
internal void CreateOrUpdateTestCases(IEnumerable<ImportTestCase> tests) { var test_project = GetTestProject(); // get the test cases from the project var allTestCasesOfProject = test_project.TestCases.Query("SELECT [Title] FROM WorkItems"); List<ITestCase> testCases = new List<ITestCase>(); foreach (ITestCase tc in allTestCasesOfProject) { testCases.Add(tc); } // http://blogs.msdn.com/b/densto/archive/2010/03/04/the-test-management-api-part-2-creating-modifying-test-plans.aspx foreach (var t in tests) { var newTestCase = test_project.TestCases.Create(); newTestCase.Title = t.MethodName; newTestCase.WorkItem.Fields["Tags"].Value = string.Join(",", t.Tags.Select(x => x.Substring(1))); newTestCase.Description = ""; foreach (var s in t.Description) { newTestCase.Description += HttpUtility.HtmlEncode(s) + "<br/>"; } newTestCase.Description += "<br/>"; var tab = "<table class=w3-table-all><tbody>"; var row = "<tr>"; var rowHeadCell = "<th>"; var rowHeadCellEnd = "</th>"; var rowEnd = "</tr>"; var rowCell = "<td>"; var rowCellEnd = "</td>"; var tabEnd = "</tbody></table>"; string h = null; if (t.Examples != null) { newTestCase.Description += tab + row; foreach (var e in t.Examples) { if (h == null) { foreach (var eh in e) { h += rowHeadCell + HttpUtility.HtmlEncode(eh) + rowHeadCellEnd; } newTestCase.Description += h + rowEnd; } else { newTestCase.Description += row; foreach (var ed in e) { newTestCase.Description += rowCell + HttpUtility.HtmlEncode(ed) + rowCellEnd; } newTestCase.Description += rowEnd; } } newTestCase.Description += tabEnd; } ITmiTestImplementation imp = new TetsImplementation { Storage = SpecFlow2TFSConfig.LIB, TestId = Guid.NewGuid(), TestName = t.NameSpace + t.MethodName, TestType = "Unit Test" }; newTestCase.Implementation = imp; newTestCase.WorkItem.Fields["Microsoft.VSTS.TCM.AutomationStatus"].Value = "Automated"; newTestCase.WorkItem.Fields["Microsoft.VSTS.TCM.AutomatedTestName"].Value = imp.TestName; newTestCase.WorkItem.Fields["Microsoft.VSTS.TCM.AutomatedTestStorage"].Value = imp.Storage; newTestCase.WorkItem.Fields["Microsoft.VSTS.TCM.AutomatedTestId"].Value = imp.TestId.ToString(); newTestCase.WorkItem.Fields["Microsoft.VSTS.TCM.AutomatedTestType"].Value = imp.TestType; ArrayList ValidationResult = newTestCase.WorkItem.Validate(); newTestCase.Save(); } }