public void AddExistingItem() { using (var app = new VisualStudioApp()) { // close any projects before switching source control... app.Dte.Solution.Close(); app.SelectSourceControlProvider("Test Source Provider"); foreach (var projectType in ProjectTypes) { var testDef = SourceControlProject(projectType); using (var solution = testDef.Generate()) { TestSccProvider.DocumentEvents.Clear(); var project = app.OpenProject(solution.Filename, onDialog: OnNoSccDialog); var fileName = projectType.Code(@"ExcludedFile"); using (var newItem = AddExistingItemDialog.FromDte(app)) { newItem.FileName = fileName; newItem.OK(); } System.Threading.Thread.Sleep(250); Assert.IsNotNull(project.ProjectItems.Item(fileName)); AssertDocumentEvents(Path.GetDirectoryName(project.FullName), OnQueryAddFiles(fileName), OnAfterAddFilesEx(fileName) ); } } } }
public void AddExistingItem(PythonVisualStudioApp app) { var project = app.OpenProject(@"TestData\AddExistingItem.sln"); app.OpenSolutionExplorer().SelectProject(project); using (var addExistingDlg = AddExistingItemDialog.FromDte(app)) { addExistingDlg.FileName = TestData.GetPath(@"TestData\AddExistingItem\Program2.py"); addExistingDlg.Add(); } app.OpenSolutionExplorer().WaitForChildOfProject(project, "Program2.py"); }
/// <summary> /// Test linked files with a project home set (done by save as in this test) /// https://nodejstools.codeplex.com/workitem/1511 /// </summary> public void TestLinkedWithProjectHome(VisualStudioApp app, ProjectGenerator pg) { foreach (var projectType in pg.ProjectTypes) { using (var solution = MultiProjectLinkedFiles(projectType).ToVs(app)) { var project = (solution as VisualStudioInstance).Project; // save the project to an odd location. This will result in project home being set. var newProjName = "TempFile"; try { project.SaveAs(TestData.GetTempPath() + newProjName + projectType.ProjectExtension); } catch (UnauthorizedAccessException) { Assert.Inconclusive("Couldn't save the file"); } // create a temporary file and add a link to it in the project solution.FindItem(newProjName).Select(); string tempFile; using (FileUtils.TemporaryTextFile(out tempFile, "Test file")) { using (var addExistingDlg = AddExistingItemDialog.FromDte((solution as VisualStudioInstance).App)) { addExistingDlg.FileName = tempFile; addExistingDlg.AddLink(); } // Save the project to commit that link to the project file project.Save(); // verify that the project file contains the correct text for Link // (file path is relative to home folder) var projectHomeFolder = project.Properties.Item("ProjectHome").Value as string; var fileText = File.ReadAllText(project.FullName); var relativeTempFile = PathUtils.GetRelativeFilePath( projectHomeFolder, tempFile ); var pattern = string.Format( @"<Content Include=""{0}"">\s*<Link>{1}</Link>\s*</Content>", Regex.Escape(relativeTempFile), Regex.Escape(Path.GetFileName(tempFile))); AssertUtil.AreEqual(new Regex(pattern), fileText); } } } }
public void AddExistingItemAsLinkButFileExistsInProjectDirectory() { foreach (var projectType in ProjectTypes) { using (var solution = LinkedFiles(projectType).Generate().ToVs()) { var projectNode = solution.FindItem("LinkedFiles", "Fob"); Assert.IsNotNull(projectNode, "projectNode"); AutomationWrapper.Select(projectNode); using (var addExistingDlg = AddExistingItemDialog.FromDte(solution.App)) { addExistingDlg.FileName = Path.Combine(solution.Directory, "LinkedFiles\\Fob\\AddExistingInProjectDirButNotInProject" + projectType.CodeExtension); addExistingDlg.AddLink(); } var addExistingInProjectDirButNotInProject = solution.WaitForItem("LinkedFiles", "Fob", "AddExistingInProjectDirButNotInProject" + projectType.CodeExtension); Assert.IsNotNull(addExistingInProjectDirButNotInProject, "addExistingInProjectDirButNotInProject"); } } }
public void AddExistingItemAndFileByNameExistsInProjectButNotOnDisk() { foreach (var projectType in ProjectTypes) { using (var solution = LinkedFiles(projectType).Generate().ToVs()) { var projectNode = solution.FindItem("LinkedFiles", "FolderWithAFile"); Assert.IsNotNull(projectNode, "projectNode"); AutomationWrapper.Select(projectNode); using (var addExistingDlg = AddExistingItemDialog.FromDte(solution.App)) { addExistingDlg.FileName = Path.Combine(solution.Directory, "ExistsInProjectButNotOnDisk" + projectType.CodeExtension); addExistingDlg.AddLink(); } solution.App.WaitForDialog(); VisualStudioApp.CheckMessageBox(MessageBoxButton.Ok, "There is already a file of the same name in this folder."); } } }
public void AddExistingItemAndLinkAlreadyExists() { foreach (var projectType in ProjectTypes) { using (var solution = LinkedFiles(projectType).Generate().ToVs()) { var projectNode = solution.FindItem("LinkedFiles", "Oar"); Assert.IsNotNull(projectNode, "projectNode"); AutomationWrapper.Select(projectNode); using (var addExistingDlg = AddExistingItemDialog.FromDte(solution.App)) { addExistingDlg.FileName = Path.Combine(solution.Directory, "LinkedFilesDir\\SomeLinkedFile" + projectType.CodeExtension); addExistingDlg.AddLink(); } solution.App.WaitForDialog(); VisualStudioApp.CheckMessageBox(MessageBoxButton.Ok, "There is already a link to", "SomeLinkedFile" + projectType.CodeExtension); } } }
public void AddExistingItem() { foreach (var projectType in ProjectTypes) { using (var solution = LinkedFiles(projectType).Generate().ToVs()) { var projectNode = solution.FindItem("LinkedFiles", "FolderWithAFile"); Assert.IsNotNull(projectNode, "projectNode"); AutomationWrapper.Select(projectNode); using (var addExistingDlg = AddExistingItemDialog.FromDte(solution.App)) { addExistingDlg.FileName = Path.Combine(solution.Directory, "ExistingItem" + projectType.CodeExtension); addExistingDlg.AddLink(); } var existingItem = solution.WaitForItem("LinkedFiles", "FolderWithAFile", "ExistingItem" + projectType.CodeExtension); Assert.IsNotNull(existingItem, "existingItem"); } } }
public void TestLinkedWithProjectHome() { foreach (var projectType in ProjectTypes) { using (var solution = MultiProjectLinkedFiles(projectType).ToVs()) { var project = solution.Project; // save the project to an odd location. This will result in project home being set. var newProjName = "TempFile"; try { project.SaveAs(Path.GetTempPath() + newProjName + projectType.ProjectExtension); } catch (UnauthorizedAccessException) { Assert.Inconclusive("Couldn't save the file"); } // create a temporary file and add a link to it in the project solution.FindItem(newProjName).Select(); var tempFile = Path.GetTempFileName(); using (var addExistingDlg = AddExistingItemDialog.FromDte(solution.App)) { addExistingDlg.FileName = tempFile; addExistingDlg.AddLink(); } // Save the project to commit that link to the project file project.Save(); // verify that the project file contains the correct text for Link var fileText = File.ReadAllText(project.FullName); var pattern = string.Format( @"<Content Include=""{0}"">\s*<Link>{1}</Link>\s*</Content>", Regex.Escape(tempFile), Regex.Escape(Path.GetFileName(tempFile))); AssertUtil.AreEqual(new Regex(pattern), fileText); } } }