Permalink
Browse files

Ensure language property is read from the nupkg

  • Loading branch information...
1 parent 5d648f4 commit 91995845d04e671871217861cb75f49cf249cfa6 @pranavkm pranavkm committed Aug 17, 2012
View
@@ -9,4 +9,5 @@ _AzurePackage
*.bak
NuGetGallery.sln.docstates
_ReSharper.NuGetGallery
-_PackagedWebsite
+_PackagedWebsite
+TestResults
@@ -92,13 +92,35 @@ public void WillReadThePropertiesFromTheNuGetPackageWhenCreatingANewPackage()
Assert.Equal("theTags", package.Tags);
Assert.Equal("theTitle", package.Title);
Assert.Equal("theCopyright", package.Copyright);
+ Assert.Null(package.Language);
Assert.False(package.IsPrerelease);
Assert.Equal("theFirstAuthor, theSecondAuthor", package.FlattenedAuthors);
Assert.Equal("theFirstDependency:[1.0, 2.0):net4000|theSecondDependency:[1.0]:net4000|theThirdDependency::net4000|theFourthDependency:[1.0]:net35", package.FlattenedDependencies);
}
[Fact]
+ public void WillReadTheLanguagePropertyFromThePackage()
+ {
+ var packageRegistrationRepo = new Mock<IEntityRepository<PackageRegistration>>();
+ var service = CreateService(
+ packageRegistrationRepo: packageRegistrationRepo,
+ setup: mockPackageSvc =>
+ {
+ mockPackageSvc.Setup(x => x.FindPackageRegistrationById(It.IsAny<string>())).Returns((PackageRegistration)null);
+ });
+ var nugetPackage = CreateNuGetPackage(p => p.Setup(s => s.Language).Returns("fr"));
+ var currentUser = new User();
+
+ var package = service.CreatePackage(
+ nugetPackage.Object,
+ currentUser);
+
+ // Assert
+ Assert.Equal("fr", package.Language);
+ }
+
+ [Fact]
public void WillReadPrereleaseFlagFromNuGetPackage()
{
// Arrange
@@ -415,6 +437,21 @@ void WillThrowIfTheNuGetPackageTitleIsLongerThan4000()
}
[Fact]
+ void WillThrowIfTheNuGetPackageLanguageIsLongerThan20()
+ {
+ // Arrange
+ var service = CreateService();
+ var nugetPackage = CreateNuGetPackage();
+ nugetPackage.Setup(x => x.Language).Returns(new string('a', 21));
+
+ // Act
+ var ex = Assert.Throws<EntityException>(() => service.CreatePackage(nugetPackage.Object, null));
+
+ // Assert
+ Assert.Equal(String.Format(Strings.NuGetPackagePropertyTooLong, "Language", "20"), ex.Message);
+ }
+
+ [Fact]
void WillSaveSupportedFrameworks()
{
var packageRegistrationRepo = new Mock<IEntityRepository<PackageRegistration>>();
@@ -33,6 +33,7 @@ public static IQueryable<V1FeedPackage> ToV1FeedPackageQuery(this IQueryable<Pac
GalleryDetailsUrl = siteRoot + "packages/" + p.PackageRegistration.Id + "/" + p.Version,
IconUrl = p.IconUrl,
IsLatestVersion = p.IsLatestStable,
+ Language = p.Language,
LastUpdated = p.LastUpdated,
LicenseUrl = p.LicenseUrl,
PackageHash = p.Hash,
@@ -75,7 +76,7 @@ public static IQueryable<V2FeedPackage> ToV2FeedPackageQuery(this IQueryable<Pac
IsPrerelease = p.IsPrerelease,
LastUpdated = p.LastUpdated,
LicenseUrl = p.LicenseUrl,
- Language = null,
+ Language = p.Language,
PackageHash = p.Hash,
PackageHashAlgorithm = p.HashAlgorithm,
PackageSize = p.PackageFileSize,
@@ -24,6 +24,7 @@ public class V1FeedPackage
public string GalleryDetailsUrl { get; set; }
public string IconUrl { get; set; }
public bool IsLatestVersion { get; set; }
+ public string Language { get; set; }
public DateTime LastUpdated { get; set; }
public string LicenseUrl { get; set; }
public string PackageHash { get; set; }
@@ -62,7 +63,6 @@ public double VersionRating
}
public string Categories { get { return String.Empty; } }
- public string Language { get { return ""; } }
public string PackageType { get { return "Package"; } }
public decimal Price { get { return 0; } }
public bool Prerelease { get { return false; } }
@@ -25,9 +25,9 @@ public class V2FeedPackage
public bool IsLatestVersion { get; set; }
public bool IsAbsoluteLatestVersion { get; set; }
public bool IsPrerelease { get; set; }
+ public string Language { get; set; }
public DateTime LastUpdated { get; set; }
public DateTime Published { get; set; }
- public string Language { get; set; }
public string LicenseUrl { get; set; }
public string PackageHash { get; set; }
public string PackageHashAlgorithm { get; set; }
@@ -36,6 +36,10 @@ public Package()
public bool IsLatestStable { get; set; }
public DateTime LastUpdated { get; set; }
public string LicenseUrl { get; set; }
+
+ [StringLength(20)]
+ public string Language { get; set; }
+
public DateTime Published { get; set; }
public long PackageFileSize { get; set; }
public string ProjectUrl { get; set; }
Oops, something went wrong.
@@ -0,0 +1,17 @@
+namespace NuGetGallery.Migrations
+{
+ using System.Data.Entity.Migrations;
+
+ public partial class Language : DbMigration
+ {
+ public override void Up()
+ {
+ AddColumn("Packages", "Language", c => c.String(maxLength: 20));
+ }
+
+ public override void Down()
+ {
+ DropColumn("Packages", "Language");
+ }
+ }
+}
@@ -266,11 +266,12 @@ Package CreatePackageFromNuGetPackage(PackageRegistration packageRegistration, I
Hash = cryptoSvc.GenerateHash(packageFileStream.ReadAllBytes()),
PackageFileSize = packageFileStream.Length,
Created = now,
+ Language = nugetPackage.Language,
LastUpdated = now,
Published = now,
Copyright = nugetPackage.Copyright,
IsPrerelease = !nugetPackage.IsReleaseVersion(),
- Listed = true
+ Listed = true,
};
if (nugetPackage.IconUrl != null)
@@ -326,6 +327,7 @@ public virtual IEnumerable<FrameworkName> GetSupportedFrameworks(IPackage packag
static void ValidateNuGetPackage(IPackage nugetPackage)
{
+ // TODO: Change this to use DataAnnotations
if (nugetPackage.Id.Length > 128)
throw new EntityException(Strings.NuGetPackagePropertyTooLong, "Id", "128");
if (nugetPackage.Authors != null && String.Join(",", nugetPackage.Authors.ToArray()).Length > 4000)
@@ -342,12 +344,17 @@ static void ValidateNuGetPackage(IPackage nugetPackage)
throw new EntityException(Strings.NuGetPackagePropertyTooLong, "LicenseUrl", "4000");
if (nugetPackage.ProjectUrl != null && nugetPackage.ProjectUrl.ToString().Length > 4000)
throw new EntityException(Strings.NuGetPackagePropertyTooLong, "ProjectUrl", "4000");
- if (nugetPackage.Summary != null && nugetPackage.Summary.ToString().Length > 4000)
+ if (nugetPackage.Summary != null && nugetPackage.Summary.Length > 4000)
throw new EntityException(Strings.NuGetPackagePropertyTooLong, "Summary", "4000");
if (nugetPackage.Tags != null && nugetPackage.Tags.ToString().Length > 4000)
throw new EntityException(Strings.NuGetPackagePropertyTooLong, "Tags", "4000");
- if (nugetPackage.Title != null && nugetPackage.Title.ToString().Length > 4000)
+ if (nugetPackage.Title != null && nugetPackage.Title.Length > 4000)
throw new EntityException(Strings.NuGetPackagePropertyTooLong, "Title", "4000");
+
+ if (nugetPackage.Language != null && nugetPackage.Language.Length > 20)
+ {
+ throw new EntityException(Strings.NuGetPackagePropertyTooLong, "Language", "20");
+ }
}
private static void UpdateIsLatest(PackageRegistration packageRegistration)
View
@@ -355,6 +355,10 @@
<Compile Include="Migrations\201206250141447_ExecuteELMAHSql.Designer.cs">
<DependentUpon>201206250141447_ExecuteELMAHSql.cs</DependentUpon>
</Compile>
+ <Compile Include="Migrations\201208171904586_Language.cs" />
+ <Compile Include="Migrations\201208171904586_Language.Designer.cs">
+ <DependentUpon>201208171904586_Language.cs</DependentUpon>
+ </Compile>
<Compile Include="Migrations\MigrationsConfiguration.cs" />
<Compile Include="PackageCurators\IAutomaticPackageCurator.cs" />
<Compile Include="PackageCurators\AutomaticPackageCurator.cs" />

0 comments on commit 9199584

Please sign in to comment.