public async Task V2FeedFindPackagesByIdDoesNotReturnDeletedPackages() { // 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, Deleted = true }, new Package { PackageRegistration = packageRegistration, Version = "1.0.1", IsPrerelease = false, Listed = true, Deleted = true }, }.AsQueryable()); var configuration = new Mock<IGalleryConfigurationService>(MockBehavior.Strict); configuration.Setup(c => c.GetSiteRoot(It.IsAny<bool>())).Returns("https://localhost:8081/"); configuration.Setup(c => c.Features).Returns(new FeatureConfiguration() { FriendlyLicenses = true }); var v2Service = new TestableV2Feed(repo.Object, configuration.Object, null); v2Service.Request = new HttpRequestMessage(HttpMethod.Get, "https://localhost:8081/"); // Act var result = (await v2Service.FindPackagesById( new ODataQueryOptions<V2FeedPackage>(new ODataQueryContext(NuGetODataV2FeedConfig.GetEdmModel(), typeof(V2FeedPackage)), v2Service.Request), "Foo")) .ExpectQueryResult<V2FeedPackage>() .GetInnerResult() .ExpectOkNegotiatedContentResult<IQueryable<V2FeedPackage>>(); // Assert Assert.Equal(0, result.Count()); }
public async Task V2FeedFindPackagesByIdReturnsEmptyCollectionWhenNoPackages() { // Arrange var repo = new Mock<IEntityRepository<Package>>(MockBehavior.Strict); repo.Setup(r => r.GetAll()).Returns(() => Enumerable.Empty<Package>().AsQueryable()); var configuration = new Mock<IGalleryConfigurationService>(MockBehavior.Strict); configuration.Setup(c => c.GetSiteRoot(It.IsAny<bool>())).Returns("https://localhost:8081/"); configuration.Setup(c => c.Features).Returns(new FeatureConfiguration() { FriendlyLicenses = true }); var searchService = new Mock<ISearchService>(MockBehavior.Strict); searchService.Setup(s => s.Search(It.IsAny<SearchFilter>())).Returns <IQueryable<Package>, string>((_, __) => Task.FromResult(new SearchResults(_.Count(), DateTime.UtcNow, _))); searchService.Setup(s => s.ContainsAllVersions).Returns(false); var v2Service = new TestableV2Feed(repo.Object, configuration.Object, searchService.Object); v2Service.Request = new HttpRequestMessage(HttpMethod.Get, "https://localhost:8081/"); // Act var result = (await v2Service.FindPackagesById( new ODataQueryOptions<V2FeedPackage>(new ODataQueryContext(NuGetODataV2FeedConfig.GetEdmModel(), typeof(V2FeedPackage)), v2Service.Request), "Foo")) .ExpectQueryResult<V2FeedPackage>() .GetInnerResult() .ExpectOkNegotiatedContentResult<IQueryable<V2FeedPackage>>(); // Assert Assert.Equal(0, result.Count()); }
public async Task V2FeedFindPackagesByIdDoesNotHitBackendWhenIdIsEmpty() { // Arrange var repo = new Mock<IEntityRepository<Package>>(MockBehavior.Loose); var configuration = new Mock<IGalleryConfigurationService>(MockBehavior.Strict); configuration.Setup(c => c.GetSiteRoot(It.IsAny<bool>())).Returns("https://localhost:8081/"); configuration.Setup(c => c.Features).Returns(new FeatureConfiguration() { FriendlyLicenses = true }); var v2Service = new TestableV2Feed(repo.Object, configuration.Object, null); v2Service.Request = new HttpRequestMessage(HttpMethod.Get, "https://localhost:8081/"); // Act var result = (await v2Service.FindPackagesById( new ODataQueryOptions<V2FeedPackage>(new ODataQueryContext(NuGetODataV2FeedConfig.GetEdmModel(), typeof(V2FeedPackage)), v2Service.Request), "")) .ExpectQueryResult<V2FeedPackage>() .GetInnerResult() .ExpectOkNegotiatedContentResult<IQueryable<V2FeedPackage>>(); // Assert repo.Verify(r => r.GetAll(), Times.Never); Assert.Equal(0, result.Count()); }
public async Task 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, FlattenedAuthors = string.Empty, Description = string.Empty, Summary = string.Empty, Tags = string.Empty }, new Package { PackageRegistration = packageRegistration, Version = "1.0.1-a", IsPrerelease = true, Listed = true, FlattenedAuthors = string.Empty, Description = string.Empty, Summary = string.Empty, Tags = string.Empty }, }.AsQueryable()); var configuration = new Mock<IGalleryConfigurationService>(MockBehavior.Strict); configuration.Setup(c => c.GetSiteRoot(It.IsAny<bool>())).Returns("https://localhost:8081/"); configuration.Setup(c => c.Features).Returns(new FeatureConfiguration() { FriendlyLicenses = true }); var searchService = new Mock<ISearchService>(MockBehavior.Strict); searchService.Setup(s => s.Search(It.IsAny<SearchFilter>())).Returns <IQueryable<Package>, string>((_, __) => Task.FromResult(new SearchResults(_.Count(), DateTime.UtcNow, _))); searchService.Setup(s => s.ContainsAllVersions).Returns(false); var v2Service = new TestableV2Feed(repo.Object, configuration.Object, searchService.Object); v2Service.Request = new HttpRequestMessage(HttpMethod.Get, "https://localhost:8081/"); // Act var result = (await v2Service.FindPackagesById( new ODataQueryOptions<V2FeedPackage>(new ODataQueryContext(NuGetODataV2FeedConfig.GetEdmModel(), typeof(V2FeedPackage)), v2Service.Request), "Foo")) .ExpectQueryResult<V2FeedPackage>() .GetInnerResult() .ExpectOkNegotiatedContentResult<IQueryable<V2FeedPackage>>(); // 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); }