/// <summary> /// Return the list of Markets /// </summary> /// <returns></returns> public async Task <IActionResult> GetMarkets() { BaseResult <List <MarketViewModel> > marketResultFromCache = new BaseResult <List <MarketViewModel> > { Result = RedisCacheHelper.Instance.Get <List <MarketViewModel> >(Constants.CacheKeys.MarketList) }; if (marketResultFromCache.Result == null || marketResultFromCache.Result.Count == 0) { BaseResult <List <Market> > marketResult = await iRatesCategory.GetMarkets().ConfigureAwait(false); if (marketResult.IsError && marketResult.ExceptionMessage != null) { return(new StatusCodeResult(500)); } else if (marketResult.Result == null || marketResult.Result.Count == 0) { return(NoContent()); //204 } else { var result = RatesCategoryResponseMapper.MapMarket(marketResult); RedisCacheHelper.Instance.Set <List <MarketViewModel> >(Constants.CacheKeys.MarketList, result.Result); return(Ok(result)); //200 } } return(Ok(marketResultFromCache)); //200 }
/// <summary> /// Return the list of Markets /// </summary> /// <returns></returns> public async Task <IActionResult> GetMarkets() { BaseResult <List <Market> > marketResult = await iRatesCategory.GetMarkets().ConfigureAwait(false); if (marketResult.IsError && marketResult.ExceptionMessage != null) { return(new StatusCodeResult(500)); } else if (marketResult.Result == null || marketResult.Result.Count == 0) { return(NoContent()); //204 } var result = RatesCategoryResponseMapper.MapMarket(marketResult); return(Ok(result)); //200 }
public async Task TestGetMarkets_Success_ListOfMarkets() { //Arrange var market = new Market() { Id = 1, Name = "India", IsActive = true }; var baseResult = new BaseResult <List <Market> >() { Result = new List <Market>() { market } }; var pred = new Func <Market, bool>(x => x.IsActive); iMarketLibrary.Setup(x => x.GetListByPredicate(It.Is <Func <Market, bool> >(y => y.GetType() == pred.GetType()))).Returns(Task.FromResult(baseResult)); //Act var roomList = rateCategoryRepository.GetMarkets(); //Assert Assert.IsTrue(roomList != null); Assert.IsTrue(roomList.Result is BaseResult <List <Market> >); }