Skip to content

Commit

Permalink
Add a favorite count on DisplayPackage page. Refactor and rename 'fol…
Browse files Browse the repository at this point in the history
…low' to 'favorite' and fix migrations.
  • Loading branch information
Tim Lovell-Smith committed Apr 15, 2013
1 parent 666fefb commit 11709bc
Show file tree
Hide file tree
Showing 54 changed files with 260 additions and 225 deletions.
6 changes: 3 additions & 3 deletions Facts/Controllers/ApiControllerFacts.cs
Expand Up @@ -339,7 +339,7 @@ public void WillNotDeleteThePackageIfApiKeyDoesNotBelongToAnOwner()
var packageService = new Mock<IPackageService>();
packageService.Setup(x => x.FindPackageByIdAndVersion(It.IsAny<string>(), It.IsAny<string>(), true)).Returns(package);
packageService.Setup(svc => svc.MarkPackageUnlisted(It.IsAny<Package>(), true)).Throws(
new InvalidOperationException("Should not have unlisted the package!"));
new InvalidOperationException("Should not have unlisted the packageRegistration!"));
var userService = new Mock<IUserService>();
userService.Setup(x => x.FindByApiKey(It.IsAny<Guid>())).Returns(owner);
var controller = CreateController(userService: userService, packageService: packageService);
Expand Down Expand Up @@ -619,7 +619,7 @@ public void WillNotListThePackageIfApiKeyDoesNotBelongToAnOwner()
var packageService = new Mock<IPackageService>();
packageService.Setup(x => x.FindPackageByIdAndVersion(It.IsAny<string>(), It.IsAny<string>(), true)).Returns(package);
packageService.Setup(svc => svc.MarkPackageListed(It.IsAny<Package>(), It.IsAny<bool>())).Throws(
new InvalidOperationException("Should not have listed the package!"));
new InvalidOperationException("Should not have listed the packageRegistration!"));
var userService = new Mock<IUserService>();
userService.Setup(x => x.FindByApiKey(It.IsAny<Guid>())).Returns(owner);
var controller = CreateController(userService: userService, packageService: packageService);
Expand Down Expand Up @@ -837,4 +837,4 @@ public async void VerifyRecentPopularityStatsDownloadsCount()
}
}
}
}
}
2 changes: 1 addition & 1 deletion Facts/Controllers/JsonApiControllerFacts.cs
Expand Up @@ -50,7 +50,7 @@ public void DoesNotAllowNonPackageOwnerToAddPackageOwner()
var result = controller.AddPackageOwner("foo", "steve");

Assert.False(TestUtility.GetAnonymousPropertyValue<bool>(result, "success"));
Assert.Equal("You are not the package owner.", TestUtility.GetAnonymousPropertyValue<string>(result, "message"));
Assert.Equal("You are not the packageRegistration owner.", TestUtility.GetAnonymousPropertyValue<string>(result, "message"));
}

[Fact]
Expand Down
2 changes: 1 addition & 1 deletion Facts/Infrastructure/AnalysisHelperFacts.cs
Expand Up @@ -9,7 +9,7 @@ public class AnalysisHelperFacts
[Fact]
public void UnderstandsPhraseQueries()
{
var query = DoAnalysis(new NuGetSearchTerm {Field = "Description", TermOrPhrase = "package manager"});
var query = DoAnalysis(new NuGetSearchTerm {Field = "Description", TermOrPhrase = "packageRegistration manager"});
Assert.IsType<PhraseQuery>(query);
}

Expand Down
4 changes: 2 additions & 2 deletions Facts/Infrastructure/LuceneSearchServiceFacts.cs
Expand Up @@ -27,7 +27,7 @@ public void IndexAndSearchAPackageByDescription()
Id = "Package #1",
},
Title = "Package #1 4.2.0",
Description = "Package #1 is an awesome package",
Description = "Package #1 is an awesome packageRegistration",
Listed = true,
IsLatestStable = true,
IsLatest = true,
Expand Down Expand Up @@ -204,7 +204,7 @@ public void SearchUsingExactPackageId()
DownloadCount = 25,
},
Description =
"This isn't really NuGet.Core. The confusing package ID is the test!",
"This isn't really NuGet.Core. The confusing packageRegistration ID is the test!",
DownloadCount = 3,
Listed = true,
IsLatest = true,
Expand Down
2 changes: 1 addition & 1 deletion Facts/Packaging/NupkgFacts.cs
Expand Up @@ -133,7 +133,7 @@ public class TheIgnoredPartMethod
[InlineData("/_rels/.rels")]
[InlineData("/TestPackage.nuspec")]
[InlineData("/content/HelloWorld.cs")]
[InlineData("/package/services/metadata/core-properties/1cd48675fa0b4f89aecfa1fd01738c81.psmdcp")]
[InlineData("/packageRegistration/services/metadata/core-properties/1cd48675fa0b4f89aecfa1fd01738c81.psmdcp")]
[InlineData("/[Content_Types].xml")]
public void LegitPartNamesAreAccepted(string logicalPartName)
{
Expand Down
2 changes: 1 addition & 1 deletion Facts/Services/MessageServiceFacts.cs
Expand Up @@ -275,4 +275,4 @@ public void WillSendInstructions()
}
}
}
}
}
6 changes: 4 additions & 2 deletions Facts/Services/PackageServiceFacts.cs
Expand Up @@ -98,6 +98,7 @@ private static Mock<INupkg> CreateNuGetPackage(Action<Mock<IPackageMetadata>> se
packageRepository = packageRepository ?? new Mock<IEntityRepository<Package>>();
packageStatsRepo = packageStatsRepo ?? new Mock<IEntityRepository<PackageStatistics>>();
packageOwnerRequestRepo = packageOwnerRequestRepo ?? new Mock<IEntityRepository<PackageOwnerRequest>>();
var favoritesRepository = new Mock<IEntityRepository<PackageFavorite>>();
indexingService = indexingService ?? new Mock<IIndexingService>();

var packageService = new Mock<PackageService>(
Expand All @@ -106,6 +107,7 @@ private static Mock<INupkg> CreateNuGetPackage(Action<Mock<IPackageMetadata>> se
packageRepository.Object,
packageStatsRepo.Object,
packageOwnerRequestRepo.Object,
favoritesRepository.Object,
indexingService.Object);

packageService.CallBase = true;
Expand Down Expand Up @@ -344,9 +346,9 @@ public void WillReadThePropertiesFromTheNuGetPackageWhenCreatingANewPackage()
var package = service.CreatePackage(nugetPackage.Object, currentUser);

// Yes, I know this is a lot of asserts. Yes, I know I broke the golden, one assert per test rule.
// That said, it's still asserting one "thing": that the package data was read.
// That said, it's still asserting one "thing": that the packageRegistration data was read.
// I'm sorry, but I just can't imagine adding a test per property.
// Note that there is no assertion on package identifier, because that's at the package registration level (and covered in another test).
// Note that there is no assertion on packageRegistration identifier, because that's at the packageRegistration registration level (and covered in another test).
Assert.Equal("1.0.42.0", package.Version);
Assert.Equal("theFirstAuthor", package.Authors.ElementAt(0).Name);
Assert.Equal("theSecondAuthor", package.Authors.ElementAt(1).Name);
Expand Down
24 changes: 12 additions & 12 deletions Facts/Services/UserServiceFacts.cs
Expand Up @@ -18,14 +18,14 @@ private static UserService CreateMockUserService(Action<Mock<UserService>> setup

cryptoService = cryptoService ?? new Mock<ICryptographyService>();
userRepo = userRepo ?? new Mock<IEntityRepository<User>>();
var followsRepo = new Mock<IEntityRepository<PackageFollow>>();
var favoritesRepo = new Mock<IEntityRepository<PackageFavorite>>();
var packageRegRepo = new Mock<IEntityRepository<PackageRegistration>>();

var userService = new Mock<UserService>(
config.Object,
cryptoService.Object,
userRepo.Object,
followsRepo.Object,
favoritesRepo.Object,
packageRegRepo.Object)
{
CallBase = true
Expand Down Expand Up @@ -767,16 +767,16 @@ public void ThrowsArgumentExceptionForNullUser()
}
}

public class TheGetFollowedPackageIdsInSetMethod
public class TheWhereIsFavoriteMethod
{
[Fact]
public void GetsAListOfPackageIds()
{
var user = new User { EmailAddress = "old@example.com", Key = 1400, Username = "Bill" };
var allUsers = (new[] { user });
var allFollows = new []
var allFavorites = new []
{
new PackageFollow
new PackageFavorite
{
UserKey = 1400,
PackageRegistrationKey = 1,
Expand All @@ -786,19 +786,19 @@ public void GetsAListOfPackageIds()
Id = "Package1",
},
User = user,
IsFollowed = true,
IsFavorited = true,
}
};

var service = new TestableUserService();
service.MockUserRepository
.Setup(repo => repo.GetAll())
.Returns(allUsers.AsQueryable());
service.MockFollowsRepository
service.MockFavoritesRepository
.Setup(repo => repo.GetAll())
.Returns(allFollows.AsQueryable());
.Returns(allFavorites.AsQueryable());

string[] results = service.GetFollowedPackageIdsInSet("Bill", new[] { "Package1", "Package2" }).ToArray();
string[] results = service.WhereIsFavorite("Bill", new[] { "Package1", "Package2" }).ToArray();
Assert.Equal(1, results.Length);
Assert.Equal("Package1", results[0]);
}
Expand All @@ -812,7 +812,7 @@ public void CanThrowUserNotFound()
.Returns(new User[0].AsQueryable());

Assert.Throws<UserNotFoundException>(() =>
service.GetFollowedPackageIdsInSet("Bill", new[] { "Package1" })
service.WhereIsFavorite("Bill", new[] { "Package1" })
);
}
}
Expand All @@ -822,14 +822,14 @@ public class TestableUserService : UserService
public Mock<ICryptographyService> MockCrypto { get; protected set; }
public Mock<IConfiguration> MockConfig { get; protected set; }
public Mock<IEntityRepository<User>> MockUserRepository { get; protected set; }
public Mock<IEntityRepository<PackageFollow>> MockFollowsRepository { get; protected set; }
public Mock<IEntityRepository<PackageFavorite>> MockFavoritesRepository { get; protected set; }

public TestableUserService()
{
CryptoService = (MockCrypto = new Mock<ICryptographyService>()).Object;
Config = (MockConfig = new Mock<IConfiguration>()).Object;
UserRepository = (MockUserRepository = new Mock<IEntityRepository<User>>()).Object;
FollowsRepository = (MockFollowsRepository = new Mock<IEntityRepository<PackageFollow>>()).Object;
FavoritesRepository = (MockFavoritesRepository = new Mock<IEntityRepository<PackageFavorite>>()).Object;

// Set ConfirmEmailAddress to a default of true
MockConfig.Setup(c => c.ConfirmEmailAddresses).Returns(true);
Expand Down
6 changes: 3 additions & 3 deletions Website/App_Start/ContainerBindings.cs
Expand Up @@ -115,8 +115,8 @@ public override void Load()
.To<EntityRepository<PackageStatistics>>()
.InRequestScope();

Bind<IEntityRepository<PackageFollow>>()
.To<EntityRepository<PackageFollow>>()
Bind<IEntityRepository<PackageFavorite>>()
.To<EntityRepository<PackageFavorite>>()
.InRequestScope();

Bind<ICuratedFeedService>()
Expand Down Expand Up @@ -232,7 +232,7 @@ public override void Load()
Bind<IUploadFileService>()
.To<UploadFileService>();

// todo: bind all package curators by convention
// todo: bind all packageRegistration curators by convention
Bind<IAutomaticPackageCurator>()
.To<WebMatrixPackageCurator>();
Bind<IAutomaticPackageCurator>()
Expand Down
18 changes: 9 additions & 9 deletions Website/App_Start/Routes.cs
Expand Up @@ -144,7 +144,7 @@ public static void RegisterRoutes(RouteCollection routes)

routes.MapRoute(
RouteName.CreateCuratedPackageForm,
"forms/add-package-to-curated-feed",
"forms/add-packageRegistration-to-curated-feed",
new { controller = CuratedPackagesController.ControllerName, action = "CreateCuratedPackageForm" });

routes.MapRoute(
Expand All @@ -168,7 +168,7 @@ public static void RegisterRoutes(RouteCollection routes)

var downloadRoute = routes.MapRoute(
"v1" + RouteName.DownloadPackage,
"api/v1/package/{id}/{version}",
"api/v1/packageRegistration/{id}/{version}",
defaults: new { controller = MVC.Api.Name, action = "GetPackageApi", version = UrlParameter.Optional },
constraints: new { httpMethod = new HttpMethodConstraint("GET") });

Expand Down Expand Up @@ -197,44 +197,44 @@ public static void RegisterRoutes(RouteCollection routes)

routes.MapRoute(
"v2CuratedFeeds" + RouteName.DownloadPackage,
"api/v2/curated-feeds/package/{id}/{version}",
"api/v2/curated-feeds/packageRegistration/{id}/{version}",
defaults: new { controller = MVC.Api.Name, action = "GetPackageApi", version = UrlParameter.Optional },
constraints: new { httpMethod = new HttpMethodConstraint("GET") });

routes.MapRoute(
"v2" + RouteName.DownloadPackage,
"api/v2/package/{id}/{version}",
"api/v2/packageRegistration/{id}/{version}",
defaults: new { controller = MVC.Api.Name, action = "GetPackageApi", version = UrlParameter.Optional },
constraints: new { httpMethod = new HttpMethodConstraint("GET") });

routes.MapRoute(
"v2" + RouteName.PushPackageApi,
"api/v2/package",
"api/v2/packageRegistration",
defaults: new { controller = MVC.Api.Name, action = "PushPackageApi" },
constraints: new { httpMethod = new HttpMethodConstraint("PUT") });

routes.MapRoute(
"v2" + RouteName.DeletePackageApi,
"api/v2/package/{id}/{version}",
"api/v2/packageRegistration/{id}/{version}",
MVC.Api.DeletePackage(),
defaults: null,
constraints: new { httpMethod = new HttpMethodConstraint("DELETE") });

routes.MapRoute(
"v2" + RouteName.PublishPackageApi,
"api/v2/package/{id}/{version}",
"api/v2/packageRegistration/{id}/{version}",
MVC.Api.PublishPackage(),
defaults: null,
constraints: new { httpMethod = new HttpMethodConstraint("POST") });

routes.MapRoute(
"v2PackageIds",
"api/v2/package-ids",
"api/v2/packageRegistration-ids",
MVC.Api.GetPackageIds());

routes.MapRoute(
"v2PackageVersions",
"api/v2/package-versions/{id}",
"api/v2/packageRegistration-versions/{id}",
MVC.Api.GetPackageVersions());

routes.MapRoute(
Expand Down
2 changes: 1 addition & 1 deletion Website/Commands/DeleteCuratedPackageCommand.cs
Expand Up @@ -30,7 +30,7 @@ public DeleteCuratedPackageCommand(IEntitiesContext entities)
var curatedPackage = curatedFeed.Packages.SingleOrDefault(cp => cp.Key == curatedPackageKey);
if (curatedPackage == null)
{
throw new InvalidOperationException("The curated package does not exist.");
throw new InvalidOperationException("The curated packageRegistration does not exist.");
}

Entities.CuratedPackages.Remove(curatedPackage);
Expand Down
2 changes: 1 addition & 1 deletion Website/Commands/ModifyCuratedPackageCommand.cs
Expand Up @@ -32,7 +32,7 @@ public ModifyCuratedPackageCommand(IEntitiesContext entities)
var curatedPackage = curatedFeed.Packages.SingleOrDefault(cp => cp.Key == curatedPackageKey);
if (curatedPackage == null)
{
throw new InvalidOperationException("The curated package does not exist.");
throw new InvalidOperationException("The curated packageRegistration does not exist.");
}

curatedPackage.Included = included;
Expand Down
8 changes: 4 additions & 4 deletions Website/Constants.cs
Expand Up @@ -3,9 +3,9 @@
public static class Constants
{
public const string AdminRoleName = "Admins";
public const string AlphabeticSortOrder = "package-title";
public const string AlphabeticSortOrder = "packageRegistration-title";
public const int DefaultPackageListPageSize = 20;
public const string DefaultPackageListSortOrder = "package-download-count";
public const string DefaultPackageListSortOrder = "packageRegistration-download-count";
public const int DefaultPasswordResetTokenExpirationHours = 24;
public const int MaxEmailSubjectLength = 255;
public const string PackageContentType = "application/zip";
Expand All @@ -17,8 +17,8 @@ public static class Constants
public const string PackagesFolderName = "packages";
public const string DownloadsFolderName = "downloads";

public const string PopularitySortOrder = "package-download-count";
public const string RecentSortOrder = "package-created";
public const string PopularitySortOrder = "packageRegistration-download-count";
public const string RecentSortOrder = "packageRegistration-created";
public const string RelevanceSortOrder = "relevance";

public const string Sha1HashAlgorithmId = "SHA1";
Expand Down
2 changes: 1 addition & 1 deletion Website/Content/Site.css
@@ -1,4 +1,4 @@
/* Color Palette
fav/* Color Palette
**************************************************************
Background: #fff
Borders: #ccc
Expand Down
2 changes: 1 addition & 1 deletion Website/Controllers/ApiController.cs
Expand Up @@ -116,7 +116,7 @@ public virtual async Task<ActionResult> GetPackage(string id, string version)
QuietlyLogException(e);
}

// Fall back to constructing the URL based on the package version and ID.
// Fall back to constructing the URL based on the packageRegistration version and ID.

return await _packageFileService.CreateDownloadPackageActionResultAsync(HttpContext.Request.Url, id, version);
}
Expand Down

0 comments on commit 11709bc

Please sign in to comment.