public void SupressErrorWorksForGetDependenciesForRepositoriesThatThrowWhenInvoked() { // Arrange var mockRepository = new Mock <IPackageRepository>(); mockRepository.Setup(c => c.GetPackages()).Throws(new InvalidOperationException()).Verifiable(); var mockRepoWithLookup = new Mock <IPackageRepository>(); mockRepository.As <IDependencyResolver>().Setup(c => c.ResolveDependency(It.IsAny <PackageDependency>(), It.IsAny <IPackageConstraintProvider>(), false, It.IsAny <bool>(), DependencyVersion.Lowest)); var repository = new AggregateRepository(new[] { new MockPackageRepository { PackageUtility.CreatePackage("A"), }, mockRepository.Object, new MockPackageRepository { PackageUtility.CreatePackage("B"), }, mockRepoWithLookup.Object }); repository.IgnoreFailingRepositories = true; // Act var package = DependencyResolveUtility.ResolveDependency( repository, new PackageDependency("C"), null, allowPrereleaseVersions: false, preferListedPackages: false, dependencyVersion: DependencyVersion.Lowest); // Assert Assert.Null(package); }
public void MachineCacheUsesNullFileSystemIfItCannotAccessCachePath() { // Arrange Func <string> getCachePathDirectory = () => { throw new SecurityException("Boo"); }; var package = PackageUtility.CreatePackage("TestPackage"); // Act MachineCache cache = MachineCache.CreateDefault(getCachePathDirectory); // Assert Assert.NotNull(cache); Assert.False(cache.GetPackageFiles().Any()); // Ensure operations don't throw cache.Clear(); cache.AddPackage(PackageUtility.CreatePackage("TestPackage")); Assert.False(cache.Exists("TestPackage")); Assert.False(cache.Exists(package)); Assert.False(cache.Exists("TestPackage", new SemanticVersion("1.0"))); Assert.Null(DependencyResolveUtility.ResolveDependency(cache, new PackageDependency("Bar"), false, false)); Assert.Null(cache.FindPackage("TestPackage")); Assert.False(cache.FindPackages(new[] { "TestPackage", "B" }).Any()); Assert.False(cache.FindPackagesById("TestPackage").Any()); Assert.False(cache.GetPackages().Any()); Assert.False(cache.GetUpdates(new[] { package }, includePrerelease: true, includeAllVersions: true).Any()); cache.RemovePackage(package); Assert.Equal(0, cache.Source.Length); Assert.False(cache.TryFindPackage("TestPackage", new SemanticVersion("1.0"), out package)); }
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 = DependencyResolveUtility.ResolveDependency( repository, dependency1, constraintProvider: null, allowPrereleaseVersions: false, preferListedPackages: false, dependencyVersion: DependencyVersion.HighestPatch); IPackage package2 = DependencyResolveUtility.ResolveDependency( repository, dependency2, constraintProvider: null, allowPrereleaseVersions: false, preferListedPackages: false, dependencyVersion: DependencyVersion.HighestPatch); IPackage package3 = DependencyResolveUtility.ResolveDependency( repository, dependency3, constraintProvider: null, allowPrereleaseVersions: false, preferListedPackages: false, dependencyVersion: DependencyVersion.HighestPatch); IPackage package4 = DependencyResolveUtility.ResolveDependency( repository, dependency4, constraintProvider: null, allowPrereleaseVersions: false, preferListedPackages: false, dependencyVersion: DependencyVersion.HighestPatch); IPackage package5 = DependencyResolveUtility.ResolveDependency( repository, 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 FindDependencyPicksHighestVersionIfNotSpecified() { // 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") }; var dependency = new PackageDependency("B"); // Act IPackage package = DependencyResolveUtility.ResolveDependency(repository, dependency, allowPrereleaseVersions: false, preferListedPackages: false); // Assert Assert.Equal("B", package.Id); Assert.Equal(new SemanticVersion("2.0"), package.Version); }
protected override IPackage ResolveDependency(PackageDependency dependency) { return(DependencyResolveUtility.ResolveDependency(_repository, dependency, allowPrereleaseVersions: false, preferListedPackages: false)); }