Exemple #1
0
        public void V2FeedSearchDoesNotReturnPrereleasePackagesIfFlagIsFalse()
        {
            // Arrange
            var packageRegistration = new PackageRegistration {
                Id = "Foo"
            };
            var repo = new Mock <IEntityRepository <Package> >(MockBehavior.Strict);

            repo.Setup(r => r.GetAll()).Returns(new[] {
                new Package {
                    PackageRegistration = packageRegistration, Version = "1.0.0", IsPrerelease = false, Listed = true, DownloadStatistics = new List <PackageStatistics>()
                },
                new Package {
                    PackageRegistration = packageRegistration, Version = "1.0.1a", IsPrerelease = true, Listed = true, DownloadStatistics = new List <PackageStatistics>()
                },
            }.AsQueryable());
            var configuration = new Mock <IConfiguration>(MockBehavior.Strict);

            configuration.SetupGet(c => c.SiteRoot).Returns("https://staged.nuget.org/");
            var v2Service = new V2Feed(repo.Object, configuration.Object);

            // Act
            var result = v2Service.Search(null, null, includePrerelease: false);

            // Assert
            Assert.Equal(1, result.Count());
            var package = result.First();

            Assert.Equal("Foo", package.Id);
            Assert.Equal("1.0.0", package.Version);
            Assert.Equal("https://staged.nuget.org/packages/Foo/1.0.0", package.GalleryDetailsUrl);
            Assert.Equal("https://staged.nuget.org/package/ReportAbuse/Foo/1.0.0", package.ReportAbuseUrl);
        }
        public void V2FeedSearchDoesNotReturnPrereleasePackagesIfFlagIsFalse()
        {
            // Arrange
            var packageRegistration = new PackageRegistration { Id = "Foo" };
            var repo = new Mock<IEntityRepository<Package>>(MockBehavior.Strict);
            repo.Setup(r => r.GetAll()).Returns(new[] {
                new Package { PackageRegistration = packageRegistration, Version = "1.0.0", IsPrerelease = false, Listed = true, DownloadStatistics = new List<PackageStatistics>() },
                new Package { PackageRegistration = packageRegistration, Version = "1.0.1a", IsPrerelease = true, Listed = true, DownloadStatistics = new List<PackageStatistics>() },
            }.AsQueryable());
            var searchService = new Mock<ISearchService>(MockBehavior.Strict);
            searchService.Setup(s => s.SearchWithRelevance(It.IsAny<IQueryable<Package>>(), It.IsAny<String>())).Returns<IQueryable<Package>, string>((_, __) => _);
            var configuration = new Mock<IConfiguration>(MockBehavior.Strict);
            configuration.SetupGet(c => c.SiteRoot).Returns("https://staged.nuget.org/");
            var v2Service = new V2Feed(repo.Object, configuration.Object, searchService.Object);

            // Act
            var result = v2Service.Search(null, null, includePrerelease: false);

            // Assert
            Assert.Equal(1, result.Count());
            var package = result.First();
            Assert.Equal("Foo", package.Id);
            Assert.Equal("1.0.0", package.Version);
            Assert.Equal("https://staged.nuget.org/packages/Foo/1.0.0", package.GalleryDetailsUrl);
            Assert.Equal("https://staged.nuget.org/package/ReportAbuse/Foo/1.0.0", package.ReportAbuseUrl);
        }
Exemple #3
0
        public void V2FeedFindPackagesByIdReturnsUnlistedAndPrereleasePackages()
        {
            // Arrange
            var packageRegistration = new PackageRegistration {
                Id = "Foo"
            };
            var repo = new Mock <IEntityRepository <Package> >(MockBehavior.Strict);

            repo.Setup(r => r.GetAll()).Returns(new[] {
                new Package {
                    PackageRegistration = packageRegistration, Version = "1.0.0", IsPrerelease = false, Listed = false, DownloadStatistics = new List <PackageStatistics>()
                },
                new Package {
                    PackageRegistration = packageRegistration, Version = "1.0.1-a", IsPrerelease = true, Listed = true, DownloadStatistics = new List <PackageStatistics>()
                },
            }.AsQueryable());
            var configuration = new Mock <IConfiguration>(MockBehavior.Strict);

            configuration.SetupGet(c => c.SiteRoot).Returns("https://localhost:8081/");
            var v2Service = new V2Feed(repo.Object, configuration.Object, null);

            // Act
            var result = v2Service.FindPackagesById("Foo");

            // Assert
            Assert.Equal(2, result.Count());
            Assert.Equal("Foo", result.First().Id);
            Assert.Equal("1.0.0", result.First().Version);

            Assert.Equal("Foo", result.Last().Id);
            Assert.Equal("1.0.1-a", result.Last().Version);
        }
            public void AddsTrailingSlashes(string siteRoot, string expected)
            {
                // Arrange
                var config = new Mock<ConfigurationService>();
                config.Setup(s => s.GetSiteRoot(false)).Returns(siteRoot);
                var feed = new V2Feed(entities: null, repo: null, configuration: config.Object, searchService: null);
                feed.HttpContext = GetContext();

                // Act
                var actual = feed.SiteRoot;

                // Assert
                Assert.Equal(expected, actual);
            }
            public void UsesCurrentRequestToDetermineSiteRoot()
            {
                // Arrange
                var config = new Mock<ConfigurationService>();
                config.Setup(s => s.GetSiteRoot(true)).Returns("https://nuget.org").Verifiable();
                var feed = new V2Feed(entities: null, repo: null, configuration: config.Object, searchService: null);
                feed.HttpContext = GetContext(isSecure: true);

                // Act
                var actual = feed.SiteRoot;

                // Assert
                Assert.Equal("https://nuget.org/", actual);
                config.Verify();
            }
Exemple #6
0
        public void SiteRootAddsTrailingSlashes(string siteRoot, string expected)
        {
            // Arrange
            var config = new Mock <IConfiguration>();

            config.Setup(s => s.GetSiteRoot(false)).Returns(siteRoot);
            var feed = new V2Feed(entities: null, repo: null, configuration: config.Object, searchSvc: null);

            feed.HttpContext = GetContext();

            // Act
            var actual = feed.SiteRoot;

            // Assert
            Assert.Equal(expected, actual);
        }
Exemple #7
0
        public void SiteRootUsesCurrentRequestToDetermineSiteRoot()
        {
            // Arrange
            var config = new Mock <IConfiguration>();

            config.Setup(s => s.GetSiteRoot(true)).Returns("https://nuget.org").Verifiable();
            var feed = new V2Feed(entities: null, repo: null, configuration: config.Object, searchSvc: null);

            feed.HttpContext = GetContext(isSecure: true);

            // Act
            var actual = feed.SiteRoot;

            // Assert
            Assert.Equal("https://nuget.org/", actual);
            config.Verify();
        }
        public void V2FeedFindPackagesByIdReturnsUnlistedAndPrereleasePackages()
        {
            // Arrange
            var packageRegistration = new PackageRegistration { Id = "Foo" };
            var repo = new Mock<IEntityRepository<Package>>(MockBehavior.Strict);
            repo.Setup(r => r.GetAll()).Returns(new[] {
                new Package { PackageRegistration = packageRegistration, Version = "1.0.0", IsPrerelease = false, Listed = false, DownloadStatistics = new List<PackageStatistics>() },
                new Package { PackageRegistration = packageRegistration, Version = "1.0.1-a", IsPrerelease = true, Listed = true, DownloadStatistics = new List<PackageStatistics>() },
            }.AsQueryable());
            var configuration = new Mock<IConfiguration>(MockBehavior.Strict);
            configuration.SetupGet(c => c.SiteRoot).Returns("https://localhost:8081/");
            var v2Service = new V2Feed(repo.Object, configuration.Object, null);

            // Act
            var result = v2Service.FindPackagesById("Foo");

            // Assert
            Assert.Equal(2, result.Count());
            Assert.Equal("Foo", result.First().Id);
            Assert.Equal("1.0.0", result.First().Version);

            Assert.Equal("Foo", result.Last().Id);
            Assert.Equal("1.0.1-a", result.Last().Version);
        }