diff --git a/src/chocolatey.tests/infrastructure.app/services/AutomaticUninstallerServiceSpecs.cs b/src/chocolatey.tests/infrastructure.app/services/AutomaticUninstallerServiceSpecs.cs index 34720677c1..5706edd806 100644 --- a/src/chocolatey.tests/infrastructure.app/services/AutomaticUninstallerServiceSpecs.cs +++ b/src/chocolatey.tests/infrastructure.app/services/AutomaticUninstallerServiceSpecs.cs @@ -175,6 +175,34 @@ public void should_log_why_it_skips_auto_uninstaller() MockLogger.Verify(l => l.Info(" Skipping auto uninstaller - No registry snapshot."), Times.Once); } + [Fact] + public void should_not_call_command_executor() + { + commandExecutor.Verify( + c => c.execute(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny>(), It.IsAny>(), It.IsAny()), + Times.Never); + } + } + + public class when_package_is_missing : AutomaticUninstallerServiceSpecsBase + { + public override void Context() + { + base.Context(); + packageInformation.Package = null; + } + + public override void Because() + { + service.run(packageResult, config); + } + + [Fact] + public void should_log_why_it_skips_auto_uninstaller() + { + MockLogger.Verify(l => l.Info(" Skipping auto uninstaller - No package in package information."), Times.Once); + } + [Fact] public void should_not_call_command_executor() { diff --git a/src/chocolatey/infrastructure.app/services/AutomaticUninstallerService.cs b/src/chocolatey/infrastructure.app/services/AutomaticUninstallerService.cs index 9388db4b88..a749186a6e 100644 --- a/src/chocolatey/infrastructure.app/services/AutomaticUninstallerService.cs +++ b/src/chocolatey/infrastructure.app/services/AutomaticUninstallerService.cs @@ -28,6 +28,7 @@ namespace chocolatey.infrastructure.app.services using domain.installers; using filesystem; using infrastructure.commands; + using logging; using results; public class AutomaticUninstallerService : IAutomaticUninstallerService @@ -83,6 +84,13 @@ public void run(PackageResult packageResult, ChocolateyConfiguration config) return; } + var package = pkgInfo.Package; + if (package == null) + { + this.Log().Info(" Skipping auto uninstaller - No package in package information."); + return; + } + this.Log().Info(" Running auto uninstaller..."); if (WaitForCleanup) {