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

                FieldInfo fi;
                PropertyInfo pi;
                pi = typeof(ProjectNode).GetProperty("BuildEngine", BindingFlags.Instance | BindingFlags.NonPublic);
                pi.SetValue(project, MSBuild.ProjectCollection.GlobalProjectCollection, new object[] { });
                fi = typeof(ProjectNode).GetField("buildEngine", BindingFlags.Instance | BindingFlags.NonPublic);
                Assert.AreEqual <MSBuild.ProjectCollection>(MSBuild.ProjectCollection.GlobalProjectCollection, fi.GetValue(project) as MSBuild.ProjectCollection);
                project.SetProjectFileDirty(false);

                MSBuild.Project newBuildProject = new MSBuild.Project(MSBuild.ProjectCollection.GlobalProjectCollection);
                newBuildProject.Save(Path.GetTempFileName());
                pi = typeof(ProjectNode).GetProperty("BuildProject", BindingFlags.Instance | BindingFlags.NonPublic);
                pi.SetValue(project, newBuildProject, new object[] { });
                fi = typeof(ProjectNode).GetField("buildProject", BindingFlags.Instance | BindingFlags.NonPublic);
                Assert.AreEqual <MSBuild.Project>(newBuildProject, fi.GetValue(project) as MSBuild.Project);
            });
        }
Exemplo n.º 2
0
        public void TestDeletingAProjectItem()
        {
            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);

                List <uint> filenodeids = Utilities.SelectOrUnselectNodes <FileNode>(project, true);
                Debug.Assert(filenodeids.Count > 0, "There is no file node availabale");
                FileNode node          = project.NodeFromItemId(filenodeids[0]) as FileNode;
                ProjectElement element = node.ItemNode;
                string path            = node.GetMkDocument();
                node.Remove(true);

                //Now see if it is removed from the UI.
                HierarchyNode deletedNode = project.NodeFromItemId(filenodeids[0]);
                Assert.IsTrue(deletedNode == null, "File has not been removed correctly");

                // See if it has been removed from the procject file.
                MethodInfo mi       = typeof(ProjectElement).GetMethod("HasItemBeenDeleted", BindingFlags.Instance | BindingFlags.NonPublic);
                bool hasBeenDeleted = (bool)mi.Invoke(element, new object[] { });
                Assert.IsTrue(hasBeenDeleted, "File has not been removed correctly from the project file.");

                // See if it has been deleted physically
                Assert.IsFalse(File.Exists(path), "File has not been removed correctly from the disk.");
            });
        }
Exemplo n.º 3
0
        public void TestMoreAutomationOnProjectItems()
        {
            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 projectNode = Utilities.CreateMyNestedProject(sp, dte, TestContext.TestName, destination, true);

                EnvDTE.Project project      = projectNode.GetAutomationObject() as EnvDTE.Project;
                EnvDTE80.Solution2 solution = project.DTE.Solution as EnvDTE80.Solution2;
                string templateName         = solution.GetProjectItemTemplate("CodeFile.zip", "CSharp");

                ProjectItem item = project.ProjectItems.AddFromTemplate(templateName, "TestFile.cs");
                this.CheckForItem(projectNode, item);

                // Now add a folder and add an item to the folder.
                ProjectItem folder = project.ProjectItems.AddFolder("Directory", null);
                item = folder.ProjectItems.AddFromTemplate(templateName, "TestFile1.cs");

                this.CheckForItem(projectNode, item);
            });
        }
Exemplo n.º 4
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.º 5
0
        public void TestConfigChange()
        {
            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);

                EnvDTE.Property property = dte.Solution.Properties.Item("ActiveConfig");

                // Now change the active config
                property.Value = "Release|x86";

                // Force a designtime build to make sure the config change has been pushed through to the project
                project.GetProjectOptions();

                MSBuild.Project buildProject = typeof(ProjectNode).GetProperty("BuildProject", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(project, new object[] { }) as MSBuild.Project;
                string activeConfig          = null;
                buildProject.GlobalProperties.TryGetValue(GlobalProperty.Configuration.ToString(), out activeConfig);

                Assert.AreEqual("Release", activeConfig);
            });
        }
Exemplo n.º 6
0
        public void TestAutomationOnProjectProperties()
        {
            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 projectNode = Utilities.CreateMyNestedProject(sp, dte, TestContext.TestName, destination, true);

                //get the automation model of the project
                EnvDTE.Project project = projectNode.GetAutomationObject() as EnvDTE.Project;

                //get properties collection
                EnvDTE.Properties projectProperties = project.Properties;
                Assert.IsNotNull(projectProperties, "Could not get an instance of the project properties object");

                //test the FullPath property returns the actual project path + project filename
                string fullPathFromProjectNode = projectNode.ProjectFolder + "\\";
                EnvDTE.Property fullPath       = projectProperties.Item(ProjectAutomationProperyNames.FullPath);
                Assert.IsFalse(String.IsNullOrEmpty(fullPath.Value.ToString()), "FullPath property is null or has not been assigned any value");
                Assert.IsTrue(0 == String.Compare(fullPath.Value.ToString(), fullPathFromProjectNode, true), "FullPath property does not return the correct Value");
            });
        }
Exemplo n.º 7
0
        public void TestReferenceNodeRelatedItemProperties()
        {
            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 projectNode = Utilities.CreateMyNestedProject(sp, dte, TestContext.TestName, destination, true);

                // get the project object
                EnvDTE.Project project = projectNode.GetAutomationObject() as EnvDTE.Project;

                //get the projectitem object of the first reference object
                string referenceName    = "System";
                ProjectItem projectItem = project.ProjectItems.Item("References").ProjectItems.Item(referenceName);
                Assert.IsNotNull(projectItem, "Could not retrieve the projectitem object from the collection of references");

                //get properties collection
                EnvDTE.Properties properties = projectItem.Properties;
                Assert.IsNotNull(properties, "Could not get an instance of the projectitem properties object");

                CompareProperties(properties, typeof(ReferenceNodeAutomationPropertyNames));
            });
        }
Exemplo n.º 8
0
        public void TestNodeProperties()
        {
            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 newFileName       = TestUtils.GetNewFileName(project.ProjectFolder, "test", "cs");
                ProjectElement item      = project.CreateMsBuildFileItem(newFileName, "Content");
                FileNode node            = project.CreateFileNode(item);
                FileNodeProperties props = node.NodeProperties as FileNodeProperties;
                Assert.IsNotNull(props);

                // Test the build action.
                Assert.IsTrue(props.BuildAction == BuildAction.Content, "The BuildAction build action should be set to compile model");
                props.BuildAction = BuildAction.Compile;
                Assert.IsTrue(props.BuildAction == BuildAction.Compile, "BuildAction has not been set correctly in the project file");
                props.BuildAction = BuildAction.EmbeddedResource;
                Assert.IsTrue(props.BuildAction == BuildAction.EmbeddedResource, "BuildAction has not been set correctly in the project file");
                props.BuildAction = BuildAction.None;
                Assert.IsTrue(props.BuildAction == BuildAction.None, "BuildAction has not been set correctly in the project file");
            });
        }
Exemplo n.º 9
0
        public void TestFolderNodeRelatedProjectItemProperties()
        {
            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 projectNode = Utilities.CreateMyNestedProject(sp, dte, TestContext.TestName, destination, true);

                // get the project object
                EnvDTE.Project project = projectNode.GetAutomationObject() as EnvDTE.Project;

                // add new folder to the project
                System.Reflection.MethodInfo mi = typeof(HierarchyNode).GetMethod("AddNewFolder", BindingFlags.NonPublic | BindingFlags.Instance);
                mi.Invoke(projectNode, null);

                //Get the new foldernode object
                mi = typeof(ProjectNode).GetMethod("FindChild", BindingFlags.NonPublic | BindingFlags.Instance);
                FolderNode folderNode = (FolderNode)mi.Invoke(projectNode, new object[] { "NewFolder1" });
                Assert.IsNotNull(folderNode, "Could not find a folder node in the projec");

                //get automation object from FolderNode
                ProjectItem projectItem = (ProjectItem)folderNode.GetAutomationObject();

                //get properties collection
                EnvDTE.Properties properties = projectItem.Properties;
                Assert.IsNotNull(properties, "Could not get an instance of the projectitem properties object");

                CompareProperties(properties, typeof(FolderNodeAutomationPropertyNames));
            });
        }
Exemplo n.º 10
0
        public void TestSaveAsSameLocation()
        {
            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;
                }

                //SaveAs
                string newNameOfFile   = "Test.cs";
                string updatedFileName = Path.Combine(project.ProjectFolder, newNameOfFile);
                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");
            });
        }
Exemplo n.º 11
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.º 12
0
        public void TestRenameOfFileNode()
        {
            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);

                // Try to see if case only change succeeds
                string fileNameWithCaseOnlyChange = fileNode.FileName.ToUpper();
                fileNode.SetEditLabel(fileNameWithCaseOnlyChange);
                Assert.IsTrue((String.Compare(fileNode.FileName, fileNameWithCaseOnlyChange, StringComparison.Ordinal) == 0), "SetEditLabel failed since the file comparison test failed");

                string oldUrl       = fileNode.Url;
                string goodFileName = "test.cs";

                fileNode.SetEditLabel(goodFileName);

                Assert.IsTrue(NativeMethods.IsSamePath(fileNode.Url, Path.Combine(project.ProjectFolder, goodFileName)), "SetEditLabel failed since the Url test failed");
                Assert.IsTrue((String.Compare(fileNode.FileName, goodFileName, StringComparison.Ordinal) == 0), "SetEditLabel failed since the file comparison test failed");
            });
        }
Exemplo n.º 13
0
        public void TestGlobalPropertyMatch()
        {
            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);

                Microsoft.Build.BuildEngine.Project buildProject = typeof(ProjectNode).GetProperty("BuildProject", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(project, new object[] { }) as Microsoft.Build.BuildEngine.Project;
                IVsHierarchy nestedProject = Utilities.GetNestedHierarchy(project, "ANestedProject");

                IVsBuildPropertyStorage nestedProjectPropertyStorage = nestedProject as IVsBuildPropertyStorage;
                foreach (string property in Enum.GetNames(typeof(GlobalProperty)))
                {
                    string nestedProjectGlobalProperty;

                    // We will pass in the debug configuration since the GetPropertyValue will change the global property to whatever does not exist as configuration like empty or null.
                    nestedProjectPropertyStorage.GetPropertyValue(property, "Debug", (uint)_PersistStorageType.PST_PROJECT_FILE, out nestedProjectGlobalProperty);

                    string parentProjectGlobalProperty = buildProject.GlobalProperties[property].Value;

                    bool result;
                    bool isBoolean = (Boolean.TryParse(parentProjectGlobalProperty, out result) == true);
                    Assert.IsTrue(String.Compare(nestedProjectGlobalProperty, parentProjectGlobalProperty, isBoolean ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal) == 0, "The following global Properties do not match for Property: " + property + " Nested :" + nestedProjectGlobalProperty + " Parent:" + parentProjectGlobalProperty);
                }
            });
        }
Exemplo n.º 14
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");
            });
        }
Exemplo n.º 15
0
        //[TestMethod()]
        // This test is failing because of a bug in VS 2008 RTM.
        //TODO: Enable after VS 2008 SP1
        public void TestAutomationOnConfigDependentProperties()
        {
            const int expectedConfigs = 2;

            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 projectNode = Utilities.CreateMyNestedProject(sp, dte, TestContext.TestName, destination, true);

                // get the config object for active configuration
                EnvDTE.Project project             = projectNode.GetAutomationObject() as EnvDTE.Project;
                ConfigurationManager configManager = project.ConfigurationManager;
                Assert.IsNotNull(configManager, "Could not get configutation Manager object from project object");
                Assert.AreEqual(configManager.Count, expectedConfigs, "Wrong number of configs");
                Configuration activeConfig = configManager.ActiveConfiguration;
                Assert.IsNotNull(activeConfig, "Could not get active configuration");

                //get properties collection
                EnvDTE.Properties properties = activeConfig.Properties;
                Assert.IsNotNull(properties, "Could not get an instance of the properties object from active configuration");

                CompareProperties(properties, typeof(ProjectConfigPropertyNames));
            });
        }
Exemplo n.º 16
0
        public void TestDoDefaultActionOnFileNode()
        {
            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);

                MethodInfo doDefaultAction = typeof(ProjectNode).GetMethod("DoDefaultAction", BindingFlags.NonPublic | BindingFlags.Instance);

                // select the model file, close it and then do deafult action on it. test whether it has opened it.
                List <uint> filenodeids = Utilities.SelectOrUnselectNodes <FileNode>(project, true);

                foreach (uint id in filenodeids)
                {
                    FileNode node = project.NodeFromItemId(id) as FileNode;
                    Assert.IsNotNull(node);
                    string document = node.GetMkDocument();

                    if (String.Compare(Path.GetExtension(document), ".cs", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        VsShellUtilities.SaveFileIfDirty(project.Site, document);

                        MethodInfo getDocumentManager = typeof(FileNode).GetMethod("GetDocumentManager", BindingFlags.NonPublic | BindingFlags.Instance);
                        DocumentManager manager       = getDocumentManager.Invoke(node, new object[] { }) as DocumentManager;

                        // Close the node.
                        Assert.IsTrue(manager.Close(__FRAMECLOSE.FRAMECLOSE_SaveIfDirty) == VSConstants.S_OK);

                        // Be sure the node is selected.
                        Utilities.ManipulateNode(project, node.ID, EXPANDFLAGS.EXPF_SelectItem);

                        // Invoke opening of the node.
                        doDefaultAction.Invoke(node, new object[] { });

                        // Check whether the document has been opened.
                        Guid logicalView = Guid.Empty;
                        IVsUIHierarchy hierOpen;
                        uint itemId;
                        IVsWindowFrame windowFrame;
                        Assert.IsTrue(VsShellUtilities.IsDocumentOpen(node.ProjectMgr.Site, document, logicalView, out hierOpen, out itemId, out windowFrame), "DoDeafult action did not open the file");
                        Assert.IsTrue(itemId == node.ID, "We did not open the correct document");
                        Assert.IsNotNull(windowFrame, "Do deafult action did not retun a window frame");
                        Assert.IsTrue(windowFrame.IsVisible() == VSConstants.S_OK, "Do deafult action did not show a window frame");
                    }
                }
            });
        }
Exemplo n.º 17
0
        public void TestBuild()
        {
            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);

                Assert.IsTrue(project.Build("Build") == MSBuildResult.Successful);
            });
        }
Exemplo n.º 18
0
        public void TestHasProjectOpened()
        {
            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);

                bool hasProjectOpened = project.HasProjectOpened;
                Assert.IsTrue(hasProjectOpened, "The event listener for opening the project has failed");
            });
        }
Exemplo n.º 19
0
        public void TestHasProjectOpened()
        {
            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);

                PropertyInfo pi       = typeof(ProjectNode).GetProperty("HasProjectOpened", BindingFlags.Instance | BindingFlags.NonPublic);
                bool hasProjectOpened = (bool)pi.GetValue(project, new object[] { });
                Assert.IsTrue(hasProjectOpened, "The event listener for opening the project has failed");
            });
        }
Exemplo n.º 20
0
        public void TestGetAutomationObject()
        {
            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);

                object retValue = project.GetAutomationObject();

                Assert.IsNotNull(retValue);
            });
        }
Exemplo n.º 21
0
        public void TestCreatingFileNode()
        {
            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 newFileName  = TestUtils.GetNewFileName(project.ProjectFolder, "test", "cs");
                ProjectElement item = project.CreateMsBuildFileItem(newFileName, "Compile");
                FileNode node       = project.CreateFileNode(item);
                Assert.IsNotNull(node);
            });
        }
Exemplo n.º 22
0
        public void TestProjectCreationWithDTE()
        {
            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);

                // test nested project item
                EnvDTE.ProjectItem nestedProject = ((OAProject)project.GetAutomationObject()).ProjectItems.Item("ANestedProject");

                Assert.IsNotNull(nestedProject, "Failed to retrieve nested projects");

                Assert.IsNotNull(nestedProject.SubProject, "Failed to retrieve nested projects's subproject");

                // Add a cs file to the nested project.
                string newFileName = Path.GetFullPath(TestUtils.GetNewFileName(project.ProjectFolder, "GetClassWithCodeModel", "cs"));

                EnvDTE.ProjectItem newFile = nestedProject.SubProject.ProjectItems.AddFromFile(newFileName);
                CodeModel codeModel        = nestedProject.SubProject.CodeModel;
                Assert.IsNotNull(codeModel, "Failed to retrieve nested projects's subproject");

                FileCodeModel fileCodeModel = newFile.FileCodeModel;

                CodeClass cc = fileCodeModel.AddClass("MyClass", 0, null, null, vsCMAccess.vsCMAccessPublic);

                IEnumerator enumerator = fileCodeModel.CodeElements.GetEnumerator();

                bool found = false;
                while (enumerator.MoveNext())
                {
                    CodeElement element = enumerator.Current as CodeElement;

                    if (element.Name == "MyClass")
                    {
                        found = true;
                        break;
                    }
                }

                Assert.IsTrue(found, "Could not find the class in the code model associated to the nested project");
            });
        }
Exemplo n.º 23
0
        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");
            });
        }
Exemplo n.º 24
0
        public void TestProjectCreationInSolutionExplorer()
        {
            UIThreadInvoker.Invoke((ThreadInvoker) delegate()
            {
                //Get the global service provider and the dte
                IServiceProvider sp = VsIdeTestHostContext.ServiceProvider;
                DTE dte             = (DTE)sp.GetService(typeof(DTE));

                try
                {
                    string destination  = Path.Combine(TestContext.TestDir, TestContext.TestName);
                    ProjectNode project = Utilities.CreateMyNestedProject(sp, dte, TestContext.TestName, destination, true);
                }
                catch (Exception e)
                {
                    Assert.Fail("Failed to retrieve a project. Reason :", e.Message);
                }
            });
        }
Exemplo n.º 25
0
        public void TestUnloadReloadOfProject()
        {
            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);

                Utilities.SelectOrUnselectNodes <ProjectNode>(project, true);

                // Save everything.
                IVsSolution solutionService = (IVsSolution)sp.GetService(typeof(IVsSolution));
                solutionService.SaveSolutionElement((uint)__VSSLNSAVEOPTIONS.SLNSAVEOPT_SaveIfDirty, project.InteropSafeIVsHierarchy, 0);

                // Unload the project
                IVsSolution4 solutionService4 = solutionService as IVsSolution4;
                Assert.IsNotNull(solutionService4, "IVsSolution4 should be implemented!");

                solutionService4.UnloadProject(project.ProjectIDGuid, (uint)_VSProjectUnloadStatus.UNLOADSTATUS_UnloadedByUser);
                Assert.IsTrue(project.IsClosed, "The project has not been unloaded");

                // Reload the project
                solutionService4.ReloadProject(project.ProjectIDGuid);

                // Check to see if the project is reloaded. we cannot use the instance for the project since that is zombied at this point.
                IVsHierarchy ourHierarchy;
                string projectFullpath = project.GetMkDocument();
                solutionService.GetProjectOfUniqueName(projectFullpath, out ourHierarchy);
                Assert.IsTrue(ourHierarchy is IProjectEventsListener, "Our hierarchy has not been reloaded successfully");

                // Check to see if the nested project is there.
                EnvDTE.Project projectDTE = Utilities.GetAutomationObject(ourHierarchy);
                Assert.IsNotNull(projectDTE.ProjectItems.Item("ANestedProject"), "The nested project has not been loaded correctly.");

                // Check that bug 106520 does not happen anymore. We will check that the parent project is not dirty.
                int isDirty;
                ((IPersistFileFormat)ourHierarchy).IsDirty(out isDirty);
                Assert.IsTrue(isDirty == 0, "The parent project is dirtied after it has been reloaded");
            });
        }
Exemplo n.º 26
0
        public void TestRenameOfProjectFile()
        {
            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 extension = Path.GetExtension(project.ProjectFile);
                #region test for bad filenames
                this.TestBadFileNameForSetEditLabel(project);
                #endregion

                string oldUrl       = project.Url;
                string goodFileName = "test";

                project.SetEditLabel(goodFileName);
                Assert.IsTrue(NativeMethods.IsSamePath(project.Url, Path.Combine(project.ProjectFolder, goodFileName + ".nestedProj")), "SetEditLabel failed since the Url test failed");

                Assert.IsTrue((String.Compare(project.ProjectFile, "test" + extension, StringComparison.Ordinal) == 0), "SetEditLabel failed since the file comparison test failed. Expected that " + project.ProjectFile + " equals test.nestedProj");

                // Now do a case only change
                project.SetEditLabel("Test");
                Assert.IsTrue((String.Compare(project.ProjectFile, "Test" + extension, StringComparison.Ordinal) == 0), "SetEditLabel failed since the file comparison test failed. Expected that " + project.ProjectFile + " equals Test.nestedProj");


                this.TestFileNameThatHasToPassForSetEditLabel(project);

                // Now close the project and reopen with the renamed file.
                string projectFullPath      = project.Url;
                IVsSolution solutionService = (IVsSolution)sp.GetService(typeof(IVsSolution));
                // Close already open solution
                solutionService.CloseSolutionElement((uint)__VSSLNSAVEOPTIONS.SLNSAVEOPT_SaveIfDirty, null, 0);

                EnvDTE.Project newProject = dte.Solution.AddFromFile(projectFullPath, true);

                Assert.IsTrue(newProject != null, "failed to load the renamed project");
            });
        }
Exemplo n.º 27
0
        public void TestLoadingOfProjectWithDuplicateItems()
        {
            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 path = project.GetMkDocument();

                // It would be nice if we could just copy the embedded resource to the opened project file, but implicit reload of nested projects crashes on non SP1 versions.
                // For now we are going to close the project and reopen it with the embedded project.
                IVsSolution solutionService = (IVsSolution)sp.GetService(typeof(IVsSolution));

                solutionService.CloseSolutionElement((uint)__VSSLNSAVEOPTIONS.SLNSAVEOPT_ForceSave, project, 0);

                TestUtils.WriteEmbeddedResourceToBinaryFile(typeof(TestProject).Assembly, EmbeddedResourceProjectLocation, path);

                IntPtr projectPtr = IntPtr.Zero;
                Guid guid         = Guid.Empty;
                Guid iid          = new Guid("{00000000-0000-0000-C000-000000000046}");        // IID_IUnknown;

                try
                {
                    ErrorHandler.ThrowOnFailure(solutionService.CreateProject(ref guid, path, null, null, (uint)__VSCREATEPROJFLAGS.CPF_OPENFILE, ref iid, out projectPtr));

                    // Now see that we have only unique items. We do not care much about canonicalization issues in this test.
                    this.CheckForUniqueCaptions(project);
                }
                finally
                {
                    if (projectPtr != IntPtr.Zero)
                    {
                        Marshal.Release(projectPtr);
                    }
                }
            });
        }
Exemplo n.º 28
0
        public void TestUnloadReloadOfProject()
        {
            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);

                Utilities.SelectOrUnselectNodes <ProjectNode>(project, true);

                // Save everything.
                IVsSolution solutionService = (IVsSolution)sp.GetService(typeof(IVsSolution));
                solutionService.SaveSolutionElement((uint)__VSSLNSAVEOPTIONS.SLNSAVEOPT_SaveIfDirty, project, 0);

                string projectFullpath = project.GetMkDocument();
                object customin        = null;
                object customout       = null;
                dte.Commands.Raise(VsMenus.guidStandardCommandSet97.ToString("B"), (int)Microsoft.VisualStudio.VSConstants.VSStd97CmdID.UnloadProject, ref customin, ref customout);
                // Check to see if the project is unloaded
                Assert.IsTrue(project.IsClosed, "The project has not been unloaded");

                dte.Commands.Raise(VsMenus.guidStandardCommandSet97.ToString("B"), (int)Microsoft.VisualStudio.VSConstants.VSStd97CmdID.ReloadProject, ref customin, ref customout);

                // Check to see if the project is reloaded. we cannot use the instance for the project since that is zombied at this point.
                IVsHierarchy ourHierarchy;
                solutionService.GetProjectOfUniqueName(projectFullpath, out ourHierarchy);
                Assert.IsTrue(ourHierarchy is IProjectEventsListener, "Our hierarchy has not been reloaded successfully");

                // Check to see if the nested project is there.
                EnvDTE.Project projectDTE = Utilities.GetAutomationObject(ourHierarchy);
                Assert.IsNotNull(projectDTE.ProjectItems.Item("ANestedProject"), "The nested project has not been loaded correctly.");

                // Check that bug 106520 does not happen anymore. We will check that the parent project is not dirty.
                int isDirty;
                ((IPersistFileFormat)ourHierarchy).IsDirty(out isDirty);
                Assert.IsTrue(isDirty == 0, "The parent project is dirtied after it has been reloaded");
            });
        }
Exemplo n.º 29
0
        public void TestAddChild()
        {
            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 newFileName = "output.txt";

                FileNode node = project.CreateFileNode(newFileName);
                Assert.IsNotNull(node);

                project.AddChild(node);

                Assert.IsTrue(node == project.FindChildByProjectElement(node.ItemNode));
            });
        }
Exemplo n.º 30
0
        public void TestAutomationOnProject()
        {
            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);
                Utilities.CreateMyNestedProject(sp, dte, TestContext.TestName, destination, true);

                EnvDTE.Project automation = Utilities.FindExtObject(sp, Utilities.NestedProjectGuid, TestContext.TestName);

                // Test save and Save As
                #region Save with bad input
                this.BadFileNameChecks(automation, true);
                string badFileName = "AnotherFileNotThesameAsTheProjectFile.nestedProj";
                Assert.IsTrue(this.CheckForSaveWithBadFileName <InvalidOperationException>(automation, true, badFileName, String.Empty), "The file named " + badFileName + " could be saved");
                #endregion

                ProjectNode project = ((OANestedProject)automation).Project;
                automation.Save(project.Url);
                int isDirty;
                project.IsDirty(out isDirty);
                Assert.IsTrue(isDirty == 0, "The project was not saved correctly from automation");

                #region save as bad input
                this.BadFileNameChecks(automation, false);
                badFileName = @"..\..\";
                Assert.IsTrue(this.CheckForSaveWithBadFileName <InvalidOperationException>(automation, true, badFileName, String.Empty), "The file named " + badFileName + " could be saved");
                #endregion

                string goodFileName = "ANewProjectFile.nestedproj";
                automation.SaveAs(goodFileName);
                Assert.IsTrue((String.Compare(project.ProjectFile, goodFileName, StringComparison.OrdinalIgnoreCase) == 0), "Save as failed since the file comparison test failed");

                this.TestFileNamesThatShouldPassForSaveAs(automation);
            });
        }