Skip to content
Browse files

Adding unit tests for column length changes

  • Loading branch information...
1 parent e1f2302 commit 4be827f695b333a1fd2cc5d83fe44c00b55e4038 @pranavkm pranavkm committed Aug 22, 2012
Showing with 67 additions and 11 deletions.
  1. +64 −9 Facts/Services/PackageServiceFacts.cs
  2. +3 −2 Website/Services/PackageService.cs
View
73 Facts/Services/PackageServiceFacts.cs
@@ -330,26 +330,81 @@ void WillThrowIfTheNuGetPackageCopyrightIsLongerThan4000()
}
[Fact]
+ void WillThrowIfTheVersionIsLongerThan64Characters()
+ {
+ var service = CreateService();
+ var nugetPackage = CreateNuGetPackage();
+ var versionString = "1.0.0-".PadRight(65, 'a');
+ nugetPackage.Setup(x => x.Version).Returns(SemanticVersion.Parse(versionString));
+
+ var ex = Assert.Throws<EntityException>(() => service.CreatePackage(nugetPackage.Object, null));
+
+ Assert.Equal(String.Format(Strings.NuGetPackagePropertyTooLong, "Version", "64"), ex.Message);
+ }
+
+ [Fact]
void WillThrowIfTheNuGetPackageDependenciesIsLongerThanInt16MaxValue()
{
var service = CreateService();
var nugetPackage = CreateNuGetPackage();
+ var versionSpec = VersionUtility.ParseVersionSpec("[1.0]");
+ nugetPackage.Setup(x => x.DependencySets).Returns(new[]
+ {
+ new PackageDependencySet(VersionUtility.DefaultTargetFramework,
+ Enumerable.Repeat(new NuGet.PackageDependency("theFirstDependency", versionSpec), 5000))
+ });
+
+ var ex = Assert.Throws<EntityException>(() => service.CreatePackage(nugetPackage.Object, null));
+
+ Assert.Equal(String.Format(Strings.NuGetPackagePropertyTooLong, "Dependencies", Int16.MaxValue), ex.Message);
+ }
+
+ [Fact]
+ void WillThrowIfThPackageDependencyIdIsLongerThan128()
+ {
+ var service = CreateService();
+ var nugetPackage = CreateNuGetPackage();
nugetPackage.Setup(x => x.DependencySets).Returns(new[]
{
- new PackageDependencySet(VersionUtility.DefaultTargetFramework, new[]
+ new PackageDependencySet(VersionUtility.DefaultTargetFramework, new NuGet.PackageDependency[0]),
+ new PackageDependencySet(new FrameworkName(".NetFramework", new Version(4, 0)),
+ new[]
{
- new NuGet.PackageDependency("theFirstDependency".PadRight(Int16.MaxValue, '_'), new VersionSpec {
- MinVersion = new SemanticVersion("1.0"),
- MaxVersion = new SemanticVersion("2.0"),
- IsMinInclusive = true,
- IsMaxInclusive = false }),
- new NuGet.PackageDependency("theSecondDependency".PadRight(Int16.MaxValue, '_'), new VersionSpec(new SemanticVersion("1.0"))),
+ new NuGet.PackageDependency("theFirstDependency".PadRight(129, '_'), new VersionSpec {
+ MinVersion = new SemanticVersion("1.0"),
+ MaxVersion = new SemanticVersion("2.0"),
+ IsMinInclusive = true,
+ IsMaxInclusive = false }),
})
});
var ex = Assert.Throws<EntityException>(() => service.CreatePackage(nugetPackage.Object, null));
- Assert.Equal(String.Format(Strings.NuGetPackagePropertyTooLong, "Dependencies", Int16.MaxValue), ex.Message);
+ Assert.Equal(String.Format(Strings.NuGetPackagePropertyTooLong, "Dependency.Id", 128), ex.Message);
+ }
+
+ [Fact]
+ void WillThrowIfThPackageDependencyVersionSpecIsLongerThan256()
+ {
+ var service = CreateService();
+ var nugetPackage = CreateNuGetPackage();
+ nugetPackage.Setup(x => x.DependencySets).Returns(new[]
+ {
+ new PackageDependencySet(VersionUtility.DefaultTargetFramework, new NuGet.PackageDependency[0]),
+ new PackageDependencySet(new FrameworkName(".NetFramework", new Version(4, 0)),
+ new[]
+ {
+ new NuGet.PackageDependency("theFirstDependency", new VersionSpec {
+ MinVersion = new SemanticVersion("1.0-".PadRight(257, 'a')),
+ MaxVersion = new SemanticVersion("2.0"),
+ IsMinInclusive = true,
+ IsMaxInclusive = false }),
+ })
+ });
+
+ var ex = Assert.Throws<EntityException>(() => service.CreatePackage(nugetPackage.Object, null));
+
+ Assert.Equal(String.Format(Strings.NuGetPackagePropertyTooLong, "Dependency.VersionSpec", 256), ex.Message);
}
[Fact]
@@ -433,7 +488,7 @@ void WillThrowIfTheNuGetPackageTitleIsLongerThan4000()
var ex = Assert.Throws<EntityException>(() => service.CreatePackage(nugetPackage.Object, null));
- Assert.Equal(String.Format(Strings.NuGetPackagePropertyTooLong, "Title", "4000"), ex.Message);
+ Assert.Equal(String.Format(Strings.NuGetPackagePropertyTooLong, "Title", "256"), ex.Message);
}
[Fact]
View
5 Website/Services/PackageService.cs
@@ -334,8 +334,6 @@ static void ValidateNuGetPackage(IPackage nugetPackage)
throw new EntityException(Strings.NuGetPackagePropertyTooLong, "Authors", "4000");
if (nugetPackage.Copyright != null && nugetPackage.Copyright.Length > 4000)
throw new EntityException(Strings.NuGetPackagePropertyTooLong, "Copyright", "4000");
- if (nugetPackage.DependencySets != null && nugetPackage.DependencySets.Flatten().Length > Int16.MaxValue)
- throw new EntityException(Strings.NuGetPackagePropertyTooLong, "Dependencies", Int16.MaxValue);
if (nugetPackage.Description != null && nugetPackage.Description.Length > 4000)
throw new EntityException(Strings.NuGetPackagePropertyTooLong, "Description", "4000");
if (nugetPackage.IconUrl != null && nugetPackage.IconUrl.ToString().Length > 4000)
@@ -373,6 +371,9 @@ static void ValidateNuGetPackage(IPackage nugetPackage)
throw new EntityException(Strings.NuGetPackagePropertyTooLong, "Dependency.VersionSpec", "256");
}
}
+
+ if (nugetPackage.DependencySets != null && nugetPackage.DependencySets.Flatten().Length > Int16.MaxValue)
+ throw new EntityException(Strings.NuGetPackagePropertyTooLong, "Dependencies", Int16.MaxValue);
}
private static void UpdateIsLatest(PackageRegistration packageRegistration)

0 comments on commit 4be827f

Please sign in to comment.
Something went wrong with that request. Please try again.