public AddFilesToStorage ( IList |
||
files | IList |
|
return | void |
public void AddFilesToStorageTest() { string projectFile = Path.GetTempFileName(); string storageFile = projectFile + ".storage"; if (File.Exists(storageFile)) { File.Delete(storageFile); } SccProviderStorage target = new SccProviderStorage(projectFile); IList<string> files = new List<string>(); files.Add(projectFile); files.Add("dummy.txt"); target.AddFilesToStorage(files); // Test that project file is now controlled Assert.AreEqual(SourceControlStatus.scsCheckedIn, target.GetFileStatus(projectFile), "Failed to add the project file"); // Test the storage file was written Assert.IsTrue(File.Exists(storageFile), "Storage file was not created"); // Cleanup the files written by the test File.SetAttributes(projectFile, FileAttributes.Normal); File.Delete(projectFile); File.Delete(storageFile); }
/// <summary> /// Adds the specified projects and solution to source control /// </summary> public void AddProjectsToSourceControl(ref Hashtable hashUncontrolledProjects, bool addSolutionToSourceControl) { // A real source control provider will ask the user for a location where the projects will be controlled // From the user input it should create up to 4 strings that will pass them to the projects to persist, // so next time the project is open from disk, it will callback source control package, and the package // could use the 4 binding strings to identify the correct database location of the project files. foreach (IVsHierarchy pHier in hashUncontrolledProjects.Keys) { IVsSccProject2 sccProject2 = (IVsSccProject2)pHier; sccProject2.SetSccLocation("<Project Location In Database>", "<Source Control Database>", "<Local Binding Root of Project>", _sccProvider.ProviderName); // Add the newly controlled projects now to the list of controlled projects in this solution _controlledProjects[pHier] = null; } // Also, if the solution was selected to be added to scc, write in the solution properties the controlled status if (addSolutionToSourceControl) { IVsHierarchy solHier = (IVsHierarchy)_sccProvider.GetService(typeof(SVsSolution)); _controlledProjects[solHier] = null; _sccProvider.SolutionHasDirtyProps = true; } // Now save all the modified files IVsSolution sol = (IVsSolution)_sccProvider.GetService(typeof(SVsSolution)); sol.SaveSolutionElement((uint)__VSSLNSAVEOPTIONS.SLNSAVEOPT_SaveIfDirty, null, 0); // Add now the solution and project files to the source control database // which in our case means creating a text file containing the list of controlled files foreach (IVsHierarchy pHier in hashUncontrolledProjects.Keys) { IVsSccProject2 sccProject2 = (IVsSccProject2)pHier; IList<string> files = _sccProvider.GetProjectFiles(sccProject2); SccProviderStorage storage = new SccProviderStorage(_sccProvider.GetProjectFileName(sccProject2)); storage.AddFilesToStorage(files); _controlledProjects[pHier] = storage; } // If adding solution to source control, create a storage for the solution, too if (addSolutionToSourceControl) { IVsHierarchy solHier = (IVsHierarchy)_sccProvider.GetService(typeof(SVsSolution)); IList<string> files = new List<string>(); string solutionFile = _sccProvider.GetSolutionFileName(); files.Add(solutionFile); SccProviderStorage storage = new SccProviderStorage(solutionFile); storage.AddFilesToStorage(files); _controlledProjects[solHier] = storage; } // For all the projects added to source control, refresh their source control glyphs IList<VSITEMSELECTION> nodes = new List<VSITEMSELECTION>(); foreach (IVsHierarchy pHier in hashUncontrolledProjects.Keys) { VSITEMSELECTION vsItem; vsItem.itemid = VSConstants.VSITEMID_ROOT; vsItem.pHier = pHier; nodes.Add(vsItem); } // Also, add the solution if necessary to the list of glyphs to refresh if (addSolutionToSourceControl) { VSITEMSELECTION vsItem; vsItem.itemid = VSConstants.VSITEMID_ROOT; vsItem.pHier = null; nodes.Add(vsItem); } _sccProvider.RefreshNodesGlyphs(nodes); }
public void RenameFileInStorageTest() { string projectFile = Path.GetTempFileName(); string storageFile = projectFile + ".storage"; string newStorageFile = "dummy.txt.storage"; if (File.Exists(storageFile)) { File.Delete(storageFile); } if (File.Exists(newStorageFile)) { File.Delete(newStorageFile); } SccProviderStorage target = new SccProviderStorage(projectFile); IList<string> files = new List<string>(); files.Add(projectFile); target.AddFilesToStorage(files); target.RenameFileInStorage(projectFile, "dummy.txt"); // Test that project file is now uncontrolled Assert.AreEqual(SourceControlStatus.scsUncontrolled, target.GetFileStatus(projectFile), "GetFileStatus failed for old name"); // Test that dummy file is now controlled (and checked in since it's missing from disk) Assert.AreEqual(SourceControlStatus.scsCheckedIn, target.GetFileStatus("Dummy.txt"), "GetFileStatus failed for new name"); // Cleanup the files written by the test File.SetAttributes(projectFile, FileAttributes.Normal); File.Delete(projectFile); File.Delete(newStorageFile); }
public void GetFileStatusTest() { string projectFile = Path.GetTempFileName(); string storageFile = projectFile + ".storage"; if (File.Exists(storageFile)) { File.Delete(storageFile); } SccProviderStorage target = new SccProviderStorage(projectFile); IList<string> files = new List<string>(); files.Add(projectFile); target.AddFilesToStorage(files); // Test that project file is now controlled Assert.AreEqual(SourceControlStatus.scsCheckedIn, target.GetFileStatus(projectFile), "GetFileStatus failed for project file"); // Checkout the file and test status again target.CheckoutFile(projectFile); Assert.AreEqual(SourceControlStatus.scsCheckedOut, target.GetFileStatus(projectFile), "GetFileStatus failed for project file"); // Test that a dummy file is uncontrolled Assert.AreEqual(SourceControlStatus.scsUncontrolled, target.GetFileStatus("Dummy.txt"), "GetFileStatus failed for uncontrolled file"); // Cleanup the files written by the test File.Delete(projectFile); File.Delete(storageFile); }