public PackageTestEnvironment() { // Create the project project = new ProjectTestClass(new ProjectTestPackage()); // Site the project services = Microsoft.VsSDK.UnitTestLibrary.OleServiceProvider.CreateOleServiceProviderWithBasicServices(); LocalRegistryMock localRegistry = new LocalRegistryMock(); localRegistry.RegistryRoot = @"Software\Microsoft\VisualStudio\9.0"; services.AddService(typeof(SLocalRegistry), localRegistry, true); BaseMock mockConfiguration = new GenericMockFactory("MockConfiguration", new[] { typeof(Configuration) }).GetInstance(); mockConfiguration.AddMethodReturnValues(string.Format("{0}.{1}", typeof(Configuration).FullName, "ConfigurationName"), new[] { "Debug" }); mockConfiguration.AddMethodReturnValues(string.Format("{0}.{1}", typeof(Configuration).FullName, "PlatformName"), new[] { "AnyCPU" }); BaseMock mockConfigMgr = ConfigurationManagerFactory.GetInstance(); mockConfigMgr.AddMethodReturnValues(string.Format("{0}.{1}", typeof(ConfigurationManager).FullName, ""), new[] { mockConfiguration }); BaseMock extensibility = ExtensibilityFactory.GetInstance(); extensibility.AddMethodReturnValues( string.Format("{0}.{1}", typeof(IVsExtensibility3).FullName, "GetConfigMgr"), new object[] { 0, null, null, mockConfigMgr }); services.AddService(typeof(IVsExtensibility), extensibility, false); project.SetSite(services); // Init the msbuild engine Microsoft.Build.Evaluation.ProjectCollection engine = VisualStudio.Project.Utilities.InitializeMsBuildEngine(null, services); Assert.IsNotNull(engine, "MSBuild Engine could not be initialized"); // Retrieve the project file content, load it and save it string fullpath = Path.Combine(new DirectoryInfo(Assembly.GetExecutingAssembly().Location).Parent.FullName, "TestProject.proj"); if (string.IsNullOrEmpty(projectXml)) { projectXml = Properties.Resources.TestProject; using (TextWriter writer = new StreamWriter(fullpath)) { writer.Write(projectXml); } } // Init the msbuild project Microsoft.Build.Evaluation.Project buildProject = VisualStudio.Project.Utilities.InitializeMsBuildProject(engine, fullpath); Assert.IsNotNull(buildProject, "MSBuild project not initialized correctly in InitializeMsBuildProject"); //Verify that we can set the build project on the projectnode project.BuildProject = buildProject; // Now the project is opened, so we can update its internal variable. if (null == projectOpened) { projectOpened = typeof(VisualStudio.Project.ProjectNode).GetField("projectOpened", BindingFlags.Instance | BindingFlags.NonPublic); } projectOpened.SetValue(project, true); }
public void SetNullSource() { ProjectTestClass project = new ProjectTestClass(); IProjectEventsProvider eventProvider = project as IProjectEventsProvider; Assert.IsNotNull(eventProvider, "Project class does not implements IProjectEventsProvider."); eventProvider.ProjectEventsProvider = null; project.Close(); }
public void SetNullSource() { ProjectTestClass project = new ProjectTestClass(new ProjectTestPackage()); IProjectEventsProvider eventProvider = project as IProjectEventsProvider; Assert.IsNotNull(eventProvider, "Project class does not implements IProjectEventsProvider."); eventProvider.ProjectEventsProvider = null; project.Close(); }
public void SetOpenStatusTest() { using (ProjectEventsSource eventSource = new ProjectEventsSource()) { ProjectTestClass project = new ProjectTestClass(new ProjectTestPackage()); IProjectEventsProvider eventProvider = project as IProjectEventsProvider; Assert.IsNotNull(eventProvider, "Project class does not implements IProjectEventsProvider."); Assert.IsFalse(IsProjectOpened(project), "Project is opened right after its creation."); eventProvider.ProjectEventsProvider = eventSource; eventSource.SignalOpenStatus(true); Assert.IsTrue(IsProjectOpened(project), "Project is not opened after the AfterProjectFileOpened is signaled."); project.Close(); } }
public void SetOpenStatusTest() { using(ProjectEventsSource eventSource = new ProjectEventsSource()) { ProjectTestClass project = new ProjectTestClass(); IProjectEventsProvider eventProvider = project as IProjectEventsProvider; Assert.IsNotNull(eventProvider, "Project class does not implements IProjectEventsProvider."); Assert.IsFalse(IsProjectOpened(project), "Project is opened right after its creation."); eventProvider.ProjectEventsProvider = eventSource; eventSource.SignalOpenStatus(true); Assert.IsTrue(IsProjectOpened(project), "Project is not opened after the AfterProjectFileOpened is signaled."); project.Close(); } }
public void Dispose() { IVsHierarchy hierarchy = project as IVsHierarchy; if (null != hierarchy) { hierarchy.Close(); } project = null; if (null != services) { services.Dispose(); services = null; } }
public void SetMultipleSource() { using(ProjectEventsSource firstSource = new ProjectEventsSource()) { using(ProjectEventsSource secondSource = new ProjectEventsSource()) { ProjectTestClass project = new ProjectTestClass(); IProjectEventsProvider eventProvider = project as IProjectEventsProvider; Assert.IsNotNull(eventProvider, "Project class does not implements IProjectEventsProvider."); eventProvider.ProjectEventsProvider = firstSource; eventProvider.ProjectEventsProvider = secondSource; Assert.IsFalse(IsProjectOpened(project)); firstSource.SignalOpenStatus(true); Assert.IsFalse(IsProjectOpened(project)); secondSource.SignalOpenStatus(true); Assert.IsTrue(IsProjectOpened(project)); project.Close(); } } }
public void SetMultipleSource() { using (ProjectEventsSource firstSource = new ProjectEventsSource()) { using (ProjectEventsSource secondSource = new ProjectEventsSource()) { ProjectTestClass project = new ProjectTestClass(new ProjectTestPackage()); IProjectEventsProvider eventProvider = project as IProjectEventsProvider; Assert.IsNotNull(eventProvider, "Project class does not implements IProjectEventsProvider."); eventProvider.ProjectEventsProvider = firstSource; eventProvider.ProjectEventsProvider = secondSource; Assert.IsFalse(IsProjectOpened(project)); firstSource.SignalOpenStatus(true); Assert.IsFalse(IsProjectOpened(project)); secondSource.SignalOpenStatus(true); Assert.IsTrue(IsProjectOpened(project)); project.Close(); } } }
public void Dispose() { IVsHierarchy hierarchy = project as IVsHierarchy; if(null != hierarchy) { hierarchy.Close(); } project = null; if(null != services) { services.Dispose(); services = null; } }
public PackageTestEnvironment() { // Create the project project = new ProjectTestClass(new ProjectTestPackage()); // Site the project services = Microsoft.VsSDK.UnitTestLibrary.OleServiceProvider.CreateOleServiceProviderWithBasicServices(); LocalRegistryMock localRegistry = new LocalRegistryMock(); localRegistry.RegistryRoot = @"Software\Microsoft\VisualStudio\9.0"; services.AddService(typeof(SLocalRegistry), localRegistry, true); BaseMock mockConfiguration = new GenericMockFactory("MockConfiguration", new[] { typeof(Configuration) }).GetInstance(); mockConfiguration.AddMethodReturnValues(string.Format("{0}.{1}", typeof(Configuration).FullName, "ConfigurationName"), new[] { "Debug" }); mockConfiguration.AddMethodReturnValues(string.Format("{0}.{1}", typeof(Configuration).FullName, "PlatformName"), new[] { "AnyCPU" }); BaseMock mockConfigMgr = ConfigurationManagerFactory.GetInstance(); mockConfigMgr.AddMethodReturnValues(string.Format("{0}.{1}", typeof(ConfigurationManager).FullName, ""), new[] { mockConfiguration }); BaseMock extensibility = ExtensibilityFactory.GetInstance(); extensibility.AddMethodReturnValues( string.Format("{0}.{1}", typeof(IVsExtensibility3).FullName, "GetConfigMgr"), new object[] { 0, null, null, mockConfigMgr }); services.AddService(typeof(IVsExtensibility), extensibility, false); project.SetSite(services); // Init the msbuild engine Microsoft.Build.Evaluation.ProjectCollection engine = VisualStudio.Project.Utilities.InitializeMsBuildEngine(null, services); Assert.IsNotNull(engine, "MSBuild Engine could not be initialized"); // Retrieve the project file content, load it and save it string fullpath = Path.Combine(new DirectoryInfo(Assembly.GetExecutingAssembly().Location).Parent.FullName, "TestProject.proj"); if(string.IsNullOrEmpty(projectXml)) { projectXml = Properties.Resources.TestProject; using(TextWriter writer = new StreamWriter(fullpath)) { writer.Write(projectXml); } } // Init the msbuild project Microsoft.Build.Evaluation.Project buildProject = VisualStudio.Project.Utilities.InitializeMsBuildProject(engine, fullpath); Assert.IsNotNull(buildProject, "MSBuild project not initialized correctly in InitializeMsBuildProject"); //Verify that we can set the build project on the projectnode project.BuildProject = buildProject; // Now the project is opened, so we can update its internal variable. if(null == projectOpened) { projectOpened = typeof(VisualStudio.Project.ProjectNode).GetField("projectOpened", BindingFlags.Instance | BindingFlags.NonPublic); } projectOpened.SetValue(project, true); }