Permalink
Browse files

Merge branch 'master' into live

  • Loading branch information...
jeffhandley committed Jul 3, 2012
2 parents b002008 + 2789792 commit 0d6b52311dfc0173357c54c2cd3725e7138966f6
View
Binary file not shown.
View
@@ -131,6 +131,7 @@
<Compile Include="Infrastructure\CookieTempDataProviderFacts.cs" />
<Compile Include="Infrastructure\Jobs\UpdateStatisticsJobFacts.cs" />
<Compile Include="Infrastructure\LuceneIndexingServiceFacts.cs" />
+ <Compile Include="PackageCurators\Windows8PackageCuratorFacts.cs" />
<Compile Include="PackageCurators\WebMatrixPackageCuratorFacts.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RequireRemoteHttpsAttributeFacts.cs" />
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Data.Entity;
+using System.Linq;
using Moq;
using Xunit;
using Xunit.Extensions;
@@ -10,24 +11,26 @@ namespace NuGetGallery.Infrastructure
public class LuceneIndexingServiceFacts
{
[Theory]
- [InlineData(new object[] { "NHibernate", new string[0] })]
- [InlineData(new object[] { "NUnit", new string[0] })]
- [InlineData(new object[] { "SisoDb", new[] { "Siso", "Db" } })]
- [InlineData(new object[] { "EntityFramework", new[] { "Entity", "Framework" } })]
- [InlineData(new object[] { "Sys-netFX", new[] { "Sys", "net", "FX" } })]
- [InlineData(new object[] { "xUnit", new string[0] })]
- [InlineData(new object[] { "jQueryUI", new[] { "jQuery", "UI" } })]
- [InlineData(new object[] { "jQuery-UI", new[] { "jQuery", "UI" } })]
- [InlineData(new object[] { "NuGetPowerTools", new[] { "NuGet", "Power", "Tools" } })]
- [InlineData(new object[] { "microsoft-web-helpers", new[] { "microsoft", "web", "helpers" } })]
- [InlineData(new object[] { "EntityFramework.sample", new[] { "Entity", "Framework", "sample" } })]
+ [InlineData("NHibernate", new[] { "NHibernate" })]
+ [InlineData("NUnit", new[] { "NUnit" })]
+ [InlineData("EntityFramework", new[] { "EntityFramework", "Framework", "Entity" })]
+ [InlineData("Sys-netFX", new[] { "Sys-netFX", "Sys", "netFX" })]
+ [InlineData("xUnit", new[] { "xUnit" })]
+ [InlineData("jQueryUI", new [] { "jQueryUI" })]
+ [InlineData("jQuery-UI", new[] { "jQuery-UI", "jQuery", "UI" })]
+ [InlineData("NuGetPowerTools", new[] { "NuGetPowerTools", "NuGet", "Power", "Tools" } )]
+ [InlineData("microsoft-web-helpers", new[] { "microsoft-web-helpers", "microsoft", "web", "helpers" } )]
+ [InlineData("EntityFramework.sample", new[] { "EntityFramework.sample", "EntityFramework", "sample", "Framework", "Entity" })]
+ [InlineData("SignalR.MicroSliver", new[] { "SignalR.MicroSliver", "SignalR", "MicroSliver", "Micro", "Sliver" })]
+ [InlineData("ABCMicroFramework", new[] { "ABCMicroFramework", "ABC", "Micro", "Framework" })]
+ [InlineData("SignalR.Hosting.AspNet", new[] { "SignalR.Hosting.AspNet", "SignalR", "Hosting", "AspNet", "Asp", "Net"})]
public void CamelCaseTokenizer(string term, IEnumerable<string> tokens)
{
// Act
var result = LuceneIndexingService.TokenizeId(term);
// Assert
- Assert.Equal(tokens, result);
+ Assert.Equal(tokens.OrderBy(p => p), result.OrderBy(p => p));
}
[Fact]
@@ -0,0 +1,199 @@
+using System;
+using Moq;
+using NuGet;
+using Xunit;
+using Xunit.Extensions;
+
+namespace NuGetGallery.PackageCurators
+{
+ public class Windows8PackageCuratorFacts
+ {
+ public class TheCurateMethod
+ {
+ [Fact]
+ public void WillNotIncludeThePackageWhenTheWindows8CuratedFeedDoesNotExist()
+ {
+ var curator = new TestableWindows8PackageCurator();
+ curator.StubCuratedFeedByNameQry.Setup(stub => stub.Execute(It.IsAny<string>(), It.IsAny<bool>())).Returns((CuratedFeed)null);
+ var package = CreateStubGalleryPackage();
+ package.Tags = "winrt";
+
+ curator.Curate(package, null);
+
+ curator.StubCreatedCuratedPackageCmd.Verify(stub => stub.Execute(
+ It.IsAny<int>(),
+ It.IsAny<int>(),
+ It.IsAny<bool>(),
+ It.IsAny<bool>(),
+ It.IsAny<string>()), Times.Never());
+ }
+
+ [Theory]
+ [InlineData("winrt")]
+ [InlineData("win8")]
+ [InlineData("windows8")]
+ [InlineData("winjs")]
+ [InlineData("wInRt")]
+ [InlineData("wIn8")]
+ [InlineData("wInDows8")]
+ [InlineData("wInJs")]
+ public void WillIncludeThePackageWhenItHasAcceptedTag(string tag)
+ {
+ var curator = new TestableWindows8PackageCurator();
+ var stubGalleryPackage = CreateStubGalleryPackage();
+ stubGalleryPackage.Tags = "aTag " + tag + " aThirdTag";
+
+ curator.Curate(stubGalleryPackage, null);
+
+ curator.StubCreatedCuratedPackageCmd.Verify(stub => stub.Execute(
+ It.IsAny<int>(),
+ It.IsAny<int>(),
+ It.IsAny<bool>(),
+ It.IsAny<bool>(),
+ It.IsAny<string>()), Times.Once());
+ }
+
+ [Fact]
+ public void WillNotIncludeThePackageWhenNotTagged()
+ {
+ var curator = new TestableWindows8PackageCurator();
+ var stubGalleryPackage = CreateStubGalleryPackage();
+ stubGalleryPackage.Tags = "aTag notforwinrt aThirdTag";
+
+ curator.Curate(stubGalleryPackage, null);
+
+ curator.StubCreatedCuratedPackageCmd.Verify(stub => stub.Execute(
+ It.IsAny<int>(),
+ It.IsAny<int>(),
+ It.IsAny<bool>(),
+ It.IsAny<bool>(),
+ It.IsAny<string>()), Times.Never());
+ }
+
+ [Fact]
+ public void WillNotIncludeThePackageWhenTagsIsNull()
+ {
+ var curator = new TestableWindows8PackageCurator();
+ var stubGalleryPackage = CreateStubGalleryPackage();
+ stubGalleryPackage.Tags = null;
+
+ curator.Curate(stubGalleryPackage, null);
+
+ curator.StubCreatedCuratedPackageCmd.Verify(stub => stub.Execute(
+ It.IsAny<int>(),
+ It.IsAny<int>(),
+ It.IsAny<bool>(),
+ It.IsAny<bool>(),
+ It.IsAny<string>()), Times.Never());
+ }
+
+ [Fact]
+ public void WillIncludeThePackageUsingTheCuratedFeedKey()
+ {
+ var curator = new TestableWindows8PackageCurator();
+ curator.StubCuratedFeed.Key = 42;
+ var package = CreateStubGalleryPackage();
+ package.Tags = "winrt";
+
+ curator.Curate(package, CreateStubNuGetPackage().Object);
+
+ curator.StubCreatedCuratedPackageCmd.Verify(stub => stub.Execute(
+ 42,
+ It.IsAny<int>(),
+ It.IsAny<bool>(),
+ It.IsAny<bool>(),
+ It.IsAny<string>()));
+ }
+
+ [Fact]
+ public void WillIncludeThePackageUsingThePackageRegistrationKey()
+ {
+ var curator = new TestableWindows8PackageCurator();
+ var stubGalleryPackage = CreateStubGalleryPackage();
+ stubGalleryPackage.PackageRegistration.Key = 42;
+ stubGalleryPackage.Tags = "winrt";
+
+ curator.Curate(stubGalleryPackage, CreateStubNuGetPackage().Object);
+
+ curator.StubCreatedCuratedPackageCmd.Verify(stub => stub.Execute(
+ It.IsAny<int>(),
+ 42,
+ It.IsAny<bool>(),
+ It.IsAny<bool>(),
+ It.IsAny<string>()));
+ }
+
+ [Fact]
+ public void WillSetTheAutomaticBitWhenIncludingThePackage()
+ {
+ var curator = new TestableWindows8PackageCurator();
+ var stubGalleryPackage = CreateStubGalleryPackage();
+ stubGalleryPackage.Tags = "winrt";
+
+ curator.Curate(stubGalleryPackage, CreateStubNuGetPackage().Object);
+
+ curator.StubCreatedCuratedPackageCmd.Verify(stub => stub.Execute(
+ It.IsAny<int>(),
+ It.IsAny<int>(),
+ It.IsAny<bool>(),
+ true,
+ It.IsAny<string>()));
+ }
+
+ static Package CreateStubGalleryPackage()
+ {
+ return new Package
+ {
+ IsLatestStable = true ,
+ PackageRegistration = new PackageRegistration
+ {
+ Key = 0,
+ },
+ };
+ }
+
+ static Mock<IPackage> CreateStubNuGetPackage()
+ {
+ var stubNuGetPackage = new Mock<IPackage>();
+ stubNuGetPackage.Setup(stub => stub.GetFiles()).Returns(new IPackageFile[] {});
+ return stubNuGetPackage;
+ }
+
+ static Mock<IPackageFile> CreateStubNuGetPackageFile(string path)
+ {
+ var stubPackageFile = new Mock<IPackageFile>();
+ stubPackageFile.Setup(stub => stub.Path).Returns(path);
+ return stubPackageFile;
+ }
+ }
+
+ public class TestableWindows8PackageCurator : Windows8PackageCurator
+ {
+ public TestableWindows8PackageCurator()
+ {
+ StubCreatedCuratedPackageCmd = new Mock<ICreateCuratedPackageCommand>();
+ StubCuratedFeed = new CuratedFeed { Key = 0 };
+ StubCuratedFeedByNameQry = new Mock<ICuratedFeedByNameQuery>();
+
+ StubCuratedFeedByNameQry
+ .Setup(stub => stub.Execute(It.IsAny<string>(), It.IsAny<bool>()))
+ .Returns(StubCuratedFeed);
+ }
+
+ public Mock<ICreateCuratedPackageCommand> StubCreatedCuratedPackageCmd { get; set; }
+ public CuratedFeed StubCuratedFeed { get; private set; }
+ public Mock<ICuratedFeedByNameQuery> StubCuratedFeedByNameQry { get; private set; }
+
+ protected override T GetService<T>()
+ {
+ if (typeof(T) == typeof(ICreateCuratedPackageCommand))
+ return (T)StubCreatedCuratedPackageCmd.Object;
+
+ if (typeof(T) == typeof(ICuratedFeedByNameQuery))
+ return (T)StubCuratedFeedByNameQry.Object;
+
+ throw new Exception("Tried to get an unexpected service.");
+ }
+ }
+ }
+}
@@ -173,6 +173,8 @@ public override void Load()
// todo: bind all package curators by convention
Bind<IAutomaticPackageCurator>()
.To<WebMatrixPackageCurator>();
+ Bind<IAutomaticPackageCurator>()
+ .To<Windows8PackageCurator>();
// todo: bind all commands by convention
Bind<IAutomaticallyCuratePackageCommand>()
@@ -129,17 +129,25 @@ public virtual ActionResult DisplayPackage(string id, string version)
return View(model);
}
- public virtual ActionResult ListPackages(string q, string sortOrder = Constants.PopularitySortOrder, int page = 1)
+ public virtual ActionResult ListPackages(string q, string sortOrder = null, int page = 1)
{
if (page < 1)
{
page = 1;
}
+
IQueryable<Package> packageVersions = packageSvc.GetLatestPackageVersions(allowPrerelease: true);
q = (q ?? "").Trim();
+ if (String.IsNullOrEmpty(sortOrder))
+ {
+ // Determine the default sort order. If no query string is specified, then the sortOrder is DownloadCount
+ // If we are searching for something, sort by relevance.
+ sortOrder = q.IsEmpty() ? Constants.PopularitySortOrder : Constants.RelevanceSortOrder;
+ }
+
if (GetIdentity().IsAuthenticated)
{
// Only show listed packages. For unlisted packages, only show them if the owner is viewing it.
Oops, something went wrong.

0 comments on commit 0d6b523

Please sign in to comment.