예제 #1
0
        /// <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);
        }
 /// <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;
         }
     }
 }
예제 #3
0
        private static void UpdateTotalTestNumbers(int TeamId)
        {
            ITestManagementService test_service1 = (ITestManagementService)_tfs.GetService(typeof(ITestManagementService));
            var productTeam = db.ProductTeams.First(team => team.TeamId == TeamId);
            var projectasd1 = test_service1.GetTeamProject(productTeam.TeamProject);
            int TotalTFSTests = 0, TotalAutomatedTests = 0;

            foreach (var query in projectasd1.Queries)
            {
                if (query.Name == "TotalTFSTestCases")
                {
                    var TestCases = query.Execute();
                    TotalTFSTests = TestCases.Count();
                }
                if (query.Name == "TotalAutomatedTests")
                {
                    var TestCases = query.Execute();
                    TotalAutomatedTests = TestCases.Count();
                }
            }
            if (TotalTFSTests > 0)
            {
                productTeam.TotalTFSTests = TotalTFSTests;
            }

            if (TotalAutomatedTests > 0)
            {
                productTeam.TotalAutomatedTests = TotalAutomatedTests;
            }

            db.Entry(productTeam).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();
        }
        /// <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);
        }
예제 #5
0
        public MTMWrapper(string tpCollectionUrl, string aTeamProjectName)
        {
            tpCollection    = new TfsTeamProjectCollection(new Uri(tpCollectionUrl));
            teamProjectName = aTeamProjectName;

            testSvc = (ITestManagementService)tpCollection.GetService(typeof(ITestManagementService));
        }
예제 #6
0
        static ITestManagementTeamProject GetProject(string serverUrl, string project)
        {
            TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(TfsTeamProjectCollection.GetFullyQualifiedUriForName(serverUrl));
            ITestManagementService   tms = tfs.GetService <ITestManagementService>();

            return(tms.GetTeamProject(project));
        }
예제 #7
0
        public MTMWrapper(TeamExplorerIntergator teamExplorer)
        {
            tpCollection    = teamExplorer.tpCollection;
            teamProjectName = teamExplorer.tpName;

            testSvc = (ITestManagementService)tpCollection.GetService(typeof(ITestManagementService));
        }
예제 #8
0
        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");
        }
예제 #9
0
 public TestManagementContext(ITeamProjectContext source, string testPlanQueryBit)
 {
     this.testPlanQueryBit = testPlanQueryBit;
     this.source           = source;
     tms     = (ITestManagementService)source.Collection.GetService(typeof(ITestManagementService));
     Project = tms.GetTeamProject(source.Name);
 }
예제 #10
0
        private IList <TestDetailDto> GetTestDetails(
            CatalogNode teamProjectNode,
            ITestManagementService testService,
            IBuildDetail build)
        {
            var tests = new List <TestDetailDto>();

            try
            {
                var testProject = testService.GetTeamProject(teamProjectNode.Resource.DisplayName);
                var testRuns    = testProject.TestRuns.ByBuild(build.Uri);

                foreach (var testRun in testRuns)
                {
                    foreach (var erroringTest in testRun.QueryResults())
                    {
                        tests.Add(new TestDetailDto(erroringTest.TestCaseTitle,
                                                    erroringTest.DateStarted,
                                                    erroringTest.DateCompleted));
                    }
                }
            }
            catch (Exception e)
            {
                LogService.WriteError(e);
                throw;
            }

            return(tests);
        }
예제 #11
0
        private static void FeedTestManagementData(ICollection <TestPlanDefinition> testPlanDefinitionCollection, TfsTeamProjectCollection tpc, string projectName)
        {
            ITestManagementService     tms                = tpc.GetService <ITestManagementService>();
            ITestManagementTeamProject tmtp               = tms.GetTeamProject(projectName);
            ITestPlanHelper            testPlanHelper     = tmtp.TestPlans;
            ITestPlanCollection        testPlanCollection = testPlanHelper.Query("Select * From TestPlan");

            foreach (ITestPlan testPlan in testPlanCollection)
            {
                TestPlanDefinition testPlanDefinition = new TestPlanDefinition()
                {
                    Name          = testPlan.Name,
                    AreaPath      = testPlan.AreaPath,
                    IterationPath = testPlan.Iteration,
                    Description   = testPlan.Description,
                    Owner         = testPlan.Owner.DisplayName,
                    State         = testPlan.State.ToString(),
                    LastUpdate    = testPlan.LastUpdated,
                    StartDate     = testPlan.StartDate,
                    EndDate       = testPlan.EndDate,
                    Revision      = testPlan.Revision
                };
                testPlanDefinitionCollection.Add(testPlanDefinition);
            }
        }
예제 #12
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("");
            }
        }
예제 #13
0
 /// <summary>
 /// Disconnects the current TFS session
 /// </summary>
 public static bool VSTSDisconnect()
 {
     Session.ProjectCollection.Dispose();
     Session.ProjectCollection = null;
     Session.TestService       = null;
     return(Session.ProjectCollection == null);
 }
 public TestManagementContext(IMigrationClient source, string testPlanQueryBit)
 {
     this.testPlanQueryBit = testPlanQueryBit;
     _source = source;
     tms     = _source.GetService <ITestManagementService>();
     Project = tms.GetTeamProject(source.Config.AsTeamProjectConfig().Project);
 }
예제 #15
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");
        }
예제 #16
0
        private Thread CreateTaskThread()
        {
            return(new Thread(() => {
                while (true)
                {
                    try {
                        using (new ConsoleFormatter(ConsoleColor.DarkGreen, ConsoleColor.White)) {
                            Console.WriteLine($"Refreshing data at: {DateTime.Now.ToShortTimeString()}");
                        }

                        lock (handle) {
                            using (TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri(context.ApiUrl))) {
                                ITestManagementService service = tfs.GetService(typeof(ITestManagementService)) as ITestManagementService;
                                ITestManagementTeamProject testProject = service.GetTeamProject(context.Project);

                                //Can extract information about the test suite from here
                                ITestSuiteBase testSuite = testProject.TestSuites.Find(context.SuiteId);

                                //This is a given instance of the test suite , I.E the test plan (suites can be re-used)
                                ITestPlan testPlan = testProject.TestPlans.Find(context.PlanId);

                                Console.WriteLine($"Test Suite: {testSuite.Title} \n Description: {testPlan.Description} \n Last Updated: {testPlan.LastUpdated}");

                                testPlanDataSetFactory.Initialize(testPlan, testProject, context.ApiUrl, context.Project);
                            }
                        }

                        Thread.Sleep(TimeSpan.FromMinutes(context.RefreshTime));
                    } catch (ThreadInterruptedException) {
                        // This is used as a way to wake up sleeping thread.
                    }
                }
            }));
        }
예제 #17
0
        /**
         * This will take the TFS Project
         */
        public void setTFSProject()
        {
            TeamProjectPicker tpp = new TeamProjectPicker(TeamProjectPickerMode.SingleProject, false);

            //Following actions will be executed only if a team project is selected in the the opened dialog.
            if (tpp.SelectedTeamProjectCollection != null)
            {
                this._tfs = tpp.SelectedTeamProjectCollection;

                ITestManagementService test_service = (ITestManagementService)_tfs.GetService(typeof(ITestManagementService));

                //tmService = (ITestManagementService)_tfs.GetService(typeof(ITestManagementService));

                _store = (WorkItemStore)_tfs.GetService(typeof(WorkItemStore));

                this._teamProject = test_service.GetTeamProject(tpp.SelectedProjects[0].Name);

                //Call to method "Get_TestPlans" to get the test plans in the selected team project
                //Get_TestPlans(_teamProject);
            }
            else
            {
                System.Environment.Exit(1);
            }
        }
예제 #18
0
        public static ITestManagementTeamProject GetProject(Uri tfsUri, string projectName, string username, string password)
        {
            try
            {
                Trace.TraceInformation($"Connecting to VSTS {tfsUri.AbsoluteUri}, Project: {projectName}");

                var networkCredential          = new NetworkCredential(username, password);
                BasicAuthCredential  basicCred = new BasicAuthCredential(networkCredential);
                TfsClientCredentials tfsCred   = new TfsClientCredentials(basicCred);
                tfsCred.AllowInteractive = false;

                TfsTeamProjectCollection   projectsCollection = new TfsTeamProjectCollection(tfsUri, tfsCred);
                ITestManagementService     service            = (ITestManagementService)projectsCollection.GetService(typeof(ITestManagementService));
                ITestManagementTeamProject project            = service.GetTeamProject(projectName);

                Trace.TraceInformation($"project {projectName} found");

                return(project);
            }
            catch (TestObjectNotFoundException)
            {
                Trace.TraceError($"Project {projectName} not found");
                return(null);
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.Message);
                return(null);
            }
        }
예제 #19
0
        public WorkItemGenerator(string serverName, string projectName)
        {
            if (string.IsNullOrEmpty(serverName))
            {
                throw new ArgumentNullException("serverName", "servername is null");
            }
            if (string.IsNullOrEmpty(projectName))
            {
                throw new ArgumentNullException("projectName", "projectName is null");
            }

            TeamProjectCollection = new TfsTeamProjectCollection(new Uri(serverName), new Services.Common.VssCredentials());

            // Get the Test Management Service
            ITestManagementService service = (ITestManagementService)TeamProjectCollection.GetService(typeof(ITestManagementService));

            // Initialize the TestManagement Team Project
            m_teamProject = (ITestManagementTeamProject)service.GetTeamProject(projectName);

            ILocationService locationService = TeamProjectCollection.GetService <ILocationService>();

            IsTFS2012 = !String.IsNullOrEmpty(locationService.LocationForCurrentConnection("IdentityManagementService2",
                                                                                           new Guid("A4CE4577-B38E-49C8-BDB4-B9C53615E0DA")));

            // Set the Properties
            Server  = serverName;
            Project = projectName;

            SourceNameToFieldMapping = new Dictionary <string, IWorkItemField>();

            m_suiteCreater = new TestPlanAndSuiteCreator(m_teamProject);
            m_areaAndIterationPathCreator = new AreaAndIterationPathCreator(m_teamProject.WitProject);
            WorkItemCategoryToDefaultType = new Dictionary <string, string>();

            LinkTypeNames = new List <string>();
            m_workItemLinkTypeEndCollection = m_teamProject.WitProject.Store.WorkItemLinkTypes.LinkTypeEnds;
            foreach (WorkItemLinkTypeEnd linkTypeEnd in m_teamProject.WitProject.Store.WorkItemLinkTypes.LinkTypeEnds)
            {
                string linkTypeName = linkTypeEnd.Name;

                LinkTypeNames.Add(linkTypeName);
            }

            WorkItemTypeToCategoryMapping = new Dictionary <string, string>();
            WorkItemTypeNames             = new List <string>();

            PopulateWorkItemTypeDetailsFromCategory(m_teamProject.WitProject.Categories, BugCategory);
            PopulateWorkItemTypeDetailsFromCategory(m_teamProject.WitProject.Categories, RequirementCategory);

            Category testCaseCategory = m_teamProject.WitProject.Categories[TestCaseCategory];

            if (testCaseCategory != null)
            {
                DefaultWorkItemTypeName = testCaseCategory.DefaultWorkItemType.Name;
                PopulateWorkItemTypeDetailsFromCategory(m_teamProject.WitProject.Categories, TestCaseCategory);
            }

            CreateAreaIterationPath = true;
        }
예제 #20
0
        private static void GetLatestSuites(int TeamId)
        {
            ITestManagementService test_service = (ITestManagementService)_tfs.GetService(typeof(ITestManagementService));
            string TeamName   = db.ProductTeams.FirstOrDefault(team => team.TeamId == TeamId)?.TeamProject;
            var    projectasd = test_service.GetTeamProject(TeamName);

            GetTestPlans(projectasd, TeamId);
        }
예제 #21
0
 public Tfs2010BuildService(
     IBuildServer buildServer,
     VersionControlServer versionControlServer,
     ITestManagementService testManagementService)
 {
     this.buildServer           = buildServer;
     this.versionControlServer  = versionControlServer;
     this.testManagementService = testManagementService;
 }
예제 #22
0
 public Tfs2010BuildService(
     IBuildServer buildServer,
     VersionControlServer versionControlServer,
     ITestManagementService testManagementService)
 {
     this.buildServer = buildServer;
     this.versionControlServer = versionControlServer;
     this.testManagementService = testManagementService;
 }
예제 #23
0
        private WorkItemStub _tempStub;                                     //Used for dependency analysis to hold the stub which contains the changeset(s)
        #endregion

        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;
        }
        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;
        }
예제 #25
0
        private IEnumerable<BuildInfoDto> GetBuildInfoDtosPerBuildDefinition(List<IBuildDefinition> buildDefinitionList,
            IBuildServer buildServer, CatalogNode teamProjectNode,
            TfsTeamProjectCollection teamProjectCollection, ITestManagementService testService, DateTime filterDate)
        {
            var buildDtos = new List<BuildInfoDto>();
            try
            {
                Parallel.ForEach(buildDefinitionList, def =>
                {
                    var build = GetBuild(buildServer, teamProjectNode, def, filterDate);

                    if (build == null) return;

                    var buildInfoDto = new BuildInfoDto
                    {
                        Builddefinition = def.Name,
                        FinishBuildDateTime = build.FinishTime,
                        LastBuildTime = new TimeSpan(),
                        PassedNumberOfTests = 0,
                        RequestedByName = build.RequestedFor,
                        RequestedByPictureUrl = "",
                        StartBuildDateTime = build.StartTime,
                        Status = Char.ToLowerInvariant(build.Status.ToString()[0]) + build.Status.ToString().Substring(1),
                        TeamProject = teamProjectNode.Resource.DisplayName,
                        TeamProjectCollection = teamProjectCollection.Name,
                        TotalNumberOfTests = 0,
                        Id = "TFS" + teamProjectNode.Resource.Identifier + def.Id,
                        BuildReportUrl = _helperClass.GetReportUrl(teamProjectCollection.Uri.ToString(), teamProjectNode.Resource.DisplayName, build.Uri.OriginalString)
                    };
                    //Retrieve testruns
                    var testResults = GetTestResults(teamProjectNode, testService, build);

                    if (testResults.ContainsKey("PassedTests"))
                    {
                        buildInfoDto.PassedNumberOfTests = testResults["PassedTests"];
                        buildInfoDto.TotalNumberOfTests = testResults["TotalTests"];
                    }
                    //Add last succeeded build if in progress
                    if (build.Status == BuildStatus.InProgress)
                    {
                        buildInfoDto.LastBuildTime = GetLastSuccesfulBuildTime(buildServer, teamProjectNode, def);
                    }
                    lock (buildDtos)
                    {
                        buildDtos.Add(buildInfoDto);
                    }
                });
            }
            catch (Exception e)
            {
                LogService.WriteError(e);
                throw;
            }

            return buildDtos;
        }
예제 #26
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();
 }
예제 #27
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);
        }
예제 #28
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;
        }
예제 #29
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());
        }
예제 #30
0
        /// <summary>
        /// The constructor sets up build service based on server key
        /// </summary>
        /// <param name="tfsserverKey"></param>
        public TFSBuildService(string tfsserverKey)
        {
            var tfs = new TfsTeamProjectCollection(TfsTeamProjectCollection.GetFullyQualifiedUriForName(tfsserverKey));

            this._buildServer           = tfs.GetService <IBuildServer>();
            this._versionControlServer  = tfs.GetService <VersionControlServer>();
            this._testManagementService = tfs.GetService <ITestManagementService>();
            _httpServiceTfs             = tfs.GetService <TswaClientHyperlinkService>();
            var tp = _versionControlServer.GetTeamProject(@"AllWG");

            pathofTeamProject = tp.ServerItem;
        }
예제 #31
0
        public static void OpenProject(TFSCmdletBase cmdlet, string[] projectNames)
        {
            string currentProjectName = string.Empty;

            try {
                if (null != projectNames && 0 < projectNames.Length)
                {
                    foreach (string projectName in projectNames)
                    {
                        currentProjectName = projectName;

                        ITestManagementService testMgmtSvc =
                            (ITestManagementService)CurrentData.CurrentCollection.GetService(typeof(ITestManagementService));

                        WorkItemStore store =
                            (WorkItemStore)CurrentData.CurrentCollection.GetService(typeof(WorkItemStore));

                        ITestManagementTeamProject project =
                            testMgmtSvc.GetTeamProject(projectName);

                        cmdlet.WriteVerbose(
                            cmdlet,
                            "Connected to the project '" +
                            projectNames +
                            "'");

                        CurrentData.CurrentProject = project;

                        cmdlet.WriteObject(cmdlet, project);
                    }
                }
                else
                {
                    cmdlet.WriteError(
                        cmdlet,
                        "A wrong name or names were provided for project search",
                        "WrongProjectName",
                        ErrorCategory.InvalidArgument,
                        true);
                }
            }
            catch (Exception eOpenProject) {
                cmdlet.WriteError(
                    cmdlet,
                    "Failed to connect to project '" +
                    currentProjectName +
                    "'." +
                    eOpenProject.Message,
                    "FailedToConnect",
                    ErrorCategory.InvalidResult,
                    true);
            }
        }
예제 #32
0
        /// <summary>
        /// The add step for work item "Test Case".
        /// </summary>
        /// <param name="dataObject"></param>
        /// <param name="workItem"></param>
        public void AddStep(IDataObject dataObject, WorkItem workItem, out bool comment, bool isAddStep)
        {
            var    popup = new StepActionsResult();
            string temp  = Regex.Replace(dataObject.GetData(DataFormats.Text).ToString(), @"\s+", " ");

            popup.action.Text = temp;
            popup.Create(null, Icons.AddDetails);
            ITestManagementService testService = collection.GetService <ITestManagementService>();
            var project  = testService.GetTeamProject(workItem.Project.Name);
            var testCase = project.TestCases.Find(workItem.Id);
            var step     = testCase.CreateTestStep();

            if (!popup.IsCanceled)
            {
                switch (tfsVersion)
                {
                case TfsVersion.Tfs2011:

                    step.Title          = "<div><p><span>" + popup.action.Text + "</span></p></div>";
                    step.ExpectedResult = "<div><p><span>" + popup.expectedResult.Text + "</span></p></div>";


                    //step.Title = popup.action.Text;
                    //step.ExpectedResult = popup.expectedResult.Text;

                    break;

                case TfsVersion.Tfs2010:

                    step.Title          = popup.action.Text;
                    step.ExpectedResult = popup.expectedResult.Text;

                    break;
                }
                if (isAddStep)
                {
                    testCase.Actions.Add(step);
                }
                else
                {
                    testCase.Actions.Clear();
                    testCase.Actions.Add(step);
                }
                testCase.Save();
                workItem.Save();
                comment = true;
            }
            else
            {
                comment = false;
            }
        }
        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);
        }
예제 #34
0
        /// <summary>
        /// Get TeamProject from TFS
        /// </summary>
        /// <param name="teamProjecName">The teamProjectName object.</param>
        public void GetTeamProject(string teamProjecName)
        {
            ReadOnlyCollection <CatalogNode> collectionNodes
                = configurationServer.CatalogNode.QueryChildren(new[] { CatalogResourceTypes.ProjectCollection }, false, CatalogQueryOptions.None);

            var  collectionNode = collectionNodes.Single();
            Guid collectionId   = new Guid(collectionNode.Resource.Properties["InstanceId"]);

            teamProjectCollection = configurationServer.GetTeamProjectCollection(collectionId);

            ITestManagementService testManagementService = teamProjectCollection.GetService <ITestManagementService>();

            testProject = testManagementService.GetTeamProject(teamProjecName);
        }
예제 #35
0
 private void ViewTestPlans()
 {
     if (_tfs != null)
     {
         ITestManagementService test_service = (ITestManagementService)_tfs.GetService(typeof(ITestManagementService));
         _store = (WorkItemStore)_tfs.GetService(typeof(WorkItemStore));
         ITestManagementTeamProject _testproject = test_service.GetTeamProject(projectName);
         GetTestPlans(_testproject);
     }
     else
     {
         Console.WriteLine("  aaa ");
     }
 }
        /// <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);
            }
        }
예제 #37
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;
        }
예제 #38
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;
        }
예제 #39
0
 private ITestManagementTeamProject GetTestManagementProject(TfsTeamProjectCollection tfs, string teamProject)
 {
     this.testManagementService = (ITestManagementService)tfs.GetService(typeof(ITestManagementService));
     ITestManagementTeamProject tmProject = testManagementService.GetTeamProject(teamProject);
     return tmProject;
 }
예제 #40
0
 // 
 private static void GetTestManagementService()
 {
     _testManagementService = Collection.GetService<ITestManagementService>();
 }
예제 #41
0
        private IEnumerable<BuildInfoDto> GetBuildInfoDtosPerBuildDefinition(List<IBuildDefinition> buildDefinitionList,
            IBuildServer buildServer, CatalogNode teamProjectNode,
            TfsTeamProjectCollection teamProjectCollection, ITestManagementService testService, DateTime filterDate)
        {
            var buildDtos = new List<BuildInfoDto>();
            try
            {
                Parallel.ForEach(buildDefinitionList, def =>
                {
                    var build = GetBuild(buildServer, teamProjectNode, def, filterDate);

                    if (build == null) return;

                    var buildInfoDto = new BuildInfoDto
                    {
                        Builddefinition = def.Name,
                        FinishBuildDateTime = build.FinishTime,
                        LastBuildTime = new TimeSpan(),
                        PassedNumberOfTests = 0,
                        RequestedByName = build.RequestedFor,
                        RequestedByPictureUrl = "",
                        StartBuildDateTime = build.StartTime,
                        Status = Char.ToLowerInvariant(build.Status.ToString()[0]) + build.Status.ToString().Substring(1),
                        TeamProject = teamProjectNode.Resource.DisplayName,
                        TeamProjectCollection = teamProjectCollection.Name,
                        TotalNumberOfTests = 0,
                        Id = "TFS" + teamProjectNode.Resource.Identifier + def.Id,
                        BuildReportUrl = _helperClass.GetReportUrl(teamProjectCollection.Uri.ToString(), teamProjectNode.Resource.DisplayName, build.Uri.OriginalString)
                    };
                    //Retrieve testruns
                    var testResults = GetTestResults(teamProjectNode, testService, build);

                    if (testResults.ContainsKey("PassedTests"))
                    {
                        buildInfoDto.PassedNumberOfTests = testResults["PassedTests"];
                        buildInfoDto.TotalNumberOfTests = testResults["TotalTests"];
                    }
                    //Add last succeeded build if in progress
                    if (build.Status == BuildStatus.InProgress)
                    {
                        buildInfoDto.LastBuildTime = GetLastSuccesfulBuildTime(buildServer, teamProjectNode, def);
                    }
                    lock (buildDtos)
                    {
                        buildDtos.Add(buildInfoDto);
                    }
                });
            }
            catch (Exception e)
            {
                LogService.WriteError(e);
                throw;
            }

            return buildDtos;
        }
 public TestManagementMigrator(string sourceProjectName, string targetProjectName)
 {
     _service = ServiceFactory.Create<ITestManagementService>();
     _deloitteConnectProject = _service.GetTeamProject(sourceProjectName);
     _connectProject = _service.GetTeamProject(targetProjectName);
 }