public async Task GetScatterplotDataReturnsEmptyListIfItemsAreNotInCache() { //Arrange SetupEmptyMockCache(); //Act IEnumerable <ScatterplotViewModel> result = await _redisCache.GetScatterplotData(); //Assert Assert.AreEqual(0, result.Count()); }
public async Task <IActionResult> Index() { _logger.LogInformation("Request made to view Scatterplot page"); //Check if data is in cache and if so get the data from cache IEnumerable <ScatterplotViewModel> schoolLst = await _cache.GetScatterplotData(); ScatterplotViewModel national = await _cache.GetNationalScatterplotData(); //if data is not in cache get data from database and save data in cache if (schoolLst.Count() == 0) { _logger.LogInformation("Scatterplot data is being retrieved from the database"); 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 ScatterplotViewModel schoolLst = result.ConvertToScatterplotViewModel(); await _cache.SaveScatterplotData(schoolLst); } //if national data is not in cache get data from database and save data in cache if (national == null) { _logger.LogInformation("National Scatterplot data is being retrieved from the database"); var result = await _result.GetNational(r => r.School); national = result.First(); await _cache.SaveNationalScatterplotData(national); } var resultViewModel = new ScatterplotListViewModel() { schoolData = schoolLst, nationalData = national, }; return(View(resultViewModel)); }