public async Task <IActionResult> Run(ReportCriteriaViewModel viewModel)
        {
            PageTitle = "Run the report";

            var criterion = new ReportCriterion
            {
                SiteId                = GetCurrentSiteId(),
                EndDate               = viewModel.EndDate,
                StartDate             = viewModel.StartDate,
                SystemId              = viewModel.SystemId,
                BranchId              = viewModel.BranchId,
                ProgramId             = viewModel.ProgramId,
                SchoolDistrictId      = viewModel.SchoolDistrictId,
                SchoolId              = viewModel.SchoolId,
                GroupInfoId           = viewModel.GroupInfoId,
                VendorCodeTypeId      = viewModel.VendorCodeTypeId,
                BadgeRequiredList     = viewModel.BadgeRequiredList,
                ChallengeRequiredList = viewModel.ChallengeRequiredList
            };

            var reportRequestId = await _reportService
                                  .RequestReport(criterion, viewModel.ReportId);

            var wsUrl = await _siteService.GetWsUrl(Request.Scheme, Request.Host.Value);

            return(View("Run", new RunReportViewModel
            {
                Id = reportRequestId,
                RunReportUrl = $"{wsUrl}/MissionControl/runreport/{reportRequestId}"
            }));
        }
        public async Task GetCampaignReport_ShouldReturnReport()
        {
            // Arrange
            var scopeId    = Guid.NewGuid();
            var advertiser = new Advertiser {
                AdvertiserUuid = scopeId
            };
            var model = new ReportCriteriaViewModel
            {
                ReportLevel   = ReportLevelEnum.Daily,
                ReportScope   = ReportScopeEnum.Advertiser,
                ReportScopeId = scopeId
            };
            var report = new Report <object>(new List <PerformanceData <object> >
            {
                new PerformanceData <object>()
            });

            MockUnitOfWorkRepository <Advertiser>().Setup(x => x.Queryable())
            .Returns(new[] { advertiser }.AsQueryable());
            Mock.Mock <IReportService>().Setup(x => x.GetCampaignReport(It.Is((ReportCriteria criteria) => criteria.Level == model.ReportLevel && criteria.Advertiser == advertiser)))
            .Returns(Task.FromResult((IReport)report));

            // Act
            var result = await Controller.GetCampaignReport(model);

            // Assert
            Assert.That(result, Is.Not.Null);
            Assert.That(result.TotalItemCount, Is.EqualTo(1));
            Assert.That(result.Data.First(), Is.EqualTo(report.Data.First()));
        }
Beispiel #3
0
        public async Task <ReportViewModel> GetStrategyReport([FromUri] ReportCriteriaViewModel reportCriteriaViewModel)
        {
            var reportCriteria = _mapping.Map <ReportCriteria>(reportCriteriaViewModel);

            reportCriteria.Type = ReportTypeEnum.Strategy;
            var report = await _reportService.GetStrategyReport(reportCriteria).ConfigureAwait(false);

            return(_mapping.Map <ReportViewModel>(report, reportCriteriaViewModel));
        }
        public async Task <IActionResult> Run(ReportCriteriaViewModel viewModel)
        {
            PageTitle = "Run the report";

            var siteId = GetCurrentSiteId();

            var criterion = new ReportCriterion
            {
                SiteId                = siteId,
                EndDate               = viewModel.EndDate,
                StartDate             = viewModel.StartDate,
                SystemId              = viewModel.SystemId,
                BranchId              = viewModel.BranchId,
                ProgramId             = viewModel.ProgramId,
                SchoolDistrictId      = viewModel.SchoolDistrictId,
                SchoolId              = viewModel.SchoolId,
                GroupInfoId           = viewModel.GroupInfoId,
                VendorCodeTypeId      = viewModel.VendorCodeTypeId,
                BadgeRequiredList     = viewModel.BadgeRequiredList,
                ChallengeRequiredList = viewModel.ChallengeRequiredList
            };

            if (viewModel.TriggerList?.Count > 0)
            {
                criterion.TriggerList = string.Join(",", viewModel.TriggerList);
            }

            var(IsSet, SetValue) = await _siteLookupService.GetSiteSettingIntAsync(siteId,
                                                                                   SiteSettingKey.Users.MaximumActivityPermitted);

            if (IsSet)
            {
                criterion.MaximumAllowableActivity = SetValue;
            }

            int reportRequestId = await _reportService
                                  .RequestReport(criterion, viewModel.ReportId);

            var jobToken = await _jobService.CreateJobAsync(new Job
            {
                JobType = JobType.RunReport,
                SerializedParameters = JsonConvert.SerializeObject(new JobDetailsRunReport
                {
                    ReportRequestId = reportRequestId
                })
            });

            return(View("Job", new ViewModel.MissionControl.Shared.JobViewModel
            {
                CancelUrl = Url.Action(nameof(Index)),
                JobToken = jobToken.ToString(),
                PingSeconds = 2,
                SuccessRedirectUrl = Url.Action(nameof(View), new { id = reportRequestId }),
                SuccessUrl = "",
                Title = "Loading report..."
            }));
        }
        public async Task GetAdvertiserReport_ShouldReturnReport()
        {
            // Arrange
            var scopeId    = Guid.NewGuid();
            var advertiser = new Advertiser {
                AdvertiserUuid = scopeId
            };
            var model = new ReportCriteriaViewModel
            {
                ReportLevel   = ReportLevelEnum.Daily,
                ReportScope   = ReportScopeEnum.Advertiser,
                ReportScopeId = scopeId,
                StartDate     = DateTime.Now
            };
            var report = new Report <object>(new List <PerformanceData <object> >
            {
                new PerformanceData <object>(),
                new PerformanceData <object>()
            });

            MockUnitOfWorkRepository <Advertiser>().Setup(x => x.Queryable())
            .Returns(new[] { advertiser }.AsQueryable());
            Mock.Mock <IReportService>().Setup(x => x.GetAdvertiserReport(It.Is((ReportCriteria criteria) =>
                                                                                criteria.Level == model.ReportLevel &&
                                                                                criteria.Advertiser == advertiser &&
                                                                                criteria.LocalFromDateTime == model.StartDate &&
                                                                                !criteria.LocalToDateTime.HasValue)))
            .Returns(Task.FromResult((IReport)report));

            // Act
            var result = await Controller.GetAdvertiserReport(model);

            // Assert
            Assert.That(result, Is.Not.Null);
            Assert.That(result.TotalItemCount, Is.EqualTo(2));
            var resultData   = result.Data.ToList();
            var expectedData = report.Data.ToList();

            Assert.That(resultData[0], Is.EqualTo(expectedData[0]));
            Assert.That(resultData[1], Is.EqualTo(expectedData[1]));
        }