Skip to content

Commit

Permalink
Modify FindPackagesById to return unlisted packages
Browse files Browse the repository at this point in the history
  • Loading branch information
pranavkm committed Mar 16, 2012
1 parent 9cf60ea commit 68f7492
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 5 deletions.
56 changes: 53 additions & 3 deletions Facts/Services/FeedServiceFacts.cs
Expand Up @@ -16,7 +16,7 @@ public void V1FeedSearchDoesNotReturnPrereleasePackages()
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>() },
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/");
Expand All @@ -42,7 +42,7 @@ public void V1FeedSearchDoesNotReturnUnlistedPackages()
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>() },
new Package { PackageRegistration = packageRegistration, Version = "1.0.1-a", IsPrerelease = true, Listed = true, DownloadStatistics = new List<PackageStatistics>() },
new Package { PackageRegistration = new PackageRegistration { Id ="baz" }, Version = "2.0", Listed = false, DownloadStatistics = new List<PackageStatistics>() },
}.AsQueryable());
var searchService = new Mock<ISearchService>(MockBehavior.Strict);
Expand Down Expand Up @@ -71,7 +71,7 @@ public void V2FeedSearchDoesNotReturnPrereleasePackagesIfFlagIsFalse()
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>() },
new Package { PackageRegistration = packageRegistration, Version = "1.0.1-a", 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>((_, __) => _);
Expand All @@ -90,5 +90,55 @@ public void V2FeedSearchDoesNotReturnPrereleasePackagesIfFlagIsFalse()
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);
}

[Fact]
public void V1FeedFindPackagesByIdReturnsUnlistedPackagesButNotPrereleasePackages()
{
// 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 v1Service = new V1Feed(repo.Object, configuration.Object, null);

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

// Assert
Assert.Equal(1, result.Count());
Assert.Equal("Foo", result.First().Id);
Assert.Equal("1.0.0", result.First().Version);
Assert.Equal("https://localhost:8081/packages/Foo/1.0.0", result.First().GalleryDetailsUrl);
}

[Fact]
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);
}
}
}
2 changes: 1 addition & 1 deletion Website/DataServices/V1Feed.svc.cs
Expand Up @@ -50,7 +50,7 @@ protected override FeedContext<V1FeedPackage> CreateDataSource()
public IQueryable<V1FeedPackage> FindPackagesById(string id)
{
return PackageRepo.GetAll().Include(p => p.PackageRegistration)
.Where(p => !p.IsPrerelease && p.PackageRegistration.Id.Equals(id, StringComparison.OrdinalIgnoreCase) && p.Listed)
.Where(p => !p.IsPrerelease && p.PackageRegistration.Id.Equals(id, StringComparison.OrdinalIgnoreCase))
.ToV1FeedPackageQuery(Configuration.SiteRoot);
}

Expand Down
2 changes: 1 addition & 1 deletion Website/DataServices/V2Feed.svc.cs
Expand Up @@ -50,7 +50,7 @@ public IQueryable<V2FeedPackage> Search(string searchTerm, string targetFramewor
public IQueryable<V2FeedPackage> FindPackagesById(string id)
{
return PackageRepo.GetAll().Include(p => p.PackageRegistration)
.Where(p => p.PackageRegistration.Id.Equals(id, StringComparison.OrdinalIgnoreCase) && p.Listed)
.Where(p => p.PackageRegistration.Id.Equals(id, StringComparison.OrdinalIgnoreCase))
.ToV2FeedPackageQuery(Configuration.SiteRoot);
}

Expand Down

0 comments on commit 68f7492

Please sign in to comment.