private static string ShellPrefixesToMatch(ISuggestionRegistration suggestionProvider)
        {
            var registrations = suggestionProvider.FindAllRegistrations();

            return(string.Join(Environment.NewLine, Prefixes()));

            IEnumerable <string> Prefixes()
            {
                foreach (var r in registrations)
                {
                    var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(
                        r.ExecutablePath
                        );

                    yield return(fileNameWithoutExtension);

                    if (
                        fileNameWithoutExtension?.StartsWith("dotnet-", StringComparison.Ordinal)
                        == true
                        )
                    {
                        yield return("dotnet "
                                     + fileNameWithoutExtension.Substring("dotnet-".Length));
                    }
                }
            }
        }
Beispiel #2
0
        public void Added_suggestions_can_be_retrieved()
        {
            ISuggestionRegistration suggestionProvider = GetSuggestionRegistration();

            var suggestion1 = new Registration("commandPath1");
            var suggestion2 = new Registration("commandPath2");

            suggestionProvider.AddSuggestionRegistration(suggestion1);
            suggestionProvider.AddSuggestionRegistration(suggestion2);

            var allRegistrations = suggestionProvider.FindAllRegistrations();

            allRegistrations
            .Should()
            .HaveCount(2)
            .And.Contain(x => x.ExecutablePath == suggestion1.ExecutablePath)
            .And.Contain(x => x.ExecutablePath == suggestion2.ExecutablePath);
        }
        private static string List(
            ISuggestionRegistration suggestionProvider,
            bool detailed = false)
        {
            var registrations = suggestionProvider.FindAllRegistrations();

            if (detailed)
            {
                return(string.Join(Environment.NewLine,
                                   registrations.Select(r => $"{r.CommandPath} --> {r.SuggestionCommand}")));
            }
            else
            {
                return(string.Join(" ", registrations
                                   .Select(suggestionRegistration => suggestionRegistration.CommandPath)
                                   .Select(Path.GetFileNameWithoutExtension)));
            }
        }
        public void Added_suggestions_can_be_retrieved()
        {
            ISuggestionRegistration suggestionProvider = GetSuggestionRegistration();

            var suggestion1 = new RegistrationPair("commandPath1", "suggestionCommand1");
            var suggestion2 = new RegistrationPair("commandPath2", "suggestionCommand2");

            suggestionProvider.AddSuggestionRegistration(suggestion1);
            suggestionProvider.AddSuggestionRegistration(suggestion2);

            var allRegistrations = suggestionProvider.FindAllRegistrations();

            allRegistrations
            .Should()
            .HaveCount(2)
            .And
            .Contain(x =>
                     x.CommandPath == suggestion1.CommandPath && x.SuggestionCommand == suggestion1.SuggestionCommand)
            .And
            .Contain(x =>
                     x.CommandPath == suggestion2.CommandPath && x.SuggestionCommand == suggestion2.SuggestionCommand);
        }