public void PackageCommands()
        {
            using (OleServiceProvider provider = OleServiceProvider.CreateOleServiceProviderWithBasicServices())
            {
                IVsPackage package = null;
                try
                {
                    // Create and site the package.
                    package = new PythonConsolePackage() as IVsPackage;
                    Assert.IsNotNull(package);
                    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);
                    uint flags;
                    Assert.IsTrue(helper.IsCommandSupported(GuidList.guidIronPythonConsoleCmdSet, PkgCmdIDList.cmdidIronPythonConsole, out flags));
                    Assert.IsTrue(0 != ((uint)OLECMDF.OLECMDF_SUPPORTED & flags));
                    Assert.IsTrue(0 != ((uint)OLECMDF.OLECMDF_ENABLED & flags));
                    Assert.IsTrue(0 == ((uint)OLECMDF.OLECMDF_INVISIBLE & flags));
                }
                finally
                {
                    if (null != package)
                    {
                        package.SetSite(null);
                        package.Close();
                    }
                }
            }
        }
 public void PackageCreation()
 {
     // Create a service provider with basic services to site the package.
     using (OleServiceProvider provider = OleServiceProvider.CreateOleServiceProviderWithBasicServices())
     {
         IVsPackage package = null;
         try
         {
             // Create the package and verify that implements IVsPackage.
             package = new PythonConsolePackage() as IVsPackage;
             Assert.IsNotNull(package);
             // Verify that SetSite succeeded.
             int hr = package.SetSite(provider);
             Assert.IsTrue(Microsoft.VisualStudio.ErrorHandler.Succeeded(hr));
         }
         finally
         {
             if (null != package)
             {
                 package.SetSite(null);
                 package.Close();
             }
         }
     }
 }
        public void VerifyServices()
        {
            // Create the package.
            IVsPackage consolePackage = new PythonConsolePackage() as IVsPackage;

            Assert.IsNotNull(consolePackage);
            // Get the service provider implemented by the package.
            IServiceProvider packageProvider = consolePackage as IServiceProvider;

            Assert.IsNotNull(packageProvider);
            // Verify that the package exposes the services.
            Assert.IsNotNull(packageProvider.GetService(typeof(IPythonEngineProvider)));
        }
Exemple #4
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();
                    }
                }
            }
        }
        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();
                    }
                }
            }
        }
        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();
                    }
                }
            }
        }
        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();
                    }
                }
            }
        }
 public void VerifyServices()
 {
     // Create the package.
     IVsPackage consolePackage = new PythonConsolePackage() as IVsPackage;
     Assert.IsNotNull(consolePackage);
     // Get the service provider implemented by the package.
     IServiceProvider packageProvider = consolePackage as IServiceProvider;
     Assert.IsNotNull(packageProvider);
     // Verify that the package exposes the services.
     Assert.IsNotNull(packageProvider.GetService(typeof(IPythonEngineProvider)));
 }
 public void PackageCreation()
 {
     // Create a service provider with basic services to site the package.
     using (OleServiceProvider provider = OleServiceProvider.CreateOleServiceProviderWithBasicServices())
     {
         IVsPackage package = null;
         try
         {
             // Create the package and verify that implements IVsPackage.
             package = new PythonConsolePackage() as IVsPackage;
             Assert.IsNotNull(package);
             // Verify that SetSite succeeded.
             int hr = package.SetSite(provider);
             Assert.IsTrue(Microsoft.VisualStudio.ErrorHandler.Succeeded(hr));
         }
         finally
         {
             if (null != package)
             {
                 package.SetSite(null);
                 package.Close();
             }
         }
     }
 }
        public void PackageCommands()
        {
            using (OleServiceProvider provider = OleServiceProvider.CreateOleServiceProviderWithBasicServices())
            {
                IVsPackage package = null;
                try
                {
                    // Create and site the package.
                    package = new PythonConsolePackage() as IVsPackage;
                    Assert.IsNotNull(package);
                    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);
                    uint flags;
                    Assert.IsTrue(helper.IsCommandSupported(GuidList.guidIronPythonConsoleCmdSet, PkgCmdIDList.cmdidIronPythonConsole, out flags));
                    Assert.IsTrue(0 != ((uint)OLECMDF.OLECMDF_SUPPORTED & flags));
                    Assert.IsTrue(0 != ((uint)OLECMDF.OLECMDF_ENABLED & flags));
                    Assert.IsTrue(0 == ((uint)OLECMDF.OLECMDF_INVISIBLE & flags));
                }
                finally
                {
                    if (null != package)
                    {
                        package.SetSite(null);
                        package.Close();
                    }
                }
            }
        }