diff --git a/CHANGELOG.md b/CHANGELOG.md index d4eda3bec2..ce9a80ad17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,12 @@ Alternative sources (webpi, windowsfeature, cygwin, etc) are back (finally, righ * AutoUninstaller is on by default - see [#308](https://github.com/chocolatey/choco/issues/308) +## [0.9.9.11](https://github.com/chocolatey/choco/issues?q=milestone%3A0.9.9.11+is%3Aclosed) (October 6, 2015) + +### BUG FIXES + + * Fix - Pin list is broken - see [#452](https://github.com/chocolatey/choco/issues/452) + ## [0.9.9.10](https://github.com/chocolatey/choco/issues?q=milestone%3A0.9.9.10+is%3Aclosed) (October 3, 2015) Not to be confused with 0.9.10 (this is not that version). This fixes a small but extremely significant issue with relation to configuration managers and other tools that use choco. diff --git a/Scenarios.md b/Scenarios.md index c02f1a835a..b9b1af05b7 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,80 @@ * 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 + +### ChocolateyPinCommand [ 9 Scenario(s), 12 Observation(s) ] + +#### when listing pins with an existing pin + + * should contain existing pin messages + * should not contain list results + +#### when listing pins with existing pins + + * should contain a pin message for each existing pin + * should not contain list results + +#### when listing pins with no pins + + * should not contain any pins by default + * should not contain list results + +#### when removing a pin for a non installed package + + * should throw an error about not finding the package + +#### when removing a pin for a pinned package + + * should contain success message + +#### when removing a pin for an unpinned package + + * should contain nothing to do message + +#### when setting a pin for a non installed package + + * should throw an error about not finding the package + +#### when setting a pin for an already pinned package + + * should contain nothing to do message + +#### when setting a pin for an installed package + + * should contain success message + ### ChocolateyUninstallCommand [ 13 Scenario(s), 90 Observation(s) ] #### when force uninstalling a package diff --git a/nuget/chocolatey/chocolatey.nuspec b/nuget/chocolatey/chocolatey.nuspec index cac8f5d269..469751c349 100644 --- a/nuget/chocolatey/chocolatey.nuspec +++ b/nuget/chocolatey/chocolatey.nuspec @@ -40,6 +40,12 @@ In that mess there is a link to the [Helper Reference](https://github.com/chocol See all - https://github.com/chocolatey/choco/blob/master/CHANGELOG.md +## 0.9.9.11 + +### BUG FIXES + + * Fix - Pin list is broken - see [#452](https://github.com/chocolatey/choco/issues/452) + ## 0.9.9.10 Not to be confused with 0.9.10 (this is not that version). This fixes a small but extremely significant issue with relation to configuration managers and other tools that use choco. diff --git a/src/chocolatey.console/Program.cs b/src/chocolatey.console/Program.cs index c1fd76ad26..ba9a53ce25 100644 --- a/src/chocolatey.console/Program.cs +++ b/src/chocolatey.console/Program.cs @@ -77,7 +77,7 @@ private static void Main(string[] args) #if DEBUG "chocolatey".Log().Info(ChocolateyLoggers.Important, () => "{0} v{1} (DEBUG BUILD)".format_with(ApplicationParameters.Name, config.Information.ChocolateyProductVersion)); #else - if (config.Information.ChocolateyVersion == config.Information.ChocolateyProductVersion) + if (config.Information.ChocolateyVersion == config.Information.ChocolateyProductVersion && args.Any()) { "logfile".Log().Info(() => "{0} v{1}".format_with(ApplicationParameters.Name, config.Information.ChocolateyProductVersion)); } diff --git a/src/chocolatey.tests.integration/Scenario.cs b/src/chocolatey.tests.integration/Scenario.cs index 37a4ccf31f..b85b43d880 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,14 @@ public static ChocolateyConfiguration list() { var config = baseline_configuration(); config.CommandName = CommandNameType.list.to_string(); - config.ListCommand.LocalOnly = true; - config.Sources = ApplicationParameters.PackagesLocation; + + return config; + } + + public static ChocolateyConfiguration pin() + { + var config = baseline_configuration(); + config.CommandName = CommandNameType.pin.to_string(); 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/chocolatey.tests.integration.csproj b/src/chocolatey.tests.integration/chocolatey.tests.integration.csproj index a32033b14a..24c6f35b7c 100644 --- a/src/chocolatey.tests.integration/chocolatey.tests.integration.csproj +++ b/src/chocolatey.tests.integration/chocolatey.tests.integration.csproj @@ -87,6 +87,7 @@ + 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(); } } } diff --git a/src/chocolatey.tests.integration/scenarios/PinScenarios.cs b/src/chocolatey.tests.integration/scenarios/PinScenarios.cs new file mode 100644 index 0000000000..cd1e5b6f93 --- /dev/null +++ b/src/chocolatey.tests.integration/scenarios/PinScenarios.cs @@ -0,0 +1,306 @@ +// Copyright © 2011 - Present RealDimensions Software, LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace chocolatey.tests.integration.scenarios +{ + using System; + using System.Collections.Generic; + using System.Linq; + using NuGet; + using Should; + using bdddoc.core; + using chocolatey.infrastructure.app; + using chocolatey.infrastructure.app.attributes; + using chocolatey.infrastructure.app.commands; + using chocolatey.infrastructure.app.configuration; + using chocolatey.infrastructure.app.domain; + using chocolatey.infrastructure.commands; + using chocolatey.infrastructure.results; + + public class PinScenarios + { + public abstract class ScenariosBase : TinySpec + { + protected IList Results; + protected ChocolateyConfiguration Configuration; + protected ChocolateyPinCommand Service; + + public override void Context() + { + Configuration = Scenario.pin(); + Scenario.reset(Configuration); + Scenario.add_packages_to_source_location(Configuration, Configuration.Input + "*" + Constants.PackageExtension); + Scenario.add_packages_to_source_location(Configuration, "installpackage*" + Constants.PackageExtension); + Scenario.install_package(Configuration, "installpackage", "1.0.0"); + Scenario.install_package(Configuration, "upgradepackage", "1.0.0"); + Scenario.install_package(Configuration, "hasdependency", "1.0.0"); + + var commands = NUnitSetup.Container.GetAllInstances(); + Service = commands.Where( + (c) => + { + var attributes = c.GetType().GetCustomAttributes(typeof(CommandForAttribute), false); + return attributes.Cast().Any(attribute => attribute.CommandName.is_equal_to(Configuration.CommandName)); + }).FirstOrDefault() as ChocolateyPinCommand; + + Configuration.Sources = ApplicationParameters.PackagesLocation; + Configuration.ListCommand.LocalOnly = true; + Configuration.AllVersions = true; + Configuration.Prerelease = true; + } + } + + [Concern(typeof(ChocolateyPinCommand))] + public class when_listing_pins_with_no_pins : ScenariosBase + { + public override void Context() + { + base.Context(); + Configuration.PinCommand.Command = PinCommandType.list; + } + + public override void Because() + { + MockLogger.reset(); + Service.run(Configuration); + } + + [Fact] + public void should_not_contain_list_results() + { + MockLogger.contains_message("upgradepackage 1.0.0", LogLevel.Info).ShouldBeFalse(); + MockLogger.contains_message("upgradepackage 1.0.0", LogLevel.Warn).ShouldBeFalse(); + MockLogger.contains_message("upgradepackage 1.0.0", LogLevel.Error).ShouldBeFalse(); + } + + [Fact] + public void should_not_contain_any_pins_by_default() + { + MockLogger.contains_message("upgradepackage|1.0.0").ShouldBeFalse(); + } + } + + [Concern(typeof(ChocolateyPinCommand))] + public class when_listing_pins_with_an_existing_pin : ScenariosBase + { + public override void Context() + { + base.Context(); + Configuration.PinCommand.Command = PinCommandType.add; + Configuration.PinCommand.Name = "upgradepackage"; + Service.run(Configuration); + Configuration.PinCommand.Command = PinCommandType.list; + } + + public override void Because() + { + MockLogger.reset(); + Service.run(Configuration); + } + + [Fact] + public void should_not_contain_list_results() + { + MockLogger.contains_message("upgradepackage 1.0.0", LogLevel.Info).ShouldBeFalse(); + MockLogger.contains_message("upgradepackage 1.0.0", LogLevel.Warn).ShouldBeFalse(); + MockLogger.contains_message("upgradepackage 1.0.0", LogLevel.Error).ShouldBeFalse(); + } + + [Fact] + public void should_contain_existing_pin_messages() + { + MockLogger.contains_message("upgradepackage|1.0.0").ShouldBeTrue(); + } + } + + [Concern(typeof(ChocolateyPinCommand))] + public class when_listing_pins_with_existing_pins : ScenariosBase + { + public override void Context() + { + base.Context(); + Configuration.PinCommand.Command = PinCommandType.add; + Configuration.PinCommand.Name = "upgradepackage"; + Service.run(Configuration); + Configuration.PinCommand.Name = "installpackage"; + Service.run(Configuration); + Configuration.PinCommand.Command = PinCommandType.list; + } + + public override void Because() + { + MockLogger.reset(); + Service.run(Configuration); + } + + [Fact] + public void should_not_contain_list_results() + { + MockLogger.contains_message("upgradepackage 1.0.0", LogLevel.Info).ShouldBeFalse(); + MockLogger.contains_message("upgradepackage 1.0.0", LogLevel.Warn).ShouldBeFalse(); + MockLogger.contains_message("upgradepackage 1.0.0", LogLevel.Error).ShouldBeFalse(); + } + + [Fact] + public void should_contain_a_pin_message_for_each_existing_pin() + { + MockLogger.contains_message("installpackage|1.0.0").ShouldBeTrue(); + MockLogger.contains_message("upgradepackage|1.0.0").ShouldBeTrue(); + } + } + + [Concern(typeof(ChocolateyPinCommand))] + public class when_setting_a_pin_for_an_installed_package : ScenariosBase + { + public override void Context() + { + base.Context(); + Configuration.PinCommand.Command = PinCommandType.add; + Configuration.PinCommand.Name = "upgradepackage"; + } + + public override void Because() + { + MockLogger.reset(); + Service.run(Configuration); + } + + [Fact] + public void should_contain_success_message() + { + MockLogger.contains_message("Successfully added a pin for upgradepackage").ShouldBeTrue(); + } + } + + [Concern(typeof(ChocolateyPinCommand))] + public class when_setting_a_pin_for_an_already_pinned_package : ScenariosBase + { + public override void Context() + { + base.Context(); + Configuration.PinCommand.Command = PinCommandType.add; + Configuration.PinCommand.Name = "upgradepackage"; + Service.run(Configuration); + } + + public override void Because() + { + MockLogger.reset(); + Service.run(Configuration); + } + + [Fact] + public void should_contain_nothing_to_do_message() + { + MockLogger.contains_message("Nothing to change. Pin already set or removed.").ShouldBeTrue(); + } + } + + [Concern(typeof(ChocolateyPinCommand))] + public class when_setting_a_pin_for_a_non_installed_package : ScenariosBase + { + public override void Context() + { + base.Context(); + Configuration.PinCommand.Command = PinCommandType.add; + Configuration.PinCommand.Name = "whatisthis"; + } + + public override void Because() + { + MockLogger.reset(); + } + + [ExpectedException(typeof(ApplicationException), ExpectedMessage = "Unable to find package named 'whatisthis' to pin. Please check to ensure it is installed.")] + [Fact] + public void should_throw_an_error_about_not_finding_the_package() + { + Service.run(Configuration); + } + } + + [Concern(typeof(ChocolateyPinCommand))] + public class when_removing_a_pin_for_a_pinned_package : ScenariosBase + { + public override void Context() + { + base.Context(); + Configuration.PinCommand.Command = PinCommandType.add; + Configuration.PinCommand.Name = "upgradepackage"; + Service.run(Configuration); + + Configuration.PinCommand.Command = PinCommandType.remove; + } + + public override void Because() + { + MockLogger.reset(); + Service.run(Configuration); + } + + [Fact] + public void should_contain_success_message() + { + MockLogger.contains_message("Successfully removed a pin for upgradepackage").ShouldBeTrue(); + } + } + + [Concern(typeof(ChocolateyPinCommand))] + public class when_removing_a_pin_for_an_unpinned_package : ScenariosBase + { + public override void Context() + { + base.Context(); + Configuration.PinCommand.Command = PinCommandType.remove; + Configuration.PinCommand.Name = "upgradepackage"; + } + + public override void Because() + { + MockLogger.reset(); + Service.run(Configuration); + } + + [Fact] + public void should_contain_nothing_to_do_message() + { + MockLogger.contains_message("Nothing to change. Pin already set or removed.").ShouldBeTrue(); + } + } + + [Concern(typeof(ChocolateyPinCommand))] + public class when_removing_a_pin_for_a_non_installed_package : ScenariosBase + { + public override void Context() + { + base.Context(); + Configuration.PinCommand.Command = PinCommandType.remove; + Configuration.PinCommand.Name = "whatisthis"; + } + + public override void Because() + { + MockLogger.reset(); + } + + [ExpectedException(typeof(ApplicationException), ExpectedMessage = "Unable to find package named 'whatisthis' to pin. Please check to ensure it is installed.")] + [Fact] + public void should_throw_an_error_about_not_finding_the_package() + { + Service.run(Configuration); + } + } + } +} diff --git a/src/chocolatey.tests/MockLogger.cs b/src/chocolatey.tests/MockLogger.cs index e11bb21aca..20c53a2afe 100644 --- a/src/chocolatey.tests/MockLogger.cs +++ b/src/chocolatey.tests/MockLogger.cs @@ -43,6 +43,41 @@ public void reset() LogMessagesToConsole = false; } + public bool contains_message(string expectedMessage) + { + return contains_message_count(expectedMessage) != 0; + } + + public bool contains_message(string expectedMessage, LogLevel level) + { + return contains_message_count(expectedMessage, level) != 0; + } + + public int contains_message_count(string expectedMessage) + { + int messageCount = 0; + foreach (var messageLevel in Messages) + { + foreach (var message in messageLevel.Value.or_empty_list_if_null()) + { + if (message.Contains(expectedMessage)) messageCount++; + } + } + + return messageCount; + } + + public int contains_message_count(string expectedMessage, LogLevel level) + { + int messageCount = 0; + foreach (var message in MessagesFor(level).or_empty_list_if_null()) + { + if (message.Contains(expectedMessage)) messageCount++; + } + + return messageCount; + } + public bool LogMessagesToConsole { get; set; } private readonly Lazy>> _messages = new Lazy>>(); diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyPinCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyPinCommand.cs index e82b88e58c..5bdfa34bac 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyPinCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyPinCommand.cs @@ -139,7 +139,15 @@ public void run(ChocolateyConfiguration configuration) public void list_pins(IPackageManager packageManager, ChocolateyConfiguration config) { - foreach (var pkg in _nugetService.list_run(config)) + var input = config.Input; + config.Input = string.Empty; + var quiet = config.QuietOutput; + config.QuietOutput = true; + var packages = _nugetService.list_run(config).ToList(); + config.QuietOutput = quiet; + config.Input = input; + + foreach (var pkg in packages.or_empty_list_if_null()) { var pkgInfo = _packageInfoService.get_package_information(pkg.Package); if (pkgInfo != null && pkgInfo.IsPinned)