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"); }); }
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); } }); }
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."); } }