public void Constructor_AllParametersAreSet_ObjectIsInstantiated() { // Arrange var installationStatusProvider = new Mock<IInstallationStatusProvider>(); var packageConfigurationAccessor = new Mock<IPackageConfigurationAccessor>(); var filesystemAccessor = new Mock<IFilesystemAccessor>(); var powerShellExecutor = new Mock<IPowerShellExecutor>(); // Act var packageUninstaller = new PackageUninstaller( installationStatusProvider.Object, packageConfigurationAccessor.Object, filesystemAccessor.Object, powerShellExecutor.Object); // Assert Assert.IsNotNull(packageUninstaller); }
public void Uninstall_UninstallSpecificVersion_ResultIsFalse() { // Arrange string packageId = "Package.A"; SemanticVersion version = TestUtilities.GetPackage(packageId, true, 3).Version; var installationStatusProvider = new Mock<IInstallationStatusProvider>(); var packageConfigurationAccessor = new Mock<IPackageConfigurationAccessor>(); var filesystemAccessor = new Mock<IFilesystemAccessor>(); var powerShellExecutor = new Mock<IPowerShellExecutor>(); var packages = new List<NuDeployPackageInfo> { TestUtilities.GetPackage(packageId, false, 1), TestUtilities.GetPackage(packageId, false, 2), TestUtilities.GetPackage(packageId, true, 3) }; installationStatusProvider.Setup(i => i.GetPackageInfo(packageId)).Returns(packages); var packageUninstaller = new PackageUninstaller( installationStatusProvider.Object, packageConfigurationAccessor.Object, filesystemAccessor.Object, powerShellExecutor.Object); // Act var result = packageUninstaller.Uninstall(packageId, version); // Assert Assert.AreEqual(result.Status, ServiceResultType.Failure); }
public void Uninstall_UninstallScriptIsNotFound_ResultIsFalse() { // Arrange string packageId = "Package.A"; SemanticVersion version = null; var installationStatusProvider = new Mock<IInstallationStatusProvider>(); var packageConfigurationAccessor = new Mock<IPackageConfigurationAccessor>(); var filesystemAccessor = new Mock<IFilesystemAccessor>(); var powerShellExecutor = new Mock<IPowerShellExecutor>(); var package = TestUtilities.GetPackage(packageId, true); installationStatusProvider.Setup(i => i.GetPackageInfo(packageId)).Returns(new[] { package }); filesystemAccessor.Setup(f => f.FileExists(It.Is<string>(s => s.EndsWith(PackageUninstaller.UninstallPowerShellScriptName)))).Returns(false); var packageUninstaller = new PackageUninstaller( installationStatusProvider.Object, packageConfigurationAccessor.Object, filesystemAccessor.Object, powerShellExecutor.Object); // Act var result = packageUninstaller.Uninstall(packageId, version); // Assert Assert.AreEqual(result.Status, ServiceResultType.Failure); }
public void Uninstall_PackageIsNotInstalled_ResultIsFalse() { // Arrange string packageId = "Package.A"; SemanticVersion version = null; var installationStatusProvider = new Mock<IInstallationStatusProvider>(); var packageConfigurationAccessor = new Mock<IPackageConfigurationAccessor>(); var filesystemAccessor = new Mock<IFilesystemAccessor>(); var powerShellExecutor = new Mock<IPowerShellExecutor>(); var packageUninstaller = new PackageUninstaller( installationStatusProvider.Object, packageConfigurationAccessor.Object, filesystemAccessor.Object, powerShellExecutor.Object); // Act var result = packageUninstaller.Uninstall(packageId, version); // Assert Assert.AreEqual(result.Status, ServiceResultType.Failure); }
public void Uninstall_PackageIdIsInvalid_ArgumentExceptionIsThrown(string packageId) { // Arrange SemanticVersion version = null; var installationStatusProvider = new Mock<IInstallationStatusProvider>(); var packageConfigurationAccessor = new Mock<IPackageConfigurationAccessor>(); var filesystemAccessor = new Mock<IFilesystemAccessor>(); var powerShellExecutor = new Mock<IPowerShellExecutor>(); var packageUninstaller = new PackageUninstaller( installationStatusProvider.Object, packageConfigurationAccessor.Object, filesystemAccessor.Object, powerShellExecutor.Object); // Act packageUninstaller.Uninstall(packageId, version); }
public void Uninstall_ExecutingUninstallScriptSucceeds_ResultIsTrue() { // Arrange string packageId = "Package.A"; SemanticVersion version = null; var installationStatusProvider = new Mock<IInstallationStatusProvider>(); var packageConfigurationAccessor = new Mock<IPackageConfigurationAccessor>(); var filesystemAccessor = new Mock<IFilesystemAccessor>(); var powerShellExecutor = new Mock<IPowerShellExecutor>(); var package = TestUtilities.GetPackage(packageId, true); installationStatusProvider.Setup(i => i.GetPackageInfo(packageId)).Returns(new[] { package }); packageConfigurationAccessor.Setup(p => p.Remove(It.IsAny<string>())).Returns(new SuccessResult()); filesystemAccessor.Setup(f => f.FileExists(It.Is<string>(s => s.EndsWith(PackageUninstaller.UninstallPowerShellScriptName)))).Returns(true); filesystemAccessor.Setup(f => f.DeleteDirectory(It.IsAny<string>())).Returns(true); powerShellExecutor.Setup(p => p.ExecuteScript(It.Is<string>(s => s.EndsWith(PackageUninstaller.UninstallPowerShellScriptName)))).Returns(new SuccessResult()); var packageUninstaller = new PackageUninstaller( installationStatusProvider.Object, packageConfigurationAccessor.Object, filesystemAccessor.Object, powerShellExecutor.Object); // Act var result = packageUninstaller.Uninstall(packageId, version); // Assert Assert.AreEqual(result.Status, ServiceResultType.Success); }
public void Uninstall_ExecutingUninstallScriptSucceeds_PackageIsRemovedFromConfiguration() { // Arrange string packageId = "Package.A"; SemanticVersion version = null; var installationStatusProvider = new Mock<IInstallationStatusProvider>(); var packageConfigurationAccessor = new Mock<IPackageConfigurationAccessor>(); var filesystemAccessor = new Mock<IFilesystemAccessor>(); var powerShellExecutor = new Mock<IPowerShellExecutor>(); var package = TestUtilities.GetPackage(packageId, true); installationStatusProvider.Setup(i => i.GetPackageInfo(packageId)).Returns(new[] { package }); filesystemAccessor.Setup(f => f.FileExists(It.Is<string>(s => s.EndsWith(PackageUninstaller.UninstallPowerShellScriptName)))).Returns(true); powerShellExecutor.Setup(p => p.ExecuteScript(It.Is<string>(s => s.EndsWith(PackageUninstaller.UninstallPowerShellScriptName)))).Returns(new SuccessResult()); packageConfigurationAccessor.Setup(p => p.Remove(It.IsAny<string>())).Returns(new SuccessResult()); var packageUninstaller = new PackageUninstaller( installationStatusProvider.Object, packageConfigurationAccessor.Object, filesystemAccessor.Object, powerShellExecutor.Object); // Act packageUninstaller.Uninstall(packageId, version); // Assert packageConfigurationAccessor.Verify(p => p.Remove(packageId), Times.Once()); }