コード例 #1
0
        public void TestIndexComboSetCurValWithInt()
        {
            ComboBoxPackage packageObject = new ComboBoxPackage();

            Assert.IsNotNull(packageObject, "Failed to create package");
            OleServiceProvider serviceProvider = OleServiceProvider.CreateOleServiceProviderWithBasicServices();

            // Add site support to create and enumerate tool windows
            GenericMockFactory mockFactory = new GenericMockFactory("MockUIShell", new Type[] { typeof(IVsUIShell) });
            BaseMock           uiShell     = mockFactory.GetInstance();

            serviceProvider.AddService(typeof(SVsUIShell), uiShell, false);

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

            MethodInfo method = typeof(ComboBoxPackage).GetMethod("OnMenuMyIndexCombo", BindingFlags.NonPublic | BindingFlags.Instance);

            int    inChoice  = 1;
            object inParam1  = inChoice;
            IntPtr outParam1 = IntPtr.Zero;
            object inParam2  = null;
            IntPtr outParam2 = Marshal.AllocCoTaskMem(64);   //64 == size of a variant + a little extra padding

            try
            {
                // Set IndexCombo to 2nd choice in list
                OleMenuCmdEventArgs eventArgs1 = new OleMenuCmdEventArgs(inParam1, outParam1);
                object result = method.Invoke(packageObject, new object[] { null, eventArgs1 });

                // Retrieve current value of Index and verify it is "Oranges"
                OleMenuCmdEventArgs eventArgs2 = new OleMenuCmdEventArgs(inParam2, outParam2);
                result = method.Invoke(packageObject, new object[] { null, eventArgs2 });

                string retrieved = (string)Marshal.GetObjectForNativeVariant(outParam2);
                Assert.AreEqual <string>(expectedIndexComboChoices[inChoice], retrieved);

                Assert.AreEqual(1, uiShell.FunctionCalls(String.Format("{0}.{1}", typeof(IVsUIShell).FullName, "ShowMessageBox")), "IVsUIShell.ShowMessageBox was not called");
            }
            finally
            {
                if (outParam2 != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(outParam2);
                }
            }
        }
        public void TestDynamicComboSetCurValWithOverflowInt()
        {
            // NOTE: invalid input is ignored and treated as a NOP
            ComboBoxPackage packageObject = new ComboBoxPackage();

            Assert.IsNotNull(packageObject, "Failed to create package");
            OleServiceProvider serviceProvider = OleServiceProvider.CreateOleServiceProviderWithBasicServices();

            // Add site support to create and enumerate tool windows
            GenericMockFactory mockFactory = new GenericMockFactory("MockUIShell", new Type[] { typeof(IVsUIShell) });
            BaseMock           uiShell     = mockFactory.GetInstance();

            serviceProvider.AddService(typeof(SVsUIShell), uiShell, false);

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

            MethodInfo method = typeof(ComboBoxPackage).GetMethod("OnMenuMyDynamicCombo", BindingFlags.NonPublic | BindingFlags.Instance);

            Int64  inChoice  = Int64.MaxValue;
            object inParam1  = inChoice.ToString() + inChoice.ToString() + inChoice.ToString();
            IntPtr outParam1 = IntPtr.Zero;
            object inParam2  = null;
            IntPtr outParam2 = Marshal.AllocCoTaskMem(64);   //64 == size of a variant + a little extra padding

            try
            {
                // Set DynamicCombo to overflow value
                OleMenuCmdEventArgs eventArgs1 = new OleMenuCmdEventArgs(inParam1, outParam1);
                object result = method.Invoke(packageObject, new object[] { null, eventArgs1 });

                // Retrieve current value of Zoom and verify
                OleMenuCmdEventArgs eventArgs2 = new OleMenuCmdEventArgs(inParam2, outParam2);
                result = method.Invoke(packageObject, new object[] { null, eventArgs2 });

                string retrieved = (string)Marshal.GetObjectForNativeVariant(outParam2);
            }
            finally
            {
                if (outParam2 != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(outParam2);
                }
            }
        }
コード例 #3
0
        public void SetSite()
        {
            // Create the package
            IVsPackage package = new EditorPackage() as IVsPackage;

            Assert.IsNotNull(package, "The object does not implement IVsPackage");

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

            // Add site support to register editor factory
            BaseMock registerEditor = MockRegisterEditors.GetRegisterEditorsInstance();

            serviceProvider.AddService(typeof(SVsRegisterEditors), registerEditor, false);

            // Site the package
            Assert.AreEqual(0, package.SetSite(serviceProvider), "SetSite did not return S_OK");
        }
コード例 #4
0
        public static CodeMaidPackage CreateInitializedPackage()
        {
            // Create the package.
            var package = new CodeMaidPackage();

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

            // Add UIShell service that knows how to create a toolwindow.
            BaseMock uiShellService = UIShellServiceMock.GetUiShellInstanceCreateToolWin();

            serviceProvider.AddService(typeof(SVsUIShell), uiShellService, false);

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

            return(package);
        }
コード例 #5
0
        public void GetLocalServiceSimple()
        {
            SrcMLServicePackage packageObject = new SrcMLServicePackage();
            IVsPackage          package       = (IVsPackage)packageObject;

            using (OleServiceProvider provider = OleServiceProvider.CreateOleServiceProviderWithBasicServices()) {
                int result = package.SetSite(provider);
                Assert.IsTrue(Microsoft.VisualStudio.ErrorHandler.Succeeded(result), "SetSite failed.");
                IServiceProvider serviceProvider = package as IServiceProvider;
                object           o = serviceProvider.GetService(typeof(SSrcMLLocalService));
                Assert.IsNotNull(o, "GetService returned null for the local service.");
                ISrcMLLocalService service = o as ISrcMLLocalService;
                Assert.IsNotNull(service, "The service SMyLocalService does not implements IMyLocalService.");
                service.LocalServiceFunction();
            }
            package.SetSite(null);
            package.Close();
        }
コード例 #6
0
        public void ShowPersistedWindow2()
        {
            // Create the package
            PackageToolWindow package = new PackageToolWindow();
            // Create a basic service provider
            OleServiceProvider serviceProvider = OleServiceProvider.CreateOleServiceProviderWithBasicServices();

            // Add site support to create and enumerate tool windows
            BaseMock uiShell = MockUiShellProvider.GetWindowEnumerator2();

            serviceProvider.AddService(typeof(SVsUIShell), uiShell, false);

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

            MethodInfo method = typeof(PackageToolWindow).GetMethod("ShowPersistedWindow", BindingFlags.NonPublic | BindingFlags.Instance);

            object result = method.Invoke(package, new object[] { null, null });
        }
コード例 #7
0
        public void ValidateToolWindowShown()
        {
            IVsPackage package = new GitWorkItemsPackage() as IVsPackage;

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

            //Add uishell service that knows how to create a toolwindow
            BaseMock uiShellService = UIShellServiceMock.GetUiShellInstanceCreateToolWin();

            serviceProvider.AddService(typeof(SVsUIShell), uiShellService, false);

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

            MethodInfo method = typeof(GitWorkItemsPackage).GetMethod("ShowToolWindow", BindingFlags.NonPublic | BindingFlags.Instance);

            object result = method.Invoke(package, new object[] { null, null });
        }
コード例 #8
0
        public void CheckLogicalView()
        {
            VisualStudioHaskellPackage package = new VisualStudioHaskellPackage();

            //Create the editor factory
            EditorFactory editorFactory = new EditorFactory(package);

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

            serviceProvider.AddService(typeof(SLocalRegistry), (ILocalRegistry)LocalRegistryServiceMock.GetILocalRegistryInstance(), true);

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

            IntPtr ppunkDocView;
            IntPtr ppunkDocData;
            string pbstrEditorCaption = String.Empty;
            Guid   pguidCmdUI         = Guid.Empty;
            int    pgrfCDW            = 0;

            Assert.AreEqual(VSConstants.S_OK, editorFactory.CreateEditorInstance(VSConstants.CEF_OPENFILE,
                                                                                 null, null, null, 0, IntPtr.Zero, out ppunkDocView, out ppunkDocData, out pbstrEditorCaption,
                                                                                 out pguidCmdUI, out pgrfCDW)); //check for successfull creation of editor instance

            string bstrPhysicalView   = string.Empty;
            Guid   refGuidLogicalView = VSConstants.LOGVIEWID_Debugging;

            Assert.AreEqual(VSConstants.E_NOTIMPL, editorFactory.MapLogicalView(ref refGuidLogicalView, out bstrPhysicalView));

            refGuidLogicalView = VSConstants.LOGVIEWID_Code;
            Assert.AreEqual(VSConstants.E_NOTIMPL, editorFactory.MapLogicalView(ref refGuidLogicalView, out bstrPhysicalView));

            refGuidLogicalView = VSConstants.LOGVIEWID_TextView;
            Assert.AreEqual(VSConstants.S_OK, editorFactory.MapLogicalView(ref refGuidLogicalView, out bstrPhysicalView));

            refGuidLogicalView = VSConstants.LOGVIEWID_UserChooseView;
            Assert.AreEqual(VSConstants.E_NOTIMPL, editorFactory.MapLogicalView(ref refGuidLogicalView, out bstrPhysicalView));

            refGuidLogicalView = VSConstants.LOGVIEWID_Primary;
            Assert.AreEqual(VSConstants.S_OK, editorFactory.MapLogicalView(ref refGuidLogicalView, out bstrPhysicalView));
        }
コード例 #9
0
        public void TestIndexComboSetCurValWithOverflowInt()
        {
            ComboBoxPackage packageObject = new ComboBoxPackage();

            Assert.IsNotNull(packageObject, "Failed to create package");
            OleServiceProvider serviceProvider = OleServiceProvider.CreateOleServiceProviderWithBasicServices();

            // Add site support to create and enumerate tool windows
            GenericMockFactory mockFactory = new GenericMockFactory("MockUIShell", new Type[] { typeof(IVsUIShell) });
            BaseMock           uiShell     = mockFactory.GetInstance();

            serviceProvider.AddService(typeof(SVsUIShell), uiShell, false);

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

            MethodInfo method = typeof(ComboBoxPackage).GetMethod("OnMenuMyIndexCombo", BindingFlags.NonPublic | BindingFlags.Instance);

            Int64  inChoice  = Int64.MaxValue;
            object inParam1  = inChoice;
            IntPtr outParam1 = IntPtr.Zero;
            object inParam2  = null;
            IntPtr outParam2 = Marshal.AllocCoTaskMem(64);   //64 == size of a variant + a little extra padding

            try
            {
                // Set IndexCombo to 2nd choice in list
                OleMenuCmdEventArgs eventArgs1 = new OleMenuCmdEventArgs(inParam1, outParam1);
                bool hasTrown = Utilities.HasFunctionThrown <ArgumentException>(delegate { method.Invoke(packageObject, new object[] { null, eventArgs1 }); });
                Assert.IsTrue(hasTrown);

                OleMenuCmdEventArgs eventArgs2 = new OleMenuCmdEventArgs(inParam2, outParam2);
                object result = method.Invoke(packageObject, new object[] { null, eventArgs2 });
            }
            finally
            {
                if (outParam2 != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(outParam2);
                }
            }
        }
コード例 #10
0
        public void SetSite()
        {
            // Create the package
            var package = new VsExtAutoShelvePackage() 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");
        }
コード例 #11
0
        public void SetSite()
        {
            // Create the package
            IVsPackage package = new ProjectLinkerPackage();

            Assert.IsNotNull(package, "The object does not implement IVsPackage");

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

            serviceProvider.AddService(typeof(SVsTrackProjectDocuments), new MockDocumentTracker(), true);
            serviceProvider.AddService(typeof(SVsOutputWindow), new MockOutputWindow(), true);
            serviceProvider.AddService(typeof(SVsSolution), new MockIVsSolution(), 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");
        }
コード例 #12
0
        public void InitializeMenuCommand()
        {
            // Create the package
            IVsPackage package = new SrcMLServicePackage() as IVsPackage;

            Assert.IsNotNull(package, "The object does not implement IVsPackage");

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

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

            //Verify that the menu command can be found
            ////CommandID menuCommandID = new CommandID(GuidList.guidSrcMLServiceCmdSet, (int)PkgCmdIDList.SrcML);
            System.Reflection.MethodInfo info = typeof(Package).GetMethod("GetService", BindingFlags.Instance | BindingFlags.NonPublic);
            Assert.IsNotNull(info);
            OleMenuCommandService mcs = info.Invoke(package, new object[] { (typeof(IMenuCommandService)) }) as OleMenuCommandService;
            ////Assert.IsNotNull(mcs.FindCommand(menuCommandID));
        }
コード例 #13
0
        public void ShowToolwindowNegativeTest()
        {
            IVsPackage package = new JavaScriptBrowserPackage() as IVsPackage;

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

            //Add uishell service that knows how to create a toolwindow
            BaseMock uiShellService = UIShellServiceMock.GetUiShellInstanceCreateToolWinReturnsNull();

            serviceProvider.AddService(typeof(SVsUIShell), uiShellService, false);

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

            MethodInfo method = typeof(JavaScriptBrowserPackage).GetMethod("ShowToolWindow", BindingFlags.NonPublic | BindingFlags.Instance);

            //ShowToolWindow throw NotSupportException but the Exception is converted during the
            //call of invoke method
            object result = method.Invoke(package, new object[] { null, null });
        }
コード例 #14
0
        public void CreateEditorInstanceWithBadInputsTest()
        {
            //Create the editor factory
            EditorFactory targetFactory = editorFactory;

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

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

            IntPtr ppunkDocView;
            IntPtr ppunkDocData;
            string pbstrEditorCaption = String.Empty;
            Guid   pguidCmdUI         = Guid.Empty;
            int    pgrfCDW            = 0;
            uint   cef_option         = 0;

            // test scenario with invalid CEF_* option
            IntPtr punkDocDataExisting = IntPtr.Zero;

            int actual_result = targetFactory.CreateEditorInstance(cef_option, null, null, null,
                                                                   0, punkDocDataExisting, out ppunkDocView, out ppunkDocData, out pbstrEditorCaption, out pguidCmdUI, out pgrfCDW);

            Assert.AreEqual(VSConstants.E_INVALIDARG, actual_result, "CreateEditorInstance() can not process invalid CEF_* arguments");

            ppunkDocView       = IntPtr.Zero;
            ppunkDocData       = IntPtr.Zero;
            pbstrEditorCaption = String.Empty;
            pguidCmdUI         = Guid.Empty;
            pgrfCDW            = 0;
            cef_option         = VSConstants.CEF_OPENFILE;

            // test scenario with not-null punkDocDataExisting parameter value
            punkDocDataExisting = new IntPtr(Int32.MaxValue);

            actual_result = targetFactory.CreateEditorInstance(cef_option, null, null, null,
                                                               0, punkDocDataExisting, out ppunkDocView, out ppunkDocData, out pbstrEditorCaption, out pguidCmdUI, out pgrfCDW);
            Assert.AreEqual(VSConstants.VS_E_INCOMPATIBLEDOCDATA, actual_result, "CreateEditorInstance() can not process incompatible document data argument");
        }
コード例 #15
0
        public void GetGlobalServiceFromNativeProvider()
        {
            ServicesPackage packageObject = new ServicesPackage();
            IVsPackage      package       = (IVsPackage)packageObject;

            using (OleServiceProvider provider = OleServiceProvider.CreateOleServiceProviderWithBasicServices())
            {
                int result = package.SetSite(provider);
                Assert.IsTrue(Microsoft.VisualStudio.ErrorHandler.Succeeded(result), "SetSite failed.");
                IOleServiceProvider sp = package as IOleServiceProvider;
                Assert.IsNotNull(sp, "The pacckage does not implements the native IServiceProvider");
                Guid   guidService   = typeof(SMyGlobalService).GUID;
                Guid   guidInterface = typeof(IMyGlobalService).GUID;
                IntPtr ppvObj        = IntPtr.Zero;
                int    hr            = sp.QueryService(ref guidService, ref guidInterface, out ppvObj);
                Assert.IsTrue(Microsoft.VisualStudio.ErrorHandler.Succeeded(hr), "QueryService failed for the global service.");
                Assert.IsTrue(ppvObj != IntPtr.Zero, "QueryService returned a NULL pointer for the global service.");
                Marshal.Release(ppvObj);
            }
            package.SetSite(null);
            package.Close();
        }
コード例 #16
0
        public void InitializeMenuCommand()
        {
            // Create the package
            var package = new Package() as IVsPackage;

            Assert.IsNotNull(package, "The object does not implement IVsPackage");

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

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

            //Verify that the menu command can be found
            var menuCommandId = new CommandID(GuidList.CmdSet, (int)PkgCmdIDList.cmdidGenerateTestStub);
            var info          = typeof(Microsoft.VisualStudio.Shell.Package).GetMethod("GetService", BindingFlags.Instance | BindingFlags.NonPublic);

            Assert.IsNotNull(info);
            var mcs = info.Invoke(package, new object[] { (typeof(IMenuCommandService)) }) as OleMenuCommandService;

            Assert.IsNotNull(mcs.FindCommand(menuCommandId));
        }
        public void UseToolWindow()
        {
            // Create the package
            BasicSccProvider package = new BasicSccProvider();
            // Create a basic service provider
            OleServiceProvider serviceProvider = OleServiceProvider.CreateOleServiceProviderWithBasicServices();

            // Need to mock a service implementing IVsRegisterScciProvider, because the scc provider will register with it
            IVsRegisterScciProvider registerScciProvider = MockRegisterScciProvider.GetBaseRegisterScciProvider();

            serviceProvider.AddService(typeof(IVsRegisterScciProvider), registerScciProvider, true);

            // Add site support to create and enumerate tool windows
            BaseMock uiShell = MockUiShellProvider.GetWindowEnumerator0();

            serviceProvider.AddService(typeof(SVsUIShell), uiShell, false);

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

            // Test that toolwindow can be created
            MethodInfo method = typeof(BasicSccProvider).GetMethod("ViewToolWindow", BindingFlags.NonPublic | BindingFlags.Instance);
            object     result = method.Invoke(package, new object[] { null, null });

            // Test that toolwindow toolbar's command can be executed
            method = typeof(BasicSccProvider).GetMethod("ToolWindowToolbarCommand", BindingFlags.NonPublic | BindingFlags.Instance);
            result = method.Invoke(package, new object[] { null, null });

            // Toggle the toolwindow color back
            method = typeof(BasicSccProvider).GetMethod("ToolWindowToolbarCommand", BindingFlags.NonPublic | BindingFlags.Instance);
            result = method.Invoke(package, new object[] { null, null });

            // Get the window and test the dispose function
            SccProviderToolWindow window = (SccProviderToolWindow)package.FindToolWindow(typeof(SccProviderToolWindow), 0, true);

            method = typeof(SccProviderToolWindow).GetMethod("Dispose", BindingFlags.NonPublic | BindingFlags.Instance);
            result = method.Invoke(window, new object[] { true });
        }
コード例 #18
0
        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.
                ServicesPackage package = new ServicesPackage();
                int             result  = ((IVsPackage)package).SetSite(serviceProvider);
                Assert.IsTrue(Microsoft.VisualStudio.ErrorHandler.Succeeded(result), "SetSite failed.");

                // Now we can create an instance of the service
                MyGlobalService service = new MyGlobalService(package);
                service.GlobalServiceFunction();
                Assert.IsTrue(callbackExecuted, "OutputText not called.");
                ((IVsPackage)package).SetSite(null);
                ((IVsPackage)package).Close();
            }
        }
コード例 #19
0
        public void SetSite()
        {
            // Create the package
            IVsPackage package = new BasicSccProvider() as IVsPackage;

            Assert.IsNotNull(package, "The object does not implement IVsPackage");

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

            // Need to mock a service implementing IVsRegisterScciProvider, because the scc provider will register with it
            IVsRegisterScciProvider registerScciProvider = MockRegisterScciProvider.GetBaseRegisterScciProvider();

            serviceProvider.AddService(typeof(IVsRegisterScciProvider), registerScciProvider, 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");

            // Remove the mock service
            serviceProvider.RemoveService(typeof(IVsRegisterScciProvider));
        }
コード例 #20
0
        public void ValidateToolWindowShown()
        {
            IVsPackage package = new oop3Package() as IVsPackage;

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

            //Add uishell service that knows how to create a toolwindow
            BaseMock uiShellService = UIShellServiceMock.GetUiShellInstanceCreateToolWin();

            serviceProvider.AddService(typeof(SVsUIShell), uiShellService, false);

            // Add site support to register editor factory
            BaseMock registerEditor = oop3_UnitTests.EditorTests.RegisterEditorsServiceMock.GetRegisterEditorsInstance();

            serviceProvider.AddService(typeof(SVsRegisterEditors), registerEditor, false);

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

            MethodInfo method = typeof(oop3Package).GetMethod("ShowToolWindow", BindingFlags.NonPublic | BindingFlags.Instance);

            object result = method.Invoke(package, new object[] { null, null });
        }
コード例 #21
0
        public void StandardConstructor()
        {
            using (OleServiceProvider provider = OleServiceProvider.CreateOleServiceProviderWithBasicServices())
            {
                IVsPackage package = null;
                try
                {
                    // Create a mock object for the text buffer.
                    BaseMock textLinesMock = MockFactories.TextBufferFactory.GetInstance();
                    // Create a new local registry class.
                    LocalRegistryMock mockRegistry = new LocalRegistryMock();
                    // Add the text buffer to the list of the classes that local registry can create.
                    mockRegistry.AddClass(typeof(VsTextBufferClass), textLinesMock);
                    provider.AddService(typeof(SLocalRegistry), mockRegistry, false);

                    // Now create a package object and site it.
                    package = new PythonConsolePackage() as IVsPackage;
                    package.SetSite(provider);

                    // Create a console window using the standard constructor and verify that the
                    // text buffer is created and sited.
                    using (IDisposable consoleObject = CommandWindowHelper.CreateConsoleWindow() as IDisposable)
                    {
                        Assert.IsTrue(0 < textLinesMock.FunctionCalls(string.Format("{0}.{1}", typeof(IObjectWithSite).FullName, "SetSite")));
                    }
                }
                finally
                {
                    if (null != package)
                    {
                        package.SetSite(null);
                        package.Close();
                    }
                }
            }
        }
コード例 #22
0
        public void OnApplyTest()
        {
            SccProviderOptions target = new SccProviderOptions();

            // Create a basic service provider
            using (OleServiceProvider serviceProvider = OleServiceProvider.CreateOleServiceProviderWithBasicServices())
            {
                // Mock the UIShell service to answer Cancel to the dialog invocation
                BaseMock mockUIShell = MockUiShellProvider.GetShowMessageBoxCancel();
                serviceProvider.AddService(typeof(IVsUIShell), mockUIShell, true);

                // Create an ISite wrapper over the service provider
                SiteWrappedServiceProvider wrappedProvider = new SiteWrappedServiceProvider(serviceProvider);
                target.Site = wrappedProvider;

                Assembly shell   = typeof(Microsoft.VisualStudio.Shell.DialogPage).Assembly;
                Type     argtype = shell.GetType("Microsoft.VisualStudio.Shell.DialogPage+PageApplyEventArgs", true);

                MethodInfo method    = typeof(SccProviderOptions).GetMethod("OnApply", BindingFlags.NonPublic | BindingFlags.Instance);
                object     eventargs = shell.CreateInstance(argtype.FullName);

                method.Invoke(target, new object[] { eventargs });
            }
        }
コード例 #23
0
        public void ConsoleCreation()
        {
            using (OleServiceProvider provider = OleServiceProvider.CreateOleServiceProviderWithBasicServices())
            {
                // In order to create a console window we have to add the text buffer to the
                // local registry.

                // Create a mock object for the text buffer.
                BaseMock textLinesMock = MockFactories.TextBufferFactory.GetInstance();
                // Create a new local registry class.
                LocalRegistryMock mockRegistry = new LocalRegistryMock();
                // Add the text buffer to the list of the classes that local registry can create.
                mockRegistry.AddClass(typeof(VsTextBufferClass), textLinesMock);

                // Define the mock object for the text view.
                BaseMock textViewMock = MockFactories.TextViewFactory.GetInstance();
                mockRegistry.AddClass(typeof(VsTextViewClass), textViewMock);

                // Add the local registry mock to the service provider.
                provider.AddService(typeof(SLocalRegistry), mockRegistry, false);

                // Create a mock UIShell to be able to create the tool window.
                BaseMock uiShell = MockFactories.UIShellFactory.GetInstance();
                uiShell["Frame"] = MockFactories.WindowFrameFactory.GetInstance() as IVsWindowFrame;
                uiShell.AddMethodCallback(
                    string.Format("{0}.{1}", typeof(IVsUIShell), "CreateToolWindow"),
                    new EventHandler <CallbackArgs>(CreateToolwindowCallback));
                provider.AddService(typeof(SVsUIShell), uiShell, false);

                IVsPackage package = null;
                try
                {
                    // Create the package.
                    package = new PythonConsolePackage() as IVsPackage;
                    Assert.IsNotNull(package);

                    // Make sure that the static variable about the global service provider is null;
                    FieldInfo globalProvider = typeof(Microsoft.VisualStudio.Shell.Package).GetField("_globalProvider", BindingFlags.Static | BindingFlags.NonPublic);
                    globalProvider.SetValue(null, null);

                    // Site it.
                    int hr = package.SetSite(provider);
                    Assert.IsTrue(Microsoft.VisualStudio.ErrorHandler.Succeeded(hr));

                    // Get the command target from the package.
                    IOleCommandTarget target = package as IOleCommandTarget;
                    Assert.IsNotNull(target);

                    CommandTargetHelper helper = new CommandTargetHelper(target);
                    helper.ExecCommand(GuidList.guidIronPythonConsoleCmdSet, PkgCmdIDList.cmdidIronPythonConsole);
                }
                finally
                {
                    if (null != package)
                    {
                        package.SetSite(null);
                        package.Close();
                    }
                }
            }
        }
コード例 #24
0
 public TortoiseGitToolbarPackageShould()
 {
     _package         = new TortoiseGitToolbarPackage();
     _serviceProvider = OleServiceProvider.CreateOleServiceProviderWithBasicServices();
 }
コード例 #25
0
        public void ViewCreationWithLanguage()
        {
            using (OleServiceProvider provider = OleServiceProvider.CreateOleServiceProviderWithBasicServices())
            {
                // Create a mock text buffer for the console.
                BaseMock textLinesMock = MockFactories.TextBufferFactory.GetInstance();
                // The buffer have to handle a few of connection points in order to enable the
                // creation of a Source object from the language service.
                ConnectionPointHelper.AddConnectionPointsToContainer(
                    textLinesMock,
                    new Type[] { typeof(IVsFinalTextChangeCommitEvents), typeof(IVsTextLinesEvents), typeof(IVsUserDataEvents) });

                // Create the local registry mock and add the text buffer to it.
                LocalRegistryMock mockLocalRegistry = new LocalRegistryMock();
                mockLocalRegistry.AddClass(typeof(VsTextBufferClass), textLinesMock);

                // Define the mock object for the text view.
                BaseMock textViewMock = MockFactories.TextViewFactory.GetInstance();
                // Create the connection point for IVsTextViewEvents (needed for the language service).
                ConnectionPointHelper.AddConnectionPointsToContainer(textViewMock, new Type[] { typeof(IVsTextViewEvents) });

                // Add the text view to the local registry.
                mockLocalRegistry.AddClass(typeof(VsTextViewClass), textViewMock);

                MockPackage package = new MockPackage();
                ((IVsPackage)package).SetSite(provider);
                provider.AddService(typeof(Microsoft.VisualStudio.Shell.Package), package, true);

                // Create the language service and add it to the list of services.
                PythonLanguage language = new MockLanguage();
                provider.AddService(typeof(PythonLanguage), language, true);
                language.SetSite(provider);

                // We need to add a method tip window to the local registry in order to create
                // a Source object.
                IVsMethodTipWindow methodTip = MockFactories.MethodTipFactory.GetInstance() as IVsMethodTipWindow;
                mockLocalRegistry.AddClass(typeof(VsMethodTipWindowClass), methodTip);

                // Create a mock expansion manager that is needed for the language service.
                BaseMock expansionManager = MockFactories.ExpansionManagerFactory.GetInstance();
                ConnectionPointHelper.AddConnectionPointsToContainer(expansionManager, new Type[] { typeof(IVsExpansionEvents) });
                Assembly asm        = typeof(Microsoft.VisualStudio.Package.LanguageService).Assembly;
                Type     expMgrType = asm.GetType("Microsoft.VisualStudio.Package.SVsExpansionManager");
                provider.AddService(expMgrType, expansionManager, false);

                // Add the local registry to the list of services.
                provider.AddService(typeof(SLocalRegistry), mockLocalRegistry, false);
                using (ToolWindowPane windowPane = CommandWindowHelper.CreateConsoleWindow(provider) as ToolWindowPane)
                {
                    Assert.IsNotNull(windowPane);

                    // Call the CreatePaneWindow method that will force the creation of the text view.
                    IntPtr newHwnd;
                    Assert.IsTrue(Microsoft.VisualStudio.ErrorHandler.Succeeded(
                                      ((IVsWindowPane)windowPane).CreatePaneWindow(IntPtr.Zero, 0, 0, 0, 0, out newHwnd)));

                    // Verify that the language service contains a special view for this text view.
                    FieldInfo specialSourcesField = typeof(PythonLanguage).GetField("specialSources", BindingFlags.Instance | BindingFlags.NonPublic);
                    Assert.IsNotNull(specialSourcesField);
                    Dictionary <IVsTextView, PythonSource> specialSources =
                        (Dictionary <IVsTextView, PythonSource>)specialSourcesField.GetValue(language);
                    PythonSource source;
                    Assert.IsTrue(specialSources.TryGetValue(textViewMock as IVsTextView, out source));
                    Assert.IsNotNull(source);
                    // Set ColorState to null so that Dispose will not call Marshal.ReleaseComObject on it.
                    source.ColorState = null;
                }
            }
        }
コード例 #26
0
 static ServiceProviderHelper()
 {
     serviceProvider = OleServiceProvider.CreateOleServiceProviderWithBasicServices();
     AddService(typeof(Ankh.UI.IAnkhPackage), AnkhSvn_UnitTestProject.Mocks.PackageMock.EmptyContext(serviceProvider));
 }