Permalink
Browse files

Modify FindPackagesById to return unlisted packages

  • Loading branch information...
1 parent 9cf60ea commit 68f7492bac83b9b6d03c9550d2de9ed83937682a @pranavkm pranavkm committed Mar 16, 2012
Showing with 55 additions and 5 deletions.
  1. +53 −3 Facts/Services/FeedServiceFacts.cs
  2. +1 −1 Website/DataServices/V1Feed.svc.cs
  3. +1 −1 Website/DataServices/V2Feed.svc.cs
@@ -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/");
@@ -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);
@@ -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>((_, __) => _);
@@ -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);
+ }
}
}
@@ -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);
}
@@ -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);
}

0 comments on commit 68f7492

Please sign in to comment.