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 });
        }
Пример #2
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 });
            }
        }