protected void Create(bool insertMode, params string[] lines)
        {
            _factory = new MockRepository(MockBehavior.Strict);
            _factory.DefaultValue = DefaultValue.Mock;
            _textView             = CreateTextView(lines);
            _textBuffer           = _textView.TextBuffer;
            _vim               = _factory.Create <IVim>(MockBehavior.Loose);
            _editorOptions     = _factory.Create <IEditorOptions>(MockBehavior.Loose);
            _textChangeTracker = _factory.Create <ITextChangeTracker>(MockBehavior.Loose);
            _textChangeTracker.SetupGet(x => x.CurrentChange).Returns(FSharpOption <TextChange> .None);
            _undoRedoOperations = new UndoRedoOperations(VimHost, new StatusUtil(), FSharpOption <ITextUndoHistory> .None, null);
            _wordCompletionSessionFactoryService = _factory.Create <IWordCompletionSessionFactoryService>();

            var localSettings = new LocalSettings(Vim.GlobalSettings);

            _vimBuffer      = Vim.CreateVimBuffer(_textView);
            _globalSettings = _vimBuffer.GlobalSettings;
            var vimTextBuffer = Vim.GetOrCreateVimTextBuffer(_textView.TextBuffer);
            var vimBufferData = CreateVimBufferData(vimTextBuffer, _textView);

            _operations = CommonOperationsFactory.GetCommonOperations(vimBufferData);
            _broker     = _factory.Create <IDisplayWindowBroker>();
            _broker.SetupGet(x => x.IsCompletionActive).Returns(false);
            _broker.SetupGet(x => x.IsQuickInfoActive).Returns(false);
            _broker.SetupGet(x => x.IsSignatureHelpActive).Returns(false);
            _broker.SetupGet(x => x.IsSmartTagSessionActive).Returns(false);
            _insertUtil  = _factory.Create <IInsertUtil>();
            _motionUtil  = _factory.Create <IMotionUtil>();
            _commandUtil = _factory.Create <ICommandUtil>();
            _capture     = _factory.Create <IMotionCapture>();

            // Setup the mouse.  By default we say it has no buttons down as that's the normal state
            _mouseDevice = _factory.Create <IMouseDevice>();
            _mouseDevice.SetupGet(x => x.IsLeftButtonPressed).Returns(false);

            // Setup the keyboard.  By default we don't say that any button is pressed.  Insert mode is usually
            // only concerned with arrow keys and we will set those up as appropriate for the typing tests
            _keyboardDevice = _factory.Create <IKeyboardDevice>();
            _keyboardDevice.Setup(x => x.IsArrowKeyDown).Returns(false);

            _modeRaw = new global::Vim.Modes.Insert.InsertMode(
                _vimBuffer,
                _operations,
                _broker.Object,
                _editorOptions.Object,
                _undoRedoOperations,
                _textChangeTracker.Object,
                _insertUtil.Object,
                _motionUtil.Object,
                _commandUtil.Object,
                _capture.Object,
                !insertMode,
                _keyboardDevice.Object,
                _mouseDevice.Object,
                WordUtil,
                _wordCompletionSessionFactoryService.Object);
            _mode = _modeRaw;
            _mode.OnEnter(ModeArgument.None);
            _mode.CommandRan += (sender, e) => { _lastCommandRan = e.CommandRunData; };
        }
Example #2
0
 public void RaiseCommandRan(CommandRunData data, CommandResult result)
 {
     var e = CommandRan;
     if (e != null)
     {
         e(this, Tuple.Create(data, result));
     }
 }
        public IEnumerable <string> GetArgValidationErrors()
        {
            var errors = new List <string>();

            if (List)
            {
                return(errors);
            }

            if (!ShowDefaults && Account == ServiceAccount.User)
            {
                if (string.IsNullOrWhiteSpace(Username))
                {
                    errors.Add("user is required when account=User");
                }
                if (string.IsNullOrWhiteSpace(Password))
                {
                    errors.Add("pwd is required when account=User");
                }
            }

            if (string.IsNullOrWhiteSpace(CommandLine))
            {
                errors.Add("command is required");
            }
            else
            {
                if (ExtraArgs.Count > 0)
                {
                    CommandLine = CommandLine.TrimEnd() + " " + string.Join(" ", ExtraArgs);
                    ExtraArgs.Clear();
                }

                _commandRunData = CommandsOptions.Load(CommandLine);

                if (_commandRunData.Errors.Count > 0)
                {
                    errors.Add("errors with arguments for /command");
                    errors.AddRange(_commandRunData.Errors);
                }
                else
                {
                    _serviceCommand = _commandRunData.Command as ICanRunAsService;
                    if (_serviceCommand == null)
                    {
                        errors.Add(_commandRunData.Command.GetType().Name + " does not implement ICanRunAsService");
                    }
                    else
                    {
                        ServiceName = ServiceName ?? _serviceCommand.ServiceName;
                        DisplayName = DisplayName ?? _serviceCommand.DisplayName;
                        Description = Description ?? _serviceCommand.Description;
                    }
                }
            }
            return(errors);
        }
Example #4
0
        private void Create(bool insertMode, params string[] lines)
        {
            _factory = new MockRepository(MockBehavior.Strict);
            _factory.DefaultValue = DefaultValue.Mock;
            _textView             = CreateTextView(lines);
            _textBuffer           = _textView.TextBuffer;
            _vim               = _factory.Create <IVim>(MockBehavior.Loose);
            _editorOptions     = _factory.Create <IEditorOptions>(MockBehavior.Loose);
            _textChangeTracker = _factory.Create <ITextChangeTracker>(MockBehavior.Loose);
            _textChangeTracker.SetupGet(x => x.CurrentChange).Returns(FSharpOption <TextChange> .None);
            _undoRedoOperations = _factory.Create <IUndoRedoOperations>();
            _wordCompletionSessionFactoryService = _factory.Create <IWordCompletionSessionFactoryService>();

            var localSettings = new LocalSettings(Vim.GlobalSettings);

            _vimBuffer = MockObjectFactory.CreateVimBuffer(
                _textView,
                localSettings: localSettings,
                vim: _vim.Object,
                factory: _factory);
            _vimBuffer.SetupGet(x => x.ModeKind).Returns(ModeKind.Insert);
            _operations = _factory.Create <ICommonOperations>();
            _operations.SetupGet(x => x.EditorOperations).Returns(EditorUtil.FactoryService.EditorOperationsFactory.GetEditorOperations(_textView));
            _broker = _factory.Create <IDisplayWindowBroker>();
            _broker.SetupGet(x => x.IsCompletionActive).Returns(false);
            _broker.SetupGet(x => x.IsQuickInfoActive).Returns(false);
            _broker.SetupGet(x => x.IsSignatureHelpActive).Returns(false);
            _insertUtil = _factory.Create <IInsertUtil>();

            // Setup the mouse.  By default we say it has no buttons down as that's the normal state
            _mouseDevice = _factory.Create <IMouseDevice>();
            _mouseDevice.SetupGet(x => x.IsLeftButtonPressed).Returns(false);

            // Setup the keyboard.  By default we don't say that any button is pressed.  Insert mode is usually
            // only concerned with arrow keys and we will set those up as appropriate for the typing tests
            _keyboardDevice = _factory.Create <IKeyboardDevice>();
            _keyboardDevice.Setup(x => x.IsKeyDown(It.IsAny <VimKey>())).Returns(false);

            _modeRaw = new Vim.Modes.Insert.InsertMode(
                _vimBuffer.Object,
                _operations.Object,
                _broker.Object,
                _editorOptions.Object,
                _undoRedoOperations.Object,
                _textChangeTracker.Object,
                _insertUtil.Object,
                !insertMode,
                _keyboardDevice.Object,
                _mouseDevice.Object,
                EditorUtil.FactoryService.WordUtilFactory.GetWordUtil(_textView.TextBuffer),
                _wordCompletionSessionFactoryService.Object);
            _mode             = _modeRaw;
            _mode.CommandRan += (sender, e) => { _lastCommandRan = e; };
        }
Example #5
0
        protected void Create(bool insertMode, params string[] lines)
        {
            _factory = new MockRepository(MockBehavior.Strict);
            _factory.DefaultValue = DefaultValue.Mock;
            _textView = CreateTextView(lines);
            _textBuffer = _textView.TextBuffer;
            _vim = _factory.Create<IVim>(MockBehavior.Loose);
            _editorOptions = _factory.Create<IEditorOptions>(MockBehavior.Loose);
            _textChangeTracker = _factory.Create<ITextChangeTracker>(MockBehavior.Loose);
            _textChangeTracker.SetupGet(x => x.CurrentChange).Returns(FSharpOption<TextChange>.None);
            _undoRedoOperations = CreateUndoRedoOperations();
            _wordCompletionSessionFactoryService = _factory.Create<IWordCompletionSessionFactoryService>();

            var localSettings = new LocalSettings(Vim.GlobalSettings);
            _vimBuffer = Vim.CreateVimBuffer(_textView);
            _globalSettings = _vimBuffer.GlobalSettings;
            var vimTextBuffer = Vim.GetOrCreateVimTextBuffer(_textView.TextBuffer);
            var vimBufferData = CreateVimBufferData(vimTextBuffer, _textView);
            _operations = CommonOperationsFactory.GetCommonOperations(vimBufferData);
            _broker = _factory.Create<IDisplayWindowBroker>();
            _broker.SetupGet(x => x.IsCompletionActive).Returns(false);
            _broker.SetupGet(x => x.IsQuickInfoActive).Returns(false);
            _broker.SetupGet(x => x.IsSignatureHelpActive).Returns(false);
            _broker.SetupGet(x => x.IsSmartTagSessionActive).Returns(false);
            _insertUtil = _factory.Create<IInsertUtil>();
            _motionUtil = _factory.Create<IMotionUtil>();
            _commandUtil = _factory.Create<ICommandUtil>();
            _capture = _factory.Create<IMotionCapture>();

            // Setup the mouse.  By default we say it has no buttons down as that's the normal state
            _mouseDevice = _factory.Create<IMouseDevice>();
            _mouseDevice.SetupGet(x => x.IsLeftButtonPressed).Returns(false);

            // Setup the keyboard.  By default we don't say that any button is pressed.  Insert mode is usually
            // only concerned with arrow keys and we will set those up as appropriate for the typing tests
            _keyboardDevice = _factory.Create<IKeyboardDevice>();
            _keyboardDevice.Setup(x => x.IsArrowKeyDown).Returns(false);

            _modeRaw = new global::Vim.Modes.Insert.InsertMode(
                _vimBuffer,
                _operations,
                _broker.Object,
                _editorOptions.Object,
                _undoRedoOperations,
                _textChangeTracker.Object,
                _insertUtil.Object,
                _motionUtil.Object,
                _commandUtil.Object,
                _capture.Object,
                !insertMode,
                _keyboardDevice.Object,
                _mouseDevice.Object,
                WordUtil,
                _wordCompletionSessionFactoryService.Object);
            _mode = _modeRaw;
            _mode.OnEnter(ModeArgument.None);
            _mode.CommandRan += (sender, e) => { _lastCommandRan = e.CommandRunData; };
        }
        public IEnumerable<string> GetArgValidationErrors()
        {
            var errors = new List<string>();
            if (List)
            {
                return errors;
            }

            if (!ShowDefaults && Account == ServiceAccount.User)
            {
                if (string.IsNullOrWhiteSpace(Username))
                {
                    errors.Add("user is required when account=User");
                }
                if (string.IsNullOrWhiteSpace(Password))
                {
                    errors.Add("pwd is required when account=User");
                }
            }

            if (string.IsNullOrWhiteSpace(CommandLine))
            {
                errors.Add("command is required");
            }
            else
            {
                if (ExtraArgs.Count > 0)
                {
                    CommandLine = CommandLine.TrimEnd() + " " + string.Join(" ", ExtraArgs);
                    ExtraArgs.Clear();
                }

                _commandRunData = CommandsOptions.Load(CommandLine);

                if (_commandRunData.Errors.Count > 0)
                {
                    errors.Add("errors with arguments for /command");
                    errors.AddRange(_commandRunData.Errors);
                }
                else
                {
                    _serviceCommand = _commandRunData.Command as ICanRunAsService;
                    if (_serviceCommand == null)
                    {
                        errors.Add(_commandRunData.Command.GetType().Name + " does not implement ICanRunAsService");
                    }
                    else
                    {
                        ServiceName = ServiceName ?? _serviceCommand.ServiceName;
                        DisplayName = DisplayName ?? _serviceCommand.DisplayName;
                        Description = Description ?? _serviceCommand.Description;
                    }
                }
            }
            return errors;
        }
Example #7
0
 public void TearDown()
 {
     _lastCommandRan = null;
 }
Example #8
0
 public void TearDown()
 {
     _lastCommandRan = null;
 }
Example #9
0
        private void Create(bool insertMode, params string[] lines)
        {
            _factory = new MockRepository(MockBehavior.Strict);
            _factory.DefaultValue = DefaultValue.Mock;
            _textView = EditorUtil.CreateTextView(lines);
            _textBuffer = _textView.TextBuffer;
            _vim = _factory.Create<IVim>(MockBehavior.Loose);
            _editorOptions = _factory.Create<IEditorOptions>(MockBehavior.Loose);
            _globalSettings = _factory.Create<IVimGlobalSettings>();
            _globalSettings.SetupGet(x => x.IgnoreCase).Returns(true);
            _localSettings = _factory.Create<IVimLocalSettings>();
            _localSettings.SetupGet(x => x.GlobalSettings).Returns(_globalSettings.Object);
            _textChangeTracker = _factory.Create<ITextChangeTracker>(MockBehavior.Loose);
            _textChangeTracker.SetupGet(x => x.CurrentChange).Returns(FSharpOption<TextChange>.None);
            _undoRedoOperations = _factory.Create<IUndoRedoOperations>();
            _wordCompletionSessionFactoryService = _factory.Create<IWordCompletionSessionFactoryService>();

            _vimBuffer = MockObjectFactory.CreateVimBuffer(
                _textView,
                localSettings: _localSettings.Object,
                vim: _vim.Object,
                factory: _factory);
            _operations = _factory.Create<ICommonOperations>();
            _operations.SetupGet(x => x.EditorOperations).Returns(EditorUtil.FactoryService.EditorOperationsFactory.GetEditorOperations(_textView));
            _broker = _factory.Create<IDisplayWindowBroker>();
            _broker.SetupGet(x => x.IsCompletionActive).Returns(false);
            _broker.SetupGet(x => x.IsQuickInfoActive).Returns(false);
            _broker.SetupGet(x => x.IsSignatureHelpActive).Returns(false);
            _insertUtil = _factory.Create<IInsertUtil>();

            // Setup the mouse.  By default we say it has no buttons down as that's the normal state
            _mouseDevice = _factory.Create<IMouseDevice>();
            _mouseDevice.SetupGet(x => x.IsLeftButtonPressed).Returns(false);

            // Setup the keyboard.  By default we don't say that any button is pressed.  Insert mode is usually
            // only concerned with arrow keys and we will set those up as appropriate for the typing tests
            _keyboardDevice = _factory.Create<IKeyboardDevice>();
            _keyboardDevice.Setup(x => x.IsKeyDown(It.IsAny<VimKey>())).Returns(false);

            _modeRaw = new Vim.Modes.Insert.InsertMode(
                _vimBuffer.Object,
                _operations.Object,
                _broker.Object,
                _editorOptions.Object,
                _undoRedoOperations.Object,
                _textChangeTracker.Object,
                _insertUtil.Object,
                !insertMode,
                _keyboardDevice.Object,
                _mouseDevice.Object,
                EditorUtil.FactoryService.WordUtilFactory.GetWordUtil(_textView.TextBuffer),
                _wordCompletionSessionFactoryService.Object);
            _mode = _modeRaw;
            _mode.CommandRan += (sender, e) => { _lastCommandRan = e; };
        }