コード例 #1
0
        public void Dispose()
        {
            IDisposable i = _instance as IDisposable;

            if (i != null)
            {
                i.Dispose();
            }

            if (type != null && serviceProvider.GetService(type) != null)
            {
                serviceProvider.RemoveService(type);
            }
        }
コード例 #2
0
        public void MenuItemCallback()
        {
            // Create the package
            IVsPackage package = new VsOnBuildExtensionPackage() as IVsPackage;

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

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

            // Create a UIShell service mock and proffer the service so that it can called from the MenuItemCallback method
            BaseMock uishellMock = UIShellServiceMock.GetUiShellInstance();

            serviceProvider.AddService(typeof(SVsUIShell), uishellMock, true);

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

            //Invoke private method on package class and observe that the method does not throw
            System.Reflection.MethodInfo info = package.GetType().GetMethod("MenuItemCallback", BindingFlags.Instance | BindingFlags.NonPublic);
            Assert.IsNotNull(info, "Failed to get the private method MenuItemCallback throug refplection");
            info.Invoke(package, new object[] { null, null });

            //Clean up services
            serviceProvider.RemoveService(typeof(SVsUIShell));
        }
コード例 #3
0
        public void Invoke_all_command_handlers_without_exception(ToolbarCommand toolbarCommand)
        {
            try
            {
                var uishellMock = UIShellServiceMock.GetUiShellInstance();
                _serviceProvider.AddService(typeof(SVsUIShell), uishellMock, true);
                var tortoiseGitLauncherService = Substitute.For <ITortoiseGitLauncherService>();
                _serviceProvider.AddService(typeof(TortoiseGitLauncherService), tortoiseGitLauncherService, true);
                var command     = GetMenuCommand(toolbarCommand);
                var execHandler = (EventHandler)typeof(MenuCommand).GetField("execHandler", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(command);

                execHandler.Invoke(null, null);

                tortoiseGitLauncherService.Received().ExecuteTortoiseProc(toolbarCommand);
            }
            finally
            {
                _serviceProvider.RemoveService(typeof(SVsUIShell));
            }
        }
コード例 #4
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));
        }