Пример #1
0
        public void IndexRedirectTest()
        {
            // Setup
            A.CallTo(() => fakeReportRepository.GetJobProfileApprenticeshipVacancyReport()).Returns(GetDummyReportData(1, 2));
            A.CallTo(() => fakeWebAppContext.RequestQueryString).Returns(query);
            A.CallTo(() => fakeWebAppContext.GetCurrentQueryString(A <Dictionary <string, object> > ._)).Returns("http://url");
            query.Add("NOTctx", "something");

            // Assign
            var reportController = new ApprenticeshipVacancyReportController(fakeLoggingService, fakeReportRepository, fakeWebAppContext, fakeCachingPolicy);

            // Act
            var indexMethodCall = reportController.WithCallTo(c => c.Index());

            // Assert
            indexMethodCall.ShouldRedirectTo("http://url");
            A.CallTo(() => fakeReportRepository.GetJobProfileApprenticeshipVacancyReport()).MustNotHaveHappened();
        }
        // GET: AVReport
        public ActionResult Index()
        {
            if (webAppContext.RequestQueryString?.AllKeys.Any(k => k.Equals(CacheContextQuery, StringComparison.OrdinalIgnoreCase)) == false)
            {
                var redirectUrl = webAppContext.GetCurrentQueryString(new Dictionary <string, object> {
                    [CacheContextQuery] = Guid.NewGuid()
                });
                return(Redirect(redirectUrl));
            }

            var watch        = Stopwatch.StartNew();
            var cacheContext = webAppContext.RequestQueryString?.Get(CacheContextQuery);
            var result       = cachingPolicy.Execute(reportRepository.GetJobProfileApprenticeshipVacancyReport, CachePolicyType.AbsoluteContext, nameof(ApprenticeshipVacancyReportController), cacheContext);

            watch.Stop();
            var avvm = new JobProfileApprenticeshipVacancyReportViewModel
            {
                ReportData    = CreateReportDataView(result),
                ReportName    = $"JobProfilesAVs{DateTime.Now.ToString("ddMMyyyy")}",
                ExecutionTime = watch.Elapsed,
            };

            return(View(avvm));
        }