public void UninstallPackageCmdletPassesForceSwitchCorrectly() { // Arrange var packageA = PackageUtility.CreatePackage( "A", "1.0", dependencies: new[] { new PackageDependency("B") }); var packageB = PackageUtility.CreatePackage("B", "1.0"); var packageRepository = new MockPackageRepository { packageA, packageB }; var packageManager = new MockVsPackageManager2( @"c:\solution", packageRepository); InstallPackage("A", packageManager); var installedPackages = packageManager.LocalRepository.GetPackages().ToList(); Assert.Equal(new[] { packageA, packageB }, installedPackages, PackageEqualityComparer.IdAndVersion); // Act var packageManagerFactory = new Mock <IVsPackageManagerFactory>(); packageManagerFactory.Setup(m => m.CreatePackageManager()).Returns(packageManager); var cmdlet = new UninstallPackageCommand( packageManager.SolutionManager, packageManagerFactory.Object, null, new Mock <IVsCommonOperations>().Object, new Mock <IDeleteOnRestartManager>().Object); cmdlet.Id = "B"; // Assert: packageB cannot be uninstalled without -Force ExceptionAssert.Throws <InvalidOperationException>(() => cmdlet.Execute(), "Unable to uninstall 'B 1.0' because 'A 1.0' depends on it."); // Assert: packageB can be uninstalled with -Force cmdlet.Force = new SwitchParameter(true); cmdlet.Execute(); installedPackages = packageManager.LocalRepository.GetPackages().ToList(); Assert.Equal(1, installedPackages.Count); Assert.Equal(packageA, installedPackages[0], PackageEqualityComparer.IdAndVersion); }
public void UninstallPackageCmdletWithRemoveDependencySwitch() { // Arrange var packageA = PackageUtility.CreatePackage( "A", "1.0", dependencies: new[] { new PackageDependency("B") }); var packageB = PackageUtility.CreatePackage("B", "1.0"); var packageRepository = new MockPackageRepository { packageA, packageB }; var packageManager = new MockVsPackageManager2( @"c:\solution", packageRepository); InstallPackage("A", packageManager); var installedPackages = packageManager.LocalRepository.GetPackages().ToList(); Assert.Equal(new[] { packageA, packageB }, installedPackages, PackageEqualityComparer.IdAndVersion); // Act var packageManagerFactory = new Mock <IVsPackageManagerFactory>(); packageManagerFactory.Setup(m => m.CreatePackageManager()).Returns(packageManager); var cmdlet = new UninstallPackageCommand( packageManager.SolutionManager, packageManagerFactory.Object, null, new Mock <IVsCommonOperations>().Object, new Mock <IDeleteOnRestartManager>().Object); cmdlet.Id = "A"; cmdlet.RemoveDependencies = new SwitchParameter(true); cmdlet.Execute(); // Assert: both packageA & packageB are uninstalled installedPackages = packageManager.LocalRepository.GetPackages().ToList(); Assert.Equal(0, installedPackages.Count); }
public void UninstallPackageCmdletPassesForceSwitchCorrectly() { // Arrange var packageA = PackageUtility.CreatePackage( "A", "1.0", dependencies: new[] { new PackageDependency("B") }); var packageB = PackageUtility.CreatePackage("B", "1.0"); var packageRepository = new MockPackageRepository { packageA, packageB }; var packageManager = new MockVsPackageManager2( @"c:\solution", packageRepository); InstallPackage("A", packageManager); var installedPackages = packageManager.LocalRepository.GetPackages().ToList(); Assert.Equal(new[] { packageA, packageB }, installedPackages, PackageEqualityComparer.IdAndVersion); // Act var packageManagerFactory = new Mock<IVsPackageManagerFactory>(); packageManagerFactory.Setup(m => m.CreatePackageManager()).Returns(packageManager); var cmdlet = new UninstallPackageCommand( packageManager.SolutionManager, packageManagerFactory.Object, null, new Mock<IVsCommonOperations>().Object, new Mock<IDeleteOnRestartManager>().Object); cmdlet.Id = "B"; // Assert: packageB cannot be uninstalled without -Force ExceptionAssert.Throws<InvalidOperationException>(() => cmdlet.Execute(), "Unable to uninstall 'B 1.0' because 'A 1.0' depends on it."); // Assert: packageB can be uninstalled with -Force cmdlet.Force = new SwitchParameter(true); cmdlet.Execute(); installedPackages = packageManager.LocalRepository.GetPackages().ToList(); Assert.Equal(1, installedPackages.Count); Assert.Equal(packageA, installedPackages[0], PackageEqualityComparer.IdAndVersion); }
public void UninstallPackageCmdletWithRemoveDependencySwitch() { // Arrange var packageA = PackageUtility.CreatePackage( "A", "1.0", dependencies: new[] { new PackageDependency("B") }); var packageB = PackageUtility.CreatePackage("B", "1.0"); var packageRepository = new MockPackageRepository { packageA, packageB }; var packageManager = new MockVsPackageManager2( @"c:\solution", packageRepository); InstallPackage("A", packageManager); var installedPackages = packageManager.LocalRepository.GetPackages().ToList(); Assert.Equal(new[] { packageA, packageB }, installedPackages, PackageEqualityComparer.IdAndVersion); // Act var packageManagerFactory = new Mock<IVsPackageManagerFactory>(); packageManagerFactory.Setup(m => m.CreatePackageManager()).Returns(packageManager); var cmdlet = new UninstallPackageCommand( packageManager.SolutionManager, packageManagerFactory.Object, null, new Mock<IVsCommonOperations>().Object, new Mock<IDeleteOnRestartManager>().Object); cmdlet.Id = "A"; cmdlet.RemoveDependencies = new SwitchParameter(true); cmdlet.Execute(); // Assert: both packageA & packageB are uninstalled installedPackages = packageManager.LocalRepository.GetPackages().ToList(); Assert.Equal(0, installedPackages.Count); }