Exemple #1
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();
        }