コード例 #1
0
        public void SetSite()
        {
            // Create the package
            IVsPackage package = new SccProvider() 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);

            // Register solution events because the provider will try to subscribe to them
            MockSolution solution = new MockSolution();

            serviceProvider.AddService(typeof(SVsSolution), solution as IVsSolution, true);

            // Register TPD service because the provider will try to subscribe to TPD
            IVsTrackProjectDocuments2 tpd = MockTrackProjectDocumentsProvider.GetTrackProjectDocuments() as IVsTrackProjectDocuments2;

            serviceProvider.AddService(typeof(SVsTrackProjectDocuments), tpd, 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");
        }
        public void UseToolWindow()
        {
            // Create the package
            SccProvider package = new SccProvider();
            // 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);

            // Register solution events because the provider will try to subscribe to them
            MockSolution solution = new MockSolution();

            serviceProvider.AddService(typeof(SVsSolution), solution as IVsSolution, true);

            // Register TPD service because the provider will try to subscribe to TPD
            IVsTrackProjectDocuments2 tpd = MockTrackProjectDocumentsProvider.GetTrackProjectDocuments() as IVsTrackProjectDocuments2;

            serviceProvider.AddService(typeof(SVsTrackProjectDocuments), tpd, true);

            // 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(SccProvider).GetMethod("Exec_icmdViewToolWindow", BindingFlags.NonPublic | BindingFlags.Instance);
            object     result = method.Invoke(package, new object[] { null, null });

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

            // Toggle the toolwindow color back
            method = typeof(SccProvider).GetMethod("Exec_icmdToolWindowToolbarCommand", 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 });
        }