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, 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>(), true, It.IsAny<bool>()), Times.Never()); }
public void GetPackagesReturnsAllValidPackages() { // Arrange var fileSystem = new MockFileSystem("c:\\"); AddPackage(fileSystem, "A", "1.0"); AddPackage(fileSystem, "B", "1.0-alpha"); AddPackage(fileSystem, "C", "2.0.1-RC"); AddPackage(fileSystem, "D", "3.0"); // these are invalid packages (missing corresponding directory) fileSystem.AddFile("AA.2.0.nupkg"); fileSystem.AddFile("BB.4.0.nupkg"); fileSystem.CreateDirectory("BB.3.0"); var pathResolver = new DefaultPackagePathResolver("c:\\"); var repository = new UnzippedPackageRepository(pathResolver, fileSystem); // Act var packages = repository.GetPackages().ToList(); // Assert Assert.Equal(4, packages.Count); AssertPackage(packages[0], "A", new SemanticVersion("1.0")); AssertPackage(packages[1], "B", new SemanticVersion("1.0.0-alpha")); AssertPackage(packages[2], "C", new SemanticVersion("2.0.1-RC")); AssertPackage(packages[3], "D", new SemanticVersion("3.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 InstallMetadataPackageWithReadMeInstallsIntoProjectAndPackageManager() { // Arrange var localRepository = new Mock<MockPackageRepository>() { CallBase = true }.As<ISharedPackageRepository>().Object; var sourceRepository = new MockPackageRepository(); var projectSystem = new MockProjectSystem(); var pathResolver = new DefaultPackagePathResolver(projectSystem); var projectManager = new ProjectManager(localRepository, pathResolver, new MockProjectSystem(), new MockPackageRepository()); var packageManager = new VsPackageManager(TestUtils.GetSolutionManager(), sourceRepository, new Mock<IFileSystemProvider>().Object, projectSystem, localRepository, new Mock<IDeleteOnRestartManager>().Object, new Mock<VsPackageInstallerEvents>().Object); var packageA = PackageUtility.CreatePackage("A", "1.0", dependencies: new[] { new PackageDependency("B") }); var mockPackageA = Mock.Get(packageA); mockPackageA.Setup(m => m.GetFiles()).Returns(PackageUtility.CreateFiles(new[] { "readme.txt" })); var packageB = PackageUtility.CreatePackage("B", "1.0", content: new[] { "hello.txt" }); sourceRepository.AddPackage(packageA); sourceRepository.AddPackage(packageB); // Act packageManager.InstallPackage(projectManager, "A", new SemanticVersion("1.0"), ignoreDependencies: false, allowPrereleaseVersions: false, logger: NullLogger.Instance); // Assert Assert.True(packageManager.LocalRepository.Exists(packageA)); Assert.True(projectManager.LocalRepository.Exists(packageA)); Assert.True(packageManager.LocalRepository.Exists(packageB)); Assert.True(projectManager.LocalRepository.Exists(packageB)); }
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()); }
/// <summary> /// Checks whether an IPackage exists within a PackageManager. By default, will use the UseSideBySide settings of the DefaultPackagePathProvider the PackageManager is instantiated with. /// If passed in TRUE for exhaustive, will check both with and without UseSideBySide set. /// </summary> /// <param name="packageManager"></param> /// <param name="package"></param> /// <param name="exhaustive"></param> /// <returns></returns> public static bool IsPackageInstalled(this PackageManager packageManager, IPackage package, bool exhaustive = false) { var pathsDictionary = new Dictionary <string, bool>(); //Oh god oh god. The <center> cannot hold it is too late. var useSideBySide = packageManager.PathResolver.GetPrivateField <bool>("_useSideBySidePaths"); pathsDictionary.Add(Path.Combine(packageManager.PathResolver.GetInstallPath(package), packageManager.PathResolver.GetPackageFileName(package.Id, package.Version)), useSideBySide); //We need to also check the inverse, to see if it was installed with the other setting.... if (exhaustive) { var inversePathResolver = new DefaultPackagePathResolver(packageManager.PathResolver.GetPrivateField <IFileSystem>("_fileSystem"), !useSideBySide); pathsDictionary.Add(Path.Combine(inversePathResolver.GetInstallPath(package), inversePathResolver.GetPackageFileName(package.Id, package.Version)), !useSideBySide); } foreach (var path in pathsDictionary.Where(path => packageManager.FileSystem.FileExists(path.Key))) { if (path.Value) { return(true); } //If not useSideBySide, we need to crack open the zip file. //Need to crack the package open at this point and check the version, otherwise we just need to download it regardless var zipPackage = new ZipPackage(packageManager.FileSystem.OpenFile(path.Key)); if (zipPackage.Version == package.Version) { return(true); } } //Its not here. Really. We tried. return(false); }
public void InstallCommandFromConfigIgnoresDependencies() { // Arrange var fileSystem = new MockFileSystem(); fileSystem.AddFile(@"X:\test\packages.config", @"<?xml version=""1.0"" encoding=""utf-8""?> <packages> <package id=""Foo"" version=""1.0.0"" /> <package id=""Qux"" version=""2.3.56-beta"" /> </packages>"); var pathResolver = new DefaultPackagePathResolver(fileSystem); var packageManager = new Mock <IPackageManager>(MockBehavior.Strict); var repository = new MockPackageRepository(); packageManager.Setup(p => p.InstallPackage("Foo", new SemanticVersion("1.0.0"), true, true)).Verifiable(); packageManager.Setup(p => p.InstallPackage("Qux", new SemanticVersion("2.3.56-beta"), true, true)).Verifiable(); packageManager.SetupGet(p => p.PathResolver).Returns(pathResolver); packageManager.SetupGet(p => p.LocalRepository).Returns(new LocalPackageRepository(pathResolver, fileSystem)); packageManager.SetupGet(p => p.FileSystem).Returns(fileSystem); packageManager.SetupGet(p => p.SourceRepository).Returns(repository); var repositoryFactory = new Mock <IPackageRepositoryFactory>(); repositoryFactory.Setup(r => r.CreateRepository("My Source")).Returns(repository); var packageSourceProvider = new Mock <IPackageSourceProvider>(MockBehavior.Strict); // Act var installCommand = new TestInstallCommand(repositoryFactory.Object, packageSourceProvider.Object, fileSystem, packageManager.Object); installCommand.Arguments.Add(@"X:\test\packages.config"); installCommand.Execute(); // Assert packageManager.Verify(); }
public void UpdatePackageWillAskForEachFileWhenThereAreFileConflict() { // Arrange var localRepository = new MockPackageRepository(); var sourceRepository = new MockPackageRepository(); var constraintProvider = NullConstraintProvider.Instance; var fileSystem = new MockFileSystem(); var pathResolver = new DefaultPackagePathResolver(fileSystem); var projectSystem = new MockProjectSystem(); projectSystem.AddFile("one.txt", "this is one"); projectSystem.AddFile("two.txt", "this is two"); var packages = new List <IPackage>(); var package_A10 = PackageUtility.CreatePackage("A", "1.0", content: new[] { "1.txt" }); var package_A12 = PackageUtility.CreatePackage("A", "1.2", content: new[] { "one.txt", "two.txt" }); localRepository.Add(package_A10); sourceRepository.Add(package_A12); var sharedRepository = new Mock <ISharedPackageRepository>(MockBehavior.Strict); sharedRepository.Setup(s => s.AddPackage(package_A12)).Callback <IPackage>(p => packages.Add(p)); sharedRepository.Setup(s => s.GetPackages()).Returns(packages.AsQueryable()); var repositoryFactory = new Mock <IPackageRepositoryFactory>(); repositoryFactory.Setup(s => s.CreateRepository(It.IsAny <string>())).Returns(sourceRepository); var packageSourceProvider = new Mock <IPackageSourceProvider>(); packageSourceProvider.Setup(s => s.LoadPackageSources()).Returns(new[] { new PackageSource("foo-source") }); var answers = new[] { FileConflictResolution.Overwrite, FileConflictResolution.Ignore, }; int cursor = 0; var console = new Mock <IConsole>(); console.Setup(c => c.ResolveFileConflict(It.IsAny <string>())).Returns(() => answers[cursor++]); var updateCommand = new UpdateCommand() { RepositoryFactory = repositoryFactory.Object, SourceProvider = packageSourceProvider.Object, Console = console.Object, }; // Act updateCommand.UpdatePackages(localRepository, fileSystem, sharedRepository.Object, sourceRepository, constraintProvider, pathResolver, projectSystem); // Assert Assert.True(localRepository.Exists("A", new SemanticVersion("1.2"))); Assert.Equal("content\\one.txt", projectSystem.ReadAllText("one.txt")); Assert.Equal("this is two", projectSystem.ReadAllText("two.txt")); Assert.Equal(2, cursor); }
void CreatePackageManager(IProject project, PackageReferenceRepositoryHelper packageRefRepositoryHelper) { options = new TestablePackageManagementOptions(); options.PackagesDirectory = "packages"; repositoryPaths = new SolutionPackageRepositoryPath(project, options); var pathResolver = new DefaultPackagePathResolver(repositoryPaths.PackageRepositoryPath); fakeFileSystem = new FakeFileSystem(); fakeFeedSourceRepository = new FakePackageRepository(); fakeSolutionSharedRepository = packageRefRepositoryHelper.FakeSharedSourceRepository; fakePackageOperationResolverFactory = new FakePackageOperationResolverFactory(); var fakeSolutionPackageRepository = new FakeSolutionPackageRepository(); fakeSolutionPackageRepository.FileSystem = fakeFileSystem; fakeSolutionPackageRepository.PackagePathResolver = pathResolver; fakeSolutionPackageRepository.FakeSharedRepository = fakeSolutionSharedRepository; packageManager = new SharpDevelopPackageManager(fakeFeedSourceRepository, packageRefRepositoryHelper.FakeProjectSystem, fakeSolutionPackageRepository, fakePackageOperationResolverFactory); }
public void InstallPackageSetOperationToInstall3() { // Arrange var localRepository = new MockSharedPackageRepository(); var sourceRepository = new MockPackageRepository(); var projectSystem = new MockProjectSystem(); var pathResolver = new DefaultPackagePathResolver(projectSystem); var projectManager = new ProjectManager(localRepository, pathResolver, new MockProjectSystem(), new MockPackageRepository()); var packageManager = new VsPackageManager(TestUtils.GetSolutionManager(), sourceRepository, new Mock<IFileSystemProvider>().Object, projectSystem, localRepository, new Mock<IDeleteOnRestartManager>().Object, new Mock<VsPackageInstallerEvents>().Object); var package = PackageUtility.CreatePackage("foo", "1.0", new[] { "hello" }); sourceRepository.AddPackage(package); var package2 = PackageUtility.CreatePackage("bar", "2.0", new[] { "world" }); sourceRepository.AddPackage(package2); // Act packageManager.InstallPackage( projectManager, package2, new PackageOperation[] { new PackageOperation(package, PackageAction.Install), new PackageOperation(package2, PackageAction.Install), }, ignoreDependencies: false, allowPrereleaseVersions: false, logger: NullLogger.Instance); // Assert Assert.Equal("Install", sourceRepository.LastOperation); Assert.Equal("bar", sourceRepository.LastMainPackageId); Assert.Equal("2.0", sourceRepository.LastMainPackageVersion); }
public void FindPackageReturnsNullForNonExistingPackage() { // Arrange var fileSystem = new MockFileSystem("c:\\"); AddPackage(fileSystem, "A", "1.0"); AddPackage(fileSystem, "B", "1.0-alpha"); AddPackage(fileSystem, "C", "2.0.1-RC"); AddPackage(fileSystem, "D", "3.0"); // these are invalid packages (missing corresponding directory) fileSystem.AddFile("AA.2.0.nupkg"); fileSystem.AddFile("BB.4.0.nupkg"); fileSystem.CreateDirectory("BB.3.0"); var pathResolver = new DefaultPackagePathResolver("c:\\"); var repository = new UnzippedPackageRepository(pathResolver, fileSystem); // Act var packageA = repository.FindPackage("A", new SemanticVersion("2.0")); var packageB = repository.FindPackage("BBB", new SemanticVersion("1.0-alpha")); // Assert Assert.Null(packageA); Assert.Null(packageB); }
public void ReinstallPackagesRestoresPackageWithTheSameVersion() { // Arrange var localRepository = new Mock<MockPackageRepository>() { CallBase = true }.As<ISharedPackageRepository>().Object; var sourceRepository = new MockPackageRepository(); var projectSystem = new MockProjectSystem(); var pathResolver = new DefaultPackagePathResolver(projectSystem); var projectManager = new ProjectManager(localRepository, pathResolver, projectSystem, new MockPackageRepository()); var packageManager = new VsPackageManager( TestUtils.GetSolutionManager(), sourceRepository, new Mock<IFileSystemProvider>().Object, projectSystem, localRepository, new Mock<IDeleteOnRestartManager>().Object, new Mock<VsPackageInstallerEvents>().Object); var packageA = PackageUtility.CreatePackage("A", "1.2", new[] { "content.txt" }); sourceRepository.Add(packageA); localRepository.AddPackage(packageA); projectManager.LocalRepository.AddPackage(packageA); // Act packageManager.ReinstallPackage(projectManager, "A", updateDependencies: true, allowPrereleaseVersions: true, logger: null); // Assert Assert.True(packageManager.LocalRepository.Exists("A", new SemanticVersion("1.2"))); Assert.True(projectManager.LocalRepository.Exists("A", new SemanticVersion("1.2"))); }
public void DnuPackagesAddOverwritesInstalledPackageWhenShasDoNotMatch(string flavor, string os, string architecture) { var runtimeHomeDir = TestUtils.GetRuntimeHomeDir(flavor, os, architecture); using (var tempSamplesDir = TestUtils.PrepareTemporarySamplesFolder(runtimeHomeDir)) { var projectFilePath = Path.Combine(tempSamplesDir, ProjectName, Runtime.Project.ProjectFileName); var packagesDir = Path.Combine(tempSamplesDir, PackagesDirName); var packagePathResolver = new DefaultPackagePathResolver(packagesDir); var nuspecPath = packagePathResolver.GetManifestFilePath(ProjectName, ProjectVersion); SetProjectDescription(projectFilePath, "Old"); BuildPackage(tempSamplesDir, runtimeHomeDir); string stdOut; var exitCode = DnuPackagesAddOutputPackage(tempSamplesDir, runtimeHomeDir, out stdOut); Assert.Equal(0, exitCode); Assert.Contains($"Installing {ProjectName}.{ProjectVersion}", stdOut); var lastInstallTime = new FileInfo(nuspecPath).LastWriteTimeUtc; SetProjectDescription(projectFilePath, "New"); BuildPackage(tempSamplesDir, runtimeHomeDir); exitCode = DnuPackagesAddOutputPackage(tempSamplesDir, runtimeHomeDir, out stdOut); Assert.Equal(0, exitCode); Assert.Contains($"Overwriting {ProjectName}.{ProjectVersion}", stdOut); var xDoc = XDocument.Load(packagePathResolver.GetManifestFilePath(ProjectName, ProjectVersion)); var actualDescription = xDoc.Root.Descendants() .Single(x => string.Equals(x.Name.LocalName, "description")).Value; Assert.Equal("New", actualDescription); Assert.NotEqual(lastInstallTime, new FileInfo(nuspecPath).LastWriteTimeUtc); } }
public void GetRemotePackagesTest() { // Arrange var siteRoot = "x:\\"; var localRepository = new MockPackageRepository(); var sourceRepository = new MockServiceBasePackageRepository(); var projectSystem = new WebProjectSystem(siteRoot); var pathResolver = new DefaultPackagePathResolver(projectSystem); var projectManager = new ProjectManager(sourceRepository, pathResolver, projectSystem, localRepository); var net40 = new FrameworkName(".NETFramework", new Version("4.0.0.0")); var net45 = new FrameworkName(".NETFramework", new Version("4.5.0.0")); IPackage packageA = PackageFactory.Create("A", new Version("1.0"), null, new FrameworkName[] { net40 }); IPackage packageB = PackageFactory.Create("B", new Version("1.0"), null, new FrameworkName[] { net45 }); IPackage packageC = PackageFactory.Create("C", new Version("1.0")); sourceRepository.AddPackage(packageA); sourceRepository.AddPackage(packageB); sourceRepository.AddPackage(packageC); // NOTE THAT target framework used by WebProjectManager would be .NETFramework, Version=4.0.0.0 var webProjectManager = new WebProjectManager(projectManager, siteRoot); // Act var packages = webProjectManager.GetRemotePackages(null, false).ToList(); // Assert Assert.Equal(2, packages.Count); Assert.Equal(packageA, packages[0]); Assert.Equal(packageC, packages[1]); }
public void FindPackagesByIdIgnoresPartialIdMatches() { // Arramge var fileSystem = new MockFileSystem(); fileSystem.AddFile(@"Foo.1.0\Foo.1.0.nupkg"); fileSystem.AddFile(@"Foo.2.0.0\Foo.2.0.0.nupkg"); fileSystem.AddFile(@"Foo.Baz.2.0.0\Foo.Baz.2.0.0.nupkg"); var pathResolver = new DefaultPackagePathResolver(fileSystem); var foo_10 = PackageUtility.CreatePackage("Foo", "1.0"); var foo_20 = PackageUtility.CreatePackage("Foo", "2.0.0"); var fooBaz_20 = PackageUtility.CreatePackage("Foo.Baz", "2.0.0"); var localPackageRepository = new MockLocalRepository(fileSystem, path => { switch (path) { case @"Foo.1.0\Foo.1.0.nupkg": return(foo_10); case @"Foo.2.0.0\Foo.2.0.0.nupkg": return(foo_20); case @"Foo.Baz.2.0.0\Foo.Baz.2.0.0.nupkg": return(fooBaz_20); default: return(null); } }); // Act var packages = localPackageRepository.FindPackagesById("Foo").ToList(); // Assert Assert.Equal(new[] { foo_10, foo_20 }, packages); }
public void DnuPackagesAddSkipsInstalledPackageWhenShasMatch(string flavor, string os, string architecture) { var runtimeHomeDir = TestUtils.GetRuntimeHomeDir(flavor, os, architecture); using (var tempSamplesDir = TestUtils.PrepareTemporarySamplesFolder(runtimeHomeDir)) { var projectFilePath = Path.Combine(tempSamplesDir, ProjectName, Runtime.Project.ProjectFileName); var packagesDir = Path.Combine(tempSamplesDir, PackagesDirName); var packagePathResolver = new DefaultPackagePathResolver(packagesDir); var nuspecPath = packagePathResolver.GetManifestFilePath(ProjectName, ProjectVersion); BuildPackage(tempSamplesDir, runtimeHomeDir); string stdOut; var exitCode = DnuPackagesAddOutputPackage(tempSamplesDir, runtimeHomeDir, out stdOut); Assert.Equal(0, exitCode); Assert.Contains($"Installing {ProjectName}.{ProjectVersion}", stdOut); var lastInstallTime = new FileInfo(nuspecPath).LastWriteTimeUtc; exitCode = DnuPackagesAddOutputPackage(tempSamplesDir, runtimeHomeDir, out stdOut); Assert.Equal(0, exitCode); Assert.Contains($"{ProjectName}.{ProjectVersion} already exists", stdOut); Assert.Equal(lastInstallTime, new FileInfo(nuspecPath).LastWriteTimeUtc); } }
/// <summary> /// This is a helper method for looking up directories that directly contains assemblies that would be loaded /// given the published runtime framework. We should run crossgen on these folders /// </summary> private IEnumerable <string> ResolveOutputAssemblies(PublishRoot root) { var resolver = new DefaultPackagePathResolver(root.TargetPackagesPath); if (root.LockFile == null) { return(Enumerable.Empty <string>()); } var directories = new HashSet <string>(); foreach (var target in root.LockFile.Targets) { foreach (var library in target.Libraries) { var packagesDir = resolver.GetInstallPath(library.Name, library.Version); foreach (var path in library.RuntimeAssemblies) { var assemblyPath = CombinePath(packagesDir, path); directories.Add(Path.GetDirectoryName(assemblyPath)); } } } return(directories); }
public void InstallPackageAddsAllFilesToFileSystem() { // Arrange var projectSystem = new MockProjectSystem(); var sourceRepository = new MockPackageRepository(); var pathResolver = new DefaultPackagePathResolver(projectSystem); var packageManager = new PackageManager(sourceRepository, pathResolver, projectSystem, new SharedPackageRepository(pathResolver, projectSystem, projectSystem)); IPackage packageA = PackageUtility.CreatePackage("A", "1.0", new[] { "contentFile", @"sub\contentFile" }, new[] { @"lib\reference.dll" }, new[] { @"readme.txt" }); sourceRepository.AddPackage(packageA); // Act Install("A", new NullProjectManager(packageManager)); // Assert Assert.Equal(0, projectSystem.References.Count); Assert.Equal(5, projectSystem.Paths.Count); Assert.True(projectSystem.FileExists(@"A.1.0\content\contentFile")); Assert.True(projectSystem.FileExists(@"A.1.0\content\sub\contentFile")); Assert.True(projectSystem.FileExists(@"A.1.0\lib\reference.dll")); Assert.True(projectSystem.FileExists(@"A.1.0\tools\readme.txt")); Assert.True(projectSystem.FileExists(@"A.1.0\A.1.0.nupkg")); }
public void InstallPackageSetOperationToInstall3() { // Arrange var localRepository = new MockSharedPackageRepository(); var sourceRepository = new MockPackageRepository(); var projectSystem = new MockProjectSystem(); var pathResolver = new DefaultPackagePathResolver(projectSystem); var projectManager = new ProjectManager(localRepository, pathResolver, new MockProjectSystem(), new MockPackageRepository()); var packageManager = new VsPackageManager(TestUtils.GetSolutionManager(), sourceRepository, new Mock <IFileSystemProvider>().Object, projectSystem, localRepository, new Mock <IDeleteOnRestartManager>().Object, new Mock <VsPackageInstallerEvents>().Object); var package = PackageUtility.CreatePackage("foo", "1.0", new[] { "hello" }); sourceRepository.AddPackage(package); var package2 = PackageUtility.CreatePackage("bar", "2.0", new[] { "world" }); sourceRepository.AddPackage(package2); // Act packageManager.InstallPackage( projectManager, package2, new PackageOperation[] { new PackageOperation(package, PackageAction.Install), new PackageOperation(package2, PackageAction.Install), }, ignoreDependencies: false, allowPrereleaseVersions: false, logger: NullLogger.Instance); // Assert Assert.Equal("Install", sourceRepository.LastOperation); Assert.Equal("bar", sourceRepository.LastMainPackageId); Assert.Equal("2.0", sourceRepository.LastMainPackageVersion); }
public void UpdatePackagesSetOperationToUpdate1() { // Arrange var localRepository = new MockSharedPackageRepository(); var sourceRepository = new MockPackageRepository(); var projectRepository = new MockPackageRepository(); var projectSystem = new MockProjectSystem(); var pathResolver = new DefaultPackagePathResolver(projectSystem); var projectManager = new ProjectManager(localRepository, pathResolver, new MockProjectSystem(), projectRepository); var packageManager = new VsPackageManager(TestUtils.GetSolutionManager(), sourceRepository, new Mock <IFileSystemProvider>().Object, projectSystem, localRepository, new Mock <IDeleteOnRestartManager>().Object, new Mock <VsPackageInstallerEvents>().Object); var package = PackageUtility.CreatePackage("phuong", "1.0", new[] { "hello" }); localRepository.AddPackage(package); projectRepository.AddPackage(package); var package2 = PackageUtility.CreatePackage("phuong", "2.0", new[] { "hello" }); sourceRepository.AddPackage(package2); // Act packageManager.UpdatePackages( projectManager, updateDependencies: true, allowPrereleaseVersions: true, logger: NullLogger.Instance); // Assert Assert.Equal("Update", sourceRepository.LastOperation); Assert.Equal("phuong", sourceRepository.LastMainPackageId); Assert.Equal("2.0", sourceRepository.LastMainPackageVersion); }
static void Main(string[] args) { var orchardDirectory = args[0]; var inputDirectory = args[1]; var outputDirectory = args[2]; var cacheDirectory = args[3]; var cacheFileSystem = new PhysicalFileSystem(cacheDirectory); var cachePackageResolver = new DefaultPackagePathResolver(cacheFileSystem, false); var orchardRepository = new AggregateRepository(new IPackageRepository[] { new LocalPackageRepository(orchardDirectory), new DataServicePackageRepository(new Uri("http://nuget.org/api/v2")), }); var orchardManager = new PackageManager(orchardRepository, cachePackageResolver, cacheFileSystem); var inputRepository = new LocalPackageRepository(inputDirectory); var inputManager = new PackageManager(inputRepository, cachePackageResolver, cacheFileSystem); var references = new[] { "Orchard.Core", "Orchard.Framework", "Orchard.External" }; foreach (var reference in references) { orchardManager.InstallPackage(orchardRepository.FindPackage(reference), false, false); } foreach (var inputPackage in inputRepository.GetPackages().Where(p => p.Id.StartsWith("Orchard.Module."))) { Do(inputRepository, inputManager, inputPackage, cacheDirectory, references, outputDirectory); } }
public void FindPackageFindTheRightPackage() { // Arrange var fileSystem = new MockFileSystem("c:\\"); AddPackage(fileSystem, "A", "1.0"); AddPackage(fileSystem, "B", "1.0-alpha"); AddPackage(fileSystem, "C", "2.0.1-RC"); AddPackage(fileSystem, "D", "3.0"); // these are invalid packages (missing corresponding directory) fileSystem.AddFile("AA.2.0.nupkg"); fileSystem.AddFile("BB.4.0.nupkg"); fileSystem.CreateDirectory("BB.3.0"); var pathResolver = new DefaultPackagePathResolver("c:\\"); var repository = new UnzippedPackageRepository(pathResolver, fileSystem); // Act var packageA = repository.FindPackage("A", new SemanticVersion("1.0")); var packageB = repository.FindPackage("B", new SemanticVersion("1.0-alpha")); // Assert AssertPackage(packageA, "A", new SemanticVersion("1.0")); AssertPackage(packageB, "B", new SemanticVersion("1.0.0-alpha")); }
/// <summary> /// Constructor /// </summary> /// <param name="settings"></param> /// <param name="mapPath">A delegate method used to perform a Server.MapPath operation</param> public DefaultPackageContext(UmbracoSettings settings, Func <string, string> mapPath) { _settings = settings; _pluginInstallFolderPath = mapPath(_settings.PluginConfig.PluginsPath + "/Packages"); _localPackageRepoFolderPath = mapPath(_settings.UmbracoFolders.LocalPackageRepositoryFolder); //create lazy instances of each _localPackageRepository = new Lazy <IPackageRepository>( () => { //create a new path resolver with false as 'useSideBySidePaths' so that it doesn't install with version numbers. var packageFileSys = new PhysicalFileSystem(_localPackageRepoFolderPath); var packagePathResolver = new DefaultPackagePathResolver(packageFileSys, false); return(new LocalPackageRepository(packagePathResolver, packageFileSys, true)); }); _localPackageManager = new Lazy <IPackageManager>( () => { //create a new path resolver with false as 'useSideBySidePaths' so that it doesn't install with version numbers. var packageFileSys = new PhysicalFileSystem(_pluginInstallFolderPath); var packagePathResolver = new DefaultPackagePathResolver(packageFileSys, false); return(new PackageManager(_localPackageRepository.Value, packagePathResolver, packageFileSys)); }); _publicPackageRepository = new Lazy <IPackageRepository>( () => PackageRepositoryFactory.Default.CreateRepository(_settings.PublicPackageRepository.RepositoryAddress)); _publicPackageManager = new Lazy <IPackageManager>( () => new PackageManager(_publicPackageRepository.Value, mapPath(_settings.PluginConfig.PluginsPath + "/Packages"))); }
public void UpdatePackageAddsPackagesToSharedPackageRepositoryWhenReferencesAreAdded() { // Arrange var localRepository = new MockPackageRepository(); var sourceRepository = new MockPackageRepository(); var constraintProvider = NullConstraintProvider.Instance; var pathResolver = new DefaultPackagePathResolver(NullFileSystem.Instance); var projectSystem = new MockProjectSystem(); var package_A10 = PackageUtility.CreatePackage("A", "1.0", content: new[] { "1.txt" }); var package_A12 = PackageUtility.CreatePackage("A", "1.2", content: new[] { "1.txt" }); localRepository.Add(package_A10); sourceRepository.Add(package_A12); var sharedRepository = new Mock <ISharedPackageRepository>(MockBehavior.Strict); sharedRepository.Setup(s => s.AddPackage(package_A12)).Verifiable(); var repositoryFactory = new Mock <IPackageRepositoryFactory>(); repositoryFactory.Setup(s => s.CreateRepository(It.IsAny <string>())).Returns(sourceRepository); var packageSourceProvider = new Mock <IPackageSourceProvider>(); packageSourceProvider.Setup(s => s.LoadPackageSources()).Returns(new[] { new PackageSource("foo-source") }); var updateCommand = new UpdateCommand(repositoryFactory.Object, packageSourceProvider.Object); // Act updateCommand.UpdatePackages(localRepository, sharedRepository.Object, sourceRepository, constraintProvider, pathResolver, projectSystem); // Assert sharedRepository.Verify(); }
/// <summary> /// Checks whether an IPackage exists within a PackageManager. By default, will use the UseSideBySide settings of the DefaultPackagePathProvider the PackageManager is instantiated with. /// If passed in TRUE for exhaustive, will check both with and without UseSideBySide set. /// </summary> /// <param name="packageManager"></param> /// <param name="package"></param> /// <param name="exhaustive"></param> /// <returns></returns> public static bool IsPackageInstalled(this PackageManager packageManager, IPackage package, bool exhaustive = false) { var pathsDictionary = new Dictionary<string, bool>(); //Oh god oh god. The <center> cannot hold it is too late. var useSideBySide = packageManager.PathResolver.GetPrivateField<bool>("_useSideBySidePaths"); pathsDictionary.Add(Path.Combine(packageManager.PathResolver.GetInstallPath(package), packageManager.PathResolver.GetPackageFileName(package.Id, package.Version)), useSideBySide); //We need to also check the inverse, to see if it was installed with the other setting.... if (exhaustive) { var inversePathResolver = new DefaultPackagePathResolver(packageManager.PathResolver.GetPrivateField<IFileSystem>("_fileSystem"), !useSideBySide); pathsDictionary.Add(Path.Combine(inversePathResolver.GetInstallPath(package), inversePathResolver.GetPackageFileName(package.Id, package.Version)), !useSideBySide); } foreach (var path in pathsDictionary.Where(path => packageManager.FileSystem.FileExists(path.Key))) { if (path.Value) { return true; } //If not useSideBySide, we need to crack open the zip file. //Need to crack the package open at this point and check the version, otherwise we just need to download it regardless var zipPackage = new ZipPackage(packageManager.FileSystem.OpenFile(path.Key)); if (zipPackage.Version == package.Version) { return true; } } //Its not here. Really. We tried. return false; }
public void InstallPackageIntoWindowsStoreProjectIgnoreAppConfigFile() { // Arrange var sourceRepository = new MockPackageRepository(); var mockFileSystemProvider = new Mock <IFileSystemProvider>(); mockFileSystemProvider.Setup(fs => fs.GetFileSystem(It.IsAny <string>())).Returns(new MockFileSystem()); var project = TestUtils.GetProject("WindowsStore"); var projectSystem = new TestableWindowsStoreProjectSystem(project, mockFileSystemProvider.Object); var pathResolver = new DefaultPackagePathResolver(projectSystem); var package = NuGet.Test.PackageUtility.CreatePackage( "foo", "1.0.0", content: new[] { "readme.txt", "app.config" }); sourceRepository.AddPackage(package); var projectManager = new ProjectManager( sourceRepository, pathResolver, projectSystem, new MockPackageRepository()); // Act projectManager.AddPackageReference(package, ignoreDependencies: false, allowPrereleaseVersions: false); // Assert Assert.True(projectSystem.FileExists("readme.txt")); Assert.False(projectSystem.FileExists("app.config")); }
public void InstallPackageWithOperationsExecuteAllOperations() { // Arrange var localRepository = new Mock<MockPackageRepository>() { CallBase = true }.As<ISharedPackageRepository>().Object; var sourceRepository = new MockPackageRepository(); var projectSystem = new MockProjectSystem(); var pathResolver = new DefaultPackagePathResolver(projectSystem); var projectManager = new ProjectManager(localRepository, pathResolver, new MockProjectSystem(), new MockPackageRepository()); var packageManager = new VsPackageManager(TestUtils.GetSolutionManager(), sourceRepository, projectSystem, localRepository, new Mock<IRecentPackageRepository>().Object); var package = PackageUtility.CreatePackage("foo", "1.0", new[] { "hello" }, dependencies: new PackageDependency[] { new PackageDependency("bar") }); sourceRepository.AddPackage(package); var package2 = PackageUtility.CreatePackage("bar", "2.0", new[] { "world" }); sourceRepository.AddPackage(package2); var package3 = PackageUtility.CreatePackage("awesome", "1.0", new[] { "candy" }); localRepository.AddPackage(package3); var operations = new PackageOperation[] { new PackageOperation(package, PackageAction.Install), new PackageOperation(package2, PackageAction.Install), new PackageOperation(package3, PackageAction.Uninstall) }; // Act packageManager.InstallPackage(projectManager, package, operations, ignoreDependencies: false, logger: NullLogger.Instance); // Assert Assert.IsTrue(packageManager.LocalRepository.Exists(package)); Assert.IsTrue(packageManager.LocalRepository.Exists(package2)); Assert.IsTrue(!packageManager.LocalRepository.Exists(package3)); Assert.IsTrue(projectManager.LocalRepository.Exists(package)); Assert.IsTrue(projectManager.LocalRepository.Exists(package2)); }
public void UpdatePackageDoesNotRemovesPackageIfPackageIsReferenced() { // Arrange var localRepository = new Mock <MockPackageRepository>() { CallBase = true }.As <ISharedPackageRepository>(); localRepository.Setup(m => m.IsReferenced("A", new Version("1.0"))).Returns(true); var projectRepository = new MockProjectPackageRepository(localRepository.Object); var sourceRepository = new MockPackageRepository(); var fileSystem = new MockFileSystem(); var pathResolver = new DefaultPackagePathResolver(fileSystem); var A10 = PackageUtility.CreatePackage("A", "1.0", new[] { "hello" }); var A20 = PackageUtility.CreatePackage("A", "2.0", new[] { "hello" }); sourceRepository.AddPackage(A10); sourceRepository.AddPackage(A20); localRepository.Object.AddPackage(A10); localRepository.Object.AddPackage(A20); projectRepository.Add(A10); var packageManager = new VsPackageManager(TestUtils.GetSolutionManager(), sourceRepository, fileSystem, localRepository.Object, new Mock <IRecentPackageRepository>().Object); var projectManager = new ProjectManager(localRepository.Object, pathResolver, new MockProjectSystem(), projectRepository); // Act packageManager.UpdatePackage(projectManager, "A", version: null, updateDependencies: true, logger: NullLogger.Instance); // Assert Assert.IsTrue(packageManager.LocalRepository.Exists(A10)); }
public void UnregisterRepositoryUseTheStoreFileSystem() { // Arrange var fileSystem = new MockFileSystem("x:\\"); var storeFileSystem = new MockFileSystem("y:\\"); storeFileSystem.AddFile("repositories.config", @"<?xml version=""1.0"" encoding=""utf-8""?> <repositories> <repository path=""project1\path"" /> <repository path=""..\one\two"" /> </repositories>"); var configFileSystem = new MockFileSystem("z:\\"); var resolver = new DefaultPackagePathResolver(fileSystem); var repository = new SharedPackageRepository(resolver, fileSystem, storeFileSystem, configFileSystem); // Act repository.UnregisterRepository("x:\\project1\\path"); // Assert Assert.True(storeFileSystem.FileExists("repositories.config")); string content = storeFileSystem.ReadAllText("repositories.config"); Assert.Equal(@"<?xml version=""1.0"" encoding=""utf-8""?> <repositories> <repository path=""..\one\two"" /> </repositories>", content); }
private IEnumerable<ITaskItem> ResolvePackage(ITaskItem package) { string id = package.ItemSpec; string version = package.GetMetadata("Version"); Log.LogMessage(MessageImportance.Normal, "Resolving Package Reference {0} {1}...", id, version); // Initial version just searches a machine-level repository var localFs = new PhysicalFileSystem(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "NuGet", "Lib")); var defaultResolver = new DefaultPackagePathResolver(localFs); var machineRepo = new LocalPackageRepository(defaultResolver, localFs); var buildRepo = new BuildPackageRepository(); var remoteRepo = new DataServicePackageRepository(new Uri("https://nuget.org/api/v2")); var project = new BuildProjectSystem(ProjectDirectory, new FrameworkName(TargetFramework), CurrentReferences); var manager = new PackageManager(remoteRepo, defaultResolver, localFs, machineRepo); var projectManager = new ProjectManager(remoteRepo, defaultResolver, project, buildRepo); // Install the package var ver = new SemanticVersion(version); manager.PackageInstalling += manager_PackageInstalling; manager.InstallPackage(id, ver); projectManager.AddPackageReference(id, ver); return project.OutputReferences.Select(item => { var name = AssemblyName.GetAssemblyName(item); return new TaskItem(name.FullName, new Dictionary<string, string>() { {"HintPath", item }, {"Private", "true"} }); }); }
internal static async Task InstallFromStream(Stream stream, Library library, string packagesDirectory, SHA512 sha512) { var packagePathResolver = new DefaultPackagePathResolver(packagesDirectory); var targetPath = packagePathResolver.GetInstallPath(library.Name, library.Version); var targetNuspec = packagePathResolver.GetManifestFilePath(library.Name, library.Version); var targetNupkg = packagePathResolver.GetPackageFilePath(library.Name, library.Version); var hashPath = packagePathResolver.GetHashPath(library.Name, library.Version); // Acquire the lock on a nukpg before we extract it to prevent the race condition when multiple // processes are extracting to the same destination simultaneously await ConcurrencyUtilities.ExecuteWithFileLocked(targetNupkg, async createdNewLock => { // If this is the first process trying to install the target nupkg, go ahead // After this process successfully installs the package, all other processes // waiting on this lock don't need to install it again if (createdNewLock) { Directory.CreateDirectory(targetPath); using (var nupkgStream = new FileStream(targetNupkg, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite | FileShare.Delete)) { await stream.CopyToAsync(nupkgStream); nupkgStream.Seek(0, SeekOrigin.Begin); ExtractPackage(targetPath, nupkgStream); } //// Fixup the casing of the nuspec on disk to match what we expect //var nuspecFile = Directory.EnumerateFiles(targetPath, "*" + Constants.ManifestExtension).Single(); //if (!string.Equals(nuspecFile, targetNuspec, StringComparison.Ordinal)) //{ // Manifest manifest = null; // using (var nuspecStream = File.OpenRead(nuspecFile)) // { // manifest = Manifest.ReadFrom(nuspecStream, validateSchema: false); // manifest.Metadata.Id = library.Name; // } // // Delete the previous nuspec file // File.Delete(nuspecFile); // // Write the new manifest // using (var targetNuspecStream = File.OpenWrite(targetNuspec)) // { // manifest.Save(targetNuspecStream); // } //} stream.Seek(0, SeekOrigin.Begin); var nupkgSHA = Convert.ToBase64String(sha512.ComputeHash(stream)); File.WriteAllText(hashPath, nupkgSHA); } return(0); }); }
public void InstallPackagesFromVSExtensionRepositoryThrowsWhenPackageIsMissing() { // Arrange var extensionId = "myExtensionId"; var extensionManagerMock = new Mock <IVsExtensionManager>(); var extensionMock = new Mock <IInstalledExtension>(); extensionMock.Setup(e => e.InstallPath).Returns(@"C:\Extension\Dir"); var extension = extensionMock.Object; extensionManagerMock.Setup(em => em.TryGetInstalledExtension(extensionId, out extension)).Returns(true); var services = new Mock <IVsPackageInstallerServices>(); services.Setup(x => x.IsPackageInstalled(It.IsAny <Project>(), It.IsAny <string>())).Returns(false); 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 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 installer = new VsPackageInstaller(packageManagerFactory.Object, null, null, null, new Mock <IVsCommonOperations>().Object, new Mock <ISolutionManager>().Object, null, services.Object, extensionManagerMock.Object); var packages = new Dictionary <string, string>(); packages.Add("A", "1.0.0"); // Act & Assert var exception = Assert.Throws <InvalidOperationException>(() => installer.InstallPackagesFromVSExtensionRepository(extensionId, isPreUnzipped: false, skipAssemblyReferences: false, project: project, packageVersions: packages)); Assert.True(exception.Message.Contains("A.1.0.0 : ")); }
/// <summary> /// Creates the package manager. /// </summary> /// <param name="fileSystem">The file system.</param> /// <param name="useMachineCache">if set to <c>true</c> [use machine cache].</param> /// <returns></returns> protected virtual PackageManager CreatePackageManager(IFileSystem fileSystem, bool useMachineCache = false) { var pathResolver = new DefaultPackagePathResolver(fileSystem, useSideBySidePaths: AllowMultipleVersions); var packageManager = new PackageManager(_repository, pathResolver, fileSystem, new LocalPackageRepository(pathResolver, fileSystem)); packageManager.Logger = Console; return(packageManager); }
public IEnumerable <IPackage> GetAllPackages(string rootFolder) //rootFolder is repository root { var targetFolder = rootFolder.AppendPath(PackagesFolder); var packagePathResolver = new DefaultPackagePathResolver(targetFolder); var packagesFolderFileSystem = new PhysicalFileSystem(targetFolder); var localRepository = new LocalPackageRepository(packagePathResolver, packagesFolderFileSystem); return(localRepository.GetPackages()); }
public ApplicationPackageManager(ApplicationPackageManagerConfiguration configuration) { IPackageRepository localRepository = PackageRepositoryFactory.Default.CreateRepository(configuration.LocalPackageSource); IPackageRepository sourceRepository = PackageRepositoryFactory.Default.CreateRepository(configuration.SourcePackageSource); IPackagePathResolver pathResolver = new DefaultPackagePathResolver(configuration.LocalPackageSource); mProjectManager = new ProjectManager(sourceRepository, pathResolver, configuration.Project, localRepository); mConfigurationFileName = configuration.ConfigurationFileName; }
public void InstallPackagesFromRegistryRepositoryThrowsWhenPackageIsMissing() { // Arrange var registryPath = @"SOFTWARE\NuGet\Repository"; var registryKey = "PreinstalledPackages"; var registryValue = @"C:\PreinstalledPackages"; var hkcu_repository = new Mock <IRegistryKey>(); var hkcu = new Mock <IRegistryKey>(); hkcu_repository.Setup(k => k.GetValue(registryKey)).Returns(registryValue); hkcu.Setup(r => r.OpenSubKey(registryPath)).Returns(hkcu_repository.Object); var services = new Mock <IVsPackageInstallerServices>(); services.Setup(x => x.IsPackageInstalled(It.IsAny <Project>(), It.IsAny <string>())).Returns(false); 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 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 installer = new VsPackageInstaller(packageManagerFactory.Object, null, null, null, new Mock <IVsCommonOperations>().Object, new Mock <ISolutionManager>().Object, null, services.Object, registryKeys: new[] { hkcu.Object }); var packages = new Dictionary <string, string>(); packages.Add("A", "1.0.0"); // Act & Assert var exception = Assert.Throws <InvalidOperationException>(() => installer.InstallPackagesFromRegistryRepository(registryKey, isPreUnzipped: false, skipAssemblyReferences: false, project: project, packageVersions: packages)); Assert.True(exception.Message.Contains("A.1.0.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 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)); }
protected PackageManagerService() { var repo = PackageRepositoryFactory.Default.CreateRepository(MyGetRepoUrl); var path = new DefaultPackagePathResolver(MyGetRepoUrl); var fileSystem = new PhysicalFileSystem(HostingEnvironment.MapPath("~/App_Plugins/Packages")); var localRepo = PackageRepositoryFactory.Default.CreateRepository(HostingEnvironment.MapPath("~/App_Plugins/Packages")); //Create a NuGet Package Manager PackageManager = new PackageManager(repo, path, fileSystem, localRepo); }
// Methods public WebProjectManager(string remoteSource, string siteRoot) { string webRepositoryDirectory = GetWebRepositoryDirectory(siteRoot); var sourceRepository = PackageRepositoryFactory.Default.CreateRepository(remoteSource); var pathResolver = new DefaultPackagePathResolver(webRepositoryDirectory); var localRepository = PackageRepositoryFactory.Default.CreateRepository(webRepositoryDirectory); IProjectSystem project = new WebProjectSystem(siteRoot); _projectManager = new ProjectManager(sourceRepository, pathResolver, project, localRepository); }
public void SupportsPrereleasePackagesReturnsTrue() { // Arrange var fileSystem = new MockFileSystem("c:\\"); var pathResolver = new DefaultPackagePathResolver("c:\\"); // Act var repository = new UnzippedPackageRepository(pathResolver, fileSystem); // Assert Assert.True(repository.SupportsPrereleasePackages); }
public void Setup() { var mfs = new Mock<MockFileSystem>() { CallBase = true }; var pr = new DefaultPackagePathResolver(mfs.Object); var mc = MachineCache.Default; var l = new LocalPackageRepository(pr, mfs.Object); var r1 = new DataServicePackageRepository(new Uri(@"http://nuget.org")); var r2 = new DataServicePackageRepository(new Uri(@"http://beta.nuget.org")); ar = new AggregateRepository(new List<IPackageRepository>() { mc, l, r1, r2 }); }
public void GetPackageFileNameWithSideBySideOffDoesNotAppendVersionToEndOfPackageDirectory() { // Arrange MockFileSystem fs = new MockFileSystem(); DefaultPackagePathResolver resolver = new DefaultPackagePathResolver(fs, useSideBySidePaths: false); IPackage testPackage = PackageUtility.CreatePackage("Test"); // Act string packageDir = resolver.GetPackageFileName(testPackage); // Assert Assert.Equal("Test" + Constants.PackageExtension, packageDir); }
public void GetInstallPathPrependsFileSystemRootToPackageDirectory() { // Arrange MockFileSystem fs = new MockFileSystem(); DefaultPackagePathResolver resolver = new DefaultPackagePathResolver(fs); IPackage testPackage = PackageUtility.CreatePackage("Test"); // Act string installPath = resolver.GetInstallPath(testPackage); // Assert Assert.Equal(fs.Root + "Test.1.0", installPath); }
public void GetPackageDirectoryWithSideBySideOnAppendsVersionToEndOfPackageDirectory() { // Arrange MockFileSystem fs = new MockFileSystem(); DefaultPackagePathResolver resolver = new DefaultPackagePathResolver(fs); IPackage testPackage = PackageUtility.CreatePackage("Test"); // Act string packageDir = resolver.GetPackageDirectory(testPackage); // Assert Assert.Equal("Test.1.0", packageDir); }
public void FindPackageReturnsPackageWithUnVersionedFileNameWhenUsingVersionlessPathResolver(string id, string version, string packageName) { // Arrange var repositoryRoot = CreatePackage(id, version, packageName); var fileSystem = new PhysicalFileSystem(repositoryRoot); var pathResolver = new DefaultPackagePathResolver(fileSystem, useSideBySidePaths: false); var repository = new LocalPackageRepository(pathResolver, fileSystem); // Act var findPackage = repository.FindPackage(id, new SemanticVersion(version)); // Assert AssertPackage(id, version, findPackage); }
public void InstallPackageUsesProjectTargetFramework() { // Arrange var localRepository = new Mock<MockPackageRepository>() { CallBase = true }.As<ISharedPackageRepository>().Object; var sourceRepository = new MockPackageRepository(); var projectSystem = new MockProjectSystem(new FrameworkName(".NETFramework, Version=4.5")); var pathResolver = new DefaultPackagePathResolver(projectSystem); var projectManager = new ProjectManager(localRepository, pathResolver, projectSystem, new MockPackageRepository()); var packageManager = new VsPackageManager( TestUtils.GetSolutionManager(), sourceRepository, new Mock<IFileSystemProvider>().Object, projectSystem, localRepository, new Mock<IRecentPackageRepository>().Object, new Mock<VsPackageInstallerEvents>().Object); var dependencySets = new PackageDependencySet[] { new PackageDependencySet( new FrameworkName(".NETFramework, Version=4.5"), new [] { new PackageDependency("B") }), new PackageDependencySet( new FrameworkName(".NETFramework, Version=4.0"), new [] { new PackageDependency("C") }) }; var package = PackageUtility.CreatePackageWithDependencySets( "foo", "1.0", new[] { "hello" }, dependencySets: dependencySets); var packageB = PackageUtility.CreatePackage("B", "2.0", new[] { "good morning" }); var packageC = PackageUtility.CreatePackage("C", "2.0", new[] { "good morning" }); sourceRepository.AddPackage(package); sourceRepository.AddPackage(packageB); sourceRepository.AddPackage(packageC); // Act packageManager.InstallPackage(projectManager, "foo", new SemanticVersion("1.0"), ignoreDependencies: false, allowPrereleaseVersions: false, logger: NullLogger.Instance); // Assert Assert.True(packageManager.LocalRepository.Exists(package)); Assert.True(packageManager.LocalRepository.Exists(packageB)); Assert.False(packageManager.LocalRepository.Exists(packageC)); Assert.True(projectManager.LocalRepository.Exists(package)); Assert.True(projectManager.LocalRepository.Exists(packageB)); }
public void ReinstallPackagesSkipsReinstallingIfPackageDoesNotExistAndLogWarning() { // Arrange var localRepository = new Mock<MockPackageRepository>() { CallBase = true }.As<ISharedPackageRepository>().Object; var sourceRepository = new MockPackageRepository(); var projectSystem = new MockProjectSystem(); var pathResolver = new DefaultPackagePathResolver(projectSystem); var projectManager = new ProjectManager(localRepository, pathResolver, projectSystem, new MockPackageRepository()); var installerEvents = new Mock<VsPackageInstallerEvents>(MockBehavior.Strict); int eventCount = 0; RegisterInstallerEvents(installerEvents, _ => eventCount++); var packageManager = new VsPackageManager( TestUtils.GetSolutionManager(), sourceRepository, new Mock<IFileSystemProvider>().Object, projectSystem, localRepository, new Mock<IDeleteOnRestartManager>().Object, installerEvents.Object); var packageA = PackageUtility.CreatePackage("A", "1.2", new[] { "content.txt" }); sourceRepository.Add(packageA); localRepository.AddPackage(packageA); projectManager.LocalRepository.AddPackage(packageA); // remove package from source repository to simulate missing package condition sourceRepository.Remove(packageA); var logger = new Mock<ILogger>(); logger.Setup(s => s.Log( MessageLevel.Warning, "Skipped reinstalling package '{0}' in project '{1}' because the package does not exist in the package source.", "A 1.2", "x:\\MockFileSystem") ).Verifiable(); // Act packageManager.ReinstallPackage(projectManager, "A", updateDependencies: true, allowPrereleaseVersions: true, logger: logger.Object); // Assert logger.Verify(); Assert.Equal(0, eventCount); Assert.True(packageManager.LocalRepository.Exists("A", new SemanticVersion("1.2"))); Assert.True(projectManager.LocalRepository.Exists("A", new SemanticVersion("1.2"))); }
public void UpdatePackageOverwriteAllFilesWhenFileConflictActionSetToOverwrite() { // Arrange var localRepository = new MockPackageRepository(); var sourceRepository = new MockPackageRepository(); var constraintProvider = NullConstraintProvider.Instance; var fileSystem = new MockFileSystem(); var pathResolver = new DefaultPackagePathResolver(fileSystem); var projectSystem = new MockProjectSystem(); projectSystem.AddFile("one.txt", "this is one"); projectSystem.AddFile("two.txt", "this is two"); var packages = new List<IPackage>(); var package_A10 = PackageUtility.CreatePackage("A", "1.0", content: new[] { "1.txt" }); var package_A12 = PackageUtility.CreatePackage("A", "1.2", content: new[] { "one.txt", "two.txt" }); localRepository.Add(package_A10); sourceRepository.Add(package_A12); var sharedRepository = new Mock<ISharedPackageRepository>(MockBehavior.Strict); sharedRepository.Setup(s => s.AddPackage(package_A12)).Callback<IPackage>(p => packages.Add(p)); sharedRepository.Setup(s => s.GetPackages()).Returns(packages.AsQueryable()); var repositoryFactory = new Mock<IPackageRepositoryFactory>(); repositoryFactory.Setup(s => s.CreateRepository(It.IsAny<string>())).Returns(sourceRepository); var packageSourceProvider = new Mock<IPackageSourceProvider>(); packageSourceProvider.Setup(s => s.LoadPackageSources()).Returns(new[] { new PackageSource("foo-source") }); var console = new Mock<IConsole>(); console.Setup(c => c.ResolveFileConflict(It.IsAny<string>())).Returns(FileConflictResolution.Ignore); var updateCommand = new UpdateCommand() { RepositoryFactory = repositoryFactory.Object, SourceProvider = packageSourceProvider.Object, Console = console.Object, FileConflictAction = FileConflictAction.Overwrite }; // Act updateCommand.UpdatePackages(localRepository, fileSystem, sharedRepository.Object, sourceRepository, constraintProvider, pathResolver, projectSystem); // Assert Assert.True(localRepository.Exists("A", new SemanticVersion("1.2"))); Assert.Equal("content\\one.txt", projectSystem.ReadAllText("one.txt")); Assert.Equal("content\\two.txt", projectSystem.ReadAllText("two.txt")); }
public void MarkPackageDirectoryForDeletionDoesNotAddDeletemeFileWhenDirectoryRemovalSuccessful() { // Arrange IPackage package = NuGet.Test.PackageUtility.CreatePackage("foo", "1.0.0"); var fileSystem = new MockFileSystem(); var pathResolver = new DefaultPackagePathResolver(fileSystem); string packageDirectoryPath = pathResolver.GetPackageDirectory(package); var deleteOnRestartManager = new DeleteOnRestartManager(() => fileSystem, () => pathResolver); // Act deleteOnRestartManager.MarkPackageDirectoryForDeletion(package, _ => package); // Assert Assert.False(fileSystem.DirectoryExists(packageDirectoryPath)); Assert.False(fileSystem.FileExists(packageDirectoryPath + _deletionMarkerSuffix)); }
public void InstallPackgeWithNullProjectManagerOnlyInstallsIntoPackageManager() { // Arrange var localRepository = new Mock<MockPackageRepository>() { CallBase = true }.As<ISharedPackageRepository>().Object; var sourceRepository = new MockPackageRepository(); var projectSystem = new MockProjectSystem(); var pathResolver = new DefaultPackagePathResolver(projectSystem); var packageManager = new VsPackageManager(TestUtils.GetSolutionManager(), sourceRepository, projectSystem, localRepository, new Mock<IRecentPackageRepository>().Object, new Mock<VsPackageInstallerEvents>().Object); var package = PackageUtility.CreatePackage("foo", "1.0", new[] { "hello" }); sourceRepository.AddPackage(package); // Act packageManager.InstallPackage((IProjectManager)null, "foo", new SemanticVersion("1.0"), ignoreDependencies: false, allowPrereleaseVersions: false, logger: NullLogger.Instance); // Assert Assert.True(packageManager.LocalRepository.Exists(package)); }
public IPackageInstaller CreatePackageInstaller(string installationPath, string configurationPath) { var packagePath = this.configurationManager.PackagePath; var sourceRepository = this.source.CreatePackageRepository(); var logger = new PackageLogger(); var packagePathResolver = new DefaultPackagePathResolver(packagePath); var fileSystem = new PhysicalFileSystem(installationPath ?? this.directorySystem.CurrentDirectory) { Logger = logger }; var destinationRepository = new LocalPackageRepository(packagePath); var manager = new PackageManager( sourceRepository, packagePathResolver, fileSystem, destinationRepository) { Logger = logger }; var powerShellPackageFile = new PowerShellPackageFile( new BackgroundProcess(), manager, new PhysicalFileSystem(this.directorySystem.TemporaryPath), configurationPath); return new DefaultPackageInstaller(manager, powerShellPackageFile, logger); }
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 UpdatePackageUpdatesPackagesWithCommonDependency() { // Arrange var localRepository = new MockPackageRepository(); var sourceRepository = new MockPackageRepository(); var constraintProvider = NullConstraintProvider.Instance; var fileSystem = new MockFileSystem(); var pathResolver = new DefaultPackagePathResolver(fileSystem); var projectSystem = new MockProjectSystem(); var packages = new List<IPackage>(); var package_A10 = PackageUtility.CreatePackage("A", "1.0", content: new[] { "A.txt" }, dependencies: new[] { new PackageDependency("C", VersionUtility.ParseVersionSpec("1.0")) }); var package_B10 = PackageUtility.CreatePackage("B", "1.0", content: new[] { "B.txt" }, dependencies: new[] { new PackageDependency("C", VersionUtility.ParseVersionSpec("1.0")) }); var package_A12 = PackageUtility.CreatePackage("A", "1.2", content: new[] { "A.txt" }, dependencies: new[] { new PackageDependency("C", VersionUtility.ParseVersionSpec("1.0")) }); var package_B20 = PackageUtility.CreatePackage("B", "2.0", content: new[] { "B.txt" }); var package_C10 = PackageUtility.CreatePackage("C", "1.0", content: new[] { "C.txt" }); localRepository.AddRange(new[] { package_A10, package_B10, package_C10}); sourceRepository.AddRange(new[] { package_A12, package_B20 }); var sharedRepository = new Mock<ISharedPackageRepository>(MockBehavior.Strict); sharedRepository.Setup(s => s.AddPackage(package_A12)).Callback<IPackage>(p => packages.Add(p)).Verifiable(); sharedRepository.Setup(s => s.AddPackage(package_B20)).Callback<IPackage>(p => packages.Add(p)).Verifiable(); sharedRepository.Setup(s => s.GetPackages()).Returns(packages.AsQueryable()); var repositoryFactory = new Mock<IPackageRepositoryFactory>(); repositoryFactory.Setup(s => s.CreateRepository(It.IsAny<string>())).Returns(sourceRepository); var packageSourceProvider = new Mock<IPackageSourceProvider>(); packageSourceProvider.Setup(s => s.LoadPackageSources()).Returns(new[] { new PackageSource("foo-source") }); var updateCommand = new UpdateCommand() { RepositoryFactory = repositoryFactory.Object, SourceProvider = packageSourceProvider.Object }; // Act updateCommand.UpdatePackages(localRepository, fileSystem, sharedRepository.Object, sourceRepository, constraintProvider, pathResolver, projectSystem); // Assert sharedRepository.Verify(); }
public void MarkPackageDirectoryForDeletionAddsDeletemeFileWhenDirectoryRemovalUnsuccessful() { // Arrange IPackage package = NuGet.Test.PackageUtility.CreatePackage(id: "foo", version: "1.0.0", content: new string[] { }, assemblyReferences: new string[] { }, tools: new[] { "lockedFile.txt" }); var fileSystem = new MockFileSystem(); var pathResolver = new DefaultPackagePathResolver(fileSystem); string packageDirectoryPath = pathResolver.GetPackageDirectory(package); string lockedFilePath = Path.Combine("tools", "lockedFile.txt"); fileSystem.AddFile(Path.Combine(packageDirectoryPath, pathResolver.GetPackageFileName(package)), Stream.Null); fileSystem.AddFile(Path.Combine(packageDirectoryPath, packageDirectoryPath + Constants.ManifestExtension), Stream.Null); fileSystem.AddFile(Path.Combine(packageDirectoryPath, lockedFilePath), lockedFilePath.AsStream()); var deleteOnRestartManager = new DeleteOnRestartManager(() => fileSystem, () => pathResolver); // Act deleteOnRestartManager.MarkPackageDirectoryForDeletion(package); // Assert Assert.True(fileSystem.DirectoryExists(packageDirectoryPath)); Assert.True(fileSystem.FileExists(packageDirectoryPath + _deletionMarkerSuffix)); }
public void MarkPackageDirectoryForDeletionDoesNotAddDeletemeFileWhenFileModified() { // Arrange IPackage package = NuGet.Test.PackageUtility.CreatePackage(id: "foo", version: "1.0.0", content: new string[] {}, assemblyReferences: new string[] {}, tools: new[] { "modifiedFile.txt" }); var fileSystem = new MockFileSystem(); var pathResolver = new DefaultPackagePathResolver(fileSystem); string packageDirectoryPath = pathResolver.GetPackageDirectory(package); string modifiedFilePath = Path.Combine("tools", "modifiedFile.txt"); fileSystem.AddFile(Path.Combine(packageDirectoryPath, pathResolver.GetPackageFileName(package)), Stream.Null); fileSystem.AddFile(Path.Combine(packageDirectoryPath, modifiedFilePath), "Modified Content".AsStream()); var deleteOnRestartManager = new DeleteOnRestartManager(() => fileSystem, () => pathResolver); // Act deleteOnRestartManager.MarkPackageDirectoryForDeletion(package, _ => package); // Assert Assert.True(fileSystem.DirectoryExists(packageDirectoryPath)); Assert.True(fileSystem.FileExists(Path.Combine(packageDirectoryPath, modifiedFilePath))); Assert.False(fileSystem.FileExists(packageDirectoryPath + _deletionMarkerSuffix)); }
public void UpdatePackageAddsPackagesToSharedPackageRepositoryWhenReferencesAreAdded() { // Arrange var localRepository = new MockPackageRepository(); var sourceRepository = new MockPackageRepository(); var constraintProvider = NullConstraintProvider.Instance; var fileSystem = new MockFileSystem(); var pathResolver = new DefaultPackagePathResolver(fileSystem); var projectSystem = new MockProjectSystem(); var packages = new List<IPackage>(); var package_A10 = PackageUtility.CreatePackage("A", "1.0", content: new[] { "1.txt" }); var package_A12 = PackageUtility.CreatePackage("A", "1.2", content: new[] { "1.txt" }); localRepository.Add(package_A10); sourceRepository.Add(package_A12); var sharedRepository = new Mock<ISharedPackageRepository>(MockBehavior.Strict); sharedRepository.SetupSet(s => s.PackageSaveMode = PackageSaveModes.Nupkg); sharedRepository.Setup(s => s.AddPackage(package_A12)).Callback<IPackage>(p => packages.Add(p)).Verifiable(); sharedRepository.Setup(s => s.GetPackages()).Returns(packages.AsQueryable()); var repositoryFactory = new Mock<IPackageRepositoryFactory>(); repositoryFactory.Setup(s => s.CreateRepository(It.IsAny<string>())).Returns(sourceRepository); var packageSourceProvider = new Mock<IPackageSourceProvider>(); packageSourceProvider.Setup(s => s.LoadPackageSources()).Returns(new[] { new PackageSource("foo-source") }); var updateCommand = new UpdateCommand() { RepositoryFactory = repositoryFactory.Object, SourceProvider = packageSourceProvider.Object }; // Act updateCommand.UpdatePackages(localRepository, fileSystem, sharedRepository.Object, sourceRepository, constraintProvider, pathResolver, projectSystem); // Assert sharedRepository.Verify(); }
public bool CanDetermineVersionlessPackageIsInstalled(string id, string onDiskVersion, string packageVersion, bool installedUsingMultipleVersion, bool currentlyAllowMultipleVersions, bool exhaustive) { var mfs = new Mock<MockFileSystem>() { CallBase = true }; mfs.Setup(m => m.Root).Returns(@"c:\packages"); var installPathResolver = new DefaultPackagePathResolver(mfs.Object, installedUsingMultipleVersion); var currentPathResolver = new DefaultPackagePathResolver(mfs.Object, currentlyAllowMultipleVersions); var testPackage = new DataServicePackage() { Version = packageVersion, Id = id }; var filePackage = new DataServicePackage() { Version = onDiskVersion, Id = id }; IPackage zipPackage = null; if (!string.IsNullOrEmpty(onDiskVersion)) { string baseLocation = installPathResolver.GetInstallPath(filePackage); string fileName = installPathResolver.GetPackageFileName(filePackage.Id, SemanticVersion.Parse(filePackage.Version)); string filePath = Path.Combine(baseLocation, fileName); zipPackage = PackageUtility.GetZipPackage(filePackage.Id, filePackage.Version); mfs.Setup(m => m.FileExists(filePath)).Returns(true); mfs.Setup(m => m.OpenFile(filePath)).Returns(zipPackage.GetStream()); mfs.Object.AddFile(filePath, zipPackage.GetStream()); } var pm = new PackageManager(new MockPackageRepository(), currentPathResolver, mfs.Object); var exists = pm.IsPackageInstalled(testPackage,exhaustive: exhaustive); //var test = testPackage.IsPackageInstalled(allowMultipleVersions, pm, mfs.Object); return exists; }
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()); }