public async void VerifyRecentPopularityStatsDownloadsCount() { JArray report = new JArray { new JObject { { "PackageId", "A" }, { "PackageVersion", "1.0" }, { "Downloads", 3 } }, new JObject { { "PackageId", "A" }, { "PackageVersion", "1.1" }, { "Downloads", 4 } }, new JObject { { "PackageId", "B" }, { "PackageVersion", "1.0" }, { "Downloads", 5 } }, new JObject { { "PackageId", "B" }, { "PackageVersion", "1.1" }, { "Downloads", 6 } }, new JObject { { "PackageId", "C" }, { "PackageVersion", "1.0" }, { "Downloads", 7 } }, new JObject { { "PackageId", "C" }, { "PackageVersion", "1.1" }, { "Downloads", 8 } }, }; var fakePackageVersionReport = report.ToString(); var fakeReportService = new Mock<IReportService>(); fakeReportService.Setup(x => x.Load("RecentPopularityDetail.json")).Returns(Task.FromResult(fakePackageVersionReport)); var controller = new ApiController(null, null, null, null, new JsonStatisticsService(fakeReportService.Object)); TestUtility.SetupUrlHelperForUrlGeneration(controller, new Uri("http://nuget.org")); T4MVCHelpers.ProcessVirtualPath = s => s; ActionResult actionResult = await controller.GetStatsDownloads(3); ContentResult contentResult = (ContentResult)actionResult; JArray result = JArray.Parse(contentResult.Content); Assert.True(result.Count == 3, "unexpected content"); }
public async void VerifyRecentPopularityStatsDownloads() { JArray report = new JArray { new JObject { { "PackageId", "A" }, { "PackageVersion", "1.0" }, { "PackageTitle", "Package A Title" }, { "PackageDescription", "Package A Description" }, { "PackageIconUrl", "Package A IconUrl" }, { "Downloads", 3 } }, new JObject { { "PackageId", "A" }, { "PackageVersion", "1.1" }, { "PackageTitle", "Package A Title" }, { "PackageDescription", "Package A Description" }, { "PackageIconUrl", "Package A IconUrl" }, { "Downloads", 4 } }, new JObject { { "PackageId", "B" }, { "PackageVersion", "1.0" }, { "PackageTitle", "Package B Title" }, { "PackageDescription", "Package B Description" }, { "PackageIconUrl", "Package B IconUrl" }, { "Downloads", 5 } }, new JObject { { "PackageId", "B" }, { "PackageVersion", "1.1" }, { "PackageTitle", "Package B Title" }, { "PackageDescription", "Package B Description" }, { "PackageIconUrl", "Package B IconUrl" }, { "Downloads", 6 } }, }; var fakePackageVersionReport = report.ToString(); var fakeReportService = new Mock<IReportService>(); fakeReportService.Setup(x => x.Load("RecentPopularityDetail.json")).Returns(Task.FromResult(fakePackageVersionReport)); var controller = new ApiController(null, null, null, null, new JsonStatisticsService(fakeReportService.Object)); TestUtility.SetupUrlHelperForUrlGeneration(controller, new Uri("http://nuget.org")); ActionResult actionResult = await controller.GetStatsDownloads(null); ContentResult contentResult = (ContentResult)actionResult; JArray result = JArray.Parse(contentResult.Content); Assert.True((string)result[3]["Gallery"] == "http://nuget.org/packages/B/1.1", "unexpected content result[3].Gallery"); Assert.True((int)result[2]["Downloads"] == 5, "unexpected content result[2].Downloads"); Assert.True((string)result[1]["PackageDescription"] == "Package A Description", "unexpected content result[1].PackageDescription"); }
public async void VerifyStatsDownloadsReturnsNotFoundWhenStatsNotAvailable() { var fakeStatisticsService = new Mock<IStatisticsService>(); fakeStatisticsService.Setup(x => x.LoadDownloadPackageVersions()).Returns(Task.FromResult(false)); var controller = new ApiController(null, null, null, null, fakeStatisticsService.Object); TestUtility.SetupUrlHelperForUrlGeneration(controller, new Uri("http://nuget.org")); ActionResult actionResult = await controller.GetStatsDownloads(null); HttpStatusCodeResult httpStatusResult = (HttpStatusCodeResult)actionResult; Assert.True(httpStatusResult.StatusCode == (int)HttpStatusCode.NotFound, "unexpected StatusCode"); }
public async void VerifyRecentPopularityStatsDownloads() { JArray report = new JArray { new JObject { { "PackageId", "A" }, { "PackageVersion", "1.0" }, { "PackageTitle", "Package A Title" }, { "PackageDescription", "Package A Description" }, { "PackageIconUrl", "Package A IconUrl" }, { "Downloads", 3 } }, new JObject { { "PackageId", "A" }, { "PackageVersion", "1.1" }, { "PackageTitle", "Package A Title" }, { "PackageDescription", "Package A Description" }, { "PackageIconUrl", "Package A IconUrl" }, { "Downloads", 4 } }, new JObject { { "PackageId", "B" }, { "PackageVersion", "1.0" }, { "PackageTitle", "Package B Title" }, { "PackageDescription", "Package B Description" }, { "PackageIconUrl", "Package B IconUrl" }, { "Downloads", 5 } }, new JObject { { "PackageId", "B" }, { "PackageVersion", "1.1" }, { "PackageTitle", "Package B Title" }, { "PackageDescription", "Package B Description" }, { "PackageIconUrl", "Package B IconUrl" }, { "Downloads", 6 } }, }; var fakePackageVersionReport = report.ToString(); var fakeReportService = new Mock <IReportService>(); fakeReportService.Setup(x => x.Load("RecentPopularityDetail.json")).Returns(Task.FromResult(fakePackageVersionReport)); var controller = new ApiController(null, null, null, null, null, null, new JsonStatisticsService(fakeReportService.Object)); TestUtility.SetupUrlHelperForUrlGeneration(controller, new Uri("http://nuget.org")); ActionResult actionResult = await controller.GetStatsDownloads(null); ContentResult contentResult = (ContentResult)actionResult; JArray result = JArray.Parse(contentResult.Content); Assert.True((string)result[3]["Gallery"] == "http://nuget.org/packages/B/1.1", "unexpected content result[3].Gallery"); Assert.True((int)result[2]["Downloads"] == 5, "unexpected content result[2].Downloads"); Assert.True((string)result[1]["PackageDescription"] == "Package A Description", "unexpected content result[1].PackageDescription"); }