Exemplo n.º 1
0
        public async Task GetAutoCompleteDataReturnsEmptyListIfItemsAreNotInCache()
        {
            //Arrange
            SetupEmptyMockCache();

            //Act
            IEnumerable <AutocompleteViewModel> result = await _redisCache.GetAutoCompleteData();

            //Assert
            Assert.AreEqual(0, result.Count());
        }
        /// <summary>
        /// Get school data to use for search autocomplete functionality
        /// </summary>
        /// <returns>
        /// List of autcomplete data to use for search autocomplete functionality
        /// </returns>
        public async Task <IEnumerable <AutocompleteViewModel> > Get()
        {
            _logger.LogInformation("Executing Get method in AutoCompleteService class.");

            //Get data if the _schools list is empty
            if (_schools.Count() == 0)
            {
                //Attempt to get data from cache first
                var cacheData = await _cache.GetAutoCompleteData();

                //Get data from database if it is not in cache
                if (cacheData.Count() == 0)
                {
                    _logger.LogInformation("Autocomplete data is being retrieved from the database");

                    var schoolLst = await _result.GetAll(r => r.School);

                    _schools = schoolLst.ConvertToAutocompleteViewModel();

                    //Save data to cache for future use
                    await _cache.SaveAutoCompleteData(_schools);
                }
                else
                {
                    _schools = cacheData;
                }
            }

            return(_schools);
        }