public void InstallPackageRunsInitAndInstallScripts()
        {
            // Arrange
            var localRepository = new Mock <MockPackageRepository>()
            {
                CallBase = true
            }.As <ISharedPackageRepository>().Object;
            var sourceRepository  = new MockPackageRepository();
            var projectRepository = new MockProjectPackageRepository(localRepository);
            var fileSystem        = new MockFileSystem();
            var projectSystem     = new MockProjectSystem();
            var pathResolver      = new DefaultPackagePathResolver(new MockProjectSystem());
            var project           = TestUtils.GetProject("Foo");
            var scriptExecutor    = new Mock <IScriptExecutor>();
            var packageManager    = new MockVsPackageManager2(
                @"c:\solution",
                sourceRepository);
            var packageManagerFactory = new Mock <IVsPackageManagerFactory>();

            packageManagerFactory.Setup(m => m.CreatePackageManager(It.IsAny <IPackageRepository>(), false)).Returns(packageManager);

            var package = NuGet.Test.PackageUtility.CreatePackage("foo", "1.0", new[] { "hello" }, tools: new[] { "init.ps1", "install.ps1" });

            sourceRepository.AddPackage(package);
            var installer = new VsPackageInstaller(packageManagerFactory.Object, scriptExecutor.Object, new Mock <IPackageRepositoryFactory>().Object, new Mock <IOutputConsoleProvider>().Object, new Mock <IVsCommonOperations>().Object, new Mock <ISolutionManager>().Object, null, null);

            // Act
            installer.InstallPackage(sourceRepository, project, "foo", new SemanticVersion("1.0"), ignoreDependencies: false, skipAssemblyReferences: false);

            // Assert
            scriptExecutor.Verify(e => e.Execute(It.IsAny <string>(), PowerShellScripts.Init, It.IsAny <IPackage>(), null, null, It.IsAny <ILogger>()), Times.Once());
            scriptExecutor.Verify(e => e.Execute(It.IsAny <string>(), PowerShellScripts.Install, It.IsAny <IPackage>(), It.IsAny <Project>(), It.IsAny <FrameworkName>(), It.IsAny <ILogger>()), Times.Once());
        }
Exemple #2
0
        public void UninstallPackageDoesNotRemoveDependenciesIfFlagIsFalse()
        {
            // 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();
            var packageUninstaller = new VsPackageUninstaller(
                packageManagerFactory.Object,
                packageManager.LocalRepository,
                scriptExecutor.Object);

            // Act            
            packageUninstaller.UninstallPackage(project, "A", removeDependencies: false);

            // Assert: packageA is uninstalled, while packageB is not
            scriptExecutor.Verify();
            installedPackages = packageManager.LocalRepository.GetPackages().ToList();
            Assert.Equal(new[] { packageB }, installedPackages, PackageEqualityComparer.IdAndVersion);
        }
        public void InstallPackageCmdletPassesParametersCorrectlyWhenIdAndVersionAreSpecified()
        {
            // Arrange
            var packageA28 = PackageUtility.CreatePackage("A", "2.8");
            var packageA31 = PackageUtility.CreatePackage("A", "3.1");
            var packageRepository = new MockPackageRepository { packageA28, packageA31 };
            var packageManager = new MockVsPackageManager2(
                @"c:\solution",
                packageRepository);
            var packageManagerFactory = new Mock<IVsPackageManagerFactory>();
            packageManagerFactory.Setup(m => m.CreatePackageManager()).Returns(packageManager);

            // Act
            var cmdlet = new InstallPackageCommand(
                packageManager.SolutionManager,
                packageManagerFactory.Object,
                null,
                new Mock<IVsPackageSourceProvider>().Object,
                null,
                null,
                new Mock<IVsCommonOperations>().Object,
                new Mock<IDeleteOnRestartManager>().Object, true);
            cmdlet.Id = "A";
            cmdlet.Version = new SemanticVersion("2.8");
            cmdlet.Execute();

            // Assert: version 2.8 is installed.
            var installedPackages = packageManager.LocalRepository.GetPackages().ToList();
            Assert.Equal(1, installedPackages.Count);
            Assert.Equal(packageA28, installedPackages[0], PackageEqualityComparer.IdAndVersion);
        }
Exemple #4
0
        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 UninstallPackageCmdletWhenIdAndVersionAreSpecified()
        {
            // Arrange
            var packageA = PackageUtility.CreatePackage("A", "1.0");
            var packageRepository = new MockPackageRepository { packageA };
            var packageManager = new MockVsPackageManager2(
                @"c:\solution",
                packageRepository);
            InstallPackage("A", packageManager);
            var installedPackages = packageManager.LocalRepository.GetPackages().ToList();
            Assert.Equal(new[] { packageA }, installedPackages, PackageEqualityComparer.IdAndVersion);

            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.Version = new SemanticVersion("1.1");

            // Act and Assert
            ExceptionAssert.Throws<InvalidOperationException>(() => cmdlet.GetResults(),
                "Unable to find package 'A'.");
        }
        public void InstallPackageCmdletThrowsWhenSolutionIsClosed()
        {
            // Arrange
            var packageA = PackageUtility.CreatePackage("A", "1.0.0");
            var packageRepository = new MockPackageRepository { packageA };
            var packageManager = new MockVsPackageManager2(
                @"c:\solution",
                packageRepository);

            var packageManagerFactory = new Mock<IVsPackageManagerFactory>();
            packageManagerFactory.Setup(m => m.CreatePackageManager()).Returns(packageManager);
            ((MockSolutionManager2)packageManager.SolutionManager).IsSolutionOpen = false;
            var cmdlet = new InstallPackageCommand(packageManager.SolutionManager, packageManagerFactory.Object, null, null, null, null, new Mock<IVsCommonOperations>().Object, new Mock<IDeleteOnRestartManager>().Object, true);

            // Act and Assert
            ExceptionAssert.Throws<InvalidOperationException>(() => cmdlet.GetResults(),
                "The current environment doesn't have a solution open.");
        }
        public void InstallPackageTurnOffBindingRedirectIfSkipAssemblyReferences()
        {
            // Arrange
            var localRepository = new Mock <MockPackageRepository>()
            {
                CallBase = true
            }.As <ISharedPackageRepository>().Object;
            var sourceRepository  = new MockPackageRepository();
            var projectRepository = new MockProjectPackageRepository(localRepository);
            var fileSystem        = new MockFileSystem();
            var projectSystem     = new MockProjectSystem();
            var pathResolver      = new DefaultPackagePathResolver(new MockProjectSystem());
            var project           = TestUtils.GetProject("Foo");
            var scriptExecutor    = new Mock <IScriptExecutor>();

            var packageManager = new MockVsPackageManager2(
                @"c:\solution",
                sourceRepository);

            var packageManagerFactory = new Mock <IVsPackageManagerFactory>();

            packageManagerFactory.Setup(m => m.CreatePackageManager(It.IsAny <IPackageRepository>(), false)).Returns(packageManager);

            var package = NuGet.Test.PackageUtility.CreatePackage("foo", "1.0", new[] { "hello" }, tools: new[] { "init.ps1", "install.ps1" });

            sourceRepository.AddPackage(package);
            var installer = new VsPackageInstaller(
                packageManagerFactory.Object,
                scriptExecutor.Object,
                new Mock <IPackageRepositoryFactory>().Object,
                new Mock <IOutputConsoleProvider>().Object,
                new Mock <IVsCommonOperations>().Object,
                new Mock <ISolutionManager>().Object,
                null,
                null);

            // Act
            installer.InstallPackage(sourceRepository, project, "foo", new SemanticVersion("1.0"), ignoreDependencies: false, skipAssemblyReferences: true);

            // Assert: no binding redirection is called.
            Assert.Equal(0, packageManager.BindingRedirectedProjects.Count);
            Assert.True(packageManager.BindingRedirectEnabled);
        }
        private void InstallPackage(string id, MockVsPackageManager2 packageManager)
        {   
            var projectManager = packageManager.GetProjectManager(packageManager.SolutionManager.GetProject("default"));

            // Resolve the package to install
            IPackage package = PackageRepositoryHelper.ResolvePackage(
                packageManager.SourceRepository,
                packageManager.LocalRepository,
                id,
                version: null,
                allowPrereleaseVersions: false);

            // Resolve operations
            var resolver = new ActionResolver();
            resolver.AddOperation(PackageAction.Install, package, projectManager);
            var actions = resolver.ResolveActions();

            var actionExecutor = new ActionExecutor();
            actionExecutor.Execute(actions);
        }
Exemple #9
0
        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);
        }
Exemple #10
0
        private void InstallPackage(string id, MockVsPackageManager2 packageManager)
        {
            var projectManager = packageManager.GetProjectManager(packageManager.SolutionManager.GetProject("default"));

            // Resolve the package to install
            IPackage package = PackageRepositoryHelper.ResolvePackage(
                packageManager.SourceRepository,
                packageManager.LocalRepository,
                id,
                version: null,
                allowPrereleaseVersions: false);

            // Resolve operations
            var resolver = new ActionResolver();

            resolver.AddOperation(NuGet.PackageAction.Install, package, projectManager);
            var actions = resolver.ResolveActions();

            var executor = new ActionExecutor();

            executor.Execute(actions);
        }
        public void InstallPackageShouldPickUnListedPrereleasePackagesIfItSatisfiesContrainsAndOthersAreNot()
        {
            // Arrange
            var packageA = PackageUtility.CreatePackage("A", "1.0", dependencies: new[] { new PackageDependency("B", new VersionSpec { MinVersion = new SemanticVersion("1.0"), IsMinInclusive = true }) });
            var packageB1 = PackageUtility.CreatePackage("B", "0.0.9", listed: true);
            var packageB2 = PackageUtility.CreatePackage("B", "1.0.1-a", listed: false);
            var packageRepository = new MockPackageRepository { packageA, packageB1, packageB2 };
            var packageManager = new MockVsPackageManager2(
                @"c:\solution",
                packageRepository);
            var packageManagerFactory = new Mock<IVsPackageManagerFactory>(MockBehavior.Strict);
            packageManagerFactory.Setup(m => m.CreatePackageManager()).Returns(packageManager);

            // Act
            var cmdlet = new InstallPackageCommand(packageManager.SolutionManager, packageManagerFactory.Object, null, new Mock<IVsPackageSourceProvider>().Object, new Mock<IHttpClientEvents>().Object, null, new Mock<IVsCommonOperations>().Object, new Mock<IDeleteOnRestartManager>().Object, true);
            cmdlet.Id = "A";
            cmdlet.IncludePrerelease = true;
            cmdlet.Execute();

            // Assert: packageA and packageB2 are installed.
            // packageB1 is not picked because it cannot be used as a dependency of packageA
            var installedPackages = packageManager.LocalRepository.GetPackages().ToList();
            Assert.Equal(2, installedPackages.Count);
            Assert.Equal(packageA, installedPackages[0], PackageEqualityComparer.IdAndVersion);
            Assert.Equal(packageB2, installedPackages[1], PackageEqualityComparer.IdAndVersion);
        }
        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 InstallPackageCmdletInstallPrereleasePackageIfFlagIsPresent()
        {
            // Arrange
            var packageA = PackageUtility.CreatePackage("A", "1.0.0-a");
            var packageRepository = new MockPackageRepository { packageA };
            var packageManager = new MockVsPackageManager2(
                @"c:\solution", 
                packageRepository);

            var packageManagerFactory = new Mock<IVsPackageManagerFactory>(MockBehavior.Strict);
            packageManagerFactory.Setup(m => m.CreatePackageManager()).Returns(packageManager);

            // packageA is not installed yet.
            Assert.False(packageManager.LocalRepository.IsSolutionReferenced(packageA.Id, packageA.Version));

            // Act
            var cmdlet = new InstallPackageCommand(packageManager.SolutionManager, packageManagerFactory.Object, null, new Mock<IVsPackageSourceProvider>().Object, new Mock<IHttpClientEvents>().Object, null, new Mock<IVsCommonOperations>().Object, new Mock<IDeleteOnRestartManager>().Object, true);            

            cmdlet.Id = "A";
            cmdlet.IncludePrerelease = true;
            cmdlet.Execute();

            // Assert: packageA is installed.
            var 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 InstallPackageInstallUnlistedPrereleasePackageIfVersionIsSet()
        {
            // Arrange
            var packageA1 = PackageUtility.CreatePackage("A", "1.0.0");
            var packageA2 = PackageUtility.CreatePackage("A", "1.0.0-ReleaseCandidate", listed: false);
            
            var packageRepository = new MockPackageRepository { packageA1, packageA2 };
            var packageManager = new MockVsPackageManager2(
                @"c:\solution",
                packageRepository);
            var packageManagerFactory = new Mock<IVsPackageManagerFactory>(MockBehavior.Strict);
            packageManagerFactory.Setup(m => m.CreatePackageManager()).Returns(packageManager);

            // Act
            var cmdlet = new InstallPackageCommand(packageManager.SolutionManager, packageManagerFactory.Object, null, new Mock<IVsPackageSourceProvider>().Object, new Mock<IHttpClientEvents>().Object, null, new Mock<IVsCommonOperations>().Object, new Mock<IDeleteOnRestartManager>().Object, true);
            cmdlet.Id = "A";
            cmdlet.Version = new SemanticVersion("1.0.0-ReleaseCandidate");
            cmdlet.IncludePrerelease = true;
            cmdlet.Execute();

            // Assert: the unlisted prerelease packageA2 is installed.
            var installedPackages = packageManager.LocalRepository.GetPackages().ToList();
            Assert.Equal(1, installedPackages.Count);
            Assert.Equal(packageA2, installedPackages[0], PackageEqualityComparer.IdAndVersion);
        }
Exemple #16
0
        public void InstallPackageDoesNotTurnOffBindingRedirectIfNotSkipAssemblyReferences()
        {
            // Arrange
            var localRepository = new Mock<MockPackageRepository>() { CallBase = true }.As<ISharedPackageRepository>().Object;
            var sourceRepository = new MockPackageRepository();
            var projectRepository = new MockProjectPackageRepository(localRepository);
            var fileSystem = new MockFileSystem();
            var projectSystem = new MockProjectSystem();
            var pathResolver = new DefaultPackagePathResolver(new MockProjectSystem());
            var project = TestUtils.GetProject("Foo");
            var scriptExecutor = new Mock<IScriptExecutor>();

            var packageManager = new MockVsPackageManager2(
                @"c:\solution",
                sourceRepository);
            var packageManagerFactory = new Mock<IVsPackageManagerFactory>();
            packageManagerFactory.Setup(m => m.CreatePackageManager(It.IsAny<IPackageRepository>(), false)).Returns(packageManager);

            var package = NuGet.Test.PackageUtility.CreatePackage("foo", "1.0", new[] { "hello" }, tools: new[] { "init.ps1", "install.ps1" });
            sourceRepository.AddPackage(package);
            var installer = new VsPackageInstaller(
                packageManagerFactory.Object,
                scriptExecutor.Object,
                new Mock<IPackageRepositoryFactory>().Object,
                new Mock<IOutputConsoleProvider>().Object,
                new Mock<IVsCommonOperations>().Object,
                new Mock<ISolutionManager>().Object,
                null,
                null);

            // Act
            installer.InstallPackage(sourceRepository, project, "foo", new SemanticVersion("1.0"), ignoreDependencies: false, skipAssemblyReferences: false);

            // Assert: binding redirection is called for project "Foo"
            Assert.Equal(1, packageManager.BindingRedirectedProjects.Count);
            Assert.Equal("Foo", packageManager.BindingRedirectedProjects[0]);
        }
Exemple #17
0
        public void InstallPackageRunsInitAndInstallScripts()
        {
            // Arrange
            var localRepository = new Mock<MockPackageRepository>() { CallBase = true }.As<ISharedPackageRepository>().Object;
            var sourceRepository = new MockPackageRepository();
            var projectRepository = new MockProjectPackageRepository(localRepository);
            var fileSystem = new MockFileSystem();
            var projectSystem = new MockProjectSystem();
            var pathResolver = new DefaultPackagePathResolver(new MockProjectSystem());
            var project = TestUtils.GetProject("Foo");            
            var scriptExecutor = new Mock<IScriptExecutor>();
            var packageManager = new MockVsPackageManager2(
                @"c:\solution",
                sourceRepository);
            var packageManagerFactory = new Mock<IVsPackageManagerFactory>();
            packageManagerFactory.Setup(m => m.CreatePackageManager(It.IsAny<IPackageRepository>(), false)).Returns(packageManager);

            var package = NuGet.Test.PackageUtility.CreatePackage("foo", "1.0", new[] { "hello" }, tools: new[] { "init.ps1", "install.ps1" });
            sourceRepository.AddPackage(package);
            var installer = new VsPackageInstaller(packageManagerFactory.Object, scriptExecutor.Object, new Mock<IPackageRepositoryFactory>().Object, new Mock<IOutputConsoleProvider>().Object, new Mock<IVsCommonOperations>().Object, new Mock<ISolutionManager>().Object, null, null);

            // Act
            installer.InstallPackage(sourceRepository, project, "foo", new SemanticVersion("1.0"), ignoreDependencies: false, skipAssemblyReferences: false);

            // Assert
            scriptExecutor.Verify(e => e.Execute(It.IsAny<string>(), PowerShellScripts.Init, It.IsAny<IPackage>(), null, null, It.IsAny<ILogger>()), Times.Once());
            scriptExecutor.Verify(e => e.Execute(It.IsAny<string>(), PowerShellScripts.Install, It.IsAny<IPackage>(), It.IsAny<Project>(), It.IsAny<FrameworkName>(), It.IsAny<ILogger>()), Times.Once());
        }
        public void InstallPackageCmdletPassesIgnoreDependencySwitchCorrectly()
        {
            // Arrange
            var packageA = PackageUtility.CreatePackage("A", "1.0.0", dependencies: new[] { new PackageDependency("B") });
            var packageB = PackageUtility.CreatePackage("B", "1.0.0");
            var packageRepository = new MockPackageRepository { packageA, packageB };
            var packageManager = new MockVsPackageManager2(
                @"c:\solution",
                packageRepository);
            var packageManagerFactory = new Mock<IVsPackageManagerFactory>();
            packageManagerFactory.Setup(m => m.CreatePackageManager()).Returns(packageManager);

            // Act
            var cmdlet = new InstallPackageCommand(
                packageManager.SolutionManager, 
                packageManagerFactory.Object, 
                null, 
                new Mock<IVsPackageSourceProvider>().Object, 
                null,
                null,
                new Mock<IVsCommonOperations>().Object,
                new Mock<IDeleteOnRestartManager>().Object, true);
            cmdlet.Id = "A";
            cmdlet.IgnoreDependencies = new SwitchParameter(true);
            cmdlet.Execute();

            // Assert: only packageA is installed. packageB is not.
            var installedPackages = packageManager.LocalRepository.GetPackages().ToList();
            Assert.Equal(1, installedPackages.Count);
            Assert.Equal(packageA, installedPackages[0], PackageEqualityComparer.IdAndVersion);
        }
Exemple #19
0
        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 InstallPackageShouldPickListedPackagesOverUnlistedOnesAsDependency2()
        {
            // Arrange
            var packageA = PackageUtility.CreatePackage("A", "1.0", dependencies: new[] { new PackageDependency("B", new VersionSpec { MinVersion = new SemanticVersion("0.5") }) });
            var packageB1 = PackageUtility.CreatePackage("B", "1.0.0", listed: true);
            var packageB2 = PackageUtility.CreatePackage("B", "1.0.2-alpha", listed: true);
            var packageB3 = PackageUtility.CreatePackage("B", "1.0.2", listed: false);
            var packageRepository = new MockPackageRepository { packageA, packageB1, packageB2, packageB3 };
            var packageManager = new MockVsPackageManager2(
               @"c:\solution",
               packageRepository);
            var packageManagerFactory = new Mock<IVsPackageManagerFactory>(MockBehavior.Strict);
            packageManagerFactory.Setup(m => m.CreatePackageManager()).Returns(packageManager);

            // Act
            var cmdlet = new InstallPackageCommand(packageManager.SolutionManager, packageManagerFactory.Object, null, new Mock<IVsPackageSourceProvider>().Object, new Mock<IHttpClientEvents>().Object, null, new Mock<IVsCommonOperations>().Object, new Mock<IDeleteOnRestartManager>().Object, true);
            cmdlet.Id = "A";
            cmdlet.IncludePrerelease = true;
            cmdlet.DependencyVersion = DependencyVersion.HighestPatch;
            cmdlet.Execute();

            // Assert: packageA and packageB2 are installed.
            // packageB1 is not picked because packageB2's version is later.
            // packageB3 is not picked because it's unlisted.
            var installedPackages = packageManager.LocalRepository.GetPackages().ToList();
            Assert.Equal(2, installedPackages.Count);
            Assert.Equal(packageA, installedPackages[0], PackageEqualityComparer.IdAndVersion);
            Assert.Equal(packageB2, installedPackages[1], PackageEqualityComparer.IdAndVersion);
        }
        public void InstallPackageIgnoresFailingRepositoriesWhenInstallingPackageWithOrWithoutDependencies()
        {
            // Arrange
            var packageA = PackageUtility.CreatePackage("A", "1.0", dependencies: new[] { new PackageDependency("B") });
            var packageB = PackageUtility.CreatePackage("B", "1.0.0", listed: true);
            var packageC = PackageUtility.CreatePackage("C", "2.0.0");
            
            var mockRepository = new Mock<IPackageRepository>();
            mockRepository.Setup(c => c.GetPackages()).Returns(GetPackagesWithException().AsQueryable()).Verifiable();
            var packageRepository = new AggregateRepository(new[] { 
                new MockPackageRepository { 
                    packageA
                }, 
                mockRepository.Object,
                new MockPackageRepository { 
                   packageB 
                },
                new MockPackageRepository { 
                   packageC 
                },
            });

            var packageManager = new MockVsPackageManager2(
                @"c:\solution",
                packageRepository);
            var packageManagerFactory = new Mock<IVsPackageManagerFactory>(MockBehavior.Strict);
            packageManagerFactory.Setup(m => m.CreatePackageManager()).Returns(packageManager);

            // Act
            var cmdlet = new InstallPackageCommand(packageManager.SolutionManager, packageManagerFactory.Object, null, new Mock<IVsPackageSourceProvider>().Object, new Mock<IHttpClientEvents>().Object, null, new Mock<IVsCommonOperations>().Object, new Mock<IDeleteOnRestartManager>().Object, true);
            cmdlet.Id = "A";
            cmdlet.Execute();
            cmdlet.Id = "C";
            cmdlet.Execute();

            // Assert            
            var installedPackages = packageManager.LocalRepository.GetPackages().ToList();
            Assert.Equal(3, installedPackages.Count);
            Assert.Equal(packageA, installedPackages[0], PackageEqualityComparer.IdAndVersion);
            Assert.Equal(packageB, installedPackages[1], PackageEqualityComparer.IdAndVersion);
            Assert.Equal(packageC, installedPackages[2], PackageEqualityComparer.IdAndVersion);

            mockRepository.Verify();
        }
        public void InstallPackageInstallUnlistedPrereleasePackageAsADependency(string versionA, string versionB)
        {
            // Arrange
            var packageA = PackageUtility.CreatePackage("A", versionA, dependencies: new[] { new PackageDependency("B") });
            var packageB = PackageUtility.CreatePackage("B", versionB, listed: false);
            
            var packageRepository = new MockPackageRepository { packageA, packageB };
            var packageManager = new MockVsPackageManager2(
                @"c:\solution",
                packageRepository);
            var packageManagerFactory = new Mock<IVsPackageManagerFactory>(MockBehavior.Strict);
            packageManagerFactory.Setup(m => m.CreatePackageManager()).Returns(packageManager);

            // Act
            var cmdlet = new InstallPackageCommand(packageManager.SolutionManager, packageManagerFactory.Object, null, new Mock<IVsPackageSourceProvider>().Object, new Mock<IHttpClientEvents>().Object, null, new Mock<IVsCommonOperations>().Object, new Mock<IDeleteOnRestartManager>().Object, true);
            cmdlet.Id = "A";
            cmdlet.IncludePrerelease = true;
            cmdlet.Execute();

            // Assert
            var installedPackages = packageManager.LocalRepository.GetPackages().ToList();
            Assert.Equal(2, installedPackages.Count);
            Assert.Equal(packageA, installedPackages[0], PackageEqualityComparer.IdAndVersion);
            Assert.Equal(packageB, installedPackages[1], PackageEqualityComparer.IdAndVersion);
        }
        public void UpdatePackageUpdateToUnlistedPackageIfVersionIsSet(string versionA1, string versionA2)
        {
            // Arrange
            var packageA1 = PackageUtility.CreatePackage("A", versionA1);
            var packageA2 = PackageUtility.CreatePackage("A", versionA2, listed: false);

            var packageRepository = new MockPackageRepository { packageA1, packageA2 };
            var packageManager = new MockVsPackageManager2(
                @"c:\solution",
                packageRepository);
            InstallPackage(packageA1.Id, packageA1.Version, packageManager);
            var installedPackages = packageManager.LocalRepository.GetPackages().ToList();
            Assert.Equal(new[] { packageA1 }, installedPackages, PackageEqualityComparer.IdAndVersion);

            var packageManagerFactory = new Mock<IVsPackageManagerFactory>(MockBehavior.Strict);
            packageManagerFactory.Setup(m => m.CreatePackageManager()).Returns(packageManager);

            // Act
            var cmdlet = new UpdatePackageCommand(packageManager.SolutionManager, packageManagerFactory.Object, null, new Mock<IVsPackageSourceProvider>().Object, new Mock<IHttpClientEvents>().Object, null, new Mock<IVsCommonOperations>().Object, new Mock<IDeleteOnRestartManager>().Object);
            cmdlet.Id = "A";
            cmdlet.Version = new SemanticVersion(versionA2);
            cmdlet.GetResults();

            // Assert: packageA1 is updated to packageA2. 
            installedPackages = packageManager.LocalRepository.GetPackages().ToList();
            Assert.Equal(new[] { packageA2 }, installedPackages, PackageEqualityComparer.IdAndVersion);
        }
        public void InstallPackageCmdletOnlyOpenReadmeFileFromTheRootPackage()
        {
            // Arrange
            // A --> B
            var packageA = new Mock<IPackage>();
            packageA.Setup(p => p.Id).Returns("A");
            packageA.Setup(p => p.Version).Returns(new SemanticVersion("1.0"));
            var depSet = new PackageDependencySet(null, new[] { new PackageDependency("B") });
            packageA.Setup(p => p.DependencySets).Returns(new[] { depSet });
            packageA.Setup(p => p.Listed).Returns(true);
            var readme = new Mock<IPackageFile>();
            readme.Setup(f => f.Path).Returns("readMe.txt");
            readme.Setup(f => f.GetStream()).Returns(new MemoryStream());
            packageA.Setup(p => p.GetFiles()).Returns(new IPackageFile[] { readme.Object });
            packageA.Setup(p => p.GetStream()).Returns(new MemoryStream());

            var packageB = new Mock<IPackage>();
            packageB.Setup(p => p.Id).Returns("B");
            packageB.Setup(p => p.Version).Returns(new SemanticVersion("1.0"));
            var readmeB = new Mock<IPackageFile>();
            readmeB.Setup(f => f.Path).Returns("readMe.txt");
            readmeB.Setup(f => f.GetStream()).Returns(new MemoryStream());
            packageB.Setup(p => p.GetFiles()).Returns(new IPackageFile[] { readmeB.Object });
            packageB.Setup(p => p.GetStream()).Returns(new MemoryStream());

            var packageRepository = new MockPackageRepository { packageA.Object, packageB.Object };
            var packageManager = new MockVsPackageManager2(
                @"c:\solution",
                packageRepository);

            var packageManagerFactory = new Mock<IVsPackageManagerFactory>(MockBehavior.Strict);
            packageManagerFactory.Setup(m => m.CreatePackageManager()).Returns(packageManager);

            var fileOperations = new Mock<IVsCommonOperations>();

            // Act
            var cmdlet = new InstallPackageCommand(
                packageManager.SolutionManager, 
                packageManagerFactory.Object, 
                null,
                new Mock<IVsPackageSourceProvider>().Object, 
                new Mock<IHttpClientEvents>().Object, 
                null, 
                fileOperations.Object,
                new Mock<IDeleteOnRestartManager>().Object,
                true);
            cmdlet.Id = "A";
            cmdlet.Execute();

            // Assert
            fileOperations.Verify(io => io.OpenFile(It.Is<string>(s => s.EndsWith("A.1.0\\readme.txt", StringComparison.OrdinalIgnoreCase))), Times.Once());
            fileOperations.Verify(io => io.OpenFile(It.Is<string>(s => s.EndsWith("B.1.0\\readme.txt", StringComparison.OrdinalIgnoreCase))), Times.Never());
        }