Exemplo n.º 1
0
        public void TestRenameOfNestedProject()
        {
            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);

                IVsHierarchy nestedProjectHierarchy = Utilities.GetNestedHierarchy(project, "ANestedProject");

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

                // Get the id
                NestedProjectNode nestedProjectNode = Utilities.GetNodesOfType <NestedProjectNode>(project)[0];

                project.SetProperty(nestedProjectNode.ID, (int)__VSHPROPID.VSHPROPID_EditLabel, "NewProject");

                this.VerifyNestedProjectRename(project, nestedProjectNode, nestedProjectHierarchy, "NewProject");

                // Now do an indirect rename through the property window.
                object extensibility;
                ErrorHandler.ThrowOnFailure(nestedProjectHierarchy.GetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ExtObject, out extensibility));
                EnvDTE.Project nestedAutomationProject = extensibility as EnvDTE.Project;

                EnvDTE.Property fileNameProperty = nestedAutomationProject.Properties.Item("FileName");
                fileNameProperty.Value           = "Project";
                this.VerifyNestedProjectRename(project, nestedProjectNode, nestedProjectHierarchy, "Project");
            });
        }
Exemplo n.º 2
0
        public void TestSingleFileGeneratorOnNodes()
        {
            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);

                MethodInfo mi = typeof(FileNode).GetMethod("CreateSingleFileGenerator", BindingFlags.Instance | BindingFlags.NonPublic);

                List <FileNode> nodes = Utilities.GetNodesOfType <FileNode>(project);
                foreach (FileNode node in nodes)
                {
                    ISingleFileGenerator generator = mi.Invoke(node, new object[] { }) as ISingleFileGenerator;
                    string extension = Path.GetExtension(node.GetMkDocument());
                    if (String.Compare(extension, ".moxl", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        Assert.IsNull(generator, "There should be no single file generators defined for a moxl file");
                        Assert.IsFalse(node.NodeProperties is SingleFileGeneratorNodeProperties, "If no generators are supported then the properties should not be of type SingleFileGeneratorNodeProperties");
                    }
                    else if (String.Compare(extension, ".cs", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        Assert.IsNotNull(generator, "There should be a single file generator defined for a cs file");
                        Assert.IsTrue(node.NodeProperties is SingleFileGeneratorNodeProperties, "The properties for a node supporting single file generators should be of type SingleFileGeneratorNodeProperties");
                    }
                }
            });
        }
Exemplo n.º 3
0
 /// <summary>
 /// Find the first instance of a filenode with a given caption
 /// </summary>
 /// <param name="caption"></param>
 /// <returns></returns>
 private FileNode FindFileNode(ProjectNode project, string caption)
 {
     foreach (FileNode n in Utilities.GetNodesOfType <FileNode>(project))
     {
         if (string.Compare(n.Caption, caption, true) == 0)
         {
             return(n);
         }
     }
     return(null);
 }
Exemplo n.º 4
0
        private FileNode GetFirstFileNode(ProjectNode project)
        {
            List <FileNode> nodes = Utilities.GetNodesOfType <FileNode>(project);

            foreach (FileNode node in nodes)
            {
                if (String.Compare(Path.GetExtension(node.GetMkDocument()), ".cs", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    return(node);
                }
            }

            return(null);
        }
Exemplo 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");
            });
        }