public MatrixExcel(RequirementMatrix matrix) { ExcelApp = new Excel.Application(); ExcelApp.Visible = true; Workbook = ExcelApp.Workbooks.Add(1); Worksheet = (Excel.Worksheet)Workbook.Sheets[1]; Matrix = matrix; }
public void Process() { var tpc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(TpcUrl)); var store = tpc.GetService<WorkItemStore>(); var testSvc = tpc.GetService<ITestManagementService>(); Matrix = new RequirementMatrix(); var wiql = string.Format( @"SELECT [System.Id] FROM WorkItemLinks WHERE Source.[System.TeamProject] = @project AND {0} Source.[System.WorkItemType] IN GROUP 'Microsoft.RequirementCategory' AND Target.[System.WorkItemType] IN GROUP 'Microsoft.TestCaseCategory' MODE(MAYCONTAIN)", GetIDClause(store)); var hQyery = new Query(store, wiql, new Dictionary<string, object>() { { "project", ProjectName } }); var links = hQyery.RunLinkQuery(); // add items with children Matrix.Requirements = (from link in links where link.SourceId > 0 group link by link.SourceId into reqs select new Requirement { Id = reqs.Key, TestIds = reqs.Select(t => t.TargetId).ToList() }).ToList(); // add items without children var childLess = from link in links where link.SourceId == 0 && !Matrix.Requirements.Any(t => t.Id == link.TargetId) select new Requirement { Id = link.TargetId }; Matrix.Requirements.AddRange(childLess); var testIds = new List<int>(); Matrix.Requirements.ForEach(t => testIds = testIds.Union(t.TestIds).ToList()); Matrix.Tests = testIds.ConvertAll(i => new WorkItemInfo() { Id = i }); var plans = testSvc.GetTeamProject(ProjectName).TestPlans.Query("SELECT * FROM TestPlan"); foreach (var testId in testIds) { var mostRecent = GetLatestTestResult(testId, plans); Matrix.Tests.First(t => t.Id == testId).MatrixState = mostRecent; } Matrix.Requirements.ForEach(r => GetItemInfo(r, store)); Matrix.Tests.ForEach(t => GetItemInfo(t, store, false)); }
private static void PrintMatrix(RequirementMatrix matrix) { foreach (var req in matrix.Requirements) { Console.WriteLine("[{0}]: {1}", req.Id, req.Title); foreach (var testId in req.TestIds) { var test = matrix.Tests.FirstOrDefault(t => t.Id == testId); if (test != null) { Console.WriteLine("\t[{0}][{1}]: {2}", test.Id, test.MatrixState, test.Title); } } } Console.WriteLine("Press any key to continue..."); Console.ReadLine(); }
public void Process() { var tpc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(TpcUrl)); var store = tpc.GetService <WorkItemStore>(); var testSvc = tpc.GetService <ITestManagementService>(); Matrix = new RequirementMatrix(); var wiql = string.Format( @"SELECT [System.Id] FROM WorkItemLinks WHERE Source.[System.TeamProject] = @project AND {0} Source.[System.WorkItemType] IN GROUP 'Microsoft.RequirementCategory' AND Target.[System.WorkItemType] IN GROUP 'Microsoft.TestCaseCategory' MODE(MAYCONTAIN)", GetIDClause(store)); var hQyery = new Query(store, wiql, new Dictionary <string, object>() { { "project", ProjectName } }); var links = hQyery.RunLinkQuery(); // add items with children Matrix.Requirements = (from link in links where link.SourceId > 0 group link by link.SourceId into reqs select new Requirement { Id = reqs.Key, TestIds = reqs.Select(t => t.TargetId).ToList() }).ToList(); // add items without children var childLess = from link in links where link.SourceId == 0 && !Matrix.Requirements.Any(t => t.Id == link.TargetId) select new Requirement { Id = link.TargetId }; Matrix.Requirements.AddRange(childLess); var testIds = new List <int>(); Matrix.Requirements.ForEach(t => testIds = testIds.Union(t.TestIds).ToList()); Matrix.Tests = testIds.ConvertAll(i => new WorkItemInfo() { Id = i }); var plans = testSvc.GetTeamProject(ProjectName).TestPlans.Query("SELECT * FROM TestPlan"); foreach (var testId in testIds) { var mostRecent = GetLatestTestResult(testId, plans); Matrix.Tests.First(t => t.Id == testId).MatrixState = mostRecent; } Matrix.Requirements.ForEach(r => GetItemInfo(r, store)); Matrix.Tests.ForEach(t => GetItemInfo(t, store, false)); }