Example #1
0
        public void FallbackRepositoryRetursNullIfPrimaryRepositoryDoesNotHaveDependencyAndDependencyResolverThrows()
        {
            // Arrange
            var package            = PackageUtility.CreatePackage("M1", "1.0");
            var dependencyResolver = new Mock <IPackageRepository>(MockBehavior.Strict);

            dependencyResolver.As <IDependencyResolver>()
            .Setup(c => c.ResolveDependency(It.IsAny <PackageDependency>(), It.IsAny <IPackageConstraintProvider>(), false, It.IsAny <bool>(), DependencyVersion.Lowest))
            .Throws(new Exception("Connection failure."));
            var aggregateRepository = new AggregateRepository(new[] { dependencyResolver.Object })
            {
                IgnoreFailingRepositories = true
            };
            var primaryRepository = new MockPackageRepository();

            primaryRepository.AddPackage(package);
            var fallbackRepository = new FallbackRepository(primaryRepository, aggregateRepository);

            // Act
            var resolvedPackage = fallbackRepository.ResolveDependency(new PackageDependency("M2", new VersionSpec {
                MinVersion = new SemanticVersion("1.0.1")
            }), false, false);

            // Assert
            Assert.Null(resolvedPackage);
        }
Example #2
0
        public void FallbackRepositoryDoesNotQueryDependencyResolverIfPrimaryRepositoryContainsRequiredDependency()
        {
            // Arrange
            var package            = PackageUtility.CreatePackage("M1", "1.0");
            var dependencyResolver = new Mock <IPackageRepository>(MockBehavior.Strict);

            dependencyResolver.As <IDependencyResolver>()
            .Setup(c => c.ResolveDependency(It.IsAny <PackageDependency>(), It.IsAny <IPackageConstraintProvider>(), false, It.IsAny <bool>(), DependencyVersion.Lowest))
            .Throws(new Exception("This method should not be called."));
            var primaryRepository = new MockPackageRepository();

            primaryRepository.AddPackage(package);
            var fallbackRepository = new FallbackRepository(primaryRepository, dependencyResolver.Object);

            // Act
            var resolvedPackage = fallbackRepository.ResolveDependency(new PackageDependency("M1"), false, false);

            // Assert
            Assert.Same(package, resolvedPackage);
        }
Example #3
0
        public void FallbackRepositoryUsesDependencyResolverIfPrimaryRepositoryDoesNotHaveRequiredDependency()
        {
            // Arrange
            IPackage packageA10 = PackageUtility.CreatePackage("M1", "1.0"), packageA11 = PackageUtility.CreatePackage("M2", "1.1");

            var primaryRepository = new MockPackageRepository();

            primaryRepository.AddPackage(packageA10);
            var dependencyResolver = new MockPackageRepository();

            dependencyResolver.AddPackage(packageA11);
            var fallbackRepository = new FallbackRepository(primaryRepository, dependencyResolver);

            // Act
            var resolvedPackage = fallbackRepository.ResolveDependency(new PackageDependency("M2", new VersionSpec {
                MinVersion = new SemanticVersion("1.0.1")
            }), false, false);

            // Assert
            Assert.Same(resolvedPackage, packageA11);
        }
        public void FallbackRepositoryUsesDependencyResolverIfPrimaryRepositoryDoesNotHaveRequiredDependency()
        {
            // Arrange
            IPackage packageA10 = PackageUtility.CreatePackage("M1", "1.0"), packageA11 = PackageUtility.CreatePackage("M2", "1.1");

            var primaryRepository = new MockPackageRepository();
            primaryRepository.AddPackage(packageA10);
            var dependencyResolver = new MockPackageRepository();
            dependencyResolver.AddPackage(packageA11);
            var fallbackRepository = new FallbackRepository(primaryRepository, dependencyResolver);

            // Act
            var resolvedPackage = fallbackRepository.ResolveDependency(new PackageDependency("M2", new VersionSpec { MinVersion = new SemanticVersion("1.0.1") }), false, false);

            // Assert
            Assert.Same(resolvedPackage, packageA11);
        }
        public void FallbackRepositoryRetursNullIfPrimaryRepositoryDoesNotHaveDependencyAndDependencyResolverThrows()
        {
            // Arrange
            var package = PackageUtility.CreatePackage("M1", "1.0");
            var dependencyResolver = new Mock<IPackageRepository>(MockBehavior.Strict);
            dependencyResolver.As<IDependencyResolver>()
                              .Setup(c => c.ResolveDependency(It.IsAny<PackageDependency>(), It.IsAny<IPackageConstraintProvider>(), false, It.IsAny<bool>()))
                              .Throws(new Exception("Connection failure."));
            var aggregateRepository = new AggregateRepository(new[] { dependencyResolver.Object }) { IgnoreFailingRepositories = true };
            var primaryRepository = new MockPackageRepository();
            primaryRepository.AddPackage(package);
            var fallbackRepository = new FallbackRepository(primaryRepository, aggregateRepository);

            // Act
            var resolvedPackage = fallbackRepository.ResolveDependency(new PackageDependency("M2", new VersionSpec { MinVersion = new SemanticVersion("1.0.1") }), false, false);

            // Assert
            Assert.Null(resolvedPackage);
        }
        public void FallbackRepositoryDoesNotQueryDependencyResolverIfPrimaryRepositoryContainsRequiredDependency()
        {
            // Arrange
            var package = PackageUtility.CreatePackage("M1", "1.0");
            var dependencyResolver = new Mock<IPackageRepository>(MockBehavior.Strict);
            dependencyResolver.As<IDependencyResolver>()
                              .Setup(c => c.ResolveDependency(It.IsAny<PackageDependency>(), It.IsAny<IPackageConstraintProvider>(), false, It.IsAny<bool>()))
                              .Throws(new Exception("This method should not be called."));
            var primaryRepository = new MockPackageRepository();
            primaryRepository.AddPackage(package);
            var fallbackRepository = new FallbackRepository(primaryRepository, dependencyResolver.Object);

            // Act
            var resolvedPackage = fallbackRepository.ResolveDependency(new PackageDependency("M1"), false, false);

            // Assert
            Assert.Same(package, resolvedPackage);
        }