diff --git a/Scenarios.md b/Scenarios.md index c02f1a835a..f016d4bfe9 100644 --- a/Scenarios.md +++ b/Scenarios.md @@ -346,9 +346,9 @@ * should not have inconclusive package result * should not have warning package result -### ChocolateyListCommand [ 2 Scenario(s), 9 Observation(s) ] +### ChocolateyListCommand [ 6 Scenario(s), 30 Observation(s) ] -#### when listing local packages happy path +#### when listing local packages * should contain a summary * should contain debugging messages @@ -363,6 +363,39 @@ * should not contain packages and versions with a space between them * should only have messages related to package information +#### when searching all available packages + + * should contain a summary + * should contain debugging messages + * should contain packages and versions with a space between them + * should list available packages as many times as they show on the feed + * should not contain packages and versions with a pipe between them + +#### when searching for a particular package + + * should contain a summary + * should contain debugging messages + * should contain packages and versions with a space between them + * should not contain packages that do not match + +#### when searching packages with no filter happy path + + * should contain a summary + * should contain debugging messages + * should contain packages and versions with a space between them + * should list available packages only once + * should not contain packages and versions with a pipe between them + +#### when searching packages with verbose + + * should contain a summary + * should contain debugging messages + * should contain description + * should contain download counts + * should contain packages and versions with a space between them + * should contain tags + * should not contain packages and versions with a pipe between them + ### ChocolateyUninstallCommand [ 13 Scenario(s), 90 Observation(s) ] #### when force uninstalling a package diff --git a/src/chocolatey.tests.integration/Scenario.cs b/src/chocolatey.tests.integration/Scenario.cs index 2e46ef2440..aa077fe571 100644 --- a/src/chocolatey.tests.integration/Scenario.cs +++ b/src/chocolatey.tests.integration/Scenario.cs @@ -110,6 +110,8 @@ public static void install_package(ChocolateyConfiguration config, string packag private static ChocolateyConfiguration baseline_configuration() { + // note that this does not mean an empty configuration. It does get influenced by + // prior commands, so ensure that all items go back to the default values here var config = NUnitSetup.Container.GetInstance(); config.AcceptLicense = true; @@ -133,6 +135,10 @@ private static ChocolateyConfiguration baseline_configuration() config.Sources = _fileSystem.get_full_path(_fileSystem.combine_paths(get_top_level(), "packages")); config.Version = null; config.Debug = true; + config.AllVersions = false; + config.Verbose = false; + config.Input = config.PackageNames = string.Empty; + config.ListCommand.LocalOnly = false; return config; } @@ -165,8 +171,6 @@ public static ChocolateyConfiguration list() { var config = baseline_configuration(); config.CommandName = CommandNameType.list.to_string(); - config.ListCommand.LocalOnly = true; - config.Sources = ApplicationParameters.PackagesLocation; return config; } diff --git a/src/chocolatey.tests.integration/TODO.cs b/src/chocolatey.tests.integration/TODO.cs index 2708a3b038..9fc4e14810 100644 --- a/src/chocolatey.tests.integration/TODO.cs +++ b/src/chocolatey.tests.integration/TODO.cs @@ -40,9 +40,6 @@ public class TODO * - uninstall as a dependency * - uninstall as a dependency with force * - * List scenarios: - * - list local - * - list lp * */ } diff --git a/src/chocolatey.tests.integration/scenarios/ListScenarios.cs b/src/chocolatey.tests.integration/scenarios/ListScenarios.cs index 1de4829e98..ef2ec14572 100644 --- a/src/chocolatey.tests.integration/scenarios/ListScenarios.cs +++ b/src/chocolatey.tests.integration/scenarios/ListScenarios.cs @@ -20,6 +20,7 @@ namespace chocolatey.tests.integration.scenarios using NuGet; using Should; using bdddoc.core; + using chocolatey.infrastructure.app; using chocolatey.infrastructure.app.commands; using chocolatey.infrastructure.app.configuration; using chocolatey.infrastructure.app.services; @@ -37,48 +38,222 @@ public override void Context() { Configuration = Scenario.list(); Scenario.reset(Configuration); - Configuration.PackageNames = Configuration.Input = "upgradepackage"; Scenario.add_packages_to_source_location(Configuration, Configuration.Input + "*" + Constants.PackageExtension); Scenario.add_packages_to_source_location(Configuration, "installpackage*" + Constants.PackageExtension); - Scenario.add_packages_to_source_location(Configuration, "badpackage*" + Constants.PackageExtension); Scenario.install_package(Configuration, "installpackage", "1.0.0"); Scenario.install_package(Configuration, "upgradepackage", "1.0.0"); - Configuration.SkipPackageInstallProvider = true; - Scenario.install_package(Configuration, "badpackage", "1.0"); - Configuration.SkipPackageInstallProvider = false; Service = NUnitSetup.Container.GetInstance(); } + } + + [Concern(typeof(ChocolateyListCommand))] + public class when_searching_packages_with_no_filter_happy_path : ScenariosBase + { + public override void Because() + { + MockLogger.reset(); + Results = Service.list_run(Configuration).ToList(); + } + + [Fact] + public void should_list_available_packages_only_once() + { + MockLogger.contains_message_count("upgradepackage").ShouldEqual(1); + } + + [Fact] + public void should_contain_packages_and_versions_with_a_space_between_them() + { + MockLogger.contains_message("upgradepackage 1.1.0").ShouldBeTrue(); + } + + [Fact] + public void should_not_contain_packages_and_versions_with_a_pipe_between_them() + { + MockLogger.contains_message("upgradepackage|1.1.0").ShouldBeFalse(); + } + + [Fact] + public void should_contain_a_summary() + { + MockLogger.contains_message("packages found").ShouldBeTrue(); + } + + [Fact] + public void should_contain_debugging_messages() + { + MockLogger.contains_message("Searching for package information", LogLevel.Debug).ShouldBeTrue(); + MockLogger.contains_message("Running list with the following filter", LogLevel.Debug).ShouldBeTrue(); + MockLogger.contains_message("Start of List", LogLevel.Debug).ShouldBeTrue(); + MockLogger.contains_message("End of List", LogLevel.Debug).ShouldBeTrue(); + } + } + + [Concern(typeof(ChocolateyListCommand))] + public class when_searching_for_a_particular_package : ScenariosBase + { + public override void Context() + { + base.Context(); + Configuration.Input = Configuration.PackageNames = "upgradepackage"; + } + + public override void Because() + { + MockLogger.reset(); + Results = Service.list_run(Configuration).ToList(); + } + + [Fact] + public void should_contain_packages_and_versions_with_a_space_between_them() + { + MockLogger.contains_message("upgradepackage 1.1.0").ShouldBeTrue(); + } + + [Fact] + public void should_not_contain_packages_that_do_not_match() + { + MockLogger.contains_message("installpackage").ShouldBeFalse(); + } + + [Fact] + public void should_contain_a_summary() + { + MockLogger.contains_message("packages found").ShouldBeTrue(); + } + + [Fact] + public void should_contain_debugging_messages() + { + MockLogger.contains_message("Searching for package information", LogLevel.Debug).ShouldBeTrue(); + MockLogger.contains_message("Running list with the following filter", LogLevel.Debug).ShouldBeTrue(); + MockLogger.contains_message("Start of List", LogLevel.Debug).ShouldBeTrue(); + MockLogger.contains_message("End of List", LogLevel.Debug).ShouldBeTrue(); + } + } + + [Concern(typeof(ChocolateyListCommand))] + public class when_searching_all_available_packages : ScenariosBase + { + public override void Context() + { + base.Context(); + Configuration.AllVersions = true; + } - public bool has_expected_message(string expectedMessage) + public override void Because() + { + MockLogger.reset(); + Results = Service.list_run(Configuration).ToList(); + } + + [Fact] + public void should_list_available_packages_as_many_times_as_they_show_on_the_feed() + { + MockLogger.contains_message_count("upgradepackage").ShouldNotEqual(0); + MockLogger.contains_message_count("upgradepackage").ShouldNotEqual(1); + } + + [Fact] + public void should_contain_packages_and_versions_with_a_space_between_them() + { + MockLogger.contains_message("upgradepackage 1.1.0").ShouldBeTrue(); + } + + [Fact] + public void should_not_contain_packages_and_versions_with_a_pipe_between_them() + { + MockLogger.contains_message("upgradepackage|1.1.0").ShouldBeFalse(); + } + + [Fact] + public void should_contain_a_summary() + { + MockLogger.contains_message("packages found").ShouldBeTrue(); + } + + [Fact] + public void should_contain_debugging_messages() + { + MockLogger.contains_message("Searching for package information", LogLevel.Debug).ShouldBeTrue(); + MockLogger.contains_message("Running list with the following filter", LogLevel.Debug).ShouldBeTrue(); + MockLogger.contains_message("Start of List", LogLevel.Debug).ShouldBeTrue(); + MockLogger.contains_message("End of List", LogLevel.Debug).ShouldBeTrue(); + } + } + + [Concern(typeof(ChocolateyListCommand))] + public class when_searching_packages_with_verbose : ScenariosBase + { + public override void Context() + { + base.Context(); + Configuration.Verbose = true; + } + + public override void Because() { - bool messageFound = false; - foreach (var messageLevel in MockLogger.Messages) - { - foreach (var message in messageLevel.Value.or_empty_list_if_null()) - { - if (message.Contains(expectedMessage)) messageFound = true; - } - } + MockLogger.reset(); + Results = Service.list_run(Configuration).ToList(); + } - return messageFound; + [Fact] + public void should_contain_packages_and_versions_with_a_space_between_them() + { + MockLogger.contains_message("upgradepackage 1.1.0").ShouldBeTrue(); } - public bool has_expected_message(string expectedMessage, LogLevel level) + [Fact] + public void should_contain_description() { - bool messageFound = false; - foreach (var message in MockLogger.MessagesFor(level).or_empty_list_if_null()) - { - if (message.Contains(expectedMessage)) messageFound = true; - } + MockLogger.contains_message("Description: ").ShouldBeTrue(); + } - return messageFound; + [Fact] + public void should_contain_tags() + { + MockLogger.contains_message("Tags: ").ShouldBeTrue(); + } + + [Fact] + public void should_contain_download_counts() + { + MockLogger.contains_message("Number of Downloads: ").ShouldBeTrue(); + } + + [Fact] + public void should_not_contain_packages_and_versions_with_a_pipe_between_them() + { + MockLogger.contains_message("upgradepackage|1.1.0").ShouldBeFalse(); + } + + [Fact] + public void should_contain_a_summary() + { + MockLogger.contains_message("packages found").ShouldBeTrue(); + } + + [Fact] + public void should_contain_debugging_messages() + { + MockLogger.contains_message("Searching for package information", LogLevel.Debug).ShouldBeTrue(); + MockLogger.contains_message("Running list with the following filter", LogLevel.Debug).ShouldBeTrue(); + MockLogger.contains_message("Start of List", LogLevel.Debug).ShouldBeTrue(); + MockLogger.contains_message("End of List", LogLevel.Debug).ShouldBeTrue(); } } [Concern(typeof(ChocolateyListCommand))] - public class when_listing_local_packages_happy_path : ScenariosBase + public class when_listing_local_packages : ScenariosBase { + public override void Context() + { + base.Context(); + Configuration.ListCommand.LocalOnly = true; + Configuration.Sources = ApplicationParameters.PackagesLocation; + } + public override void Because() { MockLogger.reset(); @@ -88,28 +263,28 @@ public override void Because() [Fact] public void should_contain_packages_and_versions_with_a_space_between_them() { - has_expected_message("upgradepackage 1.1.0").ShouldBeTrue(); + MockLogger.contains_message("upgradepackage 1.0.0").ShouldBeTrue(); } [Fact] public void should_not_contain_packages_and_versions_with_a_pipe_between_them() { - has_expected_message("upgradepackage|1.1.0").ShouldBeFalse(); + MockLogger.contains_message("upgradepackage|1.0.0").ShouldBeFalse(); } [Fact] public void should_contain_a_summary() { - has_expected_message("packages installed").ShouldBeTrue(); + MockLogger.contains_message("packages installed").ShouldBeTrue(); } [Fact] public void should_contain_debugging_messages() { - has_expected_message("Searching for package information", LogLevel.Debug).ShouldBeTrue(); - has_expected_message("Running list with the following filter", LogLevel.Debug).ShouldBeTrue(); - has_expected_message("Start of List", LogLevel.Debug).ShouldBeTrue(); - has_expected_message("End of List", LogLevel.Debug).ShouldBeTrue(); + MockLogger.contains_message("Searching for package information", LogLevel.Debug).ShouldBeTrue(); + MockLogger.contains_message("Running list with the following filter", LogLevel.Debug).ShouldBeTrue(); + MockLogger.contains_message("Start of List", LogLevel.Debug).ShouldBeTrue(); + MockLogger.contains_message("End of List", LogLevel.Debug).ShouldBeTrue(); } } @@ -119,6 +294,9 @@ public class when_listing_local_packages_limiting_output : ScenariosBase public override void Context() { base.Context(); + + Configuration.ListCommand.LocalOnly = true; + Configuration.Sources = ApplicationParameters.PackagesLocation; Configuration.RegularOutput = false; } @@ -131,35 +309,35 @@ public override void Because() [Fact] public void should_contain_packages_and_versions_with_a_pipe_between_them() { - has_expected_message("upgradepackage|1.1.0").ShouldBeTrue(); + MockLogger.contains_message("upgradepackage|1.0.0").ShouldBeTrue(); } [Fact] public void should_only_have_messages_related_to_package_information() { var count = MockLogger.Messages.SelectMany(messageLevel => messageLevel.Value.or_empty_list_if_null()).Count(); - count.ShouldEqual(1); + count.ShouldEqual(2); } [Fact] public void should_not_contain_packages_and_versions_with_a_space_between_them() { - has_expected_message("upgradepackage 1.1.0").ShouldBeFalse(); + MockLogger.contains_message("upgradepackage 1.0.0").ShouldBeFalse(); } [Fact] public void should_not_contain_a_summary() { - has_expected_message("packages installed").ShouldBeFalse(); + MockLogger.contains_message("packages installed").ShouldBeFalse(); } [Fact] public void should_not_contain_debugging_messages() { - has_expected_message("Searching for package information", LogLevel.Debug).ShouldBeFalse(); - has_expected_message("Running list with the following filter", LogLevel.Debug).ShouldBeFalse(); - has_expected_message("Start of List", LogLevel.Debug).ShouldBeFalse(); - has_expected_message("End of List", LogLevel.Debug).ShouldBeFalse(); + MockLogger.contains_message("Searching for package information", LogLevel.Debug).ShouldBeFalse(); + MockLogger.contains_message("Running list with the following filter", LogLevel.Debug).ShouldBeFalse(); + MockLogger.contains_message("Start of List", LogLevel.Debug).ShouldBeFalse(); + MockLogger.contains_message("End of List", LogLevel.Debug).ShouldBeFalse(); } } }