public void When_duplicate_suggestions_are_registered_the_last_one_is_used()
        {
            ISuggestionRegistration suggestionProvider = GetSuggestionRegistration();

            suggestionProvider.AddSuggestionRegistration(
                new RegistrationPair(Path.GetFullPath("commandPath"), "suggestionCommand2"));

            suggestionProvider.AddSuggestionRegistration(
                new RegistrationPair(Path.GetFullPath("commandPath"), "suggestionCommand2"));

            RegistrationPair registration = suggestionProvider.FindRegistration(new FileInfo("commandPath"));

            registration.CommandPath.Should().Be(Path.GetFullPath("commandPath"));
            registration.SuggestionCommand.Should().Be("suggestionCommand2");
        }
Exemple #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);
        }
        public void Suggestion_command_path_is_not_case_sensitive()
        {
            ISuggestionRegistration suggestionProvider = GetSuggestionRegistration();

            suggestionProvider.AddSuggestionRegistration(
                new Registration(Path.GetFullPath("commandPath")));

            Registration registration = suggestionProvider.FindRegistration(new FileInfo("COMMANDPATH"));

            registration.ExecutablePath.Should().Be(Path.GetFullPath("commandPath"));
        }
        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);
        }
        private void Register(string commandPath, string suggestionCommand, IConsole console)
        {
            var existingRegistration = _suggestionRegistration.FindRegistration(
                new FileInfo(commandPath)
                );

            if (existingRegistration == null)
            {
                _suggestionRegistration.AddSuggestionRegistration(new Registration(commandPath));

                console.Out.WriteLine($"Registered {commandPath}");
            }
            else
            {
                console.Out.WriteLine($"Registered {commandPath}");
            }
        }
Exemple #6
0
        public void Added_suggestion_can_be_found()
        {
            ISuggestionRegistration suggestionProvider = GetSuggestionRegistration();

            var path = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

            try
            {
                Directory.CreateDirectory(path);
                var registeredFile = Path.Combine(path, "im-registered");
                File.WriteAllText(registeredFile, "");

                suggestionProvider.AddSuggestionRegistration(new Registration(registeredFile));
                var foundRegistration = suggestionProvider.FindRegistration(
                    new FileInfo(registeredFile)
                    );

                foundRegistration.Should().NotBeNull();
            }
            finally
            {
                Directory.Delete(path, true);
            }
        }