本文整理汇总了C#中NuGetGallery.TestableApiController.GetStatsDownloads方法的典型用法代码示例。如果您正苦于以下问题:C# TestableApiController.GetStatsDownloads方法的具体用法?C# TestableApiController.GetStatsDownloads怎么用?C# TestableApiController.GetStatsDownloads使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NuGetGallery.TestableApiController
的用法示例。
在下文中一共展示了TestableApiController.GetStatsDownloads方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VerifyStatsDownloadsReturnsNotFoundWhenStatsNotAvailable
public async Task VerifyStatsDownloadsReturnsNotFoundWhenStatsNotAvailable()
{
var controller = new TestableApiController();
controller.MockStatisticsService.Setup(x => x.LoadDownloadPackageVersions()).Returns(Task.FromResult(StatisticsReportResult.Failed));
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");
}
示例2: VerifyRecentPopularityStatsDownloadsCount
public async Task 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(new StatisticsReport(fakePackageVersionReport, DateTime.UtcNow)));
var controller = new TestableApiController
{
StatisticsService = 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");
}
示例3: VerifyRecentPopularityStatsDownloads
public async Task 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(new StatisticsReport(fakePackageVersionReport, DateTime.UtcNow)));
var controller = new TestableApiController
{
StatisticsService = 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");
}