Exemple #1
0
        public void FixtureSetUp()
        {
            tfsUrl = Environment.GetEnvironmentVariable("TFS_URL");
            if (String.IsNullOrEmpty(tfsUrl))
                {
                    Console.WriteLine("Warning: Environment variable TFS_URL not set.");
                    Console.WriteLine("					Some tests cannot be executed without TFS_URL.");
                    return;
                }

            string username = Environment.GetEnvironmentVariable("TFS_USERNAME");
            if (String.IsNullOrEmpty(username))
                {
                    Console.WriteLine("Warning: No TFS user credentials specified.");
                    return;
                }

            credentials = new NetworkCredential(username,
                                                                                    Environment.GetEnvironmentVariable("TFS_PASSWORD"),
                                                                                    Environment.GetEnvironmentVariable("TFS_DOMAIN"));

            // need TFS_ envvars for this test
            if (String.IsNullOrEmpty(tfsUrl)) return;
            TeamFoundationServer tfs = new TeamFoundationServer(tfsUrl, credentials);
            versionControlServer = (VersionControlServer) tfs.GetService(typeof(VersionControlServer));

            workspace = versionControlServer.CreateWorkspace("WorkspaceTest",
                                                                            Environment.GetEnvironmentVariable("TFS_USERNAME"));
        }
        public void FixtureSetUp()
        {
            tfsUrl = Environment.GetEnvironmentVariable("TFS_URL");
            if (String.IsNullOrEmpty(tfsUrl))
            {
                Console.WriteLine("Warning: Environment variable TFS_URL not set.");
                Console.WriteLine("					Some tests cannot be executed without TFS_URL.");
                return;
            }

            string username = Environment.GetEnvironmentVariable("TFS_USERNAME");

            if (String.IsNullOrEmpty(username))
            {
                Console.WriteLine("Warning: No TFS user credentials specified.");
                return;
            }

            credentials = new NetworkCredential(username,
                                                Environment.GetEnvironmentVariable("TFS_PASSWORD"),
                                                Environment.GetEnvironmentVariable("TFS_DOMAIN"));

            // need TFS_ envvars for this test
            if (String.IsNullOrEmpty(tfsUrl))
            {
                return;
            }
            TeamFoundationServer tfs = new TeamFoundationServer(tfsUrl, credentials);

            versionControlServer = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));

            workspace = versionControlServer.CreateWorkspace("WorkspaceTest",
                                                             Environment.GetEnvironmentVariable("TFS_USERNAME"));
        }
Exemple #3
0
        public void Workspace_GetViaInfo()
        {
            // need TFS_ envvars for this test
            if (String.IsNullOrEmpty(tfsUrl))
            {
                return;
            }
            TeamFoundationServer tfs = new TeamFoundationServer(tfsUrl, credentials);
            VersionControlServer vcs = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));

            WorkingFolder[] folders    = new WorkingFolder[1];
            string          serverItem = String.Format("$/{0}", Environment.GetEnvironmentVariable("TFS_PROJECT"));

            folders[0] = new WorkingFolder(serverItem, Environment.CurrentDirectory);

            Workspace w1 = vcs.CreateWorkspace("CreateDelete1_Workspace",
                                               Environment.GetEnvironmentVariable("TFS_USERNAME"),
                                               "My Comment", folders, Environment.MachineName);

            //Workstation.Current.UpdateWorkspaceInfoCache(vcs, Environment.GetEnvironmentVariable("TFS_USERNAME"));

            WorkspaceInfo info = Workstation.Current.GetLocalWorkspaceInfo(Environment.CurrentDirectory);
            Workspace     w2   = info.GetWorkspace(tfs);

            // does info.GetWorkspace talk to the server and get the
            // mapped paths or no? ANSWER: NO IT DOESN'T
            string serverItem2 = w2.TryGetServerItemForLocalItem("foo.txt");

            Assert.AreEqual(null, serverItem2);
            w1.Delete();
        }
Exemple #4
0
        public void Workspace_RefreshMappings2()
        {
            // need TFS_ envvars for this test
            if (String.IsNullOrEmpty(tfsUrl))
            {
                return;
            }
            TeamFoundationServer tfs = new TeamFoundationServer(tfsUrl, credentials);
            VersionControlServer vcs = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));

            WorkingFolder[] folders    = new WorkingFolder[1];
            string          serverItem = String.Format("$/{0}", Environment.GetEnvironmentVariable("TFS_PROJECT"));

            folders[0] = new WorkingFolder(serverItem, Environment.CurrentDirectory);

            Workspace w1 = vcs.CreateWorkspace("CreateDelete1_Workspace",
                                               Environment.GetEnvironmentVariable("TFS_USERNAME"),
                                               "My Comment", folders, Environment.MachineName);

            //Workstation.Current.UpdateWorkspaceInfoCache(vcs, Environment.GetEnvironmentVariable("TFS_USERNAME"));

            WorkspaceInfo info = Workstation.Current.GetLocalWorkspaceInfo(Environment.CurrentDirectory);
            Workspace     w2   = info.GetWorkspace(tfs);

            // this will talk to the server and get the mapped paths
            // BUT it will fail because we don't pass a full path like in RefreshMappings1
            w2.RefreshMappings();

            string serverItem2 = w2.TryGetServerItemForLocalItem("foo.txt");

            Assert.IsNull(serverItem2);
            w1.Delete();
        }
Exemple #5
0
        public void Workspace_Get()
        {
            // need TFS_ envvars for this test
            if (String.IsNullOrEmpty(tfsUrl))
            {
                return;
            }
            TeamFoundationServer tfs = new TeamFoundationServer(tfsUrl, credentials);
            VersionControlServer vcs = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));

            WorkingFolder[] folders    = new WorkingFolder[1];
            string          serverItem = String.Format("$/{0}", Environment.GetEnvironmentVariable("TFS_PROJECT"));

            folders[0] = new WorkingFolder(serverItem, Environment.CurrentDirectory);

            Workspace w1 = vcs.CreateWorkspace("CreateDelete1_Workspace",
                                               Environment.GetEnvironmentVariable("TFS_USERNAME"),
                                               "My Comment", folders, Environment.MachineName);

            Workspace w2 = vcs.GetWorkspace("CreateDelete1_Workspace");

            Assert.AreEqual("My Comment", w2.Comment);

            w1.Delete();
        }
        public void Workspace_CreateDelete1()
        {
            // need TFS_ envvars for this test
            if (String.IsNullOrEmpty(tfsUrl))
            {
                return;
            }
            TeamFoundationServer tfs = new TeamFoundationServer(tfsUrl, credentials);

            VersionControlServer vcs = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));
            Workspace            w1  = vcs.CreateWorkspace("CreateDelete1_Workspace",
                                                           Environment.GetEnvironmentVariable("TFS_USERNAME"));

            w1.Delete();
        }
Exemple #7
0
        public void Workspace_TryGetWorkingFolderForServerItem()
        {
            // need TFS_ envvars for this test
            if (String.IsNullOrEmpty(tfsUrl))
            {
                return;
            }
            TeamFoundationServer tfs = new TeamFoundationServer(tfsUrl, credentials);
            VersionControlServer vcs = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));

            WorkingFolder[] folders    = new WorkingFolder[2];
            string          serverItem = String.Format("$/{0}", Environment.GetEnvironmentVariable("TFS_PROJECT"));

            folders[0] = new WorkingFolder(serverItem, Environment.CurrentDirectory);

            string deeper = Path.Combine(Environment.CurrentDirectory, "deeper");

            folders[1] = new WorkingFolder(serverItem + "/deeper", deeper);

            Workspace w1 = vcs.CreateWorkspace("CreateDelete1_Workspace",
                                               Environment.GetEnvironmentVariable("TFS_USERNAME"),
                                               "My Comment", folders, Environment.MachineName);

            WorkspaceInfo info = Workstation.Current.GetLocalWorkspaceInfo(Environment.CurrentDirectory);
            Workspace     w2   = info.GetWorkspace(tfs);

            // this will talk to the server and get the mapped paths
            w2.RefreshMappings();

            {
                string        serverItem1 = String.Format("{0}/deeper/foo.txt", serverItem);
                WorkingFolder folder      = w2.TryGetWorkingFolderForServerItem(serverItem1);
                Assert.AreEqual(deeper, folder.LocalItem);
            }

            {
                string        serverItem1 = String.Format("junk/deeper/foo.txt", serverItem);
                WorkingFolder folder      = w2.TryGetWorkingFolderForServerItem(serverItem1);
                Assert.IsNull(deeper);
            }

            w1.Delete();
        }
Exemple #8
0
        public void FixtureSetUp()
        {
            tfsUrl = Environment.GetEnvironmentVariable("TFS_URL");
            if (String.IsNullOrEmpty(tfsUrl))
            {
                Console.WriteLine("Warning: Environment variable TFS_URL not set.");
                Console.WriteLine("					Some tests cannot be executed without TFS_URL.");
                return;
            }

            string username = Environment.GetEnvironmentVariable("TFS_USERNAME");

            if (String.IsNullOrEmpty(username))
            {
                Console.WriteLine("Warning: No TFS user credentials specified.");
                return;
            }

            credentials = new NetworkCredential(username,
                                                Environment.GetEnvironmentVariable("TFS_PASSWORD"),
                                                Environment.GetEnvironmentVariable("TFS_DOMAIN"));

            // need TFS_ envvars for this test
            if (String.IsNullOrEmpty(tfsUrl))
            {
                return;
            }
            TeamFoundationServer tfs = new TeamFoundationServer(tfsUrl, credentials);

            versionControlServer = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));

            WorkingFolder[] folders    = new WorkingFolder[1];
            string          serverItem = String.Format("$/{0}", Environment.GetEnvironmentVariable("TFS_PROJECT"));

            folders[0] = new WorkingFolder(serverItem, Environment.CurrentDirectory);

            workspace = versionControlServer.CreateWorkspace("UpdateWorkspaceInfoCache_Workspace",
                                                             Environment.GetEnvironmentVariable("TFS_USERNAME"),
                                                             "My Comment", folders, Environment.MachineName);
        }
        /// <summary>
        /// Gets a TFS workspace mapped to the specified target path (i.e. generally the /SRC temporary directory)
        /// </summary>
        /// <param name="server">The server.</param>
        /// <param name="sourcePath">The source path.</param>
        /// <param name="targetPath">The target path.</param>
        private Workspace GetMappedWorkspace(VersionControlServer server, string sourcePath, string targetPath)
        {
            string workspaceName = "BuildMaster" + Guid.NewGuid().ToString().Replace("-", "");

            var workspaces = server.QueryWorkspaces(workspaceName, server.AuthorizedUser, Environment.MachineName);
            var workspace = workspaces.SingleOrDefault(ws => ws.Name == workspaceName);
            if (workspace != null)
            {
                workspace.Delete();
            }

            workspace = server.CreateWorkspace(workspaceName);

            workspace.CreateMapping(new WorkingFolder(sourcePath, targetPath));

            if (!workspace.HasReadPermission)
            {
                throw new SecurityException(String.Format("{0} does not have read permission for {1}", server.AuthorizedUser, targetPath));
            }

            return workspace;
        }
 private string GetLatestVerstion(VersionControlServer versionControl, TfsGetCodeParams objTfsGetCodeParams)
 {
     Workspace[] workspaces = versionControl.QueryWorkspaces(objTfsGetCodeParams.WorkStationName, versionControl.AuthenticatedUser, Workstation.Current.Name);
     if (workspaces.Length > 0)
     {
         versionControl.DeleteWorkspace(objTfsGetCodeParams.WorkStationName, versionControl.AuthenticatedUser);
     }
     Workspace workspace = versionControl.CreateWorkspace(objTfsGetCodeParams.WorkStationName, versionControl.AuthenticatedUser, "Temporary Workspace");
     try
     {
         workspace.Map(objTfsGetCodeParams.SourcePath, objTfsGetCodeParams.TargetPath+"/"+objTfsGetCodeParams.BuildVersion );
         GetRequest request = new GetRequest(new ItemSpec(objTfsGetCodeParams.SourcePath, RecursionType.Full), VersionSpec.Latest);
         GetStatus status = workspace.Get(request, GetOptions.GetAll | GetOptions.Overwrite); // this line doesn't do anything - no failures or errors
         return "done";
     }
     finally
     {
         if (workspace != null)
         {
             workspace.Delete();
         }
     }
 }
        private static Workspace GetWorkspace(string rootFolder, VersionControlServer versionControlServer, string workspaceName, string workingDirectory)
        {
            TraceHelper.TraceInformation(TraceSwitches.TfsDeployer, "Getting Workspace:{0} RootFolder:{1}", workspaceName,rootFolder);
            Workspace workspace = versionControlServer.CreateWorkspace(workspaceName, versionControlServer.AuthenticatedUser);

            workspace.Map(rootFolder, workingDirectory);
            return workspace;
        }
Exemple #12
0
        public void FixtureSetUp()
        {
            tfsUrl = Environment.GetEnvironmentVariable("TFS_URL");
            if (String.IsNullOrEmpty(tfsUrl))
                {
                    Console.WriteLine("Warning: Environment variable TFS_URL not set.");
                    Console.WriteLine("					Some tests cannot be executed without TFS_URL.");
                    return;
                }

            string username = Environment.GetEnvironmentVariable("TFS_USERNAME");
            if (String.IsNullOrEmpty(username))
                {
                    Console.WriteLine("Warning: No TFS user credentials specified.");
                    return;
                }

            credentials = new NetworkCredential(username,
                                                                                    Environment.GetEnvironmentVariable("TFS_PASSWORD"),
                                                                                    Environment.GetEnvironmentVariable("TFS_DOMAIN"));

            // need TFS_ envvars for this test
            if (String.IsNullOrEmpty(tfsUrl)) return;
            TeamFoundationServer tfs = new TeamFoundationServer(tfsUrl, credentials);
            versionControlServer = (VersionControlServer) tfs.GetService(typeof(VersionControlServer));

            WorkingFolder[] folders = new WorkingFolder[1];
            string serverItem = String.Format("$/{0}", Environment.GetEnvironmentVariable("TFS_PROJECT"));
            folders[0] = new WorkingFolder(serverItem, Environment.CurrentDirectory);

            workspace = versionControlServer.CreateWorkspace("UpdateWorkspaceInfoCache_Workspace",
                                                                                Environment.GetEnvironmentVariable("TFS_USERNAME"),
                                                                                "My Comment", folders, Environment.MachineName);
        }
        /// <summary>
        /// Gets a TFS workspace mapped to the specified target path
        /// </summary>
        /// <param name="server">The server.</param>
        /// <param name="sourcePath">The source path.</param>
        /// <param name="targetPath">The target path.</param>
        private Workspace GetMappedWorkspace(VersionControlServer server, TfsSourceControlContext context)
        {
            var workspaces = server.QueryWorkspaces(context.WorkspaceName, server.AuthorizedUser, Environment.MachineName);
            var workspace = workspaces.FirstOrDefault();
            if (workspace == null) 
        {
                this.LogDebug("Existing workspace not found, creating workspace \"{0}\"...", context.WorkspaceName);
                workspace = server.CreateWorkspace(context.WorkspaceName);
            }
            else 
            {
                this.LogDebug("Workspace found: " + workspace.Name);
            }

            this.LogDebug("Workspace mappings: \r\n" + string.Join(Environment.NewLine, workspace.Folders.Select(m => m.LocalItem + "\t->\t" + m.ServerItem)));

            if (!workspace.IsLocalPathMapped(context.WorkspaceDiskPath))
            {
                this.LogDebug("Local path is not mapped, creating mapping to \"{0}\"...", context.WorkspaceDiskPath);
                this.DeleteWorkspace(context);
                workspace.Map(context.SourcePath, context.WorkspaceDiskPath);
            }

            if (!workspace.HasReadPermission)
                throw new System.Security.SecurityException(string.Format("{0} does not have read permission for {1}", server.AuthorizedUser, context.WorkspaceDiskPath));

            return workspace;
        }
        private void SetupWorkspace(string workingDirectory, string cpSourceBranch, VersionControlServer versionControl)
        {
            List<WorkingFolder> workingFolders = new List<WorkingFolder>();
            workingFolders.Add(new WorkingFolder(cpSourceBranch, workingDirectory));

            // Create a workspace.
            Workspace[] workspaces = versionControl.QueryWorkspaces(sourcePuller.WorkspaceName, versionControl.AuthorizedUser, Environment.MachineName);

            if (workspaces.Length > 0)
                versionControl.DeleteWorkspace(sourcePuller.WorkspaceName, versionControl.AuthorizedUser);

            workspace = versionControl.CreateWorkspace(sourcePuller.WorkspaceName, versionControl.AuthorizedUser, "Work for GetTFSSourceUtil tool", workingFolders.ToArray(), Environment.MachineName);
        }