Beispiel #1
0
        public void ExpansionControllerTest()
        {
            var textBuffer = new TextBufferMock("if", RContentTypeDefinition.ContentType);
            var textView   = new TextViewMock(textBuffer);
            var o          = new object();

            var controller = new ExpansionsController(textView, textBuffer, _expansionManager, _cache);

            controller.Status(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.INSERTSNIPPET).Should().Be(CommandStatus.SupportedAndEnabled);
            controller.Status(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.SURROUNDWITH).Should().Be(CommandStatus.SupportedAndEnabled);

            controller.Invoke(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.RETURN, null, ref o).Should().Be(CommandResult.NotSupported);
            controller.Invoke(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.BACKTAB, null, ref o).Should().Be(CommandResult.NotSupported);
            controller.Invoke(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.CANCEL, null, ref o).Should().Be(CommandResult.NotSupported);

            textView.Caret.MoveTo(new SnapshotPoint(textView.TextBuffer.CurrentSnapshot, 2));
            bool inserted;

            var client = controller.ExpansionClient as ExpansionClient;

            client.StartSnippetInsertion(out inserted);

            controller.Status(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.INSERTSNIPPET).Should().Be(CommandStatus.SupportedAndEnabled);
            controller.Status(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.SURROUNDWITH).Should().Be(CommandStatus.SupportedAndEnabled);

            client.Session.Should().NotBeNull();
            var session = client.Session;
            var mock    = session as VsExpansionSessionMock;

            controller.Invoke(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.TAB, null, ref o).Should().Be(CommandResult.Executed);
            mock.ExpansionFieldIndex.Should().Be(1);

            controller.Invoke(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.BACKTAB, null, ref o).Should().Be(CommandResult.Executed);
            mock.ExpansionFieldIndex.Should().Be(0);

            client.EndExpansion();
        }