예제 #1
0
        public async Task GetNationalTableDataDisadvantagedReturnsEmptyObjectIfDataIsNotInCache()
        {
            //Arrange
            SetupEmptyMockCache();

            //Act
            TableViewModelDisadvantaged result = await _redisCache.GetNationalTableDataDisadvantaged();

            //Assert
            Assert.IsNull(result);
        }
예제 #2
0
        public async Task <IActionResult> GetResultsDisadvantaged()
        {
            _logger.LogInformation("Request made to get JSON object with data for Table All page");

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

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

                //Get results for all schools
                //where the percentage of disadvantaged pupils is not null
                var result = await _result.Get(
                    r => r.PTFSM6CLA1A != null,
                    r => r.OrderBy(s => s.School.SCHNAME),
                    r => r.School);

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

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

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

            //Get the national data from database if not in cache
            if (resultNatViewModel == null)
            {
                _logger.LogInformation("Table national disadvantaged 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.SaveNationalTableDataDisadvantaged(resultNatViewModel);
            }


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

            return(Json(data));
        }