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());
        }
Example #2
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 projectManager = new ProjectManager(localRepository, pathResolver, projectSystem, projectRepository);
            var scriptExecutor = new Mock<IScriptExecutor>();
            var packageManager = new Mock<VsPackageManager>(TestUtils.GetSolutionManager(), sourceRepository, new Mock<IFileSystemProvider>().Object, fileSystem, localRepository, new Mock<IRecentPackageRepository>().Object, 
                new Mock<VsPackageInstallerEvents>().Object) { CallBase = true };
            var packageManagerFactory = new Mock<IVsPackageManagerFactory>();
            packageManagerFactory.Setup(m => m.CreatePackageManager(It.IsAny<IPackageRepository>(), false, false)).Returns(packageManager.Object);
            packageManager.Setup(m => m.GetProjectManager(project)).Returns(projectManager);

            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<IVsCommonOperations>().Object, new Mock<ISolutionManager>().Object);

            // 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>(), It.IsAny<Project>(), It.IsAny<ILogger>()), Times.Once());
            scriptExecutor.Verify(e => e.Execute(It.IsAny<string>(), PowerShellScripts.Install, It.IsAny<IPackage>(), It.IsAny<Project>(), It.IsAny<ILogger>()), Times.Once());
        }
        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 projectManager    = new ProjectManager(localRepository, pathResolver, projectSystem, projectRepository);
            var scriptExecutor    = new Mock <IScriptExecutor>();
            var packageManager    = new Mock <VsPackageManager>(
                TestUtils.GetSolutionManager(),
                sourceRepository,
                new Mock <IFileSystemProvider>().Object,
                fileSystem,
                localRepository,
                new Mock <IDeleteOnRestartManager>().Object,
                new Mock <VsPackageInstallerEvents>().Object,
                /* multiFrameworkTargeting */ null)
            {
                CallBase = true
            };
            var packageManagerFactory = new Mock <IVsPackageManagerFactory>();

            packageManager.As <IVsPackageManager>().SetupGet(m => m.BindingRedirectEnabled).Returns(true);

            packageManager.As <IVsPackageManager>().SetupSet(m => m.BindingRedirectEnabled = false);
            packageManager.As <IVsPackageManager>().SetupSet(m => m.BindingRedirectEnabled = true);
            packageManagerFactory.Setup(m => m.CreatePackageManager(It.IsAny <IPackageRepository>(), false)).Returns(packageManager.Object);
            packageManager.Setup(m => m.GetProjectManager(project)).Returns(projectManager);

            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
            packageManager.As <IVsPackageManager>().VerifySet(m => m.BindingRedirectEnabled = false, Times.Never());
            packageManager.As <IVsPackageManager>().VerifySet(m => m.BindingRedirectEnabled = true, Times.Exactly(2));
        }
        public void InstallPackageConvertsVersionToSemanticVersion()
        {
            // 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 Mock <VsPackageManager>(
                TestUtils.GetSolutionManager(),
                sourceRepository,
                new Mock <IFileSystemProvider>().Object,
                fileSystem,
                localRepository,
                new Mock <IDeleteOnRestartManager>().Object,
                new Mock <VsPackageInstallerEvents>().Object,
                /* multiFrameworkTargeting */ null)
            {
                CallBase = true
            };
            var projectManager           = new ProjectManager(packageManager.Object, pathResolver, projectSystem, projectRepository);
            var packageManagerFactory    = new Mock <IVsPackageManagerFactory>();
            var packageRepositoryFactory = new Mock <IPackageRepositoryFactory>(MockBehavior.Strict);

            packageManagerFactory.Setup(m => m.CreatePackageManager(It.IsAny <IPackageRepository>(), false)).Returns(packageManager.Object);
            packageManager.Setup(m => m.GetProjectManager(project)).Returns(projectManager);
            packageRepositoryFactory.Setup(r => r.CreateRepository(@"x:\test")).Returns(new MockPackageRepository()).Verifiable();

            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, packageRepositoryFactory.Object, new Mock <IOutputConsoleProvider>().Object, new Mock <IVsCommonOperations>().Object, new Mock <ISolutionManager>().Object, null, null);

            // Act
            installer.InstallPackage(@"x:\test", project, "foo", new Version("1.0"), ignoreDependencies: 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());
            packageRepositoryFactory.Verify();
        }
Example #5
0
        public void InstallPackageTurnOffBindingRedirect()
        {
            // 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 projectManager    = new ProjectManager(localRepository, pathResolver, projectSystem, projectRepository);
            var scriptExecutor    = new Mock <IScriptExecutor>();
            var packageManager    = new Mock <VsPackageManager>(TestUtils.GetSolutionManager(), sourceRepository, new Mock <IFileSystemProvider>().Object, fileSystem, localRepository,
                                                                new Mock <IDeleteOnRestartManager>().Object, new Mock <VsPackageInstallerEvents>().Object)
            {
                CallBase = true
            };
            var packageManagerFactory = new Mock <IVsPackageManagerFactory>();

            packageManager.As <IVsPackageManager>().SetupGet(m => m.BindingRedirectEnabled).Returns(true);

            int state = 1;

            packageManager.As <IVsPackageManager>().SetupSet(m => m.BindingRedirectEnabled = false).Callback(() => state += 1);
            packageManager.As <IVsPackageManager>().SetupSet(m => m.BindingRedirectEnabled = true).Callback(() => state *= 2);
            packageManagerFactory.Setup(m => m.CreatePackageManager(It.IsAny <IPackageRepository>(), false)).Returns(packageManager.Object);
            packageManager.Setup(m => m.GetProjectManager(project)).Returns(projectManager);

            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 <IVsCommonOperations>().Object, new Mock <ISolutionManager>().Object);

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

            // Assert
            // state = 4 means that BindingRedirectEnabled is set to 'false', then to 'true', in that order.
            // no other value of 4 can result in the same value of 4.
            Assert.Equal(4, state);
            packageManager.As <IVsPackageManager>().VerifySet(m => m.BindingRedirectEnabled = false, Times.Once());
            packageManager.As <IVsPackageManager>().VerifySet(m => m.BindingRedirectEnabled = true, Times.Once());
        }
        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);
        }
Example #7
0
        public void InstallPackageConvertsVersionToSemanticVersion()
        {
            // 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 projectManager = new ProjectManager(localRepository, pathResolver, projectSystem, projectRepository);
            var scriptExecutor = new Mock<IScriptExecutor>();
            var packageManager = new Mock<VsPackageManager>(
                TestUtils.GetSolutionManager(), 
                sourceRepository, 
                new Mock<IFileSystemProvider>().Object, 
                fileSystem, 
                localRepository, 
                new Mock<IDeleteOnRestartManager>().Object, 
                new Mock<VsPackageInstallerEvents>().Object,
                /* multiFrameworkTargeting */ null) 
                { 
                    CallBase = true 
                };
            var packageManagerFactory = new Mock<IVsPackageManagerFactory>();
            var packageRepositoryFactory = new Mock<IPackageRepositoryFactory>(MockBehavior.Strict);
            packageManagerFactory.Setup(m => m.CreatePackageManager(It.IsAny<IPackageRepository>(), false)).Returns(packageManager.Object);
            packageManager.Setup(m => m.GetProjectManager(project)).Returns(projectManager);
            packageRepositoryFactory.Setup(r => r.CreateRepository(@"x:\test")).Returns(new MockPackageRepository()).Verifiable();

            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, packageRepositoryFactory.Object, new Mock<IOutputConsoleProvider>().Object, new Mock<IVsCommonOperations>().Object, new Mock<ISolutionManager>().Object, null, null);

            // Act
            installer.InstallPackage(@"x:\test", project, "foo", new Version("1.0"), ignoreDependencies: 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());
            packageRepositoryFactory.Verify();
        }
        public void InstallPackageThrowsIfRepositoryIsNull()
        {
            // 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 projectManager    = new ProjectManager(null, pathResolver, projectSystem, projectRepository);
            var scriptExecutor    = new Mock <IScriptExecutor>();
            var packageManager    = new Mock <VsPackageManager>(
                TestUtils.GetSolutionManager(),
                sourceRepository,
                new Mock <IFileSystemProvider>().Object,
                fileSystem,
                localRepository,
                new Mock <IDeleteOnRestartManager>().Object,
                new Mock <VsPackageInstallerEvents>().Object,
                /* multiFrameworkTargeting */ null)
            {
                CallBase = true
            };
            var packageManagerFactory    = new Mock <IVsPackageManagerFactory>();
            var packageRepositoryFactory = new Mock <IPackageRepositoryFactory>(MockBehavior.Strict);

            packageManagerFactory.Setup(m => m.CreatePackageManager(It.Is <IPackageRepository>(p => p != null), false))
            .Returns(packageManager.Object);
            packageManager.Setup(m => m.GetProjectManager(project)).Returns(projectManager);

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

            // Act && Assert
            Assert.Throws <ArgumentNullException>(() =>
                                                  installer.InstallPackage(/* repository */ null, project, "foo", "1.0", ignoreDependencies: false, skipAssemblyReferences: true)
                                                  );
        }
Example #9
0
        public void InstallPackageDoesNotUseFallbackRepository()
        {
            // 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 projectManager    = new ProjectManager(localRepository, pathResolver, projectSystem, projectRepository);
            var scriptExecutor    = new Mock <IScriptExecutor>();
            var packageManager    = new Mock <VsPackageManager>(TestUtils.GetSolutionManager(), sourceRepository, new Mock <IFileSystemProvider>().Object, fileSystem, localRepository,
                                                                new Mock <IDeleteOnRestartManager>().Object, new Mock <VsPackageInstallerEvents>().Object)
            {
                CallBase = true
            };
            var packageManagerFactory = new Mock <IVsPackageManagerFactory>();

            packageManagerFactory.Setup(m => m.CreatePackageManager(It.IsAny <IPackageRepository>(), false)).Returns(packageManager.Object);
            packageManagerFactory.Setup(m => m.CreatePackageManager()).Throws(new Exception("A"));
            packageManagerFactory.Setup(m => m.CreatePackageManager(It.IsAny <IPackageRepository>(), true)).Throws(new Exception("B"));
            packageManager.Setup(m => m.GetProjectManager(project)).Returns(projectManager);

            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 <IVsCommonOperations>().Object, new Mock <ISolutionManager>().Object);

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

            // Assert
            packageManagerFactory.Verify(m => m.CreatePackageManager(It.IsAny <IPackageRepository>(), false), Times.Once());
            packageManagerFactory.Verify(m => m.CreatePackageManager(), Times.Never());
            packageManagerFactory.Verify(m => m.CreatePackageManager(It.IsAny <IPackageRepository>(), true), Times.Never());
        }
Example #10
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 projectManager    = new ProjectManager(localRepository, pathResolver, projectSystem, projectRepository);
            var scriptExecutor    = new Mock <IScriptExecutor>();
            var packageManager    = new Mock <VsPackageManager>(TestUtils.GetSolutionManager(), sourceRepository, fileSystem, localRepository, new Mock <IRecentPackageRepository>().Object)
            {
                CallBase = true
            };
            var packageManagerFactory = new Mock <IVsPackageManagerFactory>();

            packageManagerFactory.Setup(m => m.CreatePackageManager(It.IsAny <IPackageRepository>())).Returns(packageManager.Object);
            packageManager.Setup(m => m.GetProjectManager(project)).Returns(projectManager);

            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);

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

            // Assert
            scriptExecutor.Verify(e => e.Execute(It.IsAny <string>(), PowerShellScripts.Init, It.IsAny <IPackage>(), It.IsAny <Project>(), It.IsAny <ILogger>()), Times.Once());
            scriptExecutor.Verify(e => e.Execute(It.IsAny <string>(), PowerShellScripts.Install, It.IsAny <IPackage>(), It.IsAny <Project>(), It.IsAny <ILogger>()), Times.Once());
        }
Example #11
0
        public void InstallPackageTurnOffBindingRedirect()
        {
            // 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 projectManager = new ProjectManager(localRepository, pathResolver, projectSystem, projectRepository);
            var scriptExecutor = new Mock<IScriptExecutor>();
            var packageManager = new Mock<VsPackageManager>(TestUtils.GetSolutionManager(), sourceRepository, new Mock<IFileSystemProvider>().Object, fileSystem, localRepository, new Mock<IRecentPackageRepository>().Object,
                new Mock<VsPackageInstallerEvents>().Object) { CallBase = true };
            var packageManagerFactory = new Mock<IVsPackageManagerFactory>();
            packageManager.As<IVsPackageManager>().SetupGet(m => m.BindingRedirectEnabled).Returns(true);

            int state = 1;
            packageManager.As<IVsPackageManager>().SetupSet(m => m.BindingRedirectEnabled = false).Callback(() => state += 1);
            packageManager.As<IVsPackageManager>().SetupSet(m => m.BindingRedirectEnabled = true).Callback(() => state *= 2);
            packageManagerFactory.Setup(m => m.CreatePackageManager(It.IsAny<IPackageRepository>(), false, false)).Returns(packageManager.Object);
            packageManager.Setup(m => m.GetProjectManager(project)).Returns(projectManager);

            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<IVsCommonOperations>().Object, new Mock<ISolutionManager>().Object);

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

            // Assert
            // state = 4 means that BindingRedirectEnabled is set to 'false', then to 'true', in that order.
            // no other value of 4 can result in the same value of 4.
            Assert.Equal(4, state);
            packageManager.As<IVsPackageManager>().VerifySet(m => m.BindingRedirectEnabled = false, Times.Once());
            packageManager.As<IVsPackageManager>().VerifySet(m => m.BindingRedirectEnabled = true, Times.Once());
        }
Example #12
0
        public void InstallPackageDoesNotUseFallbackRepository()
        {
            // 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 projectManager = new ProjectManager(localRepository, pathResolver, projectSystem, projectRepository);
            var scriptExecutor = new Mock<IScriptExecutor>();
            var packageManager = new Mock<VsPackageManager>(
                TestUtils.GetSolutionManager(), 
                sourceRepository, 
                new Mock<IFileSystemProvider>().Object, 
                fileSystem, 
                localRepository,
                new Mock<IDeleteOnRestartManager>().Object, 
                new Mock<VsPackageInstallerEvents>().Object,
                /* multiFrameworkTargeting */ null) 
                { 
                    CallBase = true 
                };
            var packageManagerFactory = new Mock<IVsPackageManagerFactory>();
            packageManagerFactory.Setup(m => m.CreatePackageManager(It.IsAny<IPackageRepository>(), false)).Returns(packageManager.Object);
            packageManagerFactory.Setup(m => m.CreatePackageManager()).Throws(new Exception("A"));
            packageManagerFactory.Setup(m => m.CreatePackageManager(It.IsAny<IPackageRepository>(), true)).Throws(new Exception("B"));
            packageManager.Setup(m => m.GetProjectManager(project)).Returns(projectManager);

            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
            packageManagerFactory.Verify(m => m.CreatePackageManager(It.IsAny<IPackageRepository>(), false), Times.Once());
            packageManagerFactory.Verify(m => m.CreatePackageManager(), Times.Never());
            packageManagerFactory.Verify(m => m.CreatePackageManager(It.IsAny<IPackageRepository>(), true), Times.Never());
        }
Example #13
0
        public void InstallPackageThrowsIfRepositoryIsNull()
        {
            // 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 projectManager = new ProjectManager(localRepository, pathResolver, projectSystem, projectRepository);
            var scriptExecutor = new Mock<IScriptExecutor>();
            var packageManager = new Mock<VsPackageManager>(
                TestUtils.GetSolutionManager(),
                sourceRepository,
                new Mock<IFileSystemProvider>().Object,
                fileSystem,
                localRepository,
                new Mock<IDeleteOnRestartManager>().Object,
                new Mock<VsPackageInstallerEvents>().Object,
                /* multiFrameworkTargeting */ null)
            {
                CallBase = true
            };
            var packageManagerFactory = new Mock<IVsPackageManagerFactory>();
            var packageRepositoryFactory = new Mock<IPackageRepositoryFactory>(MockBehavior.Strict);
            packageManagerFactory.Setup(m => m.CreatePackageManager(It.Is<IPackageRepository>(p => p != null), false))
                                 .Returns(packageManager.Object);
            packageManager.Setup(m => m.GetProjectManager(project)).Returns(projectManager);
            
            var installer = new VsPackageInstaller(packageManagerFactory.Object, scriptExecutor.Object, packageRepositoryFactory.Object, new Mock<IOutputConsoleProvider>().Object, new Mock<IVsCommonOperations>().Object, new Mock<ISolutionManager>().Object, null, null);

            // Act && Assert
            Assert.Throws<ArgumentNullException>( () => 
                installer.InstallPackage(/* repository */ null, project, "foo", "1.0", ignoreDependencies: false, skipAssemblyReferences: true)
            );
        }
Example #14
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]);
        }
Example #15
0
        public void InstallPackageDoesNotAddToRecentRepository()
        {
            // 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 projectManager = new ProjectManager(localRepository, pathResolver, projectSystem, projectRepository);
            var scriptExecutor = new Mock<IScriptExecutor>();
            var packageManager = new Mock<VsPackageManager>(TestUtils.GetSolutionManager(), sourceRepository, fileSystem, localRepository, new Mock<IRecentPackageRepository>().Object, 
                new Mock<VsPackageInstallerEvents>().Object) { CallBase = true };
            var packageManagerFactory = new Mock<IVsPackageManagerFactory>();
            packageManagerFactory.Setup(m => m.CreatePackageManager(It.IsAny<IPackageRepository>(), false, false)).Returns(packageManager.Object);
            packageManagerFactory.Setup(m => m.CreatePackageManager()).Throws(new Exception("A"));
            packageManagerFactory.Setup(m => m.CreatePackageManager(It.IsAny<IPackageRepository>(), true, It.IsAny<bool>())).Throws(new Exception("B"));
            packageManager.Setup(m => m.GetProjectManager(project)).Returns(projectManager);

            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);

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

            // Assert
            packageManagerFactory.Verify(m => m.CreatePackageManager(It.IsAny<IPackageRepository>(), false, false), Times.Once());
            packageManagerFactory.Verify(m => m.CreatePackageManager(), Times.Never());
            packageManagerFactory.Verify(m => m.CreatePackageManager(It.IsAny<IPackageRepository>(), It.IsAny<bool>(), true), Times.Never());
        }