public void TestOutputNoPane() {
            // Create an instance of the package and initialize it so that the GetService
            // will succeed, but the GetPane will fail.

            // As first create a service provider.
            using(OleServiceProvider serviceProvider = OleServiceProvider.CreateOleServiceProviderWithBasicServices()) {
                // Now create the mock object for the output window.
                if(null == mockOutputWindowFactory) {
                    mockOutputWindowFactory = new GenericMockFactory("MockOutputWindow", new Type[] { typeof(IVsOutputWindow) });
                }
                BaseMock mockBase = mockOutputWindowFactory.GetInstance() as BaseMock;
                mockBase.AddMethodReturnValues(string.Format("{0}.{1}", typeof(IVsOutputWindow).FullName, "GetPane"),
                                               new object[] { -1, Guid.Empty, null });
                // Add the output window to the services provided by the service provider.
                serviceProvider.AddService(typeof(SVsOutputWindow), mockBase, false);

                // Create an instance of the package and initialize it calling SetSite.
                SrcMLServicePackage package = new SrcMLServicePackage();
                int result = ((IVsPackage)package).SetSite(serviceProvider);
                Assert.IsTrue(Microsoft.VisualStudio.ErrorHandler.Succeeded(result), "SetSite failed.");

                // Now we can create an instance of the service
                SetUpSrcMLServiceExtensionDirectory();
                SrcMLGlobalService service = new SrcMLGlobalService(package, extensionDirectory);
                
                service.GlobalServiceFunction();
                                
                ((IVsPackage)package).SetSite(null);
                ((IVsPackage)package).Close();
            }
        }
Beispiel #2
0
        public void SetSite()
        {
            // Create the package
            var package = new PowerToolsCommandsPackage() as IVsPackage;
            Assert.IsNotNull(package, "The object does not implement IVsPackage");

            // Create a basic service provider
            var serviceProvider = OleServiceProvider.CreateOleServiceProviderWithBasicServices();

            var activityLogMock =
                new GenericMockFactory(
                    "MockVsActivityLog",
                    new[] { typeof(Microsoft.VisualStudio.Shell.Interop.IVsActivityLog) }
                    ).GetInstance();

            serviceProvider.AddService(
                typeof(Microsoft.VisualStudio.Shell.Interop.SVsActivityLog),
                activityLogMock,
                true);

            // Site the package
            //Assert.AreEqual(0, package.SetSite(serviceProvider), "SetSite did not return S_OK");

            // Unsite the package
            Assert.AreEqual(0, package.SetSite(null), "SetSite(null) did not return S_OK");
        }
 /// <summary>
 /// Returns a monitor selection object that does not implement any methods
 /// </summary>
 /// <returns></returns>
 internal static BaseMock GetBaseMonSelInstance()
 {
     if (MonSelFactory == null)
         MonSelFactory = new GenericMockFactory("MonitorSelection", new Type[] { typeof(IVsMonitorSelection), typeof (IVsMultiItemSelect) });
     BaseMock pb = MonSelFactory.GetInstance();
     return pb;
 }
 /// <summary>
 /// Returns an IVsShell that does not implement any methods
 /// </summary>
 /// <returns></returns>
 internal static BaseMock GetShellInstance()
 {
     if (ShellFactory == null)
         ShellFactory = new GenericMockFactory("Shell", new Type[] { typeof(IVsShell) });
     BaseMock Shell = ShellFactory.GetInstance();
     return Shell;
 }
 /// <summary>
 /// Return a IVsRegisterScciProvider without any special implementation
 /// </summary>
 /// <returns></returns>
 internal static IVsRegisterScciProvider GetBaseRegisterScciProvider()
 {
     if (registerScciProviderFactory == null)
         registerScciProviderFactory = new GenericMockFactory("RegisterScciProvider", new Type[] { typeof(IVsRegisterScciProvider) });
     IVsRegisterScciProvider registerProvider = (IVsRegisterScciProvider)registerScciProviderFactory.GetInstance();
     return registerProvider;
 }
Beispiel #6
0
 /// <summary>
 /// Return a IVsWindowFrame without any special implementation
 /// </summary>
 /// <returns></returns>
 internal static IVsWindowFrame GetBaseFrame()
 {
     if (frameFactory == null)
         frameFactory = new GenericMockFactory("WindowFrame", new Type[] { typeof(IVsWindowFrame) });
     IVsWindowFrame frame = (IVsWindowFrame)frameFactory.GetInstance();
     return frame;
 }
 /// <summary>
 /// Returns an IVsUiShell that does not implement any methods
 /// </summary>
 /// <returns></returns>
 internal static BaseMock GetUiShellInstance()
 {
     if (uiShellFactory == null)
         uiShellFactory = new GenericMockFactory("UiShell", new Type[] { typeof(IVsUIShell) });
     BaseMock uiShell = uiShellFactory.GetInstance();
     return uiShell;
 }
 /// <summary>
 /// Returns an SVsRegisterEditors service that does not implement any methods
 /// </summary>
 /// <returns></returns>
 internal static BaseMock GetRegisterEditorsInstance()
 {
     if (registerEditorFactory == null)
         registerEditorFactory = new GenericMockFactory("SVsRegisterEditors", new Type[] { typeof(IVsRegisterEditors) });
     BaseMock registerEditor = registerEditorFactory.GetInstance();
     return registerEditor;
 }
 /// <summary>
 /// Returns a property bag that does not implement any methods
 /// </summary>
 /// <returns></returns>
 internal static BaseMock GetPBInstance()
 {
     if (PBFactory == null)
         PBFactory = new GenericMockFactory("PropertyBag", new Type[] { typeof(IPropertyBag) });
     BaseMock pb = PBFactory.GetInstance();
     return pb;
 }
 internal static BaseMock GetILocalRegistryInstance()
 {
     GenericMockFactory factory = new GenericMockFactory("ILocalRegistry", new Type[] { typeof(ILocalRegistry) });
     BaseMock mockObj = factory.GetInstance();
     string name = string.Format("{0}.{1}", typeof(ILocalRegistry).FullName, "CreateInstance");
     mockObj.AddMethodCallback(name, new EventHandler<CallbackArgs>(CreateInstanceCallBack));
     return mockObj;
 }
 internal static BaseMock GetUiShellInstance()
 {
     if (_uiShellFactory == null)
     {
         _uiShellFactory = new GenericMockFactory("UiShell", new[] { typeof(IVsUIShell), typeof(IVsUIShellOpenDocument) });
     }
     var uiShell = _uiShellFactory.GetInstance();
     return uiShell;
 }
 /// <summary>
 /// Returns an IVSUserSettings that does not implement any methods.
 /// </summary>
 /// <returns></returns>
 internal static BaseMock GetUserSettingsFactoryInstance()
 {
     if (userSettingsFactory == null)
     {
         userSettingsFactory = new GenericMockFactory("MockUserSettings", new Type[] { typeof(IVsUserSettings) });
     }
     BaseMock userSettings = userSettingsFactory.GetInstance();
     return userSettings;
 }
 /// <summary>
 /// Returns a SVsSolutionBuildManager that does not implement any methods
 /// </summary>
 /// <returns></returns>
 internal static BaseMock GetSolutionBuildManagerInstance()
 {
     if(solutionBuildManager == null)
     {
         solutionBuildManager = new GenericMockFactory("SolutionBuildManager", new Type[] { typeof(IVsSolutionBuildManager2), typeof(IVsSolutionBuildManager3) });
     }
     BaseMock buildManager = solutionBuildManager.GetInstance();
     return buildManager;
 }
        /// <summary>
        /// Gets an IVsRegisterProject service mock object
        /// </summary>
        /// <returns></returns>
        internal static BaseMock GetRegisterProjectInstance()
        {
            if(null == registerProjectFactory)
            {
                registerProjectFactory = new GenericMockFactory("MockRegisterProject", new Type[] { typeof(IVsRegisterProjectTypes) });
            }
            BaseMock mock = registerProjectFactory.GetInstance();

            return mock;
        }
Beispiel #15
0
        /// <summary>
        /// Return a IVsWindowFrame without any special implementation
        /// </summary>
        internal static IVsWindowFrame GetBaseFrame()
        {
            if (_frameFactory == null)
            {
                _frameFactory = new GenericMockFactory("WindowFrame", new[] { typeof(IVsWindowFrame), typeof(IVsWindowFrame2) });
            }

            var frame = (IVsWindowFrame)_frameFactory.GetInstance();
            return frame;
        }
        /// <summary>
        /// Gets an IVsFileChnageEx service mock object
        /// </summary>
        /// <returns></returns>
        internal static BaseMock GetIVsFileChangeEx()
        {
            if (null == fileChangeEx)
            {
                fileChangeEx = new GenericMockFactory("MockIVsFileChangeEx", new Type[] { typeof(IVsFileChangeEx) });
            }
            BaseMock mock = fileChangeEx.GetInstance();

            return mock;
        }
        internal static BaseMock GetInstance()
        {
            //Create a base mock
            GenericMockFactory factory = new GenericMockFactory("ILocalRegistry3", new Type[] { typeof(ILocalRegistry3) });
            BaseMock mockObj = factory.GetInstance();

            //Add method call back for GetLocalRegistryRoot
            string methodName = string.Format("{0}.{1}", typeof(ILocalRegistry3).FullName, "GetLocalRegistryRoot");
            mockObj.AddMethodCallback(methodName, new EventHandler<CallbackArgs>(GetLocalRegistryRootCallBack));

            return mockObj;
        }
		/// <summary>
		/// Use to create an IOleServiceProvider with the basic services required by
		/// MS.VS.Shell.Package.SetSite() base implementation
		/// </summary>
		/// <returns></returns>
		public static OleServiceProvider CreateOleServiceProviderWithBasicServices()
		{
			// Create the service provider
			OleServiceProvider serviceProvider = new OleServiceProvider();

			// Add IProfferService
			// Create the type only once, then create as many instances as required.
			if (profferServiceFactory == null)
			{
				profferServiceFactory = new GenericMockFactory("MockProfferService", new Type[] { typeof(IProfferService) });
			}
			BaseMock mockObject = profferServiceFactory.GetInstance();
			mockObject.AddMethodCallback(string.Format(CultureInfo.InvariantCulture, "{0}.{1}", typeof(IProfferService).FullName, "ProfferService"),
                                         new EventHandler<CallbackArgs>(ProfferServiceCallback));
			serviceProvider.AddService(typeof(SProfferService), mockObject, false);

			// Add IUIHostLocale
			if (hostLocaleFactory == null)
			{
				hostLocaleFactory = new GenericMockFactory("MockUiHostLocale", new Type[] { typeof(IUIHostLocale), typeof(IUIHostLocale2) });
			}
			mockObject = hostLocaleFactory.GetInstance();
			// Set the return value to 0 (S_OK) and the out parameter to 1033 (enu).
			mockObject.AddMethodReturnValues(string.Format(CultureInfo.InvariantCulture,
                                                      "{0}.{1}",
                                                      typeof(IUIHostLocale).FullName,
                                                      "GetUILocale"), 
                                             new object[] { 0, (uint)1033 });
			serviceProvider.AddService(typeof(SUIHostLocale), mockObject, false);

			// Add IVsResourceManager
			if (resourceManagerFactory == null)
			{
				resourceManagerFactory = new GenericMockFactory("MockResourceManager", new Type[] { typeof(IVsResourceManager) });
			}
			mockObject = resourceManagerFactory.GetInstance();
			mockObject.AddMethodReturnValues(string.Format(CultureInfo.InvariantCulture,
                                                      "{0}.{1}",
                                                      typeof(IVsResourceManager).FullName,
                                                      "LoadResourceString"), 
                                             new object[] { 0, Guid.Empty, 0, null, "Mock Localized String" });
			serviceProvider.AddService(typeof(SVsResourceManager), mockObject, false);

            if(activityLogFactory == null)
            {
                activityLogFactory = new GenericMockFactory("Microsoft.VisualStudio.Shell.Interop.SVsActivityLog", new Type[] { typeof(SVsActivityLog), typeof(IVsActivityLog) });
            }
            BaseMock fakeActivityLog = activityLogFactory.GetInstance();
            serviceProvider.AddService(typeof(SVsActivityLog), fakeActivityLog, false);


            return serviceProvider;
		}
        private void AddMockActivityLogService(OleServiceProvider provider)
        {
            BaseMock activityLogMock =
                new GenericMockFactory(
                    "MockVsActivityLog",
                    new[] { typeof(Microsoft.VisualStudio.Shell.Interop.IVsActivityLog) }
                ).GetInstance();

            provider.AddService(
                typeof(Microsoft.VisualStudio.Shell.Interop.SVsActivityLog),
                activityLogMock,
                true
            );
        }
        /// <summary>
        /// Return an IVsWindowFrame implements GetProperty
        /// The peopertiesList will be used too look up PropertyIDs to find values for
        /// requested properties
        /// </summary>
        /// <param name="propertiesList">The dictionary contains PropertyID/Value pairs</param>
        /// <returns></returns>
        internal static IVsWindowFrame GetFrameWithProperties(Dictionary<int, object> propertiesList)
        {
            if (frameFactory == null)
                frameFactory = new GenericMockFactory("WindowFrame", new Type[] { typeof(IVsWindowFrame), typeof(IVsWindowFrame2) });
            BaseMock frame = (BaseMock)frameFactory.GetInstance();
            frame[propertiesName] = propertiesList;
            // Add support for GetProperty
            string name = string.Format("{0}.{1}", typeof(IVsWindowFrame).FullName, "GetProperty");
            frame.AddMethodCallback(name, new EventHandler<CallbackArgs>(GetPropertiesCallBack));
            // Add support for GetGuidProperty
            name = string.Format("{0}.{1}", typeof(IVsWindowFrame).FullName, "GetGuidProperty");
            frame.AddMethodCallback(name, new EventHandler<CallbackArgs>(GetPropertiesCallBack));

            return (IVsWindowFrame)frame;
        }
        /// <summary>
        /// Gets an IVsQueryEditQuerySave2 mock object which implements QuerySaveFile and QueryEditFiles methods
        /// </summary>
        /// <returns></returns>
        internal static BaseMock GetQueryEditQuerySaveInstance()
        {
            if(null == qeqsFactory)
            {
                qeqsFactory = new GenericMockFactory("QueryEditQuerySave", new Type[] { typeof(IVsQueryEditQuerySave2) });
            }

            BaseMock qeqs = qeqsFactory.GetInstance();

            string name = string.Format("{0}.{1}", typeof(IVsQueryEditQuerySave2).FullName, "QuerySaveFile");
            qeqs.AddMethodCallback(name, new EventHandler<CallbackArgs>(QuerySaveFileCallBack));
            name = string.Format("{0}.{1}", typeof(IVsQueryEditQuerySave2).FullName, "QueryEditFiles");
            qeqs.AddMethodCallback(name, new EventHandler<CallbackArgs>(QueryEditFilesCallBack));
            return qeqs;
        }
        /// <summary>
        /// Gets an IVsLocalRegistry mock object
        /// </summary>
        /// <returns></returns>
        internal static BaseMock GetLocalRegistryInstance()
        {
            if(null == localRegistryFactory)
            {
                localRegistryFactory = new GenericMockFactory("MockLocalRegistry", new Type[] { typeof(ILocalRegistry), typeof(ILocalRegistry3) });
            }
            BaseMock localRegistry = localRegistryFactory.GetInstance();

            string name = string.Format("{0}.{1}", typeof(IVsWindowFrame).FullName, "SetProperty");
            localRegistry.AddMethodReturnValues(name, new object[] { VSConstants.S_OK });

            name = string.Format("{0}.{1}", typeof(ILocalRegistry3).FullName, "GetLocalRegistryRoot");
            localRegistry.AddMethodCallback(name, new EventHandler<CallbackArgs>(GetLocalRegistryRoot));

            return localRegistry;
        }
Beispiel #23
0
        /// <summary>
        /// Use to create an IOleServiceProvider with the basic services required by
        /// MS.VS.Shell.Package.SetSite() base implementation
        /// </summary>
        /// <returns></returns>
        public static OleServiceProvider CreateOleServiceProviderWithBasicServices()
        {
            // Create the service provider
            OleServiceProvider serviceProvider = new OleServiceProvider();

            // Add IProfferService
            // Create the type only once, then create as many instances as required.
            if (profferServiceFactory == null)
            {
                profferServiceFactory = new GenericMockFactory("MockProfferService", new Type[] { typeof(IProfferService) });
            }
            BaseMock mockObject = profferServiceFactory.GetInstance();

            mockObject.AddMethodCallback(string.Format(CultureInfo.InvariantCulture, "{0}.{1}", typeof(IProfferService).FullName, "ProfferService"),
                                         new EventHandler <CallbackArgs>(ProfferServiceCallback));
            serviceProvider.AddService(typeof(SProfferService), mockObject, false);

            // Add IUIHostLocale
            if (hostLocaleFactory == null)
            {
                hostLocaleFactory = new GenericMockFactory("MockUiHostLocale", new Type[] { typeof(IUIHostLocale), typeof(IUIHostLocale2) });
            }
            mockObject = hostLocaleFactory.GetInstance();
            // Set the return value to 0 (S_OK) and the out parameter to 1033 (enu).
            mockObject.AddMethodReturnValues(string.Format(CultureInfo.InvariantCulture,
                                                           "{0}.{1}",
                                                           typeof(IUIHostLocale).FullName,
                                                           "GetUILocale"),
                                             new object[] { 0, (uint)1033 });
            serviceProvider.AddService(typeof(SUIHostLocale), mockObject, false);

            // Add IVsResourceManager
            if (resourceManagerFactory == null)
            {
                resourceManagerFactory = new GenericMockFactory("MockResourceManager", new Type[] { typeof(IVsResourceManager) });
            }
            mockObject = resourceManagerFactory.GetInstance();
            mockObject.AddMethodReturnValues(string.Format(CultureInfo.InvariantCulture,
                                                           "{0}.{1}",
                                                           typeof(IVsResourceManager).FullName,
                                                           "LoadResourceString"),
                                             new object[] { 0, Guid.Empty, 0, null, "Mock Localized String" });
            serviceProvider.AddService(typeof(SVsResourceManager), mockObject, false);

            return(serviceProvider);
        }
        /// <summary>
        /// Given a mock object, this function will add to it a callback function to handle
        /// IConnectionPointContainer.FindConnectionPoint for all the event interfaces contained
        /// in the array passed as parameter.
        /// </summary>
        public static void AddConnectionPointsToContainer(BaseMock mockContainer, Type[] eventInterfaces)
        {
            // Check that the mock object implements IConnectionPointContainer.
            if (null == (mockContainer as IConnectionPointContainer))
            {
                throw new InvalidCastException("Parameter mockContainer does not implement IConnectionPointContainer.");
            }
            // Check if there is any interface in the array.
            if ((null == eventInterfaces) || (eventInterfaces.Length == 0))
            {
                throw new ArgumentNullException("eventIterfaces");
            }
            // Create the Dictionary that will store the connection points.
            Dictionary <Guid, IConnectionPoint> connectionPoints = new Dictionary <Guid, IConnectionPoint>();

            // Get the factory for the connection points.
            if (null == connectionPointFactory)
            {
                connectionPointFactory = new GenericMockFactory("MockLibraryConnectionPoint", new Type[] { typeof(IConnectionPoint) });
            }

            // Create a connection point for every type in the array.
            foreach (Type eventInterface in eventInterfaces)
            {
                BaseMock connectionMock = connectionPointFactory.GetInstance();
                // Set a return value for the Advise method so that the cookie will be not zero.
                connectionMock.AddMethodReturnValues(
                    string.Format(CultureInfo.InvariantCulture, "{0}.{1}", typeof(IConnectionPoint).FullName, "Advise"),
                    new object[] { null, (uint)1 });
                // Add this connection point to the dictionary.
                connectionPoints.Add(eventInterface.GUID, connectionMock as IConnectionPoint);
            }

            // Set the dictionary as member data for the container mock.
            mockContainer[connectionPointsCollection] = connectionPoints;

            // Set the callback for the FindConnectionPoint method.
            mockContainer.AddMethodCallback(
                string.Format(CultureInfo.InvariantCulture, "{0}.{1}", typeof(IConnectionPointContainer).FullName, "FindConnectionPoint"),
                new EventHandler <CallbackArgs>(FindConnectionPointCallback));
        }
        /// <summary>
        /// Given a mock object, this function will add to it a callback function to handle
        /// IConnectionPointContainer.FindConnectionPoint for all the event interfaces contained
        /// in the array passed as parameter.
        /// </summary>
        public static void AddConnectionPointsToContainer(BaseMock mockContainer, Type[] eventInterfaces)
        {
            // Check that the mock object implements IConnectionPointContainer.
            if (null == (mockContainer as IConnectionPointContainer))
            {
                throw new InvalidCastException("Parameter mockContainer does not implement IConnectionPointContainer.");
            }
            // Check if there is any interface in the array.
            if ((null == eventInterfaces) || (eventInterfaces.Length == 0))
            {
                throw new ArgumentNullException("eventIterfaces");
            }
            // Create the Dictionary that will store the connection points.
            Dictionary<Guid, IConnectionPoint> connectionPoints = new Dictionary<Guid, IConnectionPoint>();

            // Get the factory for the connection points.
            if (null == connectionPointFactory)
            {
                connectionPointFactory = new GenericMockFactory("MockLibraryConnectionPoint", new Type[] { typeof(IConnectionPoint) });
            }

            // Create a connection point for every type in the array.
            foreach (Type eventInterface in eventInterfaces)
            {
                BaseMock connectionMock = connectionPointFactory.GetInstance();
                // Set a return value for the Advise method so that the cookie will be not zero.
                connectionMock.AddMethodReturnValues(
                    string.Format(CultureInfo.InvariantCulture, "{0}.{1}", typeof(IConnectionPoint).FullName, "Advise"),
                    new object[] { null, (uint)1 });
                // Add this connection point to the dictionary.
                connectionPoints.Add(eventInterface.GUID, connectionMock as IConnectionPoint);
            }

            // Set the dictionary as member data for the container mock.
            mockContainer[connectionPointsCollection] = connectionPoints;

            // Set the callback for the FindConnectionPoint method.
            mockContainer.AddMethodCallback(
                string.Format(CultureInfo.InvariantCulture, "{0}.{1}", typeof(IConnectionPointContainer).FullName, "FindConnectionPoint"),
                new EventHandler<CallbackArgs>(FindConnectionPointCallback));
        }
        public void TestOutput() {
            callbackExecuted = false;
            // As first create a service provider.
            using(OleServiceProvider serviceProvider = OleServiceProvider.CreateOleServiceProviderWithBasicServices()) {
                // Create a mock object for the output window pane.
                GenericMockFactory mockWindowPaneFactory = new GenericMockFactory("MockOutputWindowPane", new Type[] { typeof(IVsOutputWindowPane) });
                BaseMock mockWindowPane = mockWindowPaneFactory.GetInstance();
                mockWindowPane.AddMethodCallback(string.Format("{0}.{1}", typeof(IVsOutputWindowPane).FullName, "OutputString"),
                                                 new EventHandler<CallbackArgs>(OutputWindowPaneCallback));

                // Now create the mock object for the output window.
                if(null == mockOutputWindowFactory) {
                    mockOutputWindowFactory = new GenericMockFactory("MockOutputWindow1", new Type[] { typeof(IVsOutputWindow) });
                }
                BaseMock mockOutputWindow = mockOutputWindowFactory.GetInstance();
                mockOutputWindow.AddMethodReturnValues(
                        string.Format("{0}.{1}", typeof(IVsOutputWindow).FullName, "GetPane"),
                        new object[] { 0, Guid.Empty, (IVsOutputWindowPane)mockWindowPane });

                // Add the output window to the services provided by the service provider.
                serviceProvider.AddService(typeof(SVsOutputWindow), mockOutputWindow, false);

                // Create an instance of the package and initialize it calling SetSite.
                SrcMLServicePackage package = new SrcMLServicePackage();
                int result = ((IVsPackage)package).SetSite(serviceProvider);
                Assert.IsTrue(Microsoft.VisualStudio.ErrorHandler.Succeeded(result), "SetSite failed.");

                // Now we can create an instance of the service
                SrcMLGlobalService service = new SrcMLGlobalService(package, extensionDirectory);

                service.GlobalServiceFunction();
                
                Assert.IsTrue(callbackExecuted, "OutputText not called.");
                ((IVsPackage)package).SetSite(null);
                ((IVsPackage)package).Close();
            }
        }
 static MockIVsFileChangeEx()
 {
     factory = new GenericMockFactory("MockIVsFileChangeEx", new Type[] { typeof(IVsFileChangeEx)});
 }
        private static void GetToolWindowEnumCallBack2(object caller, CallbackArgs arguments)
        {
            arguments.ReturnValue = VSConstants.S_OK;

            // Create the output mock object
            if (enumWindowsFactory2 == null)
                enumWindowsFactory2 = new GenericMockFactory("EnumWindows2", new Type[] { typeof(IEnumWindowFrames) });
            BaseMock enumWindows = enumWindowsFactory2.GetInstance();
            // Add support for Next
            string name = string.Format("{0}.{1}", typeof(IEnumWindowFrames).FullName, "Next");
            enumWindows.AddMethodCallback(name, new EventHandler<CallbackArgs>(NextCallBack2));
            windowCount = 0;

            arguments.SetParameter(0, enumWindows);
        }
Beispiel #29
0
 static MockIVsSolution()
 {
     factory = new GenericMockFactory("MockIVsSolution", new Type[] { typeof(IVsSolution) });
 }
 static MockIVsSolutionBuildManager()
 {
     factory = new GenericMockFactory("MockIVsSolutionBuildManager", new Type[] { typeof(IVsSolutionBuildManager2), typeof(IVsSolutionBuildManager3) });
 }
            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);
            }
 static MockIVsRegisterProjectTypes()
 {
     factory = new GenericMockFactory("MockIVsRegisterProjectTypes", new Type[] { typeof(IVsRegisterProjectTypes) });
 }