public async void StatisticsHomePage_Packages_ValidateReportStructureAndAvailability() { JArray report = new JArray { new JObject { { "PackageId", "A" }, { "Downloads", 42 }, }, new JObject { { "PackageId", "B" }, { "Downloads", 64 }, } }; var fakePackageReport = report.ToString(); var fakeReportService = new Mock <IReportService>(); fakeReportService.Setup(x => x.Load("recentpopularity.json")).Returns(Task.FromResult(new StatisticsReport(fakePackageReport, DateTime.UtcNow))); var controller = new StatisticsController(new JsonStatisticsService(fakeReportService.Object)); var model = (StatisticsPackagesViewModel)((ViewResult)await controller.Packages()).Model; int sum = 0; foreach (var item in model.DownloadPackagesAll) { sum += item.Downloads; } Assert.Equal <int>(106, sum); }
public async void StatisticsHomePage_Packages_Negative_ValidateThrowOnInvalidStructure() { JArray report = new JArray { new JObject { { "Lala", "A" }, { "Downloads", 303 } } }; var fakePackageReport = "[{\"Lala\":\"A\",\"Downloads\":303}]"; var fakeReportService = new Mock <IReportService>(); fakeReportService.Setup(x => x.Load("RecentPopularity.json")).Returns(Task.FromResult(fakePackageReport)); var controller = new StatisticsController(new JsonStatisticsService(fakeReportService.Object)); bool hasException = false; try { var model = (StatisticsPackagesViewModel)((ViewResult)await controller.Packages()).Model; hasException = false; } catch (Exception) { // we don't care too much about the exact type of the exception hasException = true; } if (!hasException) { throw new Exception("this exception thrown because expected exception was not thrown"); } }
public async void StatisticsHomePage_Packages_Negative_ValidateThrowOnInvalidStructure() { var fakePackageReport = "[{\"Lala\":\"A\",\"Downloads\":303}]"; var fakeReportService = new Mock<IReportService>(); fakeReportService.Setup(x => x.Load("RecentPopularity.json")).Returns(Task.FromResult(fakePackageReport)); var controller = new StatisticsController(new JsonStatisticsService(fakeReportService.Object)); bool hasException = false; try { var model = (StatisticsPackagesViewModel)((ViewResult) await controller.Packages()).Model; hasException = false; } catch (Exception) { // we don't care too much about the exact type of the exception hasException = true; } if (!hasException) { throw new Exception("this exception thrown because expected exception was not thrown"); } }
public async void StatisticsHomePage_Packages_ValidateReportStructureAndAvailability() { var fakePackageReport = "[{\"PackageId\":\"A\",\"Downloads\":42},{\"PackageId\":\"B\",\"Downloads\":64}]"; var fakeReportService = new Mock<IReportService>(); fakeReportService.Setup(x => x.Load("RecentPopularity.json")).Returns(Task.FromResult(fakePackageReport)); var controller = new StatisticsController(new JsonStatisticsService(fakeReportService.Object)); var model = (StatisticsPackagesViewModel)((ViewResult) await controller.Packages()).Model; int sum = 0; foreach (var item in model.DownloadPackagesAll) { sum += item.Downloads; } Assert.Equal<int>(106, sum); }
public async void StatisticsHomePage_Packages_ValidateReportStructureAndAvailability() { JArray report = new JArray { new JObject { { "PackageId", "A" }, { "Downloads", 42 }, }, new JObject { { "PackageId", "B" }, { "Downloads", 64 }, } }; var fakePackageReport = report.ToString(); var fakeReportService = new Mock<IReportService>(); fakeReportService.Setup(x => x.Load("RecentPopularity.json")).Returns(Task.FromResult(new StatisticsReport(fakePackageReport, DateTime.UtcNow))); var controller = new StatisticsController(new JsonStatisticsService(fakeReportService.Object)); var model = (StatisticsPackagesViewModel)((ViewResult) await controller.Packages()).Model; int sum = 0; foreach (var item in model.DownloadPackagesAll) { sum += item.Downloads; } Assert.Equal<int>(106, sum); }