public void UninstallPackageDoesNotRemoveDependenciesIfFlagIsFalse() { // Arrange var activeRepository = new MockPackageRepository(); var localRepository = new Mock<MockPackageRepository>() { CallBase = true }; localRepository.As<ISharedPackageRepository>(); var projectRepository = new MockProjectPackageRepository(localRepository.Object); var project = TestUtils.GetProject("Foo"); var projectSystem = new MockProjectSystem(new FrameworkName(".NETCore, Version=4.5")); var projectManager = new ProjectManager(activeRepository, new DefaultPackagePathResolver(new MockFileSystem()), projectSystem, projectRepository); var packageA = PackageUtility.CreatePackage("A", dependencies: new[] { new PackageDependency("B") }); var packageB = PackageUtility.CreatePackage("B"); var scriptExecutor = new Mock<IScriptExecutor>(MockBehavior.Strict); scriptExecutor.Setup(s => s.Execute(@"C:\MockFileSystem\A.1.0", "uninstall.ps1", packageA, project, new FrameworkName(".NETCore, Version=4.5"), NullLogger.Instance)).Returns(true).Verifiable(); var packageManager = new Mock<VsPackageManager>(TestUtils.GetSolutionManager(), activeRepository, new Mock<IFileSystemProvider>().Object, new MockFileSystem(), localRepository.Object, new Mock<IDeleteOnRestartManager>().Object, new Mock<VsPackageInstallerEvents>().Object) { CallBase = true }; var packageManagerFactory = new Mock<IVsPackageManagerFactory>(); packageManagerFactory.Setup(m => m.CreatePackageManager(activeRepository, false)).Returns(packageManager.Object); packageManager.Setup(m => m.GetProjectManager(project)).Returns(projectManager).Verifiable(); var packageUninstaller = new VsPackageUninstaller(packageManagerFactory.Object, activeRepository, scriptExecutor.Object); // Act localRepository.Object.AddPackage(packageA); localRepository.Object.AddPackage(packageB); packageUninstaller.UninstallPackage(project, "A", removeDependencies: false); // Assert scriptExecutor.Verify(); Assert.False(localRepository.Object.Contains(packageA)); Assert.True(localRepository.Object.Contains(packageB)); }
public void UninstallPackageDoesNotForceRemovesPackages() { // 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); var packageManagerFactory = new Mock <IVsPackageManagerFactory>(); packageManagerFactory.Setup(m => m.CreatePackageManager(It.IsAny <IPackageRepository>(), false)).Returns(packageManager); var scriptExecutor = new Mock <IScriptExecutor>(MockBehavior.Strict); var packageUninstaller = new VsPackageUninstaller( packageManagerFactory.Object, packageManager.LocalRepository, scriptExecutor.Object); // Act and Assert var project = packageManager.SolutionManager.GetProject("default"); ExceptionAssert.Throws <InvalidOperationException>(() => packageUninstaller.UninstallPackage(project, "B", removeDependencies: true), "Unable to uninstall 'B 1.0' because 'A 1.0' depends on it."); }
public void UninstallPackageExecutesUninstallScript() { // Arrange var activeRepository = new MockPackageRepository(); var localRepository = new Mock<MockPackageRepository>() { CallBase = true }; localRepository.As<ISharedPackageRepository>(); var projectRepository = new MockProjectPackageRepository(localRepository.Object); var project = TestUtils.GetProject("Foo"); var projectSystem = new MockProjectSystem(); var projectManager = new ProjectManager(activeRepository, new DefaultPackagePathResolver(new MockFileSystem()), projectSystem, projectRepository); var package = PackageUtility.CreatePackage("A"); var scriptExecutor = new Mock<IScriptExecutor>(MockBehavior.Strict); scriptExecutor.Setup(s => s.Execute(@"C:\MockFileSystem\A.1.0", "uninstall.ps1", package, project, NullLogger.Instance)).Returns(true).Verifiable(); var packageManager = new Mock<VsPackageManager>(TestUtils.GetSolutionManager(), activeRepository, new Mock<IFileSystemProvider>().Object, new MockFileSystem(), localRepository.Object, new Mock<IRecentPackageRepository>().Object, new Mock<VsPackageInstallerEvents>().Object) { CallBase = true }; var packageManagerFactory = new Mock<IVsPackageManagerFactory>(); packageManagerFactory.Setup(m => m.CreatePackageManager(activeRepository, false, false)).Returns(packageManager.Object); packageManager.Setup(m => m.GetProjectManager(project)).Returns(projectManager).Verifiable(); var packageUninstaller = new VsPackageUninstaller(packageManagerFactory.Object, activeRepository, scriptExecutor.Object); // Act localRepository.Object.AddPackage(package); packageUninstaller.UninstallPackage(project, "A", removeDependencies: true); // Assert scriptExecutor.Verify(); Assert.False(localRepository.Object.Contains(package)); }
public void UninstallPackageExecutesUninstallScript() { // Arrange var packageA = PackageUtility.CreatePackage("A", content: new[] {"file1.txt"}); var packageRepository = new MockPackageRepository { packageA, }; var scriptExecutor = new Mock<IScriptExecutor>(MockBehavior.Strict); var packageManager = new MockVsPackageManager2( @"c:\solution", packageRepository); InstallPackage("A", packageManager); var installedPackages = packageManager.LocalRepository.GetPackages().ToList(); Assert.Equal(new[] { packageA }, installedPackages, PackageEqualityComparer.IdAndVersion); var project = packageManager.SolutionManager.GetProject("default"); scriptExecutor.Setup(s => s.Execute(@"c:\solution\A.1.0", "uninstall.ps1", packageA, project, new FrameworkName(".NETFramework,Version=v4.0.0.0"), NullLogger.Instance)).Returns(true).Verifiable(); var packageManagerFactory = new Mock<IVsPackageManagerFactory>(); packageManagerFactory.Setup(m => m.CreatePackageManager(It.IsAny<IPackageRepository>(), false)).Returns(packageManager); var packageUninstaller = new VsPackageUninstaller( packageManagerFactory.Object, packageManager.LocalRepository, scriptExecutor.Object); // Act packageUninstaller.UninstallPackage(project, "A", removeDependencies: true); // Assert scriptExecutor.Verify(); installedPackages = packageManager.LocalRepository.GetPackages().ToList(); Assert.Equal(0, installedPackages.Count); }
public void UninstallPackageRemovesDependenciesIfFlagIsTrue() { // Arrange var activeRepository = new MockPackageRepository(); var localRepository = new Mock <MockPackageRepository>() { CallBase = true }; localRepository.As <ISharedPackageRepository>(); var projectRepository = new MockProjectPackageRepository(localRepository.Object); var project = TestUtils.GetProject("Foo"); var projectSystem = new MockProjectSystem(); var projectManager = new ProjectManager(activeRepository, new DefaultPackagePathResolver(new MockFileSystem()), projectSystem, projectRepository); var packageA = PackageUtility.CreatePackage("A", dependencies: new[] { new PackageDependency("B") }); var packageB = PackageUtility.CreatePackage("B", content: new[] { "file1.txt" }); var scriptExecutor = new Mock <IScriptExecutor>(MockBehavior.Strict); scriptExecutor.Setup(s => s.Execute(@"C:\MockFileSystem\A.1.0", "uninstall.ps1", packageA, project, It.IsAny <FrameworkName>(), NullLogger.Instance)).Returns(true).Verifiable(); scriptExecutor.Setup(s => s.Execute(@"C:\MockFileSystem\B.1.0", "uninstall.ps1", packageB, project, It.IsAny <FrameworkName>(), NullLogger.Instance)).Returns(true).Verifiable(); var packageManager = new Mock <VsPackageManager>( TestUtils.GetSolutionManager(), activeRepository, new Mock <IFileSystemProvider>().Object, new MockFileSystem(), localRepository.Object, new Mock <IDeleteOnRestartManager>().Object, new Mock <VsPackageInstallerEvents>().Object, /* multiFrameworkTargeting */ null) { CallBase = true }; projectManager.LocalRepository.AddPackage(packageA); projectManager.LocalRepository.AddPackage(packageB); var packageManagerFactory = new Mock <IVsPackageManagerFactory>(); packageManagerFactory.Setup(m => m.CreatePackageManager(activeRepository, false)).Returns(packageManager.Object); packageManager.Setup(m => m.GetProjectManager(project)).Returns(projectManager).Verifiable(); var packageUninstaller = new VsPackageUninstaller(packageManagerFactory.Object, activeRepository, scriptExecutor.Object); // Act localRepository.Object.AddPackage(packageA); localRepository.Object.AddPackage(packageB); packageUninstaller.UninstallPackage(project, "A", removeDependencies: true); // Assert scriptExecutor.Verify(); Assert.False(localRepository.Object.Contains(packageA)); Assert.False(localRepository.Object.Contains(packageB)); }
public void UninstallPackageDoesNotForceRemovesPackages() { // Arrange var activeRepository = new MockPackageRepository(); var localRepository = new Mock <MockPackageRepository>() { CallBase = true }; localRepository.As <ISharedPackageRepository>(); var projectRepository = new MockProjectPackageRepository(localRepository.Object); var project = TestUtils.GetProject("Foo"); var projectSystem = new MockProjectSystem(); var projectManager = new ProjectManager(activeRepository, new DefaultPackagePathResolver(new MockFileSystem()), projectSystem, projectRepository); var packageA = PackageUtility.CreatePackage("A", dependencies: new[] { new PackageDependency("B") }); var packageB = PackageUtility.CreatePackage("B"); var scriptExecutor = new Mock <IScriptExecutor>(MockBehavior.Strict); scriptExecutor.Setup(s => s.Execute(@"C:\MockFileSystem\A.1.0", "uninstall.ps1", packageA, project, It.IsAny <FrameworkName>(), NullLogger.Instance)).Returns(true).Verifiable(); var packageManager = new Mock <VsPackageManager>( TestUtils.GetSolutionManager(), activeRepository, new Mock <IFileSystemProvider>().Object, new MockFileSystem(), localRepository.Object, new Mock <IDeleteOnRestartManager>().Object, new Mock <VsPackageInstallerEvents>().Object, null) { CallBase = true }; var packageManagerFactory = new Mock <IVsPackageManagerFactory>(); packageManagerFactory.Setup(m => m.CreatePackageManager(activeRepository, false)).Returns(packageManager.Object); packageManager.Setup(m => m.GetProjectManager(project)).Returns(projectManager).Verifiable(); var packageUninstaller = new VsPackageUninstaller(packageManagerFactory.Object, activeRepository, scriptExecutor.Object); // Act and Assert localRepository.Object.AddPackage(packageA); localRepository.Object.AddPackage(packageB); ExceptionAssert.Throws <InvalidOperationException>(() => packageUninstaller.UninstallPackage(project, "B", removeDependencies: true), "Unable to uninstall 'B 1.0' because 'A 1.0' depends on it."); }
public void UninstallPackageRemovesDependenciesIfFlagIsTrue() { // 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); var project = packageManager.SolutionManager.GetProject("default"); var packageManagerFactory = new Mock <IVsPackageManagerFactory>(); packageManagerFactory.Setup(m => m.CreatePackageManager(It.IsAny <IPackageRepository>(), false)).Returns(packageManager); var scriptExecutor = new Mock <IScriptExecutor>(MockBehavior.Strict); scriptExecutor.Setup(s => s.Execute(@"c:\solution\A.1.0", "uninstall.ps1", packageA, project, new FrameworkName(".NETFramework,Version=v4.0.0.0"), NullLogger.Instance)).Returns(true).Verifiable(); scriptExecutor.Setup(s => s.Execute(@"c:\solution\B.1.0", "uninstall.ps1", packageB, project, It.IsAny <FrameworkName>(), NullLogger.Instance)).Returns(true).Verifiable(); var packageUninstaller = new VsPackageUninstaller( packageManagerFactory.Object, packageManager.LocalRepository, scriptExecutor.Object); // Act packageUninstaller.UninstallPackage(project, "A", removeDependencies: true); // Assert: both packageA and packageB are uninstalled scriptExecutor.Verify(); installedPackages = packageManager.LocalRepository.GetPackages().ToList(); Assert.Equal(0, installedPackages.Count); }
public void UninstallPackageExecutesUninstallScript() { // Arrange var activeRepository = new MockPackageRepository(); var localRepository = new Mock <MockPackageRepository>() { CallBase = true }; localRepository.As <ISharedPackageRepository>(); var projectRepository = new MockProjectPackageRepository(localRepository.Object); var project = TestUtils.GetProject("Foo"); var projectSystem = new MockProjectSystem(new FrameworkName(".NETCore, Version=4.5")); var projectManager = new ProjectManager(activeRepository, new DefaultPackagePathResolver(new MockFileSystem()), projectSystem, projectRepository); var package = PackageUtility.CreatePackage("A"); var scriptExecutor = new Mock <IScriptExecutor>(MockBehavior.Strict); scriptExecutor.Setup(s => s.Execute(@"C:\MockFileSystem\A.1.0", "uninstall.ps1", package, project, new FrameworkName(".NETCore, Version=4.5"), NullLogger.Instance)).Returns(true).Verifiable(); var packageManager = new Mock <VsPackageManager>(TestUtils.GetSolutionManager(), activeRepository, new Mock <IFileSystemProvider>().Object, new MockFileSystem(), localRepository.Object, new Mock <IDeleteOnRestartManager>().Object, new Mock <VsPackageInstallerEvents>().Object) { CallBase = true }; var packageManagerFactory = new Mock <IVsPackageManagerFactory>(); packageManagerFactory.Setup(m => m.CreatePackageManager(activeRepository, false)).Returns(packageManager.Object); packageManager.Setup(m => m.GetProjectManager(project)).Returns(projectManager).Verifiable(); var packageUninstaller = new VsPackageUninstaller(packageManagerFactory.Object, activeRepository, scriptExecutor.Object); // Act localRepository.Object.AddPackage(package); packageUninstaller.UninstallPackage(project, "A", removeDependencies: true); // Assert scriptExecutor.Verify(); Assert.False(localRepository.Object.Contains(package)); }
public void UninstallPackageDoesNotForceRemovesPackages() { // Arrange var activeRepository = new MockPackageRepository(); var localRepository = new Mock<MockPackageRepository>() { CallBase = true }; localRepository.As<ISharedPackageRepository>(); var projectRepository = new MockProjectPackageRepository(localRepository.Object); var project = TestUtils.GetProject("Foo"); var projectSystem = new MockProjectSystem(); var projectManager = new ProjectManager(activeRepository, new DefaultPackagePathResolver(new MockFileSystem()), projectSystem, projectRepository); var packageA = PackageUtility.CreatePackage("A", dependencies: new[] { new PackageDependency("B") }); var packageB = PackageUtility.CreatePackage("B"); var scriptExecutor = new Mock<IScriptExecutor>(MockBehavior.Strict); scriptExecutor.Setup(s => s.Execute(@"C:\MockFileSystem\A.1.0", "uninstall.ps1", packageA, project, It.IsAny<FrameworkName>(), NullLogger.Instance)).Returns(true).Verifiable(); var packageManager = new Mock<VsPackageManager>(TestUtils.GetSolutionManager(), activeRepository, new Mock<IFileSystemProvider>().Object, new MockFileSystem(), localRepository.Object, new Mock<IDeleteOnRestartManager>().Object, new Mock<VsPackageInstallerEvents>().Object) { CallBase = true }; var packageManagerFactory = new Mock<IVsPackageManagerFactory>(); packageManagerFactory.Setup(m => m.CreatePackageManager(activeRepository, false)).Returns(packageManager.Object); packageManager.Setup(m => m.GetProjectManager(project)).Returns(projectManager).Verifiable(); var packageUninstaller = new VsPackageUninstaller(packageManagerFactory.Object, activeRepository, scriptExecutor.Object); // Act and Assert localRepository.Object.AddPackage(packageA); localRepository.Object.AddPackage(packageB); ExceptionAssert.Throws<InvalidOperationException>(() => packageUninstaller.UninstallPackage(project, "B", removeDependencies: true), "Unable to uninstall 'B 1.0' because 'A 1.0' depends on it."); }
public void UninstallPackageDoesNotForceRemovesPackages() { // 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); var packageManagerFactory = new Mock<IVsPackageManagerFactory>(); packageManagerFactory.Setup(m => m.CreatePackageManager(It.IsAny<IPackageRepository>(), false)).Returns(packageManager); var scriptExecutor = new Mock<IScriptExecutor>(MockBehavior.Strict); var packageUninstaller = new VsPackageUninstaller( packageManagerFactory.Object, packageManager.LocalRepository, scriptExecutor.Object); // Act and Assert var project = packageManager.SolutionManager.GetProject("default"); ExceptionAssert.Throws<InvalidOperationException>(() => packageUninstaller.UninstallPackage(project, "B", removeDependencies: true), "Unable to uninstall 'B 1.0' because 'A 1.0' depends on it."); }