Esempio n. 1
0
        static void Main(string[] args)
        {
            string serverUrl = "http://tfs2013:8080/tfs/defaultcollection";
            string project   = "MyProject";

            TfsTeamProjectCollection   tfs  = new TfsTeamProjectCollection(new Uri(serverUrl));
            ITestManagementService     tms  = tfs.GetService <ITestManagementService>();
            ITestManagementTeamProject proj = tms.GetTeamProject(project);

            // List all Test Plans
            foreach (ITestPlan p in proj.TestPlans.Query("Select * From TestPlan"))
            {
                Console.WriteLine("------------------------------------------------");

                Console.WriteLine("Test Plan - {0} : {1}", p.Id, p.Name);
                Console.WriteLine("------------------------------------------------");

                foreach (ITestSuiteBase suite in p.RootSuite.SubSuites)
                {
                    Console.WriteLine("\tTest Suite: {0}", suite.Title);

                    IStaticTestSuite          staticSuite = suite as IStaticTestSuite;
                    ITestSuiteEntryCollection suiteentrys = suite.TestCases;

                    foreach (ITestSuiteEntry testcase in suiteentrys)
                    {
                        Console.WriteLine("\t\tTest Case - {0} : {1}", testcase.Id, testcase.Title);
                    }
                    Console.WriteLine("");
                }

                Console.WriteLine("");
            }
        }
        /// <summary>
        /// Method for processing work items down to the changesets that are related to them
        /// </summary>
        /// <param name="wi">Work Item to process</param>
        /// <param name="outputFile">File to write the dgml to</param>
        /// <param name="vcs">Version Control Server which contains the changesets</param>
        public void ProcessWorkItemRelationships(WorkItem[] wi, 
                                                 string outputFile, 
                                                 bool hideReverse,
                                                 bool groupbyIteration,
                                                 bool dependencyAnalysis,
                                                 List<TempLinkType> selectedLinks,
                                                 VersionControlServer vcs)
        {
            string projectName = wi[0].Project.Name;

            _workItemStubs = new List<WorkItemStub>();
            _wis = wi[0].Store;
            _vcs = vcs;
            _tms = vcs.TeamProjectCollection.GetService<ITestManagementService>();
            _tmp = _tms.GetTeamProject(projectName);
            _selectedLinks = selectedLinks;

            //Store options
            _hideReverse = hideReverse;
            _groupbyIteration = groupbyIteration;
            _dependencyAnalysis = dependencyAnalysis;

            for (int i = 0; i < wi.Length; i++)
            {
                ProcessWorkItemCS(wi[i]);
            }

            WriteChangesetInfo(outputFile, projectName);
        }
        public void GetTestCasesFromProject()
        {
            string interestedFields = "[System.Id], [System.Title]";             // and more
            //string testCaseName = TestContext.FullyQualifiedTestClassName + "." + TestContext.TestName;
            //string storageName = Path.GetFileName(Assembly.GetExecutingAssembly().CodeBase);
            string query = string.Format("SELECT {0} FROM WorkItems", interestedFields);


            //TfsConfigurationServer configServer = GetTFSServerInformation();
            TfsTeamProjectCollection tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(_uri);

            ITestManagementService testService = tfs.GetService <ITestManagementService>();
            //copy the WitDataStore to the bin directory -- https://stackoverflow.com/questions/31031817/unable-to-load-dll-microsoft-witdatastore32-dll-teamfoundation-workitemtracki

            //http://geekswithblogs.net/BobHardister/archive/2014/09/30/microsoft.witdatastore.dll-not-found-nuget-nuspec-references.aspx
            //https://stackoverflow.com/questions/28235448/vsto-oneclick-deplyoment-missing-microsoft-witdatastore-dll

            ITestManagementTeamProject project = testService.GetTeamProject(@"https://tfsqa.mmm.com/tfs/Alderaan/Alderaan Team");

            ITestCase foundTestCase           = null;
            IEnumerable <ITestCase> testCases = project.TestCases.Query(query);

            if (testCases.Count() == 1)
            {
                foundTestCase = testCases.First();
            }

            //ITestManagementService tms = configServer.GetService<ITestManagementService>();

            //ITestManagementTeamProject teamProject = configServer.GetService<ITestManagementService>().GetTeamProject("Alderaan");

            //IEnumerable<ITestCase> testCases = teamProject.TestCases.Query("SELECT * FROM WorkItems");
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            TFSTestManager t = new TFSTestManager();

            t.KickMe();

            //List<String> ret = t.GetTFSCollections();
            //ret.Clear();
            //ret = t.GetTFSProjects();
            //ret.Clear();
            //t.GetTestCasesFromProject();


            //TFSTestManager t2 = new TFSTestManager(@"https://tfs.mmm.com/tfs");
            //ret = t2.GetTFSProjects();

            string interestedFields = "[System.Id], [System.Title]";             // and more
            //string testCaseName = TestContext.FullyQualifiedTestClassName + "." + TestContext.TestName;
            //string storageName = Path.GetFileName(Assembly.GetExecutingAssembly().CodeBase);
            string query = string.Format("SELECT {0} FROM WorkItems", interestedFields);


            //TfsConfigurationServer configServer = GetTFSServerInformation();
            TfsTeamProjectCollection tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(@"https://tfs.mmm.com/tfs"));

            ITestManagementService testService = (ITestManagementService)tfs.GetService(typeof(ITestManagementService));


            ITestManagementTeamProject project = testService.GetTeamProject("Alderaan");
        }
        private List<WorkItemStub> _workItemStubs; //Stores the distinct list of all work items to be written to the dgml

        #endregion Fields

        #region Constructors

        public ProcessFullAnalysis(WorkItemStore wis, VersionControlServer vcs, string projectName, string outputFile)
        {
            _wis = wis;
            _vcs = vcs;
            _tms = vcs.TeamProjectCollection.GetService<ITestManagementService>();
            _tmp = _tms.GetTeamProject(projectName);
            _projectName = projectName;
            _outputFile = outputFile;
        }
Esempio n. 6
0
 private TestStatistics GetTestResults(ITestManagementService tms, Uri uri)
 {
     var testRuns = tms.GetTeamProject(_configuration.TfsTeamProjectName).TestRuns.ByBuild(uri);
     var tests = testRuns.FirstOrDefault();
     if (tests != null)
     {
         return new TestStatistics(tests.Statistics.PassedTests, tests.Statistics.FailedTests, tests.Statistics.TotalTests);
     }
     return new TestStatistics();
 }
Esempio n. 7
0
        public static string GetLastSuccededDropLocation(string projName, string buildDefinitionName)
        {
            projName = GetProjectName(projName);
            var cred = new NetworkCredential("SERVICE_ACCOUNT_NAME", "SERVICE_ACCOUNT_PASSWORD", "SERVICE_ACCOUNT_DOMAIN");

            var configurationServerUri = new Uri("TFS_URL_TILL_COLLECTION");
            TfsConfigurationServer configurationServer =
                TfsConfigurationServerFactory.GetConfigurationServer(configurationServerUri);

            CatalogNode configurationServerNode = configurationServer.CatalogNode;

            // Query the children of the configuration server node for all of the team project collection nodes
            ReadOnlyCollection <CatalogNode> tpcNodes = configurationServerNode.QueryChildren(
                new Guid[] { CatalogResourceTypes.ProjectCollection },
                false,
                CatalogQueryOptions.None);

            foreach (CatalogNode tpcNode in tpcNodes)
            {
                ServiceDefinition tpcServiceDefinition = tpcNode.Resource.ServiceReferences["Location"];

                ILocationService configLocationService = configurationServer.GetService <ILocationService>();
                Uri tpcUri = new Uri(configLocationService.LocationForCurrentConnection(tpcServiceDefinition));

                // Actually connect to the team project collection
                TfsTeamProjectCollection   tpc  = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(tpcUri);
                ITestManagementService     tms  = tpc.GetService <ITestManagementService>();
                ITestManagementTeamProject proj = tms.GetTeamProject(projName);
                IBuildServer tfsBuildServer     = tpc.GetService <IBuildServer>();
                // Reading from XML
                try
                {
                    IBuildServer buildServer = (IBuildServer)tpc.GetService(typeof(IBuildServer));
                    //Specify query
                    IBuildDetailSpec spec = buildServer.CreateBuildDetailSpec(projName.Trim(), buildDefinitionName.Trim());
                    spec.InformationTypes = null;                                // for speed improvement
                    spec.QueryOrder       = BuildQueryOrder.FinishTimeAscending; //get the latest build only
                    spec.QueryOptions     = QueryOptions.All;

                    IBuildDetail bDetail = buildServer.QueryBuilds(spec).Builds.OrderBy(x => x.CompilationStatus == BuildPhaseStatus.Succeeded).Last();
                    LatestTestBuild = bDetail.DropLocation;
                    LoggerUtil.LogMessageToFile("The ip resolve");
                    IPAddress ip   = null;
                    string    arr2 = LatestTestBuild.Split('\\')[2];
                    Network.GetResolvedConnecionIPAddress(LatestTestBuild.Split('\\')[2], out ip);
                    string temp = string.Join(@"\", LatestTestBuild.Split('\\').Select(s => s.Replace(arr2, ip.ToString())).ToArray());
                    LatestTestBuild = temp;
                    LoggerUtil.LogMessageToFile(LatestTestBuild);
                    break;
                }
                catch { }
            }
            return(LatestTestBuild);
        }
Esempio n. 8
0
        private TestStatistics GetTestResults(ITestManagementService tms, Uri uri)
        {
            var testRuns = tms.GetTeamProject(_configuration.TfsTeamProjectName).TestRuns.ByBuild(uri);
            var tests    = testRuns.FirstOrDefault();

            if (tests != null)
            {
                return(new TestStatistics(tests.Statistics.PassedTests, tests.Statistics.FailedTests, tests.Statistics.TotalTests));
            }
            return(new TestStatistics());
        }
Esempio n. 9
0
        /// <summary>
        /// Наполняет переменные.
        /// </summary>
        private void FillVariables()
        {
            tfsUri = new Uri(Uri);
            tfsTeamProjectCollection = new TfsTeamProjectCollection(tfsUri);
            workItemstore            = tfsTeamProjectCollection.GetService <WorkItemStore>();

            ITestManagementService     service = (ITestManagementService)tfsTeamProjectCollection.GetService(typeof(ITestManagementService));
            ITestManagementTeamProject testManagementTeamProject = service.GetTeamProject(projectName);

            teamProject = testManagementTeamProject;
        }
        public static SortedDictionary <string, string> GetTestPlans(string collectionName, string projectName)
        {
            tfs  = new TfsTeamProjectCollection(TfsTeamProjectCollection.GetFullyQualifiedUriForName(XML.GetCollectionURL(collectionName)));
            tms  = tfs.GetService <ITestManagementService>();
            proj = tms.GetTeamProject(projectName);
            iTPC = proj.TestPlans.Query("Select * From TestPlan");
            SortedDictionary <string, string> iTP = new SortedDictionary <string, string>();

            foreach (ITestPlan itp in iTPC)
            {
                iTP.Add(itp.Id.ToString(), itp.Name);
            }
            return(iTP);
        }
        /// <summary>
        /// Load project settings from TFS team project picker.
        /// </summary>
        /// <param name="projectPicker">The project picker.</param>
        public void LoadProjectSettingsFromUserDecision(TeamProjectPicker projectPicker, ref TfsTeamProjectCollection tfsTeamProjectCollection, ref ITestManagementTeamProject testManagementTeamProject, ref Preferences preferences, ITestManagementService testService, string selectedTestPlan, bool writeToRegistry = true)
        {
            preferences = new Preferences();
            log.Info("Load project info depending on the user choice from project picker!");
            try
            {
                using (projectPicker)
                {
                    var userSelected = projectPicker.ShowDialog();

                    if (userSelected == DialogResult.Cancel)
                    {
                        return;
                    }

                    if (projectPicker.SelectedTeamProjectCollection != null)
                    {
                        preferences.TfsUri = projectPicker.SelectedTeamProjectCollection.Uri;
                        log.InfoFormat("Picker: TFS URI: {0}", preferences.TfsUri);
                        preferences.TestProjectName = projectPicker.SelectedProjects[0].Name;
                        log.InfoFormat("Picker: Test Project Name: {0}", preferences.TestProjectName);
                        tfsTeamProjectCollection = projectPicker.SelectedTeamProjectCollection;
                        log.InfoFormat("Picker: TfsTeamProjectCollection: {0}", tfsTeamProjectCollection);
                        testService = (ITestManagementService)tfsTeamProjectCollection.GetService(typeof(ITestManagementService));
                        testManagementTeamProject = testService.GetTeamProject(preferences.TestProjectName);
                    }
                    log.InfoFormat("Test Project Name: {0}", preferences.TestProjectName);
                    log.InfoFormat("TFS URI: {0}", preferences.TfsUri);
                    if (writeToRegistry)
                    {
                        RegistryManager.Instance.WriteCurrentTeamProjectName(preferences.TestProjectName);
                        RegistryManager.Instance.WriteCurrentTeamProjectUri(preferences.TfsUri.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                ModernDialog.ShowMessage("Error selecting team project.", "Warning", MessageBoxButton.OK);
                log.Error("Project info not selected.", ex);
            }
        }
 public TestManagementMigrator(string sourceProjectName, string targetProjectName)
 {
     _service = ServiceFactory.Create<ITestManagementService>();
     _deloitteConnectProject = _service.GetTeamProject(sourceProjectName);
     _connectProject = _service.GetTeamProject(targetProjectName);
 }
Esempio n. 13
0
        private Dictionary<String, int> GetTestResults(CatalogNode teamProjectNode, ITestManagementService testService,
            IBuildDetail build)
        {
            var testResults = new Dictionary<string, int>();
            try
            {
                var testProject = testService.GetTeamProject(teamProjectNode.Resource.DisplayName);
                var testRun = testProject.TestRuns.ByBuild(build.Uri).FirstOrDefault();

                if (testRun != null)
                {
                    testResults.Add("PassedTests", testRun.PassedTests);
                    testResults.Add("TotalTests", testRun.TotalTests);
                }
            }
            catch (Exception e)
            {
                LogService.WriteError(e);
                throw;
            }
            return testResults;
        }
 /// <summary>
 /// Loads project settings from registry.
 /// </summary>
 public void LoadProjectSettingsFromRegistry(ref TfsTeamProjectCollection tfsTeamProjectCollection, ref ITestManagementTeamProject testManagementTeamProject, ref Preferences preferences, ITestManagementService testService, string selectedTestPlan)
 {
     log.Info("Load project info loaded from registry!");
     string teamProjectUri = RegistryManager.Instance.GetTeamProjectUri();
     string teamProjectName = RegistryManager.Instance.GetTeamProjectName();
     string projectDllPath = RegistryManager.Instance.GetProjectDllPath();
     if (!string.IsNullOrEmpty(teamProjectUri) && !string.IsNullOrEmpty(teamProjectName))
     {
         preferences.TfsUri = new Uri(teamProjectUri);
         log.InfoFormat("Registry> TFS URI: {0}", preferences.TfsUri);
         preferences.TestProjectName = teamProjectName;
         log.InfoFormat("Registry> Test Project Name: {0}", preferences.TestProjectName);
         tfsTeamProjectCollection = new TfsTeamProjectCollection(preferences.TfsUri);
         log.InfoFormat("Registry> TfsTeamProjectCollection: {0}", tfsTeamProjectCollection);
         testService = (ITestManagementService)tfsTeamProjectCollection.GetService(typeof(ITestManagementService));
         testManagementTeamProject = testService.GetTeamProject(preferences.TestProjectName);
         selectedTestPlan = RegistryManager.Instance.GetTestPlan();
         log.InfoFormat("Registry> SelectedTestPlan: {0}", selectedTestPlan);
         if (!string.IsNullOrEmpty(selectedTestPlan))
         {
             preferences.TestPlan = TestPlanManager.GetTestPlanByName(testManagementTeamProject, selectedTestPlan);
             this.IsInitializedFromRegistry = true;
         }
     }
 }
Esempio n. 15
0
        private Dictionary<String, int> GetTestResults(CatalogNode teamProjectNode, ITestManagementService testService,
            IBuildDetail build)
        {
            var testResults = new Dictionary<string, int>();
            try
            {
                var testProject = testService.GetTeamProject(teamProjectNode.Resource.DisplayName);

                int passedTests = 0;
                int totalTests = 0;
                bool addTestResults = false;
                foreach (var testRun in testProject.TestRuns.ByBuild(build.Uri).ToList())
                {

                    if (testRun != null)
                    {
                        passedTests += testRun.PassedTests;
                        totalTests += testRun.TotalTests;
                        addTestResults = true;
                    }
                }

                if (addTestResults)
                {
                    testResults.Add("PassedTests", passedTests);
                    testResults.Add("TotalTests", totalTests);
                }

                //var testRun = testProject.TestRuns.ByBuild(build.Uri);

                //if (testRun != null)
                //{
                //    testResults.Add("PassedTests", testRun.PassedTests);
                //    testResults.Add("TotalTests", testRun.TotalTests);
                //}
            }
            catch (Exception e)
            {
                LogService.WriteError(e);
                throw;
            }
            return testResults;
        }
Esempio n. 16
0
 private ITestManagementTeamProject GetTestManagementProject(TfsTeamProjectCollection tfs, string teamProject)
 {
     this.testManagementService = (ITestManagementService)tfs.GetService(typeof(ITestManagementService));
     ITestManagementTeamProject tmProject = testManagementService.GetTeamProject(teamProject);
     return tmProject;
 }