Esempio n. 1
0
        public void TestRenameOfRenamedProjectFile()
        {
            UIThreadInvoker.Invoke((ThreadInvoker) delegate()
            {
                //Get the global service provider and the dte
                IServiceProvider sp = VsIdeTestHostContext.ServiceProvider;
                DTE dte             = (DTE)sp.GetService(typeof(DTE));

                string destination  = Path.Combine(TestContext.TestDir, TestContext.TestName);
                ProjectNode project = Utilities.CreateMyNestedProject(sp, dte, TestContext.TestName, destination, true);

                string projectName    = project.GetMkDocument();
                string newprojectName = Path.Combine(project.ProjectFolder, Path.GetFileNameWithoutExtension(projectName) + "_temp");

                // Rename the project file on disk
                File.Move(projectName, newprojectName);

                // Now rename it within the solution explorer. This will popup the dialog box that the file cannot be renamed.
                // We are going to catch that dialog box.
                string resourceText = Utilities.GetResourceStringFromTheProjectAssembly("FileOrFolderCannotBeFound");

                string message = String.Format(System.Globalization.CultureInfo.CurrentCulture, resourceText, project.ProjectFile);

                Assert.IsTrue(Utilities.CheckForSetEditLabelBadFileName <InvalidOperationException>(project, "NewFileName", message), "The messagebox for not being able to rename a file that has been deleted has never popped up");
            });
        }
Esempio n. 2
0
        private void BadFileNameChecks(EnvDTE.Project automation, bool forSave)
        {
            string errorMessage = Utilities.GetResourceStringFromTheProjectAssembly("ErrorInvalidFileName");

            foreach (string newBadFileName in Utilities.BadFileNames)
            {
                Assert.IsTrue(this.CheckForSaveWithBadFileName <InvalidOperationException>(automation, forSave, newBadFileName, errorMessage), "The file named " + newBadFileName + " could be saved");
            }
            string badFileName = "....nestedProj";

            Assert.IsTrue(this.CheckForSaveWithBadFileName <InvalidOperationException>(automation, forSave, badFileName, errorMessage), "The file named " + badFileName + " could be saved");

            badFileName = "  ";
            Assert.IsTrue(this.CheckForSaveWithBadFileName <InvalidOperationException>(automation, forSave, badFileName, errorMessage), "The file named " + badFileName + " could be saved");

            badFileName = ".....";
            Assert.IsTrue(this.CheckForSaveWithBadFileName <InvalidOperationException>(automation, forSave, badFileName, errorMessage), "The file named " + badFileName + " could be saved");

            errorMessage = String.Format(System.Globalization.CultureInfo.CurrentCulture, Utilities.GetResourceStringFromTheProjectAssembly("PathTooLong"), Path.Combine(Path.GetDirectoryName(automation.FullName), Utilities.LongFileName));
            Assert.IsTrue(this.CheckForSaveWithBadFileName <InvalidOperationException>(automation, forSave, Utilities.LongFileName, errorMessage), "The file named " + Utilities.LongFileName + " could be saved");
        }
Esempio n. 3
0
        private void TestBadFileNameForSetEditLabel(ProjectNode project)
        {
            string errorMessage = Utilities.GetResourceStringFromTheProjectAssembly("ErrorInvalidFileName");

            foreach (string newBadFileName in Utilities.BadFileNames)
            {
                Assert.IsTrue(Utilities.CheckForSetEditLabelBadFileName <InvalidOperationException>(project, newBadFileName, errorMessage), "The file named " + newBadFileName + " could be saved as");
            }

            string badFileName = "  ";

            Assert.IsTrue(Utilities.CheckForSetEditLabelBadFileName <InvalidOperationException>(project, badFileName, errorMessage), "The file named " + badFileName + " could be saved as");

            badFileName = "..\\" + project.ProjectFile;
            Assert.IsTrue(Utilities.CheckForSetEditLabelBadFileName <InvalidOperationException>(project, badFileName, errorMessage), "The file named " + badFileName + " could be saved as");

            badFileName = "....";
            Assert.IsTrue(Utilities.CheckForSetEditLabelBadFileName <InvalidOperationException>(project, badFileName, errorMessage), "The file named " + badFileName + " could be saved as");

            errorMessage = String.Format(System.Globalization.CultureInfo.CurrentCulture, Utilities.GetResourceStringFromTheProjectAssembly("PathTooLong"), Utilities.LongFileName);
            Assert.IsTrue(Utilities.CheckForSetEditLabelBadFileName <InvalidOperationException>(project, Utilities.LongFileName, errorMessage), "The file named " + Utilities.LongFileName + " could be saved");
        }
Esempio n. 4
0
        private void TestBadFileNameForSaveAs(IServiceProvider sp, ProjectNode project, MethodInfo saveAs)
        {
            string errorMessage = String.Format(System.Globalization.CultureInfo.CurrentCulture, Utilities.GetResourceStringFromTheProjectAssembly("PathTooLong"), Utilities.LongFileName);

            Assert.IsTrue(this.CheckForSaveAsOnBadFileName <InvalidOperationException>(sp, project, saveAs, Utilities.LongFileName, errorMessage), "The file named " + Utilities.LongFileName + " could be saved");

            string badFileName = "....";

            errorMessage = Utilities.GetResourceStringFromTheProjectAssembly("FileNameCannotContainALeadingPeriod");
            Assert.IsTrue(this.CheckForSaveAsOnBadFileName <InvalidOperationException>(sp, project, saveAs, badFileName, errorMessage), "The file named " + badFileName + " could be saved as");

            badFileName  = "..\\" + project.ProjectFile;
            errorMessage = String.Format("The project file can only be saved into the project location '{0}'.", project.ProjectFolder);
            Assert.IsTrue(this.CheckForSaveAsOnBadFileName <InvalidOperationException>(sp, project, saveAs, badFileName, errorMessage), "The file named " + badFileName + " could be saved as");

            errorMessage = Utilities.GetResourceStringFromTheProjectAssembly("ErrorInvalidFileName");

            foreach (string newBadFileName in Utilities.BadFileNames)
            {
                Assert.IsTrue(this.CheckForSaveAsOnBadFileName <InvalidOperationException>(sp, project, saveAs, newBadFileName, errorMessage), "The file named " + newBadFileName + " could be saved as");
            }
        }
Esempio n. 5
0
        public void TestRenameWithBadFileName()
        {
            UIThreadInvoker.Invoke((ThreadInvoker) delegate()
            {
                //Get the global service provider and the dte
                IServiceProvider sp = VsIdeTestHostContext.ServiceProvider;
                DTE dte             = (DTE)sp.GetService(typeof(DTE));

                string destination  = Path.Combine(TestContext.TestDir, TestContext.TestName);
                ProjectNode project = Utilities.CreateMyNestedProject(sp, dte, TestContext.TestName, destination, true);

                FileNode fileNode     = null;
                List <FileNode> nodes = Utilities.GetNodesOfType <FileNode>(project);

                if (nodes.Count > 0)
                {
                    fileNode = nodes[0];
                }

                string errorMessage = Utilities.GetResourceStringFromTheProjectAssembly("ErrorInvalidFileName");

                foreach (string newBadFileName in Utilities.BadFileNames)
                {
                    Assert.IsTrue(Utilities.CheckForSetEditLabelBadFileName <InvalidOperationException>(fileNode, newBadFileName, errorMessage), "The file named " + newBadFileName + " could be saved as");
                }

                string badFileName = "  ";
                Assert.IsTrue(Utilities.CheckForSetEditLabelBadFileName <InvalidOperationException>(fileNode, badFileName, errorMessage), "The file named " + badFileName + " could be saved as");

                badFileName = "..\\" + fileNode.FileName;
                Assert.IsTrue(Utilities.CheckForSetEditLabelBadFileName <InvalidOperationException>(fileNode, badFileName, errorMessage), "The file named " + badFileName + " could be saved as");

                badFileName = "....";
                Assert.IsTrue(Utilities.CheckForSetEditLabelBadFileName <InvalidOperationException>(fileNode, badFileName, errorMessage), "The file named " + badFileName + " could be saved as");

                errorMessage = String.Format(System.Globalization.CultureInfo.CurrentCulture, Utilities.GetResourceStringFromTheProjectAssembly("PathTooLong"), Utilities.LongFileName);
                Assert.IsTrue(Utilities.CheckForSetEditLabelBadFileName <InvalidOperationException>(fileNode, Utilities.LongFileName, errorMessage), "The file named " + Utilities.LongFileName + " could be saved");
            });
        }
Esempio n. 6
0
        private void TestImplicitNestedProjectReload(IServiceProvider sp, ProjectNode project, int dialogAnswer)
        {
            // Save everything.
            IVsSolution solutionService = (IVsSolution)sp.GetService(typeof(IVsSolution));

            solutionService.SaveSolutionElement((uint)__VSSLNSAVEOPTIONS.SLNSAVEOPT_SaveIfDirty, project, 0);

            IVsProject3 nestedProject = Utilities.GetNestedHierarchy(project, "ANestedProject") as IVsProject3;

            if (nestedProject == null)
            {
                throw new InvalidOperationException("The nested project has not been loaded corectly");
            }

            string nestedProjectFileName = null;

            nestedProject.GetMkDocument(VSConstants.VSITEMID_ROOT, out nestedProjectFileName);

            if (nestedProjectFileName == null)
            {
                throw new InvalidOperationException("The nested project file name could not been retrieved corectly");
            }

            string resourceText = Utilities.GetResourceStringFromTheProjectAssembly("QueryReloadNestedProject");

            // Create the messageBoxListener Thread. This will bring up the reload of the nested project file.
            // In this scenario we will answer dialogAnswer. Also we rely on the exact messagebox text here.
            string message = String.Format(System.Globalization.CultureInfo.CurrentCulture, resourceText, nestedProjectFileName);

            DialogBoxPurger purger = new DialogBoxPurger(dialogAnswer, message);
            bool            result = false;

            try
            {
                purger.Start();
                this.AddReferenceExternallyToTheProjectFile(nestedProjectFileName);
            }
            finally
            {
                result = purger.WaitForDialogThreadToTerminate();
            }

            if (!result)
            {
                throw new InvalidOperationException("The messagebox for relaoding the nested project file has never popped up");
            }

            // Check to see if the nested project is there.
            EnvDTE.Project     projectDTE = Utilities.GetAutomationObject(project);
            EnvDTE.ProjectItem item       = projectDTE.ProjectItems.Item("ANestedProject");

            Assert.IsNotNull(item, "The nested project has not been loaded correctly.");
            EnvDTE.Project nestedAutomationProject = item.SubProject;

            // Now check to see if we can find the added reference
            VSLangProj.VSProject automationProject = nestedAutomationProject.Object as VSLangProj.VSProject;
            if (nestedAutomationProject == null)
            {
                throw new InvalidOperationException("The nested project is not a vs language project");
            }

            // Get references collection
            VSLangProj.References references = automationProject.References;

            IEnumerator enumerator = references.GetEnumerator();
            bool        found      = false;

            while (enumerator.MoveNext())
            {
                VSLangProj.Reference reference = enumerator.Current as VSLangProj.Reference;
                if (reference.Name == BuildEngineRef)
                {
                    found = true;
                }
            }

            if (dialogAnswer == NativeMethods.IDYES)
            {
                Assert.IsTrue(found, "The nested project file has not been reloaded correctly");
            }
            else
            {
                Assert.IsFalse(found, "The nested project file has been reloaded but was asked not to do that.");
            }
        }