/// <summary> /// Return the List of Countries /// </summary> /// <returns></returns> /// public async Task <IActionResult> GetCountries() { BaseResult <List <CountryViewModel> > countryResultFromCache = new BaseResult <List <CountryViewModel> > { Result = RedisCacheHelper.Instance.Get <List <CountryViewModel> >(Constants.CacheKeys.CountryList) }; if (countryResultFromCache.Result == null || countryResultFromCache.Result.Count == 0) { BaseResult <List <Country> > countryResult = await iMasterData.GetCountries().ConfigureAwait(false); if (countryResult.IsError && countryResult.ExceptionMessage != null) { return(new StatusCodeResult(500)); } else if (countryResult.Result == null || countryResult.Result.Count == 0) { return(NoContent()); //204 } else { var countryListVm = DbMapperMasterdata.MapCountry(countryResult, continentResultFromCache); RedisCacheHelper.Instance.Set <List <CountryViewModel> >(Constants.CacheKeys.CountryList, countryListVm.Result); return(Ok(countryListVm)); //200 } } return(Ok(countryResultFromCache)); //200 }
public async Task TestGetCountries_Success_ListOfCountries() { var country = new Country() { Id = 1, Name = "India", Code = "IND", ContinentId = 1, IsActive = true, IsDeleted = false }; var baseResult = new BaseResult <List <Country> >() { Result = new List <Country>() { country } }; var pred = new Func <Country, bool>(x => x.IsActive && !x.IsDeleted); iCountryLibrary.Setup(x => x.GetListByPredicate(It.Is <Func <Country, bool> >(y => y.GetType() == pred.GetType()))).Returns(Task.FromResult(baseResult)); //Act Task <BaseResult <List <Country> > > result = masterDataRepository.GetCountries(); //Assert Assert.IsTrue(result.Result != null); Assert.IsTrue(result.Result is BaseResult <List <Country> >); }