Exemple #1
0
        public async Task GetTableDataAllReturnsEmptyListIfItemsAreNotInCache()
        {
            //Arrange
            SetupEmptyMockCache();

            //Act
            IEnumerable <TableViewModelAll> result = await _redisCache.GetTableDataAll();

            //Assert
            Assert.AreEqual(0, result.Count());
        }
Exemple #2
0
        public async Task <IActionResult> GetResultsAll()
        {
            _logger.LogInformation("Request made to get JSON object with data for Table All page");

            //Check if data is in cache
            var resultViewModel = await _cache.GetTableDataAll();

            //Get results for all schools from database if data is not in cache
            if (resultViewModel.Count() == 0)
            {
                _logger.LogInformation("Table all data is being retrieved from the database");

                var result = await _result.GetAll(r => r.OrderBy(s => s.School.SCHNAME), r => r.School);

                //Converts from list of SchoolResult to List of TableViewModel
                resultViewModel = result.ConvertToTableViewModelAll();

                //Save list of TableViewModel data to cache
                await _cache.SaveTableDataAll(resultViewModel);
            }

            //Check if data is in cache
            var resultNatViewModel = await _cache.GetNationalTableDataAll();

            //Get the national data from database if data is not in cache
            if (resultNatViewModel == null)
            {
                _logger.LogInformation("Table national all data is being retrieved from the database");

                var nationalResultLst = await _result.GetNational();

                //Because there is only currently national data for 2019 there should only be 1 result
                var nationalResult = nationalResultLst.First();

                //Convert national SchoolResult object to a TableViewModel object
                resultNatViewModel = nationalResult;

                //Save National TableViewModel data to cache
                await _cache.SaveNationalTableDataAll(resultNatViewModel);
            }


            var data = new { data = resultViewModel, national = resultNatViewModel };

            return(Json(data));
        }