diff --git a/Scenarios.md b/Scenarios.md index 2468913d4b..cb70cf863b 100644 --- a/Scenarios.md +++ b/Scenarios.md @@ -647,7 +647,7 @@ * should throw an error that it is not allowed -### ChocolateyUpgradeCommand [ 29 Scenario(s), 226 Observation(s) ] +### ChocolateyUpgradeCommand [ 35 Scenario(s), 286 Observation(s) ] #### when force upgrading a package @@ -938,6 +938,20 @@ * should report for all non skipped packages * should skip packages in except list +#### when upgrading all packages with prereleases installed + + * should report for all installed packages + * should skip packages without upgrades + * should upgrade packages with upgrades + * should upgrade upgradepackage + +#### when upgrading all packages with prereleases installed with excludeprerelease specified + + * should not upgrade upgradepackage + * should report for all installed packages + * should skip packages without upgrades + * should upgrade packages with upgrades + #### when upgrading an existing package happy path * config should match package result name @@ -958,6 +972,70 @@ * should upgrade the package * should upgrade where install location reports +#### when upgrading an existing package with prerelease available and prerelease specified + + * config should match package result name + * should contain a warning message that it upgraded successfully + * should contain a warning message with old and new versions + * should contain newer version in directory + * should delete the rollback + * should have a successful package result + * should have executed chocolateyBeforeModify before chocolateyInstall + * should have executed chocolateyBeforeModify script for original package + * should have executed chocolateyInstall script for new package + * should match the upgrade version of the new beta + * should not have executed chocolateyBeforeModify script for new package + * should not have executed chocolateyUninstall script for original package + * should not have inconclusive package result + * should not have warning package result + * should upgrade a package in the lib directory + * should upgrade the package + * should upgrade where install location reports + +#### when upgrading an existing package with prerelease available without prerelease specified + + * should be the same version of the package + * should contain a message that no packages were upgraded + * should contain a message that you have the latest version available + * should have a successful package result + * should have inconclusive package result + * should match the original package version + * should not create a rollback + * should not have warning package result + * should not remove the package from the lib directory + +#### when upgrading an existing prerelease package with prerelease available with excludeprelease and without prerelease specified + + * should be the same version of the package + * should contain a message that no packages were upgraded + * should contain a message that you have the latest version available + * should have a successful package result + * should have inconclusive package result + * should not create a rollback + * should not have warning package result + * should not remove the package from the lib directory + * should only find the last stable version + +#### when upgrading an existing prerelease package without prerelease specified + + * config should match package result name + * should contain a warning message that it upgraded successfully + * should contain a warning message with old and new versions + * should contain newer version in directory + * should delete the rollback + * should have a successful package result + * should have executed chocolateyBeforeModify before chocolateyInstall + * should have executed chocolateyBeforeModify script for original package + * should have executed chocolateyInstall script for new package + * should match the upgrade version of the new beta + * should not have executed chocolateyBeforeModify script for new package + * should not have executed chocolateyUninstall script for original package + * should not have inconclusive package result + * should not have warning package result + * should upgrade a package in the lib directory + * should upgrade the package + * should upgrade where install location reports + #### when upgrading packages with packages config * should throw an error that it is not allowed diff --git a/src/chocolatey.tests.integration/chocolatey.tests.integration.csproj b/src/chocolatey.tests.integration/chocolatey.tests.integration.csproj index dbdebd39f7..484552e747 100644 --- a/src/chocolatey.tests.integration/chocolatey.tests.integration.csproj +++ b/src/chocolatey.tests.integration/chocolatey.tests.integration.csproj @@ -373,6 +373,48 @@ Always + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + Designer @@ -422,6 +464,18 @@ Always + + Always + + + Always + + + Always + + + Always + Always diff --git a/src/chocolatey.tests.integration/context/upgradepackage/1.1.1-beta/tools/chocolateyBeforeModify.ps1 b/src/chocolatey.tests.integration/context/upgradepackage/1.1.1-beta/tools/chocolateyBeforeModify.ps1 new file mode 100644 index 0000000000..af5bb142e8 --- /dev/null +++ b/src/chocolatey.tests.integration/context/upgradepackage/1.1.1-beta/tools/chocolateyBeforeModify.ps1 @@ -0,0 +1 @@ +Write-Output "$env:PackageName $env:PackageVersion Before Modification" \ No newline at end of file diff --git a/src/chocolatey.tests.integration/context/upgradepackage/1.1.1-beta/tools/chocolateyinstall.ps1 b/src/chocolatey.tests.integration/context/upgradepackage/1.1.1-beta/tools/chocolateyinstall.ps1 new file mode 100644 index 0000000000..d64eb8f47b --- /dev/null +++ b/src/chocolatey.tests.integration/context/upgradepackage/1.1.1-beta/tools/chocolateyinstall.ps1 @@ -0,0 +1 @@ +Write-Output "$env:PackageName $env:PackageVersion Installed" \ No newline at end of file diff --git a/src/chocolatey.tests.integration/context/upgradepackage/1.1.1-beta/tools/chocolateyuninstall.ps1 b/src/chocolatey.tests.integration/context/upgradepackage/1.1.1-beta/tools/chocolateyuninstall.ps1 new file mode 100644 index 0000000000..9ead91ffa3 --- /dev/null +++ b/src/chocolatey.tests.integration/context/upgradepackage/1.1.1-beta/tools/chocolateyuninstall.ps1 @@ -0,0 +1 @@ +Write-Output "$env:PackageName $env:PackageVersion Uninstalled" \ No newline at end of file diff --git a/src/chocolatey.tests.integration/context/upgradepackage/1.1.1-beta/tools/console.exe b/src/chocolatey.tests.integration/context/upgradepackage/1.1.1-beta/tools/console.exe new file mode 100644 index 0000000000..e2069184ee --- /dev/null +++ b/src/chocolatey.tests.integration/context/upgradepackage/1.1.1-beta/tools/console.exe @@ -0,0 +1 @@ +1.1.1-beta \ No newline at end of file diff --git a/src/chocolatey.tests.integration/context/upgradepackage/1.1.1-beta/tools/console.exe.config b/src/chocolatey.tests.integration/context/upgradepackage/1.1.1-beta/tools/console.exe.config new file mode 100644 index 0000000000..13dc6cb41b --- /dev/null +++ b/src/chocolatey.tests.integration/context/upgradepackage/1.1.1-beta/tools/console.exe.config @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/src/chocolatey.tests.integration/context/upgradepackage/1.1.1-beta/tools/console.exe.config.install.xdt b/src/chocolatey.tests.integration/context/upgradepackage/1.1.1-beta/tools/console.exe.config.install.xdt new file mode 100644 index 0000000000..21cc0d1d62 --- /dev/null +++ b/src/chocolatey.tests.integration/context/upgradepackage/1.1.1-beta/tools/console.exe.config.install.xdt @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/src/chocolatey.tests.integration/context/upgradepackage/1.1.1-beta/tools/graphical.exe b/src/chocolatey.tests.integration/context/upgradepackage/1.1.1-beta/tools/graphical.exe new file mode 100644 index 0000000000..e2069184ee --- /dev/null +++ b/src/chocolatey.tests.integration/context/upgradepackage/1.1.1-beta/tools/graphical.exe @@ -0,0 +1 @@ +1.1.1-beta \ No newline at end of file diff --git a/src/chocolatey.tests.integration/context/upgradepackage/1.1.1-beta/tools/graphical.exe.gui b/src/chocolatey.tests.integration/context/upgradepackage/1.1.1-beta/tools/graphical.exe.gui new file mode 100644 index 0000000000..1cc5f657e0 --- /dev/null +++ b/src/chocolatey.tests.integration/context/upgradepackage/1.1.1-beta/tools/graphical.exe.gui @@ -0,0 +1 @@ +1.1.0 \ No newline at end of file diff --git a/src/chocolatey.tests.integration/context/upgradepackage/1.1.1-beta/upgradepackage.nuspec b/src/chocolatey.tests.integration/context/upgradepackage/1.1.1-beta/upgradepackage.nuspec new file mode 100644 index 0000000000..c135dc44f8 --- /dev/null +++ b/src/chocolatey.tests.integration/context/upgradepackage/1.1.1-beta/upgradepackage.nuspec @@ -0,0 +1,18 @@ + + + + upgradepackage + 1.1.1-beta + upgradepackage + __REPLACE_AUTHORS_OF_SOFTWARE__ + __REPLACE_YOUR_NAME__ + false + __REPLACE__ + __REPLACE__ + + upgradepackage admin + + + + + \ No newline at end of file diff --git a/src/chocolatey.tests.integration/context/upgradepackage/1.1.1-beta2/tools/chocolateyBeforeModify.ps1 b/src/chocolatey.tests.integration/context/upgradepackage/1.1.1-beta2/tools/chocolateyBeforeModify.ps1 new file mode 100644 index 0000000000..af5bb142e8 --- /dev/null +++ b/src/chocolatey.tests.integration/context/upgradepackage/1.1.1-beta2/tools/chocolateyBeforeModify.ps1 @@ -0,0 +1 @@ +Write-Output "$env:PackageName $env:PackageVersion Before Modification" \ No newline at end of file diff --git a/src/chocolatey.tests.integration/context/upgradepackage/1.1.1-beta2/tools/chocolateyinstall.ps1 b/src/chocolatey.tests.integration/context/upgradepackage/1.1.1-beta2/tools/chocolateyinstall.ps1 new file mode 100644 index 0000000000..d64eb8f47b --- /dev/null +++ b/src/chocolatey.tests.integration/context/upgradepackage/1.1.1-beta2/tools/chocolateyinstall.ps1 @@ -0,0 +1 @@ +Write-Output "$env:PackageName $env:PackageVersion Installed" \ No newline at end of file diff --git a/src/chocolatey.tests.integration/context/upgradepackage/1.1.1-beta2/tools/chocolateyuninstall.ps1 b/src/chocolatey.tests.integration/context/upgradepackage/1.1.1-beta2/tools/chocolateyuninstall.ps1 new file mode 100644 index 0000000000..9ead91ffa3 --- /dev/null +++ b/src/chocolatey.tests.integration/context/upgradepackage/1.1.1-beta2/tools/chocolateyuninstall.ps1 @@ -0,0 +1 @@ +Write-Output "$env:PackageName $env:PackageVersion Uninstalled" \ No newline at end of file diff --git a/src/chocolatey.tests.integration/context/upgradepackage/1.1.1-beta2/tools/console.exe b/src/chocolatey.tests.integration/context/upgradepackage/1.1.1-beta2/tools/console.exe new file mode 100644 index 0000000000..23c8c723e0 --- /dev/null +++ b/src/chocolatey.tests.integration/context/upgradepackage/1.1.1-beta2/tools/console.exe @@ -0,0 +1 @@ +1.1.1-beta2 \ No newline at end of file diff --git a/src/chocolatey.tests.integration/context/upgradepackage/1.1.1-beta2/tools/console.exe.config b/src/chocolatey.tests.integration/context/upgradepackage/1.1.1-beta2/tools/console.exe.config new file mode 100644 index 0000000000..13dc6cb41b --- /dev/null +++ b/src/chocolatey.tests.integration/context/upgradepackage/1.1.1-beta2/tools/console.exe.config @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/src/chocolatey.tests.integration/context/upgradepackage/1.1.1-beta2/tools/console.exe.config.install.xdt b/src/chocolatey.tests.integration/context/upgradepackage/1.1.1-beta2/tools/console.exe.config.install.xdt new file mode 100644 index 0000000000..21cc0d1d62 --- /dev/null +++ b/src/chocolatey.tests.integration/context/upgradepackage/1.1.1-beta2/tools/console.exe.config.install.xdt @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/src/chocolatey.tests.integration/context/upgradepackage/1.1.1-beta2/tools/graphical.exe b/src/chocolatey.tests.integration/context/upgradepackage/1.1.1-beta2/tools/graphical.exe new file mode 100644 index 0000000000..23c8c723e0 --- /dev/null +++ b/src/chocolatey.tests.integration/context/upgradepackage/1.1.1-beta2/tools/graphical.exe @@ -0,0 +1 @@ +1.1.1-beta2 \ No newline at end of file diff --git a/src/chocolatey.tests.integration/context/upgradepackage/1.1.1-beta2/tools/graphical.exe.gui b/src/chocolatey.tests.integration/context/upgradepackage/1.1.1-beta2/tools/graphical.exe.gui new file mode 100644 index 0000000000..1cc5f657e0 --- /dev/null +++ b/src/chocolatey.tests.integration/context/upgradepackage/1.1.1-beta2/tools/graphical.exe.gui @@ -0,0 +1 @@ +1.1.0 \ No newline at end of file diff --git a/src/chocolatey.tests.integration/context/upgradepackage/1.1.1-beta2/upgradepackage.nuspec b/src/chocolatey.tests.integration/context/upgradepackage/1.1.1-beta2/upgradepackage.nuspec new file mode 100644 index 0000000000..c0ae60cbbf --- /dev/null +++ b/src/chocolatey.tests.integration/context/upgradepackage/1.1.1-beta2/upgradepackage.nuspec @@ -0,0 +1,18 @@ + + + + upgradepackage + 1.1.1-beta2 + upgradepackage + __REPLACE_AUTHORS_OF_SOFTWARE__ + __REPLACE_YOUR_NAME__ + false + __REPLACE__ + __REPLACE__ + + upgradepackage admin + + + + + \ No newline at end of file diff --git a/src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs b/src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs index 9d5dbf2e71..fef17cf8ad 100644 --- a/src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs +++ b/src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs @@ -337,6 +337,478 @@ public void should_have_executed_chocolateyInstall_script_for_new_package() } } + [Concern(typeof (ChocolateyUpgradeCommand))] + public class when_upgrading_an_existing_package_with_prerelease_available_without_prerelease_specified : ScenariosBase + { + private PackageResult _packageResult; + + public override void Context() + { + base.Context(); + Scenario.install_package(Configuration, "upgradepackage", "1.1.0"); + } + + public override void Because() + { + Results = Service.upgrade_run(Configuration); + _packageResult = Results.FirstOrDefault().Value; + } + + [Fact] + public void should_contain_a_message_that_you_have_the_latest_version_available() + { + bool expectedMessage = false; + foreach (var message in MockLogger.MessagesFor(LogLevel.Info).or_empty_list_if_null()) + { + if (message.Contains("upgradepackage v1.1.0 is the latest version available based on your source(s)")) expectedMessage = true; + } + + expectedMessage.ShouldBeTrue(); + } + + [Fact] + public void should_contain_a_message_that_no_packages_were_upgraded() + { + bool expectedMessage = false; + foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).or_empty_list_if_null()) + { + if (message.Contains("upgraded 0/1 ")) expectedMessage = true; + } + + expectedMessage.ShouldBeTrue(); + } + + [Fact] + public void should_not_create_a_rollback() + { + var packageDir = Path.Combine(Scenario.get_top_level(), "lib-bkp", Configuration.PackageNames); + + Directory.Exists(packageDir).ShouldBeFalse(); + } + + [Fact] + public void should_not_remove_the_package_from_the_lib_directory() + { + var packageDir = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames); + + Directory.Exists(packageDir).ShouldBeTrue(); + } + + [Fact] + public void should_be_the_same_version_of_the_package() + { + var packageFile = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, Configuration.PackageNames + Constants.PackageExtension); + var package = new OptimizedZipPackage(packageFile); + package.Version.Version.to_string().ShouldEqual("1.1.0.0"); + } + + [Fact] + public void should_have_a_successful_package_result() + { + _packageResult.Success.ShouldBeTrue(); + } + + [Fact] + public void should_have_inconclusive_package_result() + { + _packageResult.Inconclusive.ShouldBeTrue(); + } + + [Fact] + public void should_not_have_warning_package_result() + { + _packageResult.Warning.ShouldBeFalse(); + } + + [Fact] + public void should_match_the_original_package_version() + { + _packageResult.Version.ShouldEqual("1.1.0"); + } + } + + [Concern(typeof (ChocolateyUpgradeCommand))] + public class when_upgrading_an_existing_package_with_prerelease_available_and_prerelease_specified : ScenariosBase + { + private PackageResult _packageResult; + + public override void Context() + { + base.Context(); + Configuration.Prerelease = true; + } + + public override void Because() + { + Results = Service.upgrade_run(Configuration); + _packageResult = Results.FirstOrDefault().Value; + } + + [Fact] + public void should_upgrade_where_install_location_reports() + { + Directory.Exists(_packageResult.InstallLocation).ShouldBeTrue(); + } + + [Fact] + public void should_upgrade_a_package_in_the_lib_directory() + { + var packageDir = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames); + + Directory.Exists(packageDir).ShouldBeTrue(); + } + + [Fact] + public void should_delete_the_rollback() + { + var packageDir = Path.Combine(Scenario.get_top_level(), "lib-bkp", Configuration.PackageNames); + + Directory.Exists(packageDir).ShouldBeFalse(); + } + + [Fact] + public void should_contain_newer_version_in_directory() + { + var shimFile = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, "tools", "console.exe"); + + File.ReadAllText(shimFile).ShouldEqual("1.1.1-beta2"); + } + + [Fact] + public void should_upgrade_the_package() + { + var packageFile = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, Configuration.PackageNames + Constants.PackageExtension); + var package = new OptimizedZipPackage(packageFile); + package.Version.Version.to_string().ShouldEqual("1.1.1.0"); + package.Version.to_string().ShouldEqual("1.1.1-beta2"); + } + + [Fact] + public void should_contain_a_warning_message_that_it_upgraded_successfully() + { + bool upgradedSuccessMessage = false; + foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).or_empty_list_if_null()) + { + if (message.Contains("upgraded 1/1")) upgradedSuccessMessage = true; + } + + upgradedSuccessMessage.ShouldBeTrue(); + } + + [Fact] + public void should_contain_a_warning_message_with_old_and_new_versions() + { + bool upgradeMessage = false; + foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).or_empty_list_if_null()) + { + if (message.Contains("You have upgradepackage v1.0.0 installed. Version 1.1.1-beta2 is available based on your source")) upgradeMessage = true; + } + + upgradeMessage.ShouldBeTrue(); + } + + [Fact] + public void should_have_a_successful_package_result() + { + _packageResult.Success.ShouldBeTrue(); + } + + [Fact] + public void should_not_have_inconclusive_package_result() + { + _packageResult.Inconclusive.ShouldBeFalse(); + } + + [Fact] + public void should_not_have_warning_package_result() + { + _packageResult.Warning.ShouldBeFalse(); + } + + [Fact] + public void config_should_match_package_result_name() + { + _packageResult.Name.ShouldEqual(Configuration.PackageNames); + } + + [Fact] + public void should_match_the_upgrade_version_of_the_new_beta() + { + _packageResult.Version.ShouldEqual("1.1.1-beta2"); + } + + [Fact] + public void should_have_executed_chocolateyBeforeModify_script_for_original_package() + { + MockLogger.contains_message("upgradepackage 1.0.0 Before Modification", LogLevel.Info).ShouldBeTrue(); + } + + [Fact] + public void should_have_executed_chocolateyBeforeModify_before_chocolateyInstall() + { + MockLogger.MessagesFor(LogLevel.Info).or_empty_list_if_null() + .SkipWhile(p => !p.Contains("upgradepackage 1.0.0 Before Modification")) + .Any(p => p.EndsWith("upgradepackage 1.1.1-beta2 Installed")) + .ShouldBeTrue(); + } + + [Fact] + public void should_not_have_executed_chocolateyUninstall_script_for_original_package() + { + MockLogger.contains_message("upgradepackage 1.0.0 Uninstalled", LogLevel.Info).ShouldBeFalse(); + } + + [Fact] + public void should_not_have_executed_chocolateyBeforeModify_script_for_new_package() + { + MockLogger.contains_message("upgradepackage 1.1.1-beta2 Before Modification", LogLevel.Info).ShouldBeFalse(); + } + + [Fact] + public void should_have_executed_chocolateyInstall_script_for_new_package() + { + MockLogger.contains_message("upgradepackage 1.1.1-beta2 Installed", LogLevel.Info).ShouldBeTrue(); + } + } + + [Concern(typeof (ChocolateyUpgradeCommand))] + public class when_upgrading_an_existing_prerelease_package_without_prerelease_specified : ScenariosBase + { + private PackageResult _packageResult; + + public override void Context() + { + base.Context(); + Configuration.Prerelease = true; + Scenario.install_package(Configuration, "upgradepackage", "1.1.1-beta"); + Configuration.Prerelease = false; + } + + public override void Because() + { + Results = Service.upgrade_run(Configuration); + _packageResult = Results.FirstOrDefault().Value; + } + + [Fact] + public void should_upgrade_where_install_location_reports() + { + Directory.Exists(_packageResult.InstallLocation).ShouldBeTrue(); + } + + [Fact] + public void should_upgrade_a_package_in_the_lib_directory() + { + var packageDir = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames); + + Directory.Exists(packageDir).ShouldBeTrue(); + } + + [Fact] + public void should_delete_the_rollback() + { + var packageDir = Path.Combine(Scenario.get_top_level(), "lib-bkp", Configuration.PackageNames); + + Directory.Exists(packageDir).ShouldBeFalse(); + } + + [Fact] + public void should_contain_newer_version_in_directory() + { + var shimFile = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, "tools", "console.exe"); + + File.ReadAllText(shimFile).ShouldEqual("1.1.1-beta2"); + } + + [Fact] + public void should_upgrade_the_package() + { + var packageFile = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, Configuration.PackageNames + Constants.PackageExtension); + var package = new OptimizedZipPackage(packageFile); + package.Version.Version.to_string().ShouldEqual("1.1.1.0"); + package.Version.to_string().ShouldEqual("1.1.1-beta2"); + } + + [Fact] + public void should_contain_a_warning_message_that_it_upgraded_successfully() + { + bool upgradedSuccessMessage = false; + foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).or_empty_list_if_null()) + { + if (message.Contains("upgraded 1/1")) upgradedSuccessMessage = true; + } + + upgradedSuccessMessage.ShouldBeTrue(); + } + + [Fact] + public void should_contain_a_warning_message_with_old_and_new_versions() + { + bool upgradeMessage = false; + foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).or_empty_list_if_null()) + { + if (message.Contains("You have upgradepackage v1.1.1-beta installed. Version 1.1.1-beta2 is available based on your source")) upgradeMessage = true; + } + + upgradeMessage.ShouldBeTrue(); + } + + [Fact] + public void should_have_a_successful_package_result() + { + _packageResult.Success.ShouldBeTrue(); + } + + [Fact] + public void should_not_have_inconclusive_package_result() + { + _packageResult.Inconclusive.ShouldBeFalse(); + } + + [Fact] + public void should_not_have_warning_package_result() + { + _packageResult.Warning.ShouldBeFalse(); + } + + [Fact] + public void config_should_match_package_result_name() + { + _packageResult.Name.ShouldEqual(Configuration.PackageNames); + } + + [Fact] + public void should_match_the_upgrade_version_of_the_new_beta() + { + _packageResult.Version.ShouldEqual("1.1.1-beta2"); + } + + [Fact] + public void should_have_executed_chocolateyBeforeModify_script_for_original_package() + { + MockLogger.contains_message("upgradepackage 1.1.1-beta Before Modification", LogLevel.Info).ShouldBeTrue(); + } + + [Fact] + public void should_have_executed_chocolateyBeforeModify_before_chocolateyInstall() + { + MockLogger.MessagesFor(LogLevel.Info).or_empty_list_if_null() + .SkipWhile(p => !p.Contains("upgradepackage 1.1.1-beta Before Modification")) + .Any(p => p.EndsWith("upgradepackage 1.1.1-beta2 Installed")) + .ShouldBeTrue(); + } + + [Fact] + public void should_not_have_executed_chocolateyUninstall_script_for_original_package() + { + MockLogger.contains_message("upgradepackage 1.1.1-beta Uninstalled", LogLevel.Info).ShouldBeFalse(); + } + + [Fact] + public void should_not_have_executed_chocolateyBeforeModify_script_for_new_package() + { + MockLogger.contains_message("upgradepackage 1.1.1-beta2 Before Modification", LogLevel.Info).ShouldBeFalse(); + } + + [Fact] + public void should_have_executed_chocolateyInstall_script_for_new_package() + { + MockLogger.contains_message("upgradepackage 1.1.1-beta2 Installed", LogLevel.Info).ShouldBeTrue(); + } + } + + [Concern(typeof(ChocolateyUpgradeCommand))] + public class when_upgrading_an_existing_prerelease_package_with_prerelease_available_with_excludeprelease_and_without_prerelease_specified : ScenariosBase + { + private PackageResult _packageResult; + + public override void Context() + { + base.Context(); + Configuration.Prerelease = true; + Scenario.install_package(Configuration, "upgradepackage", "1.1.1-beta"); + Configuration.Prerelease = false; + Configuration.UpgradeCommand.ExcludePrerelease = true; + } + public override void Because() + { + Results = Service.upgrade_run(Configuration); + _packageResult = Results.FirstOrDefault().Value; + } + + [Fact] + public void should_contain_a_message_that_you_have_the_latest_version_available() + { + bool expectedMessage = false; + foreach (var message in MockLogger.MessagesFor(LogLevel.Info).or_empty_list_if_null()) + { + if (message.Contains("upgradepackage v1.1.1-beta is newer")) expectedMessage = true; + } + + expectedMessage.ShouldBeTrue(); + } + + [Fact] + public void should_contain_a_message_that_no_packages_were_upgraded() + { + bool expectedMessage = false; + foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).or_empty_list_if_null()) + { + if (message.Contains("upgraded 0/1 ")) expectedMessage = true; + } + + expectedMessage.ShouldBeTrue(); + } + + [Fact] + public void should_not_create_a_rollback() + { + var packageDir = Path.Combine(Scenario.get_top_level(), "lib-bkp", Configuration.PackageNames); + + Directory.Exists(packageDir).ShouldBeFalse(); + } + + [Fact] + public void should_not_remove_the_package_from_the_lib_directory() + { + var packageDir = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames); + + Directory.Exists(packageDir).ShouldBeTrue(); + } + + [Fact] + public void should_be_the_same_version_of_the_package() + { + var packageFile = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, Configuration.PackageNames + Constants.PackageExtension); + var package = new OptimizedZipPackage(packageFile); + package.Version.Version.to_string().ShouldEqual("1.1.1.0"); + } + + [Fact] + public void should_have_a_successful_package_result() + { + _packageResult.Success.ShouldBeTrue(); + } + + [Fact] + public void should_have_inconclusive_package_result() + { + _packageResult.Inconclusive.ShouldBeTrue(); + } + + [Fact] + public void should_not_have_warning_package_result() + { + _packageResult.Warning.ShouldBeFalse(); + } + + [Fact] + public void should_only_find_the_last_stable_version() + { + _packageResult.Version.ShouldEqual("1.1.0"); + } + } + [Concern(typeof (ChocolateyUpgradeCommand))] public class when_force_upgrading_a_package : ScenariosBase { @@ -2480,6 +2952,105 @@ public void should_upgrade_packages_with_upgrades() upgradePackageResult.First().Value.Version.ShouldEqual("1.1.0"); } + [Fact] + public void should_skip_packages_without_upgrades() + { + var installPackageResult = Results.Where(x => x.Key == "installpackage").ToList(); + installPackageResult.Count.ShouldEqual(1, "installpackage must be there once"); + installPackageResult.First().Value.Version.ShouldEqual("1.0.0"); + } + } + + [Concern(typeof(ChocolateyUpgradeCommand))] + public class when_upgrading_all_packages_with_prereleases_installed : ScenariosBase + { + public override void Context() + { + base.Context(); + Configuration.Prerelease = true; + Scenario.install_package(Configuration, "upgradepackage", "1.1.1-beta"); + Configuration.Prerelease = false; + Configuration.PackageNames = Configuration.Input = "all"; + } + + public override void Because() + { + Results = Service.upgrade_run(Configuration); + } + + [Fact] + public void should_report_for_all_installed_packages() + { + Results.Count().ShouldEqual(3); + } + + [Fact] + public void should_upgrade_packages_with_upgrades() + { + var upgradePackageResult = Results.Where(x => x.Key == "upgradepackage").ToList(); + upgradePackageResult.Count.ShouldEqual(1, "upgradepackage must be there once"); + upgradePackageResult.First().Value.Version.ShouldEqual("1.1.1-beta2"); + } + + [Fact] + public void should_upgrade_upgradepackage() + { + var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "upgradepackage", "upgradepackage" + Constants.PackageExtension); + var package = new OptimizedZipPackage(packageFile); + package.Version.to_string().ShouldEqual("1.1.1-beta2"); + } + + [Fact] + public void should_skip_packages_without_upgrades() + { + var installPackageResult = Results.Where(x => x.Key == "installpackage").ToList(); + installPackageResult.Count.ShouldEqual(1, "installpackage must be there once"); + installPackageResult.First().Value.Version.ShouldEqual("1.0.0"); + } + } + + [Concern(typeof(ChocolateyUpgradeCommand))] + public class when_upgrading_all_packages_with_prereleases_installed_with_excludeprerelease_specified : ScenariosBase + { + public override void Context() + { + base.Context(); + Configuration.Prerelease = true; + Scenario.install_package(Configuration, "upgradepackage", "1.1.1-beta"); + Configuration.Prerelease = false; + + Configuration.PackageNames = Configuration.Input = "all"; + Configuration.UpgradeCommand.ExcludePrerelease = true; + } + + public override void Because() + { + Results = Service.upgrade_run(Configuration); + } + + [Fact] + public void should_report_for_all_installed_packages() + { + Results.Count().ShouldEqual(3); + } + + [Fact] + public void should_upgrade_packages_with_upgrades() + { + var upgradePackageResult = Results.Where(x => x.Key == "upgradepackage").ToList(); + upgradePackageResult.Count.ShouldEqual(1, "upgradepackage must be there once"); + // available version will show as last stable + upgradePackageResult.First().Value.Version.ShouldEqual("1.1.0"); + } + + [Fact] + public void should_not_upgrade_upgradepackage() + { + var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "upgradepackage", "upgradepackage" + Constants.PackageExtension); + var package = new OptimizedZipPackage(packageFile); + package.Version.to_string().ShouldEqual("1.1.1-beta"); + } + [Fact] public void should_skip_packages_without_upgrades() {