Esempio n. 1
0
        public async Task CanRegisterAndInvokeCommandWithCmdletName()
        {
            await extensionService.PowerShellContext.ExecuteScriptString(
                "function Invoke-Extension { $global:extensionValue = 5 }\r\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.InvokeCommand("test.function", this.commandContext);

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

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

            Assert.Equal(5, results.FirstOrDefault());
        }