public void TestSaveAsDifferentLocation() { UIThreadInvoker.Invoke((ThreadInvoker) delegate() { //Get the global service provider and the dte IServiceProvider sp = VsIdeTestHostContext.ServiceProvider; DTE dte = (DTE)sp.GetService(typeof(DTE)); //Create a project and get the first filenode string destination = Path.Combine(TestContext.TestDir, TestContext.TestName); ProjectNode project = Utilities.CreateMyNestedProject(sp, dte, TestContext.TestName, destination, true); FileNode fileNode = GetFirstFileNode(project); //Create folder string folderPath = Path.Combine(project.ProjectFolder, "Test"); Assert.IsFalse(File.Exists(folderPath)); FolderNode folderNode = Utilities.CreateFolder(project, folderPath, project); //Add new item in folder string newFileName = TestUtils.GetNewFileName(folderNode.GetMkDocument(), "test", "cs"); ProjectItem item = ((OAFolderItem)folderNode.GetAutomationObject()).ProjectItems.AddFromFile(newFileName); Assert.IsNotNull(item, "Could not get the project item for the file just added"); //open the item before we can do the SaveAs op Window window = item.Open(EnvDTE.Constants.vsViewKindPrimary); Assert.IsNotNull(window, "Did not get a reference to the window for the file just opened"); if (!window.Visible) { window.Visible = true; } //SaveAs into project folder string updatedFileName = Path.Combine(project.ProjectFolder, item.Name); Trace.WriteLine(updatedFileName); item.SaveAs(updatedFileName); //Verify Caption of open file Assert.IsTrue(string.Compare(window.Caption, item.Name, true) == 0, "Caption of window does not match the new filename"); //Verify full path to document Assert.IsTrue(string.Compare(window.Document.FullName, updatedFileName, true) == 0, "FullName of document is not as expected"); }); }
public void TestSaveAsInExistingSubFolder() { UIThreadInvoker.Invoke((ThreadInvoker) delegate() { //Get the global service provider and the dte IServiceProvider sp = VsIdeTestHostContext.ServiceProvider; DTE dte = (DTE)sp.GetService(typeof(DTE)); //Create a project and get the first filenode string destination = Path.Combine(TestContext.TestDir, TestContext.TestName); ProjectNode project = Utilities.CreateMyNestedProject(sp, dte, TestContext.TestName, destination, true); FileNode fileNode = GetFirstFileNode(project); //open the item before we can do the SaveAs op ProjectItem item = ((OAFileItem)fileNode.GetAutomationObject()); Window window = item.Open(EnvDTE.Constants.vsViewKindPrimary); Assert.IsNotNull(window, "Did not get a reference to the window for the file just opened"); if (!window.Visible) { window.Visible = true; } //Create new subfolder string newFolderName = "NewFolder1"; FolderNode folderNode = (FolderNode)Utilities.CreateFolder(project, newFolderName, project); Assert.IsNotNull(folderNode, "Could note create new folder node"); //SaveAs to SubFolder string newNameOfFile = "Test.cs"; string relPathToFile = newFolderName + "\\" + "Test.cs"; string updatedFileName = Path.Combine(project.ProjectFolder, relPathToFile); item.SaveAs(updatedFileName); //Verify Caption in window of the file renamed Assert.IsTrue(string.Compare(window.Caption, newNameOfFile, true) == 0, "Caption of window does not match the new filename"); //Verify full path to document Assert.IsTrue(string.Compare(window.Document.FullName, updatedFileName, true) == 0, "FullName of document is not as expected"); }); }