Ejemplo n.º 1
0
        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 VerifyCommandFilter()
        {
            using (OleServiceProvider provider = new OleServiceProvider())
            {
                // Create a mock text buffer for the console.
                BaseMock textLinesMock = MockFactories.TextBufferFactory.GetInstance();
                LocalRegistryMock mockLocalRegistry = new LocalRegistryMock();
                mockLocalRegistry.AddClass(typeof(VsTextBufferClass), textLinesMock);

                // Define the mock object for the text view.
                BaseMock textViewMock = MockFactories.TextViewFactory.GetInstance();
                textViewMock.AddMethodCallback(
                    string.Format("{0}.{1}", typeof(IVsTextView).FullName, "AddCommandFilter"),
                    new EventHandler<CallbackArgs>(AddCommandFilterCallback));
                mockLocalRegistry.AddClass(typeof(VsTextViewClass), textViewMock);

                // Create a command target that handles some random command
                OleMenuCommandService commandService = new OleMenuCommandService(provider);
                Guid newCommandGroup = Guid.NewGuid();
                uint newCommandId = 42;
                CommandID id = new CommandID(newCommandGroup, (int)newCommandId);
                OleMenuCommand cmd = new OleMenuCommand(null, id);
                commandService.AddCommand(cmd);
                textViewMock["OriginalFilter"] = (IOleCommandTarget)commandService;

                // Add the local registry to the list of services.
                provider.AddService(typeof(SLocalRegistry), mockLocalRegistry, false);

                // Create the window.
                using (ToolWindowPane windowPane = CommandWindowHelper.CreateConsoleWindow(provider) as ToolWindowPane)
                {
                    Assert.IsNotNull(windowPane);

                    // Verify that the command specific to the text view are not handled yet.
                    CommandTargetHelper commandHelper = new CommandTargetHelper((IOleCommandTarget)windowPane);
                    uint flags;
                    Assert.IsFalse(commandHelper.IsCommandSupported(
                                        typeof(Microsoft.VisualStudio.VSConstants.VSStd2KCmdID).GUID,
                                        (int)(int)Microsoft.VisualStudio.VSConstants.VSStd2KCmdID.RETURN,
                                        out flags));
                    Assert.IsFalse(commandHelper.IsCommandSupported(
                                        typeof(Microsoft.VisualStudio.VSConstants.VSStd2KCmdID).GUID,
                                        (int)(int)Microsoft.VisualStudio.VSConstants.VSStd2KCmdID.UP,
                                        out flags));
                    Assert.IsFalse(commandHelper.IsCommandSupported(
                                        typeof(Microsoft.VisualStudio.VSConstants.VSStd2KCmdID).GUID,
                                        (int)(int)Microsoft.VisualStudio.VSConstants.VSStd2KCmdID.DOWN,
                                        out flags));
                    Assert.IsFalse(commandHelper.IsCommandSupported(
                                        typeof(Microsoft.VisualStudio.VSConstants.VSStd2KCmdID).GUID,
                                        (int)(int)Microsoft.VisualStudio.VSConstants.VSStd2KCmdID.SHOWCONTEXTMENU,
                                        out flags));
                    // Verify that also the command that we have defined here is not supported.
                    Assert.IsFalse(commandHelper.IsCommandSupported(newCommandGroup, newCommandId, out flags));

                    // 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)));

                    // Now we have to set the frame property on the ToolWindowFrame because
                    // this will cause the execution of OnToolWindowCreated.
                    windowPane.Frame = (IVsWindowFrame)MockFactories.WindowFrameFactory.GetInstance();

                    // Now the command filter should be set for the text view
                    Assert.IsNotNull(textViewMock["CommandFilter"]);
                    // The command target for the window pane should also be able to support
                    // the text view specific command that we have installed.
                    // Verify only two commands that are always supported
                    Assert.IsTrue(commandHelper.IsCommandSupported(
                                        typeof(Microsoft.VisualStudio.VSConstants.VSStd2KCmdID).GUID,
                                        (int)(int)Microsoft.VisualStudio.VSConstants.VSStd2KCmdID.RETURN,
                                        out flags));
                    Assert.IsTrue(commandHelper.IsCommandSupported(
                                        typeof(Microsoft.VisualStudio.VSConstants.VSStd2KCmdID).GUID,
                                        (int)(int)Microsoft.VisualStudio.VSConstants.VSStd2KCmdID.BOL,
                                        out flags));
                    Assert.IsTrue(commandHelper.IsCommandSupported(
                                        typeof(Microsoft.VisualStudio.VSConstants.VSStd2KCmdID).GUID,
                                        (int)(int)Microsoft.VisualStudio.VSConstants.VSStd2KCmdID.SHOWCONTEXTMENU,
                                        out flags));
                    // Verify that also the commands supported by the original command target are
                    // supported by the new one.
                    Assert.IsTrue(commandHelper.IsCommandSupported(newCommandGroup, newCommandId, out flags));
                }
            }
        }
Ejemplo n.º 3
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();
                    }
                }
            }
        }
        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();
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public void VerifyCommandFilter()
        {
            using (OleServiceProvider provider = new OleServiceProvider())
            {
                // Create a mock text buffer for the console.
                BaseMock          textLinesMock     = MockFactories.TextBufferFactory.GetInstance();
                LocalRegistryMock mockLocalRegistry = new LocalRegistryMock();
                mockLocalRegistry.AddClass(typeof(VsTextBufferClass), textLinesMock);

                // Define the mock object for the text view.
                BaseMock textViewMock = MockFactories.TextViewFactory.GetInstance();
                textViewMock.AddMethodCallback(
                    string.Format("{0}.{1}", typeof(IVsTextView).FullName, "AddCommandFilter"),
                    new EventHandler <CallbackArgs>(AddCommandFilterCallback));
                mockLocalRegistry.AddClass(typeof(VsTextViewClass), textViewMock);

                // Create a command target that handles some random command
                OleMenuCommandService commandService = new OleMenuCommandService(provider);
                Guid           newCommandGroup       = Guid.NewGuid();
                uint           newCommandId          = 42;
                CommandID      id  = new CommandID(newCommandGroup, (int)newCommandId);
                OleMenuCommand cmd = new OleMenuCommand(null, id);
                commandService.AddCommand(cmd);
                textViewMock["OriginalFilter"] = (IOleCommandTarget)commandService;

                // Add the local registry to the list of services.
                provider.AddService(typeof(SLocalRegistry), mockLocalRegistry, false);

                // Create the window.
                using (ToolWindowPane windowPane = CommandWindowHelper.CreateConsoleWindow(provider) as ToolWindowPane)
                {
                    Assert.IsNotNull(windowPane);

                    // Verify that the command specific to the text view are not handled yet.
                    CommandTargetHelper commandHelper = new CommandTargetHelper((IOleCommandTarget)windowPane);
                    uint flags;
                    Assert.IsFalse(commandHelper.IsCommandSupported(
                                       typeof(Microsoft.VisualStudio.VSConstants.VSStd2KCmdID).GUID,
                                       (int)(int)Microsoft.VisualStudio.VSConstants.VSStd2KCmdID.RETURN,
                                       out flags));
                    Assert.IsFalse(commandHelper.IsCommandSupported(
                                       typeof(Microsoft.VisualStudio.VSConstants.VSStd2KCmdID).GUID,
                                       (int)(int)Microsoft.VisualStudio.VSConstants.VSStd2KCmdID.UP,
                                       out flags));
                    Assert.IsFalse(commandHelper.IsCommandSupported(
                                       typeof(Microsoft.VisualStudio.VSConstants.VSStd2KCmdID).GUID,
                                       (int)(int)Microsoft.VisualStudio.VSConstants.VSStd2KCmdID.DOWN,
                                       out flags));
                    Assert.IsFalse(commandHelper.IsCommandSupported(
                                       typeof(Microsoft.VisualStudio.VSConstants.VSStd2KCmdID).GUID,
                                       (int)(int)Microsoft.VisualStudio.VSConstants.VSStd2KCmdID.SHOWCONTEXTMENU,
                                       out flags));
                    // Verify that also the command that we have defined here is not supported.
                    Assert.IsFalse(commandHelper.IsCommandSupported(newCommandGroup, newCommandId, out flags));

                    // 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)));

                    // Now we have to set the frame property on the ToolWindowFrame because
                    // this will cause the execution of OnToolWindowCreated.
                    windowPane.Frame = (IVsWindowFrame)MockFactories.WindowFrameFactory.GetInstance();

                    // Now the command filter should be set for the text view
                    Assert.IsNotNull(textViewMock["CommandFilter"]);
                    // The command target for the window pane should also be able to support
                    // the text view specific command that we have installed.
                    // Verify only two commands that are always supported
                    Assert.IsTrue(commandHelper.IsCommandSupported(
                                      typeof(Microsoft.VisualStudio.VSConstants.VSStd2KCmdID).GUID,
                                      (int)(int)Microsoft.VisualStudio.VSConstants.VSStd2KCmdID.RETURN,
                                      out flags));
                    Assert.IsTrue(commandHelper.IsCommandSupported(
                                      typeof(Microsoft.VisualStudio.VSConstants.VSStd2KCmdID).GUID,
                                      (int)(int)Microsoft.VisualStudio.VSConstants.VSStd2KCmdID.BOL,
                                      out flags));
                    Assert.IsTrue(commandHelper.IsCommandSupported(
                                      typeof(Microsoft.VisualStudio.VSConstants.VSStd2KCmdID).GUID,
                                      (int)(int)Microsoft.VisualStudio.VSConstants.VSStd2KCmdID.SHOWCONTEXTMENU,
                                      out flags));
                    // Verify that also the commands supported by the original command target are
                    // supported by the new one.
                    Assert.IsTrue(commandHelper.IsCommandSupported(newCommandGroup, newCommandId, out flags));
                }
            }
        }
        public void VerifyOnReturn()
        {
            using (OleServiceProvider provider = new OleServiceProvider())
            {
                // Create a mock text buffer for the console.
                BaseMock textLinesMock = MockFactories.CreateBufferWithMarker();
                textLinesMock.AddMethodReturnValues(
                    string.Format("{0}.{1}", typeof(IVsTextLines).FullName, "GetLastLineIndex"),
                    new object[] { 0, 0, 4 });
                textLinesMock.AddMethodReturnValues(
                    string.Format("{0}.{1}", typeof(IVsTextLines).FullName, "GetLengthOfLine"),
                    new object[] { 0, 0, 13 });
                textLinesMock.AddMethodCallback(
                    string.Format("{0}.{1}", typeof(IVsTextLines).FullName, "GetLineText"),
                    new EventHandler<CallbackArgs>(GetLineTextCallback));
                textLinesMock.AddMethodReturnValues(
                    string.Format("{0}.{1}", typeof(IVsTextLines).FullName, "GetLineCount"),
                    new object[] { 0, 13 });

                LocalRegistryMock mockLocalRegistry = new LocalRegistryMock();
                mockLocalRegistry.AddClass(typeof(VsTextBufferClass), textLinesMock);

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

                // Add the local registry to the list of services.
                provider.AddService(typeof(SLocalRegistry), mockLocalRegistry, false);

                // Create a mock engine provider.
                BaseMock mockEngineProvider = MockFactories.EngineProviderFactory.GetInstance();
                // Create a mock engine.
                BaseMock mockEngine = MockFactories.CreateStandardEngine();
                // Set this engine as the one returned from the GetSharedEngine of the engine provider.
                mockEngineProvider.AddMethodReturnValues(
                    string.Format("{0}.{1}", typeof(IPythonEngineProvider), "GetSharedEngine"),
                    new object[] { (IEngine)mockEngine });
                // Set the callback function for the ExecuteToConsole method of the engine.
                mockEngine.AddMethodCallback(
                    string.Format("{0}.{1}", typeof(IEngine).FullName, "ExecuteToConsole"),
                    new EventHandler<CallbackArgs>(ExecuteToConsoleCallback));
                // Add the engine provider to the list of the services.
                provider.AddService(typeof(IPythonEngineProvider), mockEngineProvider, false);

                // Create the console window.
                using (ToolWindowPane windowPane = CommandWindowHelper.CreateConsoleWindow(provider) as ToolWindowPane)
                {
                    // 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)));

                    // Make sure that the text marker is created.
                    CommandWindowHelper.EnsureConsoleTextMarker(windowPane);

                    // Now we have to set the frame property on the ToolWindowFrame because
                    // this will cause the execution of OnToolWindowCreated and this will add the
                    // command handling for the return key.
                    windowPane.Frame = (IVsWindowFrame)MockFactories.WindowFrameFactory.GetInstance();

                    // Simulate the cursor on a line different from the last one.
                    textViewMock.AddMethodReturnValues(
                        string.Format("{0}.{1}", typeof(IVsTextView).FullName, "GetCaretPos"),
                        new object[] { 0, 5, 8 });

                    // Execute the command handler for the RETURN key.
                    CommandTargetHelper helper = new CommandTargetHelper(windowPane as IOleCommandTarget);
                    helper.ExecCommand(typeof(Microsoft.VisualStudio.VSConstants.VSStd2KCmdID).GUID,
                                       (uint)Microsoft.VisualStudio.VSConstants.VSStd2KCmdID.RETURN);

                    // In this case nothing should happen because we are not on the input line.
                    Assert.IsTrue(0 == CommandWindowHelper.LinesInInputBuffer(windowPane));

                    // Now simulate the cursor on the input line.
                    textViewMock.AddMethodReturnValues(
                        string.Format("{0}.{1}", typeof(IVsTextView).FullName, "GetCaretPos"),
                        new object[] { 0, 12, 1 });

                    // Make sure that the mock engine can execute the command.
                    mockEngine.AddMethodReturnValues(
                        string.Format("{0}.{1}", typeof(IEngine).FullName, "ParseInteractiveInput"),
                        new object[] { true });
                    // Execute the command.
                    helper.ExecCommand(typeof(Microsoft.VisualStudio.VSConstants.VSStd2KCmdID).GUID,
                                       (uint)Microsoft.VisualStudio.VSConstants.VSStd2KCmdID.RETURN);

                    // The input buffer should not contain any text because the engine should have
                    // executed it.
                    Assert.AreEqual<int>(0, CommandWindowHelper.LinesInInputBuffer(windowPane));
                    Assert.AreEqual<string>("Test Line", (string)mockEngine["ExecutedCommand"]);

                    // Now change the length of the line so that it is shorter than the
                    // console's prompt.
                    textLinesMock.AddMethodReturnValues(
                        string.Format("{0}.{1}", typeof(IVsTextLines).FullName, "GetLengthOfLine"),
                        new object[] { 0, 0, 3 });

                    // Reset the count of the calls to GetLineText so that we can verify
                    // if it is called.
                    textLinesMock.ResetFunctionCalls(string.Format("{0}.{1}", typeof(IVsTextLines).FullName, "GetLineText"));
                    // Do the same for the ParseInteractiveInput method of the engine.
                    mockEngine.ResetFunctionCalls(string.Format("{0}.{1}", typeof(IEngine).FullName, "ParseInteractiveInput"));
                    // Simulate a partial statment.
                    mockEngine.AddMethodReturnValues(
                        string.Format("{0}.{1}", typeof(IEngine).FullName, "ParseInteractiveInput"),
                        new object[] { false });

                    // Execute again the command handler.
                    helper.ExecCommand(typeof(Microsoft.VisualStudio.VSConstants.VSStd2KCmdID).GUID,
                                       (uint)Microsoft.VisualStudio.VSConstants.VSStd2KCmdID.RETURN);

                    // Verify that GetLineText was not called.
                    Assert.IsTrue(0 == textLinesMock.FunctionCalls(string.Format("{0}.{1}", typeof(IVsTextLines).FullName, "GetLineText")));
                    // Verify that the engine was not called to run an interactive command.
                    Assert.IsTrue(1 == mockEngine.FunctionCalls(string.Format("{0}.{1}", typeof(IEngine).FullName, "ParseInteractiveInput")));
                    // Verify that the console's buffer contains an empty string.
                    Assert.IsTrue(0 == CommandWindowHelper.LinesInInputBuffer(windowPane));
                }
            }
        }
        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 ContextMenu()
        {
            using (OleServiceProvider provider = new OleServiceProvider())
            {
                // Create a mock text buffer for the console.
                BaseMock textLinesMock = MockFactories.TextBufferFactory.GetInstance();

                // Add the text buffer to the local registry
                LocalRegistryMock mockLocalRegistry = new LocalRegistryMock();
                mockLocalRegistry.AddClass(typeof(VsTextBufferClass), textLinesMock);

                // Define the mock object for the text view and add it to the local registry.
                BaseMock textViewMock = MockFactories.TextViewFactory.GetInstance();
                mockLocalRegistry.AddClass(typeof(VsTextViewClass), textViewMock);

                // Add the local registry to the list of services.
                provider.AddService(typeof(SLocalRegistry), mockLocalRegistry, false);

                // Create a mock UIShell.
                BaseMock uiShellMock = MockFactories.UIShellFactory.GetInstance();
                provider.AddService(typeof(SVsUIShell), uiShellMock, false);

                // Create the console.
                using (ToolWindowPane windowPane = CommandWindowHelper.CreateConsoleWindow(provider) as ToolWindowPane)
                {
                    // 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)));

                    // Now we have to set the frame property on the ToolWindowFrame because
                    // this will cause the execution of OnToolWindowCreated and this will add the
                    // command handlers to the console window.
                    windowPane.Frame = (IVsWindowFrame)MockFactories.WindowFrameFactory.GetInstance();

                    CommandTargetHelper helper = new CommandTargetHelper(windowPane as IOleCommandTarget);

                    // Verify that the "ShowContextMenu" command handler calls the
                    // ShowContextMenu method of IVsUIShell.
                    uiShellMock.ResetFunctionCalls(string.Format("{0}.{1}", typeof(IVsUIShell).FullName, "ShowContextMenu"));
                    helper.ExecCommand(typeof(Microsoft.VisualStudio.VSConstants.VSStd2KCmdID).GUID,
                                       (uint)Microsoft.VisualStudio.VSConstants.VSStd2KCmdID.SHOWCONTEXTMENU);
                    Assert.IsTrue(1 == uiShellMock.FunctionCalls(string.Format("{0}.{1}", typeof(IVsUIShell).FullName, "ShowContextMenu")));
                }
            }
        }
        public void VerifyOnHome()
        {
            using (OleServiceProvider provider = new OleServiceProvider())
            {
                // Create a mock text buffer for the console.
                BaseMock textLinesMock = MockFactories.CreateBufferWithMarker();

                // Add the text buffer to the local registry
                LocalRegistryMock mockLocalRegistry = new LocalRegistryMock();
                mockLocalRegistry.AddClass(typeof(VsTextBufferClass), textLinesMock);

                // Define the mock object for the text view and add it to the local registry.
                BaseMock textViewMock = MockFactories.TextViewFactory.GetInstance();
                textViewMock.AddMethodCallback(
                    string.Format("{0}.{1}", typeof(IVsTextView).FullName, "SetCaretPos"),
                    new EventHandler<CallbackArgs>(SetCaretPosCallback));
                mockLocalRegistry.AddClass(typeof(VsTextViewClass), textViewMock);

                // Add the local registry to the list of services.
                provider.AddService(typeof(SLocalRegistry), mockLocalRegistry, false);

                // Create the console.
                using (ToolWindowPane windowPane = CommandWindowHelper.CreateConsoleWindow(provider) as ToolWindowPane)
                {
                    // Make sure that the text marker is created.
                    CommandWindowHelper.EnsureConsoleTextMarker(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)));

                    // Now we have to set the frame property on the ToolWindowFrame because
                    // this will cause the execution of OnToolWindowCreated and this will add the
                    // command handling for the return key.
                    windowPane.Frame = (IVsWindowFrame)MockFactories.WindowFrameFactory.GetInstance();

                    CommandTargetHelper helper = new CommandTargetHelper(windowPane as IOleCommandTarget);

                    // Simulate the fact that the cursor is on the last line of the buffer.
                    textLinesMock.AddMethodReturnValues(
                        string.Format("{0}.{1}", typeof(IVsTextLines).FullName, "GetLineCount"),
                        new object[] { 0, 6 });
                    // Simulate a cursor 3 chars long.
                    BaseMock markerMock = (BaseMock)textLinesMock["LineMarker"];
                    TextSpan span = new TextSpan();
                    span.iEndLine = 5;
                    span.iEndIndex = 3;
                    markerMock["Span"] = span;
                    textViewMock.AddMethodReturnValues(
                        string.Format("{0}.{1}", typeof(IVsTextView).FullName, "GetCaretPos"),
                        new object[] { 0, 5, 7 });
                    helper.ExecCommand(typeof(Microsoft.VisualStudio.VSConstants.VSStd2KCmdID).GUID,
                                       (uint)Microsoft.VisualStudio.VSConstants.VSStd2KCmdID.BOL);
                    Assert.IsTrue(5 == (int)textViewMock["CaretLine"]);
                    Assert.IsTrue(3 == (int)textViewMock["CaretColumn"]);

                    // Simulate the fact that the cursor is before last line of the buffer.
                    textLinesMock.AddMethodReturnValues(
                        string.Format("{0}.{1}", typeof(IVsTextLines).FullName, "GetLineCount"),
                        new object[] { 0, 6 });
                    textViewMock.AddMethodReturnValues(
                        string.Format("{0}.{1}", typeof(IVsTextView).FullName, "GetCaretPos"),
                        new object[] { 0, 3, 7 });
                    helper.ExecCommand(typeof(Microsoft.VisualStudio.VSConstants.VSStd2KCmdID).GUID,
                                       (uint)Microsoft.VisualStudio.VSConstants.VSStd2KCmdID.BOL);
                    Assert.IsTrue(3 == (int)textViewMock["CaretLine"]);
                    Assert.IsTrue(0 == (int)textViewMock["CaretColumn"]);

                    // Simulate the fact that the cursor is after last line of the buffer.
                    textLinesMock.AddMethodReturnValues(
                        string.Format("{0}.{1}", typeof(IVsTextLines).FullName, "GetLineCount"),
                        new object[] { 0, 6 });
                    textViewMock.AddMethodReturnValues(
                        string.Format("{0}.{1}", typeof(IVsTextView).FullName, "GetCaretPos"),
                        new object[] { 0, 8, 7 });
                    helper.ExecCommand(typeof(Microsoft.VisualStudio.VSConstants.VSStd2KCmdID).GUID,
                                       (uint)Microsoft.VisualStudio.VSConstants.VSStd2KCmdID.BOL);
                    Assert.IsTrue(8 == (int)textViewMock["CaretLine"]);
                    Assert.IsTrue(0 == (int)textViewMock["CaretColumn"]);
                }
            }
        }
        public void VerifyHistoryOneElement()
        {
            using (OleServiceProvider provider = new OleServiceProvider())
            {
                // Create a mock text buffer for the console.
                BaseMock textLinesMock = MockFactories.CreateBufferWithMarker();

                // Add the text buffer to the local registry
                LocalRegistryMock mockLocalRegistry = new LocalRegistryMock();
                mockLocalRegistry.AddClass(typeof(VsTextBufferClass), textLinesMock);

                // Define the mock object for the text view and add it to the local registry.
                BaseMock textViewMock = MockFactories.TextViewFactory.GetInstance();
                mockLocalRegistry.AddClass(typeof(VsTextViewClass), textViewMock);

                // Add the local registry to the list of services.
                provider.AddService(typeof(SLocalRegistry), mockLocalRegistry, false);

                // Create the console.
                using (ToolWindowPane windowPane = CommandWindowHelper.CreateConsoleWindow(provider) as ToolWindowPane)
                {
                    // 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)));

                    // Now we have to set the frame property on the ToolWindowFrame because
                    // this will cause the execution of OnToolWindowCreated and this will add the
                    // commands handling functions.
                    windowPane.Frame = (IVsWindowFrame)MockFactories.WindowFrameFactory.GetInstance();

                    // Make sure that the text marker is created.
                    CommandWindowHelper.EnsureConsoleTextMarker(windowPane);

                    // Create the command target helper.
                    CommandTargetHelper helper = new CommandTargetHelper(windowPane as IOleCommandTarget);

                    // Add an element to the history executing a command.
                    textLinesMock.AddMethodReturnValues(
                        string.Format("{0}.{1}", typeof(IVsTextLines).FullName, "GetLineCount"),
                        new object[] { 0, 3 });
                    textViewMock.AddMethodReturnValues(
                        string.Format("{0}.{1}", typeof(IVsTextView).FullName, "GetCaretPos"),
                        new object[] { 0, 2, 4 });
                    textLinesMock.AddMethodReturnValues(
                        string.Format("{0}.{1}", typeof(IVsTextLines).FullName, "GetLengthOfLine"),
                        new object[] { 0, 3, 10 });
                    BaseMock markerMock = (BaseMock)textLinesMock["LineMarker"];
                    TextSpan span = new TextSpan();
                    span.iEndLine = 2;
                    span.iEndIndex = 4;
                    markerMock["Span"] = span;
                    textLinesMock.AddMethodReturnValues(
                        string.Format("{0}.{1}", typeof(IVsTextLines).FullName, "GetLineText"),
                        new object[] { 0, 2, 4, 2, 10, "Line 1" });
                    // Execute the OnReturn handler.
                    helper.ExecCommand(typeof(Microsoft.VisualStudio.VSConstants.VSStd2KCmdID).GUID,
                                       (uint)Microsoft.VisualStudio.VSConstants.VSStd2KCmdID.RETURN);

                    // Now there should be one element in the history buffer.
                    // Verify that DOWN key does nothing.
                    markerMock.ResetAllFunctionCalls();
                    textLinesMock.ResetAllFunctionCalls();
                    helper.ExecCommand(typeof(Microsoft.VisualStudio.VSConstants.VSStd2KCmdID).GUID,
                                       (uint)Microsoft.VisualStudio.VSConstants.VSStd2KCmdID.DOWN);
                    Assert.IsTrue(0 == markerMock.TotalCallsAllFunctions());
                    Assert.IsTrue(0 == textLinesMock.TotalCallsAllFunctions());

                    // The UP key should force the "Line 1" text in the last line of the text buffer.
                    textLinesMock.AddMethodCallback(
                        string.Format("{0}.{1}", typeof(IVsTextLines).FullName, "ReplaceLines"),
                        new EventHandler<CallbackArgs>(ReplaceLinesCallback));
                    textLinesMock["Text"] = "";
                    helper.ExecCommand(typeof(Microsoft.VisualStudio.VSConstants.VSStd2KCmdID).GUID,
                                       (uint)Microsoft.VisualStudio.VSConstants.VSStd2KCmdID.UP);
                    Assert.IsTrue(1 == textLinesMock.FunctionCalls(string.Format("{0}.{1}", typeof(IVsTextLines).FullName, "ReplaceLines")));
                    Assert.IsTrue("Line 1" == (string)textLinesMock["Text"]);
                }
            }
        }
        public void VerifyHistoryEmpty()
        {
            using (OleServiceProvider provider = new OleServiceProvider())
            {
                // Create a mock text buffer for the console.
                BaseMock textLinesMock = MockFactories.CreateBufferWithMarker();

                // Add the text buffer to the local registry
                LocalRegistryMock mockLocalRegistry = new LocalRegistryMock();
                mockLocalRegistry.AddClass(typeof(VsTextBufferClass), textLinesMock);

                // Define the mock object for the text view and add it to the local registry.
                BaseMock textViewMock = MockFactories.TextViewFactory.GetInstance();
                mockLocalRegistry.AddClass(typeof(VsTextViewClass), textViewMock);

                // Add the local registry to the list of services.
                provider.AddService(typeof(SLocalRegistry), mockLocalRegistry, false);

                // Create the console.
                using (ToolWindowPane windowPane = CommandWindowHelper.CreateConsoleWindow(provider) as ToolWindowPane)
                {
                    // 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)));

                    // Now we have to set the frame property on the ToolWindowFrame because
                    // this will cause the execution of OnToolWindowCreated and this will add the
                    // commands handling functions.
                    windowPane.Frame = (IVsWindowFrame)MockFactories.WindowFrameFactory.GetInstance();

                    // Make sure that the text marker is created.
                    CommandWindowHelper.EnsureConsoleTextMarker(windowPane);

                    // The history should be empty, so no function on the text buffer or text marker
                    // should be called. Reset all the function calls on these objects to verify.
                    BaseMock markerMock = (BaseMock)textLinesMock["LineMarker"];
                    markerMock.ResetAllFunctionCalls();
                    textLinesMock.ResetAllFunctionCalls();

                    // Create the command target helper.
                    CommandTargetHelper helper = new CommandTargetHelper(windowPane as IOleCommandTarget);

                    // Call the command handler for the UP arrow.
                    helper.ExecCommand(typeof(Microsoft.VisualStudio.VSConstants.VSStd2KCmdID).GUID,
                                       (uint)Microsoft.VisualStudio.VSConstants.VSStd2KCmdID.UP);
                    Assert.IsTrue(0 == markerMock.TotalCallsAllFunctions());
                    Assert.IsTrue(0 == textLinesMock.TotalCallsAllFunctions());

                    // Call the command handler for the DOWN arrow.
                    helper.ExecCommand(typeof(Microsoft.VisualStudio.VSConstants.VSStd2KCmdID).GUID,
                                       (uint)Microsoft.VisualStudio.VSConstants.VSStd2KCmdID.DOWN);
                    Assert.IsTrue(0 == markerMock.TotalCallsAllFunctions());
                    Assert.IsTrue(0 == textLinesMock.TotalCallsAllFunctions());
                }
            }
        }
        public void OnShiftHomeTest()
        {
            using (OleServiceProvider provider = new OleServiceProvider())
            {
                // Create a mock text buffer for the console.
                BaseMock textLinesMock = MockFactories.CreateBufferWithMarker();
                BaseMock lineMarkerMock = (BaseMock)textLinesMock["LineMarker"];

                // Add the text buffer to the local registry
                LocalRegistryMock mockLocalRegistry = new LocalRegistryMock();
                mockLocalRegistry.AddClass(typeof(VsTextBufferClass), textLinesMock);

                // Define the mock object for the text view and add it to the local registry.
                BaseMock textViewMock = MockFactories.TextViewFactory.GetInstance();
                textViewMock.AddMethodCallback(
                    string.Format("{0}.{1}", typeof(IVsTextView).FullName, "SetSelection"),
                    new EventHandler<CallbackArgs>(SetSelectionCallback));
                mockLocalRegistry.AddClass(typeof(VsTextViewClass), textViewMock);

                // Add the local registry to the list of services.
                provider.AddService(typeof(SLocalRegistry), mockLocalRegistry, false);

                // Create the console.
                using (ToolWindowPane windowPane = CommandWindowHelper.CreateConsoleWindow(provider) as ToolWindowPane)
                {
                    // Make sure that the text marker is created.
                    CommandWindowHelper.EnsureConsoleTextMarker(windowPane);

                    // Reset the span of the marker.
                    TextSpan markerSpan = new TextSpan();
                    markerSpan.iStartLine = 0;
                    markerSpan.iStartIndex = 0;
                    markerSpan.iEndLine = 4;
                    markerSpan.iEndIndex = 3;
                    lineMarkerMock["Span"] = markerSpan;

                    // 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)));

                    // Now we have to set the frame property on the ToolWindowFrame because
                    // this will cause the execution of OnToolWindowCreated and this will add the
                    // command handling for the return key.
                    windowPane.Frame = (IVsWindowFrame)MockFactories.WindowFrameFactory.GetInstance();

                    CommandTargetHelper helper = new CommandTargetHelper(windowPane as IOleCommandTarget);

                    // Set the cursor after the end of the marker, but on the same line.
                    textViewMock.AddMethodReturnValues(
                        string.Format("{0}.{1}", typeof(IVsTextView).FullName, "GetCaretPos"),
                        new object[] { 0, 4, 7 });
                    helper.ExecCommand(
                        typeof(Microsoft.VisualStudio.VSConstants.VSStd2KCmdID).GUID,
                        (int)Microsoft.VisualStudio.VSConstants.VSStd2KCmdID.BOL_EXT);
                    Assert.IsTrue(4 == (int)textViewMock["StartLine"]);
                    Assert.IsTrue(4 == (int)textViewMock["EndLine"]);
                    Assert.IsTrue(7 == (int)textViewMock["StartColumn"]);
                    Assert.IsTrue(3 == (int)textViewMock["EndColumn"]);

                    // Set the cursor before the end of the marker, but on the same line.
                    textViewMock.AddMethodReturnValues(
                        string.Format("{0}.{1}", typeof(IVsTextView).FullName, "GetCaretPos"),
                        new object[] { 0, 4, 2 });
                    helper.ExecCommand(
                        typeof(Microsoft.VisualStudio.VSConstants.VSStd2KCmdID).GUID,
                        (int)Microsoft.VisualStudio.VSConstants.VSStd2KCmdID.BOL_EXT);
                    Assert.IsTrue(4 == (int)textViewMock["StartLine"]);
                    Assert.IsTrue(4 == (int)textViewMock["EndLine"]);
                    Assert.IsTrue(2 == (int)textViewMock["StartColumn"]);
                    Assert.IsTrue(0 == (int)textViewMock["EndColumn"]);

                    // Set the cursor before the end of the marker, on a different line.
                    textViewMock.AddMethodReturnValues(
                        string.Format("{0}.{1}", typeof(IVsTextView).FullName, "GetCaretPos"),
                        new object[] { 0, 2, 8 });
                    helper.ExecCommand(
                        typeof(Microsoft.VisualStudio.VSConstants.VSStd2KCmdID).GUID,
                        (int)Microsoft.VisualStudio.VSConstants.VSStd2KCmdID.BOL_EXT);
                    Assert.IsTrue(2 == (int)textViewMock["StartLine"]);
                    Assert.IsTrue(2 == (int)textViewMock["EndLine"]);
                    Assert.IsTrue(8 == (int)textViewMock["StartColumn"]);
                    Assert.IsTrue(0 == (int)textViewMock["EndColumn"]);

                    // Set the cursor after the end of the marker, on a different line.
                    textViewMock.AddMethodReturnValues(
                        string.Format("{0}.{1}", typeof(IVsTextView).FullName, "GetCaretPos"),
                        new object[] { 0, 9, 12 });
                    helper.ExecCommand(
                        typeof(Microsoft.VisualStudio.VSConstants.VSStd2KCmdID).GUID,
                        (int)Microsoft.VisualStudio.VSConstants.VSStd2KCmdID.BOL_EXT);
                    Assert.IsTrue(9 == (int)textViewMock["StartLine"]);
                    Assert.IsTrue(9 == (int)textViewMock["EndLine"]);
                    Assert.IsTrue(12 == (int)textViewMock["StartColumn"]);
                    Assert.IsTrue(0 == (int)textViewMock["EndColumn"]);
                }
            }
        }
        public void OnClearPaneOnlyOneLine()
        {
            using (OleServiceProvider provider = new OleServiceProvider())
            {
                // Create a mock text buffer for the console.
                BaseMock textLinesMock = MockFactories.CreateBufferWithMarker();
                BaseMock lineMarkerMock = (BaseMock)textLinesMock["LineMarker"];

                // Add the text buffer to the local registry
                LocalRegistryMock mockLocalRegistry = new LocalRegistryMock();
                mockLocalRegistry.AddClass(typeof(VsTextBufferClass), textLinesMock);

                // Define the mock object for the text view and add it to the local registry.
                BaseMock textViewMock = MockFactories.TextViewFactory.GetInstance();
                mockLocalRegistry.AddClass(typeof(VsTextViewClass), textViewMock);

                // Add the local registry to the list of services.
                provider.AddService(typeof(SLocalRegistry), mockLocalRegistry, false);

                // Create the console.
                using (ToolWindowPane windowPane = CommandWindowHelper.CreateConsoleWindow(provider) as ToolWindowPane)
                {
                    // Make sure that the text marker is created.
                    CommandWindowHelper.EnsureConsoleTextMarker(windowPane);

                    // Reset the span of the marker.
                    TextSpan markerSpan = new TextSpan();
                    markerSpan.iStartLine = 0;
                    markerSpan.iStartIndex = 0;
                    markerSpan.iEndLine = 0;
                    markerSpan.iEndIndex = 3;
                    lineMarkerMock["Span"] = markerSpan;

                    // 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)));

                    // Now we have to set the frame property on the ToolWindowFrame because
                    // this will cause the execution of OnToolWindowCreated and this will add the
                    // command handling for the return key.
                    windowPane.Frame = (IVsWindowFrame)MockFactories.WindowFrameFactory.GetInstance();

                    CommandTargetHelper helper = new CommandTargetHelper(windowPane as IOleCommandTarget);

                    // Set the last index of the buffer before the end of the line marker.
                    textLinesMock.AddMethodReturnValues(
                        string.Format("{0}.{1}", typeof(IVsTextLines).FullName, "GetLastLineIndex"),
                        new object[] { 0, 0, 2 });
                    // Reset the counters of function calls for the text buffer.
                    textLinesMock.ResetAllFunctionCalls();
                    // Execute the "Clear" command.
                    helper.ExecCommand(typeof(Microsoft.VisualStudio.VSConstants.VSStd97CmdID).GUID,
                                       (uint)Microsoft.VisualStudio.VSConstants.VSStd97CmdID.ClearPane);
                    // Verify that ReplaceLines wan never called.
                    Assert.IsTrue(0 == textLinesMock.FunctionCalls(string.Format("{0}.{1}", typeof(IVsTextLines).FullName, "ReplaceLines")));

                    // Set the last index of the buffer after the end of the line marker.
                    textLinesMock.AddMethodReturnValues(
                        string.Format("{0}.{1}", typeof(IVsTextLines).FullName, "GetLastLineIndex"),
                        new object[] { 0, 2, 1 });
                    textLinesMock.AddMethodCallback(
                        string.Format("{0}.{1}", typeof(IVsTextLines).FullName, "ReplaceLines"),
                        new EventHandler<CallbackArgs>(ReplaceLinesCallback_ClearPane));
                    textLinesMock["ReplaceRegion"] = new int[] { 0, 3, 2, 1 };
                    textLinesMock["CallCount"] = 0;
                    // Reset the counters of function calls for the text buffer.
                    textLinesMock.ResetAllFunctionCalls();
                    // Execute the "Clear" command.
                    helper.ExecCommand(typeof(Microsoft.VisualStudio.VSConstants.VSStd97CmdID).GUID,
                                       (uint)Microsoft.VisualStudio.VSConstants.VSStd97CmdID.ClearPane);
                    // Verify that ReplaceLines wan called only once.
                    Assert.IsTrue(1 == textLinesMock.FunctionCalls(string.Format("{0}.{1}", typeof(IVsTextLines).FullName, "ReplaceLines")));
                }
            }
        }
        public void InputPositionCommand()
        {
            using (OleServiceProvider provider = new OleServiceProvider())
            {
                // Create a mock text buffer for the console.
                BaseMock textLinesMock = MockFactories.CreateBufferWithMarker();
                BaseMock lineMarkerMock = (BaseMock)textLinesMock["LineMarker"];

                // Add the text buffer to the local registry
                LocalRegistryMock mockLocalRegistry = new LocalRegistryMock();
                mockLocalRegistry.AddClass(typeof(VsTextBufferClass), textLinesMock);

                // Define the mock object for the text view and add it to the local registry.
                BaseMock textViewMock = MockFactories.TextViewFactory.GetInstance();
                mockLocalRegistry.AddClass(typeof(VsTextViewClass), textViewMock);

                // Add the local registry to the list of services.
                provider.AddService(typeof(SLocalRegistry), mockLocalRegistry, false);

                // Create the console.
                using (ToolWindowPane windowPane = CommandWindowHelper.CreateConsoleWindow(provider) as ToolWindowPane)
                {
                    // 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)));

                    // Now we have to set the frame property on the ToolWindowFrame because
                    // this will cause the execution of OnToolWindowCreated and this will add the
                    // command handling for the return key.
                    windowPane.Frame = (IVsWindowFrame)MockFactories.WindowFrameFactory.GetInstance();

                    // Make sure that the text marker is created.
                    CommandWindowHelper.EnsureConsoleTextMarker(windowPane);

                    // Reset the span of the marker.
                    TextSpan markerSpan = new TextSpan();
                    markerSpan.iStartLine = 0;
                    markerSpan.iStartIndex = 0;
                    markerSpan.iEndLine = 4;
                    markerSpan.iEndIndex = 3;
                    lineMarkerMock["Span"] = markerSpan;

                    // Create the helper class to handle the command target implemented
                    // by the console.
                    CommandTargetHelper helper = new CommandTargetHelper((IOleCommandTarget)windowPane);

                    // Simulate the fact that the cursor is after the end of the marker.
                    textViewMock.AddMethodReturnValues(
                        string.Format("{0}.{1}", typeof(IVsTextView).FullName, "GetCaretPos"),
                        new object[] { 0, 4, 7 });
                    // Verify that the commands are supported.
                    uint flags;
                    Assert.IsTrue(
                        helper.IsCommandSupported(
                            typeof(Microsoft.VisualStudio.VSConstants.VSStd2KCmdID).GUID,
                            (int)Microsoft.VisualStudio.VSConstants.VSStd2KCmdID.UP,
                            out flags));
                    Assert.IsTrue(
                        helper.IsCommandSupported(
                            typeof(Microsoft.VisualStudio.VSConstants.VSStd2KCmdID).GUID,
                            (int)Microsoft.VisualStudio.VSConstants.VSStd2KCmdID.DOWN,
                            out flags));
                    Assert.IsTrue(
                        helper.IsCommandSupported(
                            typeof(Microsoft.VisualStudio.VSConstants.VSStd2KCmdID).GUID,
                            (int)Microsoft.VisualStudio.VSConstants.VSStd2KCmdID.BOL_EXT,
                            out flags));

                    // Simulate the cursor on the last line, but before the end of the marker.
                    textViewMock.AddMethodReturnValues(
                        string.Format("{0}.{1}", typeof(IVsTextView).FullName, "GetCaretPos"),
                        new object[] { 0, 4, 2 });
                    Assert.IsFalse(
                        helper.IsCommandSupported(
                            typeof(Microsoft.VisualStudio.VSConstants.VSStd2KCmdID).GUID,
                            (int)Microsoft.VisualStudio.VSConstants.VSStd2KCmdID.UP,
                            out flags));
                    Assert.IsFalse(
                        helper.IsCommandSupported(
                            typeof(Microsoft.VisualStudio.VSConstants.VSStd2KCmdID).GUID,
                            (int)Microsoft.VisualStudio.VSConstants.VSStd2KCmdID.DOWN,
                            out flags));
                    Assert.IsFalse(
                        helper.IsCommandSupported(
                            typeof(Microsoft.VisualStudio.VSConstants.VSStd2KCmdID).GUID,
                            (int)Microsoft.VisualStudio.VSConstants.VSStd2KCmdID.BOL_EXT,
                            out flags));

                    // Simulate the cursor on a line before the end of the marker.
                    textViewMock.AddMethodReturnValues(
                        string.Format("{0}.{1}", typeof(IVsTextView).FullName, "GetCaretPos"),
                        new object[] { 0, 1, 7 });
                    Assert.IsFalse(
                        helper.IsCommandSupported(
                            typeof(Microsoft.VisualStudio.VSConstants.VSStd2KCmdID).GUID,
                            (int)Microsoft.VisualStudio.VSConstants.VSStd2KCmdID.UP,
                            out flags));
                    Assert.IsFalse(
                        helper.IsCommandSupported(
                            typeof(Microsoft.VisualStudio.VSConstants.VSStd2KCmdID).GUID,
                            (int)Microsoft.VisualStudio.VSConstants.VSStd2KCmdID.DOWN,
                            out flags));
                    Assert.IsFalse(
                        helper.IsCommandSupported(
                            typeof(Microsoft.VisualStudio.VSConstants.VSStd2KCmdID).GUID,
                            (int)Microsoft.VisualStudio.VSConstants.VSStd2KCmdID.BOL_EXT,
                            out flags));

                    // Simulate the cursor on a line after the last.
                    textViewMock.AddMethodReturnValues(
                        string.Format("{0}.{1}", typeof(IVsTextView).FullName, "GetCaretPos"),
                        new object[] { 0, 5, 7 });
                    Assert.IsTrue(
                        helper.IsCommandSupported(
                            typeof(Microsoft.VisualStudio.VSConstants.VSStd2KCmdID).GUID,
                            (int)Microsoft.VisualStudio.VSConstants.VSStd2KCmdID.UP,
                            out flags));
                    Assert.IsTrue(
                        helper.IsCommandSupported(
                            typeof(Microsoft.VisualStudio.VSConstants.VSStd2KCmdID).GUID,
                            (int)Microsoft.VisualStudio.VSConstants.VSStd2KCmdID.DOWN,
                            out flags));
                    Assert.IsTrue(
                        helper.IsCommandSupported(
                            typeof(Microsoft.VisualStudio.VSConstants.VSStd2KCmdID).GUID,
                            (int)Microsoft.VisualStudio.VSConstants.VSStd2KCmdID.BOL_EXT,
                            out flags));
                }
            }
        }