diff --git a/Scenarios.md b/Scenarios.md index 2488a4de8b..95edb7a46d 100644 --- a/Scenarios.md +++ b/Scenarios.md @@ -126,7 +126,7 @@ * should install where install location reports * should not create a shim for ignored executable in the bin directory * should not create a shim for mismatched case ignored executable in the bin directory - * should not create an extensions folder for the pacakge + * should not create an extensions folder for the package * should not have inconclusive package result * should not have warning package result @@ -315,7 +315,7 @@ * should not have inconclusive package result * should not have warning package result -### ChocolateyUninstallCommand [ 12 Scenario(s), 82 Observation(s) ] +### ChocolateyUninstallCommand [ 12 Scenario(s), 83 Observation(s) ] #### when force uninstalling a package @@ -359,6 +359,7 @@ * should contain a warning message that it uninstalled successfully * should delete a shim for console in the bin directory * should delete a shim for graphical in the bin directory + * should delete any files created during the install * should delete the rollback * should have a successful package result * should not have inconclusive package result diff --git a/src/chocolatey.tests.integration/Scenario.cs b/src/chocolatey.tests.integration/Scenario.cs index 9147f0fe07..08fa4ae024 100644 --- a/src/chocolatey.tests.integration/Scenario.cs +++ b/src/chocolatey.tests.integration/Scenario.cs @@ -23,10 +23,14 @@ namespace chocolatey.tests.integration using chocolatey.infrastructure.app.configuration; using chocolatey.infrastructure.app.domain; using chocolatey.infrastructure.app.nuget; + using chocolatey.infrastructure.app.services; using chocolatey.infrastructure.filesystem; public class Scenario { + + private static IChocolateyPackageService _service; + private static readonly DotNetFileSystem _fileSystem = new DotNetFileSystem(); public static string get_top_level() @@ -79,13 +83,26 @@ public static void add_packages_to_source_location(ChocolateyConfiguration confi public static void install_package(ChocolateyConfiguration config, string packageId, string version) { - var pattern = "{0}.{1}{2}".format_with(packageId, string.IsNullOrWhiteSpace(version) ? "*" : version, Constants.PackageExtension); - var files = _fileSystem.get_files(config.Sources, pattern); - foreach (var file in files) + if (_service == null) { - var packageManager = NugetCommon.GetPackageManager(config,new ChocolateyNugetLogger(), null, null, false); - packageManager.InstallPackage(new OptimizedZipPackage(file), false,false); + _service= NUnitSetup.Container.GetInstance(); } + + var originalPackageName = config.PackageNames; + var originalPackageVersion = config.Version; + + config.PackageNames = packageId; + config.Version = version; + _service.install_run(config); + config.PackageNames = originalPackageName; + config.Version = originalPackageVersion; + //var pattern = "{0}.{1}{2}".format_with(packageId, string.IsNullOrWhiteSpace(version) ? "*" : version, Constants.PackageExtension); + //var files = _fileSystem.get_files(config.Sources, pattern); + //foreach (var file in files) + //{ + // var packageManager = NugetCommon.GetPackageManager(config, new ChocolateyNugetLogger(), null, null, false); + // packageManager.InstallPackage(new OptimizedZipPackage(file), false,false); + //} } private static ChocolateyConfiguration baseline_configuration() diff --git a/src/chocolatey.tests.integration/context/installpackage/installpackage.1.0.0.nupkg b/src/chocolatey.tests.integration/context/installpackage/installpackage.1.0.0.nupkg index 749cb1a648..277f38fee2 100644 Binary files a/src/chocolatey.tests.integration/context/installpackage/installpackage.1.0.0.nupkg and b/src/chocolatey.tests.integration/context/installpackage/installpackage.1.0.0.nupkg differ diff --git a/src/chocolatey.tests.integration/context/installpackage/tools/chocolateyinstall.ps1 b/src/chocolatey.tests.integration/context/installpackage/tools/chocolateyinstall.ps1 index d64eb8f47b..2491151c21 100644 --- a/src/chocolatey.tests.integration/context/installpackage/tools/chocolateyinstall.ps1 +++ b/src/chocolatey.tests.integration/context/installpackage/tools/chocolateyinstall.ps1 @@ -1 +1,5 @@ -Write-Output "$env:PackageName $env:PackageVersion Installed" \ No newline at end of file +$toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)" +"simple file" | Out-File "$toolsDir\simplefile.txt" -force + +Write-Output "$env:PackageName $env:PackageVersion Installed" + diff --git a/src/chocolatey.tests.integration/infrastructure/filesystem/DotNetFileSystemSpecs.cs b/src/chocolatey.tests.integration/infrastructure/filesystem/DotNetFileSystemSpecs.cs index 7d032c0b37..653fb137c3 100644 --- a/src/chocolatey.tests.integration/infrastructure/filesystem/DotNetFileSystemSpecs.cs +++ b/src/chocolatey.tests.integration/infrastructure/filesystem/DotNetFileSystemSpecs.cs @@ -233,7 +233,7 @@ public override void Because() { if (FileSystem.directory_exists(TestDirectory)) { - Directory.Delete(TestDirectory); + Directory.Delete(TestDirectory, recursive: true); } FileSystem.create_directory(TestDirectory); diff --git a/src/chocolatey.tests.integration/scenarios/UninstallScenarios.cs b/src/chocolatey.tests.integration/scenarios/UninstallScenarios.cs index 15b3851dce..d207d7153c 100644 --- a/src/chocolatey.tests.integration/scenarios/UninstallScenarios.cs +++ b/src/chocolatey.tests.integration/scenarios/UninstallScenarios.cs @@ -175,6 +175,14 @@ public void should_delete_a_shim_for_graphical_in_the_bin_directory() File.Exists(shimfile).ShouldBeFalse(); } + [Fact] + public void should_delete_any_files_created_during_the_install() + { + var generatedFile = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames,"simplefile.txt"); + + File.Exists(generatedFile).ShouldBeFalse(); + } + [Fact] public void should_contain_a_warning_message_that_it_uninstalled_successfully() { diff --git a/src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs b/src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs index 12ae77dace..48f2e50ad8 100644 --- a/src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs +++ b/src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs @@ -1562,7 +1562,7 @@ public override void Context() string dotChocolatey = Path.Combine(Scenario.get_top_level(), ".chocolatey"); if (Directory.Exists(dotChocolatey)) { - Directory.Delete(dotChocolatey); + Directory.Delete(dotChocolatey, recursive: true); } } @@ -1584,8 +1584,8 @@ public void should_remove_the_legacy_folder_version_of_the_package() { var packageDir = Path.Combine(Scenario.get_top_level(), "lib", "isdependency.1.0.0"); Directory.Exists(packageDir).ShouldBeFalse(); - } - + } + [Fact] public void should_replace_the_legacy_folder_version_of_the_package_with_a_lib_package_folder_that_has_no_version() { @@ -1599,15 +1599,15 @@ public void should_not_upgrade_the_parent_package() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "hasdependency.1.0.0", "hasdependency.1.0.0.nupkg"); var package = new OptimizedZipPackage(packageFile); package.Version.Version.to_string().ShouldEqual("1.0.0.0"); - } - + } + [Fact] public void should_not_add_a_versionless_parent_package_folder_to_the_lib_dir() { var packageDir = Path.Combine(Scenario.get_top_level(), "lib", "hasdependency"); Directory.Exists(packageDir).ShouldBeFalse(); - } - + } + [Fact] public void should_leave_the_parent_package_as_legacy_folder() { @@ -1635,7 +1635,7 @@ public void should_not_add_a_versionless_exact_version_package_folder_to_the_lib { var packageDir = Path.Combine(Scenario.get_top_level(), "lib", "isexactversiondependency"); Directory.Exists(packageDir).ShouldBeFalse(); - } + } [Fact] public void should_contain_a_message_the_dependency_upgraded_successfully() @@ -1778,7 +1778,7 @@ public override void Context() string dotChocolatey = Path.Combine(Scenario.get_top_level(), ".chocolatey"); if (Directory.Exists(dotChocolatey)) { - Directory.Delete(dotChocolatey); + Directory.Delete(dotChocolatey, recursive: true); } } @@ -1853,7 +1853,7 @@ public void should_remove_the_legacy_folder_version_of_the_exact_version_package { var packageDir = Path.Combine(Scenario.get_top_level(), "lib", "isexactversiondependency.1.0.0"); Directory.Exists(packageDir).ShouldBeFalse(); - } + } [Fact] public void should_contain_a_message_that_everything_upgraded_successfully() diff --git a/src/chocolatey/infrastructure.app/services/NugetService.cs b/src/chocolatey/infrastructure.app/services/NugetService.cs index 835ef7ea43..34d04e26f2 100644 --- a/src/chocolatey/infrastructure.app/services/NugetService.cs +++ b/src/chocolatey/infrastructure.app/services/NugetService.cs @@ -921,6 +921,11 @@ public void remove_installation_files(IPackage removedPackage, ChocolateyPackage } } } + + if (_fileSystem.directory_exists(installDir) && !_fileSystem.get_files(installDir, "*.*", SearchOption.AllDirectories).or_empty_list_if_null().Any()) + { + _fileSystem.delete_directory_if_exists(installDir, recursive: true); + } } private void set_package_names_if_all_is_specified(ChocolateyConfiguration config, Action customAction)