public async Task CanRegisterAndInvokeCommandWithCmdletName()
        {
            await extensionService.PowerShellContext.ExecuteScriptStringAsync(
                TestUtilities.NormalizeNewlines("function Invoke-Extension { $global:extensionValue = 5 }\n") +
                "Register-EditorCommand -Name \"test.function\" -DisplayName \"Function extension\" -Function \"Invoke-Extension\"");

            // Wait for the add event
            EditorCommand command = await this.AssertExtensionEvent(EventType.Add, "test.function");

            // Invoke the command
            await extensionService.InvokeCommandAsync("test.function", this.commandContext);

            // Assert the expected value
            PSCommand psCommand = new PSCommand();

            psCommand.AddScript("$global:extensionValue");
            var results = await powerShellContext.ExecuteCommandAsync <int>(psCommand);

            Assert.Equal(5, results.FirstOrDefault());
        }
Пример #2
0
        public async Task <Unit> Handle(InvokeExtensionCommandParams request, CancellationToken cancellationToken)
        {
            // We can now await here because we handle asynchronous message handling.
            EditorContext editorContext =
                _editorOperationsService.ConvertClientEditorContext(
                    request.Context);

            await _extensionService.InvokeCommandAsync(
                request.Name,
                editorContext).ConfigureAwait(false);

            return(await Unit.Task.ConfigureAwait(false));
        }
 public Task InvokeCommandAsync(string commandName, EditorContext editorContext) => _extensionService.InvokeCommandAsync(commandName, editorContext);
 public Task InvokeCommandAsync(string commandName, EditorContext editorContext) => _extensionService.InvokeCommandAsync(commandName, editorContext, CancellationToken.None);