CreatePackage() public static method

public static CreatePackage ( string id, string version, IEnumerable content, IEnumerable assemblyReferences, IEnumerable tools, IEnumerable dependencies, int downloadCount, string description, string summary, bool listed, string tags ) : IPackage
id string
version string
content IEnumerable
assemblyReferences IEnumerable
tools IEnumerable
dependencies IEnumerable
downloadCount int
description string
summary string
listed bool
tags string
return IPackage
        public void FindPackagesOverloadReturnsEmptySequenceIfTermIsNotFoundInProperties()
        {
            // Arrange
            var packages = new[] {
                PackageUtility.CreatePackage("Foo.Qux"),
                PackageUtility.CreatePackage("X-Package", tags: " lib qux "),
                PackageUtility.CreatePackage("Filtered"),
                PackageUtility.CreatePackage("B", description: "This is a package for qux and not one for baz"),
            };

            // Act
            var result1 = packages.AsQueryable().Find(new[] { "Summary" }, "Qux");

            // Assert
            Assert.Empty(result1);
        }
        public void AddPackageAddSolutionLevelPackageDependingOnProjectLevelPackage()
        {
            // Arrange
            var fileSystem       = new MockFileSystem();
            var configFileSystem = new MockFileSystem();
            var repository       = new SharedPackageRepository(new DefaultPackagePathResolver(fileSystem), fileSystem, configFileSystem);
            var solutionPackage  = PackageUtility.CreatePackage("SolutionLevel2", tools: new[] { "Install.ps1" }, dependencies: new[] { new PackageDependency("ProjectLevel1") });

            // Act
            repository.AddPackage(solutionPackage);

            // Assert
            var packageReferences = repository.PackageReferenceFile.GetPackageReferences().ToArray();

            Assert.True(packageReferences.IsEmpty());
        }
        public void CallAddPackageToAddBothNuspecFileAndNupkgFile(string id, string version, string nuspecPath, string nupkgPath)
        {
            // Arrange
            var fileSystem       = new MockFileSystem("x:\\root");
            var configFileSystem = new MockFileSystem();
            var repository       = new SharedPackageRepository(new DefaultPackagePathResolver(fileSystem), fileSystem, configFileSystem);

            repository.PackageSaveMode = PackageSaveModes.Nupkg | PackageSaveModes.Nuspec;

            // Act
            repository.AddPackage(PackageUtility.CreatePackage(id, version));

            // Assert
            Assert.True(fileSystem.FileExists(nuspecPath));
            Assert.True(fileSystem.FileExists(nupkgPath));
        }
        public void FindPackageNormalizesVersionBeforeComparing()
        {
            // Arrange
            var repository = new MockPackageRepository()
            {
                PackageUtility.CreatePackage("B", "1.0.0"),
                PackageUtility.CreatePackage("B", "1.0.0.1")
            };

            // Act
            IPackage package = repository.FindPackage("B", new SemanticVersion("1.0"));

            // Assert
            Assert.Equal("B", package.Id);
            Assert.Equal(new SemanticVersion("1.0.0"), package.Version);
        }
        public void UpdatePackageThrowsIfPackageNotInstalled()
        {
            // Arrange
            var            localRepository  = new MockPackageRepository();
            var            sourceRepository = new MockPackageRepository();
            var            projectSystem    = new MockProjectSystem();
            PackageManager packageManager   = new PackageManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, localRepository);

            IPackage A20 = PackageUtility.CreatePackage("A", "2.0");

            sourceRepository.Add(A20);

            // Act
            ExceptionAssert.Throws <InvalidOperationException>(() => packageManager.UpdatePackage("A", updateDependencies: true, allowPrereleaseVersions: false),
                                                               "Unable to find package 'A'.");
        }
Esempio n. 6
0
        public void AddPackageDoesNotThrowIfUnderlyingFileSystemThrowsOnAdd()
        {
            // Arrange
            var mockFileSystem = new Mock <IFileSystem>();

            mockFileSystem.Setup(f => f.AddFile(It.IsAny <string>(), It.IsAny <Stream>()))
            .Throws(new UnauthorizedAccessException("Can't touch me."))
            .Verifiable();
            var cache = new MachineCache(mockFileSystem.Object);

            // Act
            cache.AddPackage(PackageUtility.CreatePackage("B"));

            // Assert
            mockFileSystem.Verify();
        }
        public void SearchUsesInterfaceIfImplementedByRepository()
        {
            // Arrange
            var repo = new Mock <MockPackageRepository>(MockBehavior.Strict);

            repo.Setup(m => m.GetPackages()).Returns(Enumerable.Empty <IPackage>().AsQueryable());
            repo.As <IServiceBasedRepository>().Setup(m => m.Search(It.IsAny <string>(), It.IsAny <IEnumerable <string> >(), false, false))
            .Returns(new[] { PackageUtility.CreatePackage("A") }.AsQueryable());

            // Act
            var packages = repo.Object.Search("Hello", new[] { ".NETFramework" }, allowPrereleaseVersions: false).ToList();

            // Assert
            Assert.Equal(1, packages.Count);
            Assert.Equal("A", packages[0].Id);
        }
        public void FindDependencyPicksLowestMajorAndMinorVersionButHighestBuildAndRevision()
        {
            // Arrange
            var repository = new MockPackageRepository()
            {
                PackageUtility.CreatePackage("B", "2.0"),
                PackageUtility.CreatePackage("B", "1.0"),
                PackageUtility.CreatePackage("B", "1.0.1"),
                PackageUtility.CreatePackage("B", "1.0.9"),
                PackageUtility.CreatePackage("B", "1.1")
            };

            // B >= 1.0
            PackageDependency dependency1 = PackageDependency.CreateDependency("B", "1.0");

            // B >= 1.0.0
            PackageDependency dependency2 = PackageDependency.CreateDependency("B", "1.0.0");

            // B >= 1.0.0.0
            PackageDependency dependency3 = PackageDependency.CreateDependency("B", "1.0.0.0");

            // B = 1.0
            PackageDependency dependency4 = PackageDependency.CreateDependency("B", "[1.0]");

            // B >= 1.0.0 && <= 1.0.8
            PackageDependency dependency5 = PackageDependency.CreateDependency("B", "[1.0.0, 1.0.8]");

            // Act
            IPackage package1 = repository.ResolveDependency(dependency1, constraintProvider: null, allowPrereleaseVersions: false, preferListedPackages: false, dependencyVersion: DependencyVersion.HighestPatch);
            IPackage package2 = repository.ResolveDependency(dependency2, constraintProvider: null, allowPrereleaseVersions: false, preferListedPackages: false, dependencyVersion: DependencyVersion.HighestPatch);
            IPackage package3 = repository.ResolveDependency(dependency3, constraintProvider: null, allowPrereleaseVersions: false, preferListedPackages: false, dependencyVersion: DependencyVersion.HighestPatch);
            IPackage package4 = repository.ResolveDependency(dependency4, constraintProvider: null, allowPrereleaseVersions: false, preferListedPackages: false, dependencyVersion: DependencyVersion.HighestPatch);
            IPackage package5 = repository.ResolveDependency(dependency5, constraintProvider: null, allowPrereleaseVersions: false, preferListedPackages: false, dependencyVersion: DependencyVersion.HighestPatch);

            // Assert
            Assert.Equal("B", package1.Id);
            Assert.Equal(new SemanticVersion("1.0.9"), package1.Version);
            Assert.Equal("B", package2.Id);
            Assert.Equal(new SemanticVersion("1.0.9"), package2.Version);
            Assert.Equal("B", package3.Id);
            Assert.Equal(new SemanticVersion("1.0.9"), package3.Version);
            Assert.Equal("B", package4.Id);
            Assert.Equal(new SemanticVersion("1.0"), package4.Version);
            Assert.Equal("B", package5.Id);
            Assert.Equal(new SemanticVersion("1.0.1"), package5.Version);
        }
        public void ExistsReturnsTrueIfAnyRepositoryContainsPackage()
        {
            // Arrange
            var package = PackageUtility.CreatePackage("Abc");
            var repo1   = new MockPackageRepository();
            var repo2   = new MockPackageRepository();

            repo2.Add(package);

            var aggregateRepository = new AggregateRepository(new[] { repo1, repo2 });

            // Act
            var exists = aggregateRepository.Exists("Abc", new SemanticVersion("1.0"));

            // Assert
            Assert.True(exists);
        }
Esempio n. 10
0
        public void UninstallingPackageWithNoDependents()
        {
            // Arrange
            var localRepository  = new MockPackageRepository();
            var sourceRepository = new MockPackageRepository();
            var projectSystem    = new MockProjectSystem();
            var packageManager   = new PackageManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, localRepository);
            var package          = PackageUtility.CreatePackage("foo", "1.2.33");

            localRepository.AddPackage(package);

            // Act
            packageManager.UninstallPackage("foo");

            // Assert
            Assert.IsFalse(packageManager.LocalRepository.Exists(package));
        }
Esempio n. 11
0
        public void AddingMoreThanPackageLimitClearsCache()
        {
            // Arrange
            var          mockFileSystem = new MockFileSystem();
            MachineCache cache          = new MachineCache(mockFileSystem);

            for (int i = 0; i < 100; i++)
            {
                cache.AddPackage(PackageUtility.CreatePackage("A", i + ".0"));
            }

            // Act
            cache.AddPackage(PackageUtility.CreatePackage("B"));

            // Assert
            Assert.AreEqual(1, cache.GetPackageFiles().Count());
        }
Esempio n. 12
0
        public void IsSatellitePackageReturnsTrueWhenRuntimePackageIdentified()
        {
            // Arrange
            var repository = new MockPackageRepository();
            var runtime    = PackageUtility.CreatePackage("foo");
            var package    = PackageUtility.CreatePackage("foo.fr-fr", language: "fr-fr", dependencies: new[] { new PackageDependency("foo", VersionUtility.ParseVersionSpec("[1.0]")) });

            repository.AddPackage(runtime);

            // Act
            IPackage runtimePackage;
            var      isSatellite = NuGet.PackageUtility.IsSatellitePackage(package, repository, null, out runtimePackage);

            // Assert
            Assert.True(isSatellite);
            Assert.NotNull(runtimePackage);
        }
        public void CallRemovePackageWillRemoveBothNupkgFileAndNuSpecFile(string id, string version, string nuspecPath, string nupkgPath)
        {
            // Arrange
            var fileSystem = new MockFileSystem("x:\root");

            fileSystem.AddFile(nuspecPath);
            fileSystem.AddFile(nupkgPath);
            var configFileSystem = new MockFileSystem();
            var repository       = new SharedPackageRepository(new DefaultPackagePathResolver(fileSystem), fileSystem, configFileSystem);

            // Act
            repository.RemovePackage(PackageUtility.CreatePackage(id, version));

            // Assert
            Assert.False(fileSystem.FileExists(nuspecPath));
            Assert.False(fileSystem.FileExists(nupkgPath));
        }
Esempio n. 14
0
        public void ClearRemovesAllPackageFilesFromCache()
        {
            // Arrange
            var          mockFileSystem = new MockFileSystem();
            MachineCache cache          = new MachineCache(mockFileSystem);

            for (int i = 0; i < 20; i++)
            {
                cache.AddPackage(PackageUtility.CreatePackage("A", i + ".0"));
            }

            // Act
            cache.Clear();

            // Assert
            Assert.False(cache.GetPackageFiles().Any());
        }
Esempio n. 15
0
        public void FindDependencyPicksLowestMajorAndMinorVersionButHighestBuildAndRevision()
        {
            // Arrange
            var repository = new MockPackageRepository()
            {
                PackageUtility.CreatePackage("B", "2.0"),
                PackageUtility.CreatePackage("B", "1.0"),
                PackageUtility.CreatePackage("B", "1.0.1"),
                PackageUtility.CreatePackage("B", "1.0.9"),
                PackageUtility.CreatePackage("B", "1.1")
            };

            // B >= 1.0
            PackageDependency dependency1 = PackageDependency.CreateDependency("B", "1.0");

            // B >= 1.0.0
            PackageDependency dependency2 = PackageDependency.CreateDependency("B", "1.0.0");

            // B >= 1.0.0.0
            PackageDependency dependency3 = PackageDependency.CreateDependency("B", "1.0.0.0");

            // B = 1.0
            PackageDependency dependency4 = PackageDependency.CreateDependency("B", "[1.0]");

            // B >= 1.0.0 && <= 1.0.8
            PackageDependency dependency5 = PackageDependency.CreateDependency("B", "[1.0.0, 1.0.8]");

            // Act
            IPackage package1 = repository.FindDependency(dependency1);
            IPackage package2 = repository.FindDependency(dependency2);
            IPackage package3 = repository.FindDependency(dependency3);
            IPackage package4 = repository.FindDependency(dependency4);
            IPackage package5 = repository.FindDependency(dependency5);

            // Assert
            Assert.AreEqual("B", package1.Id);
            Assert.AreEqual(new Version("1.0.9"), package1.Version);
            Assert.AreEqual("B", package2.Id);
            Assert.AreEqual(new Version("1.0.9"), package2.Version);
            Assert.AreEqual("B", package3.Id);
            Assert.AreEqual(new Version("1.0.9"), package3.Version);
            Assert.AreEqual("B", package4.Id);
            Assert.AreEqual(new Version("1.0"), package4.Version);
            Assert.AreEqual("B", package5.Id);
            Assert.AreEqual(new Version("1.0.1"), package5.Version);
        }
Esempio n. 16
0
        public void ResolveDependenciesForInstallPackageWithUnknownDependencyThrows()
        {
            // Arrange
            IPackage package = PackageUtility.CreatePackage("A",
                                                            "1.0",
                                                            dependencies: new List <PackageDependency> {
                new PackageDependency("B")
            });

            IPackageOperationResolver resolver = new InstallWalker(new MockPackageRepository(),
                                                                   new MockPackageRepository(),
                                                                   NullLogger.Instance,
                                                                   ignoreDependencies: false);

            // Act & Assert
            ExceptionAssert.Throws <InvalidOperationException>(() => resolver.ResolveOperations(package), "Unable to resolve dependency 'B'.");
        }
Esempio n. 17
0
        public void UninstallingSatellitePackageRemovesCollidingRuntimeFiles()
        {
            // Arrange
            // Create a runtime package and a satellite package that has a dependency on the runtime package, and uses the
            // local suffix convention.
            var runtimePackage = PackageUtility.CreatePackage(
                "foo", "1.0.0",
                content: Enumerable.Empty <string>(),
                assemblyReferences: new[] { @"lib\ja-jp\collision.txt" });

            var satellitePackage = PackageUtility.CreatePackage(
                "foo.ja-jp", "1.0.0", language: "ja-jp",
                content: Enumerable.Empty <string>(),
                satelliteAssemblies: new[] { @"lib\ja-jp\collision.txt" },
                dependencies: new[] { new PackageDependency("foo", VersionUtility.ParseVersionSpec("[1.0.0]")) });

            var packagesFolder   = new MockFileSystem(@"c:\packagesFolder");
            var sharedRepository = new MockSharedPackageRepository2();
            var sourceRepository = new MockPackageRepository();
            var packageManager   = new PackageManager(sourceRepository, new DefaultPackagePathResolver(packagesFolder), packagesFolder, sharedRepository);

            sourceRepository.AddPackage(runtimePackage);
            sourceRepository.AddPackage(satellitePackage);

            var projectSystem    = new MockProjectSystem();
            var projectLocalRepo = new PackageReferenceRepository(
                new MockFileSystem(@"c:\project"),
                "projectName",
                sharedRepository);
            var projectManager = new ProjectManager(
                packageManager,
                packageManager.PathResolver,
                projectSystem,
                projectLocalRepo);

            // Act
            Install("foo", projectManager);
            Install("foo.ja-jp", projectManager);

            Uninstall("foo.ja-jp", packageManager, projectManager);

            // Assert
            Assert.Equal(0, packagesFolder.Paths.Count);
            Assert.False(packagesFolder.FileExists(@"foo.1.0.0\lib\ja-jp\collision.txt"));
        }
Esempio n. 18
0
        public void RemovePackage_Succeeds_IfPackageDoesNotExist()
        {
            // Arrange
            var fileSystem = new MockFileSystem();

            fileSystem.AddFile(Path.Combine("Foo", "1.0.0", "Foo.nuspec"), "Nuspec contents");
            fileSystem.AddFile(Path.Combine("Foo", "1.0.0", "tools", "net45", "Foo.targets"), "Foo.targets contents");
            fileSystem.AddFile(Path.Combine("Foo", "1.0.0-beta4", "Foo.nupkg"), "1.0.0-beta4 Nuspec contents");

            var repository = new ExpandedPackageRepository(fileSystem);
            var package    = PackageUtility.CreatePackage("Foo", "1.0.0-beta4");

            // Act
            repository.RemovePackage(package);

            // Assert
            Assert.Empty(fileSystem.Deleted);
        }
        public void FindPackagesOverloadLooksForSearchTermsInSpecificFields()
        {
            // Arrange
            var packages = new[] {
                PackageUtility.CreatePackage("Foo.Qux", description: "Some desc"),
                PackageUtility.CreatePackage("X-Package", tags: " lib qux "),
                PackageUtility.CreatePackage("Filtered"),
                PackageUtility.CreatePackage("B", description: "This is a package for qux and not one for baz"),
            };

            // Act
            var result1 = packages.AsQueryable().Find(new[] { "Description", "Tags" }, "Qux");
            var result2 = packages.AsQueryable().Find(new[] { "Id" }, "Filtered");

            // Assert
            Assert.Equal(new[] { packages[1], packages[3] }, result1.ToArray());
            Assert.Equal(new[] { packages[2], }, result2.ToArray());
        }
Esempio n. 20
0
        public void CallAddPackageWillNotCreatePackageConfigEntryToPackageConfig()
        {
            // Arrange
            var fileSystem = new Mock <MockFileSystem>()
            {
                CallBase = true
            };

            fileSystem.Setup(m => m.Root).Returns(@"c:\foo\");
            var configFileSystem = new MockFileSystem();
            var repository       = new SharedPackageRepository(new DefaultPackagePathResolver(fileSystem.Object), fileSystem.Object, configFileSystem);

            // Act
            repository.AddPackage(PackageUtility.CreatePackage("A", "2.0"));

            // Assert
            Assert.False(configFileSystem.FileExists("packages.config"));
        }
Esempio n. 21
0
        public void UpdatePackageDoesNothingIfNoUpdatesAvailable()
        {
            // Arrange
            var            localRepository  = new MockPackageRepository();
            var            sourceRepository = new MockPackageRepository();
            var            projectSystem    = new MockProjectSystem();
            PackageManager packageManager   = new PackageManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, localRepository);

            IPackage A10 = PackageUtility.CreatePackage("A", "1.0");

            localRepository.Add(A10);

            // Act
            packageManager.UpdatePackage("A", updateDependencies: true);

            // Assert
            Assert.IsTrue(localRepository.Exists("A", new Version("1.0")));
        }
        public void GetPackagesReturnsOnlyValidPackagesFromSourceRepositoryListedInPackagesConfig()
        {
            // Arrange
            var repository = new Mock <MockPackageRepository>()
            {
                CallBase = true
            }.As <ISharedPackageRepository>();
            var packageA = PackageUtility.CreatePackage("A");

            repository.Object.AddPackage(packageA);
            var packageC = PackageUtility.CreatePackage("C", "2.0");

            repository.Object.AddPackage(packageC);
            var fileSystem = new MockFileSystem();

            fileSystem.AddFile("packages.config", @"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
  <package id=""C"" version=""2.0"" />
  <package id=""B"" version=""1.0"" />
  <package id=""A"" version=""1.0"" />
  <package id="""" version=""1.0"" />
  <package id=""G"" version="""" />
  <package />
</packages>");
            var referenceRepository = new PackageReferenceRepository(fileSystem, repository.Object);


            // Act
            var packages = referenceRepository.GetPackages().ToList();

            // Assert
            Assert.Equal(2, packages.Count);
            Assert.Same(packageC, packages[0]);
            Assert.Same(packageA, packages[1]);
            Assert.Equal(@"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
  <package id=""C"" version=""2.0"" />
  <package id=""B"" version=""1.0"" />
  <package id=""A"" version=""1.0"" />
  <package id="""" version=""1.0"" />
  <package id=""G"" version="""" />
  <package />
</packages>", fileSystem.ReadAllText("packages.config"));
        }
        public void EnsurePackageStorePackageInMemoryIfMachineCacheIsNotAvailable()
        {
            // Arrange
            var zipPackage = PackageUtility.CreatePackage("A", "1.2");

            var uri            = new Uri("http://nuget.org");
            var mockRepository = new Mock <MockPackageRepository>().As <IPackageCacheRepository>();

            mockRepository.Setup(s => s.CreatePackageStream(It.IsAny <string>(), It.IsAny <SemanticVersion>())).Returns((Stream)null);

            var packageDownloader = new Mock <PackageDownloader>();

            packageDownloader.Setup(d => d.DownloadPackage(uri, It.IsAny <IPackageMetadata>(), It.IsAny <Stream>()))
            .Callback(new Action <Uri, IPackageMetadata, Stream>(
                          (url, metadata, stream) => PackageUtility.CreateSimplePackageStream("A", "1.2").CopyTo(stream)))
            .Verifiable();
            var hashProvider = new Mock <IHashProvider>(MockBehavior.Strict);

            var context = new Mock <IDataServiceContext>();

            context.Setup(c => c.GetReadStreamUri(It.IsAny <object>())).Returns(uri).Verifiable();

            var servicePackage = new DataServicePackage
            {
                Id           = "A",
                Version      = "1.2",
                PackageHash  = "NEWHASH",
                Downloader   = packageDownloader.Object,
                HashProvider = hashProvider.Object,
                Context      = context.Object
            };

            // Act
            servicePackage.EnsurePackage(mockRepository.Object);

            // Assert
            context.Verify();
            packageDownloader.Verify();

            var foundPackage = servicePackage._package;

            Assert.NotNull(foundPackage);
            Assert.True(foundPackage is ZipPackage);
        }
Esempio n. 24
0
        public void RemovePackageRemovesPackageFileAndDirectoryAndRoot()
        {
            // Arrange
            var mockFileSystem = new MockProjectSystem();

            mockFileSystem.AddFile(PathFixUtility.FixPath(@"A.1.0\A.1.0.nupkg"));
            var repository = new LocalPackageRepository(new DefaultPackagePathResolver(mockFileSystem),
                                                        mockFileSystem);
            IPackage package = PackageUtility.CreatePackage("A", "1.0");

            // Act
            repository.RemovePackage(package);

            // Assert
            Assert.Equal(3, mockFileSystem.Deleted.Count);
            Assert.True(mockFileSystem.Deleted.Contains(""));
            Assert.True(mockFileSystem.Deleted.Contains("A.1.0"));
            Assert.True(mockFileSystem.Deleted.Contains(PathFixUtility.FixPath(@"A.1.0\A.1.0.nupkg")));
        }
Esempio n. 25
0
        public void RemovePackageDoesNotRemovesRootIfNotEmpty()
        {
            // Arrange
            var mockFileSystem = new MockProjectSystem();

            mockFileSystem.AddFile(@"A.1.0\A.1.0.nupkg");
            mockFileSystem.AddFile(@"B.1.0\B.1.0.nupkg");
            var repository = new LocalPackageRepository(new DefaultPackagePathResolver(mockFileSystem),
                                                        mockFileSystem);
            IPackage package = PackageUtility.CreatePackage("A", "1.0");

            // Act
            repository.RemovePackage(package);

            // Assert
            Assert.Equal(2, mockFileSystem.Deleted.Count);
            Assert.True(mockFileSystem.Deleted.Contains("A.1.0"));
            Assert.True(mockFileSystem.Deleted.Contains(@"A.1.0\A.1.0.nupkg"));
        }
        public void GetPackagesNoPackagesConfigReturnsEmptyList()
        {
            // Arrange
            var repository = new Mock <MockPackageRepository>()
            {
                CallBase = true
            }.As <ISharedPackageRepository>();
            var packageA = PackageUtility.CreatePackage("A");

            repository.Object.AddPackage(packageA);
            var fileSystem          = new MockFileSystem();
            var referenceRepository = new PackageReferenceRepository(fileSystem, projectName: null, sourceRepository: repository.Object);

            // Act
            var packages = referenceRepository.GetPackages().ToList();

            // Assert
            Assert.Equal(0, packages.Count);
        }
Esempio n. 27
0
        public void SelfUpdateNoNuGetExeInNuGetExePackageThrows()
        {
            // Arrange
            var factory    = new Mock <IPackageRepositoryFactory>();
            var repository = new MockPackageRepository();

            repository.Add(PackageUtility.CreatePackage("NuGet.CommandLine", "3.0"));
            factory.Setup(m => m.CreateRepository(It.IsAny <string>())).Returns(repository);

            ConsoleInfo consoleInfo = GetConsoleInfo();
            var         selfUpdater = new SelfUpdater(factory.Object)
            {
                Console = consoleInfo.Console
            };

            // Act & Assert
            ExceptionAssert.Throws <CommandLineException>(() => selfUpdater.SelfUpdate("c:\foo.exe", new SemanticVersion("2.0")),
                                                          "Invalid NuGet.CommandLine package. Unable to locate NuGet.exe within the package.");
        }
Esempio n. 28
0
        public void RemovingAllSolutionLevelPackageDeletesConfigFile()
        {
            // Arrange
            var fileSystem       = new MockFileSystem();
            var configFileSystem = new MockFileSystem();
            var repository       = new SharedPackageRepository(new DefaultPackagePathResolver(fileSystem), fileSystem, configFileSystem);
            var solutionPackage  = PackageUtility.CreatePackage("SolutionLevel", tools: new[] { "Install.ps1" });

            configFileSystem.AddFile("packages.config", @"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
  <package id=""SolutionLevel"" version=""1.0"" />
</packages>");

            // Act
            repository.RemovePackage(solutionPackage);

            // Assert
            Assert.True(configFileSystem.Deleted.Contains("packages.config"));
        }
Esempio n. 29
0
        public void InstallWalkerResolvesLowestMajorAndMinorVersionButHighestBuildAndRevisionForDependencies()
        {
            // Arrange

            // A 1.0 -> B 1.0
            // B 1.0 -> C 1.1
            // C 1.1 -> D 1.0

            var A10 = PackageUtility.CreatePackage("A", "1.0", dependencies: new[] { PackageDependency.CreateDependency("B", "1.0") });

            var repository = new MockPackageRepository()
            {
                PackageUtility.CreatePackage("B", "2.0", dependencies: new[] { PackageDependency.CreateDependency("C", "1.1") }),
                PackageUtility.CreatePackage("B", "1.0", dependencies: new[] { PackageDependency.CreateDependency("C", "1.1") }),
                PackageUtility.CreatePackage("B", "1.0.1"),
                A10,
                PackageUtility.CreatePackage("D", "2.0"),
                PackageUtility.CreatePackage("C", "1.1.3", dependencies: new[] { PackageDependency.CreateDependency("D", "1.0") }),
                PackageUtility.CreatePackage("C", "1.1.1", dependencies: new[] { PackageDependency.CreateDependency("D", "1.0") }),
                PackageUtility.CreatePackage("C", "1.5.1", dependencies: new[] { PackageDependency.CreateDependency("D", "1.0") }),
                PackageUtility.CreatePackage("B", "1.0.9", dependencies: new[] { PackageDependency.CreateDependency("C", "1.1") }),
                PackageUtility.CreatePackage("B", "1.1", dependencies: new[] { PackageDependency.CreateDependency("C", "1.1") })
            };


            IPackageOperationResolver resolver = new InstallWalker(new MockPackageRepository(),
                                                                   repository,
                                                                   NullLogger.Instance,
                                                                   ignoreDependencies: false);
            // Act
            var packages = resolver.ResolveOperations(A10).ToList();

            // Assert
            Assert.AreEqual(4, packages.Count);
            Assert.AreEqual("D", packages[0].Package.Id);
            Assert.AreEqual(new Version("2.0"), packages[0].Package.Version);
            Assert.AreEqual("C", packages[1].Package.Id);
            Assert.AreEqual(new Version("1.1.3"), packages[1].Package.Version);
            Assert.AreEqual("B", packages[2].Package.Id);
            Assert.AreEqual(new Version("1.0.9"), packages[2].Package.Version);
            Assert.AreEqual("A", packages[3].Package.Id);
            Assert.AreEqual(new Version("1.0"), packages[3].Package.Version);
        }
Esempio n. 30
0
        public void AddPackageAddSolutionLevelPackageDependingOnAnotherSolutionLevelPackage()
        {
            // Arrange
            var fileSystem       = new MockFileSystem();
            var configFileSystem = new MockFileSystem();
            var repository       = new SharedPackageRepository(new DefaultPackagePathResolver(fileSystem), fileSystem, configFileSystem);
            var solutionPackage1 = PackageUtility.CreatePackage("SolutionLevel1", tools: new[] { "Install.ps1" });
            var solutionPackage2 = PackageUtility.CreatePackage("SolutionLevel2", tools: new[] { "Install.ps1" }, dependencies: new[] { new PackageDependency("SolutionLevel1") });

            // Act
            repository.AddPackage(solutionPackage1);
            repository.AddPackage(solutionPackage2);

            // Assert
            var packageReferences = repository.PackageReferenceFile.GetPackageReferences()
                                    .Select(p => p.Id).OrderBy(id => id).ToArray();

            Assert.Equal(new [] { "SolutionLevel1", "SolutionLevel2" }, packageReferences);
        }