Beispiel #1
0
        /// <summary>
        /// Return the list of Meals
        /// </summary>
        /// <returns>MealList</returns>
        public async Task <IActionResult> GetMeals()
        {
            BaseResult <List <MealsViewModel> > mealResultFromCache = new BaseResult <List <MealsViewModel> >
            {
                Result = RedisCacheHelper.Instance.Get <List <MealsViewModel> >(Constants.CacheKeys.MealList)
            };

            if (mealResultFromCache.Result == null || mealResultFromCache.Result.Count == 0)
            {
                BaseResult <List <Meals> > mealResult = await iMealPlan.GetMeals().ConfigureAwait(false);

                if (mealResult.IsError && mealResult.ExceptionMessage != null)
                {
                    return(new StatusCodeResult(500));
                }
                else if (mealResult.Result == null || mealResult.Result.Count == 0)
                {
                    return(NoContent()); //204
                }
                else
                {
                    var result = MealPlanResponseMapper.MapMeal(mealResult);
                    RedisCacheHelper.Instance.Set <List <MealsViewModel> >(Constants.CacheKeys.MealList, result.Result);
                    return(Ok(result)); //200
                }
            }
            return(Ok(mealResultFromCache)); //200
        }
Beispiel #2
0
        public async Task TestGetMeals_positive_Predicate_sample()
        {
            //Arrange
            var meal = new Meals()
            {
                Id = 1, Meal = "Breakfast", IsActive = true
            };
            var baseResult = new BaseResult <List <Meals> >()
            {
                Result = new List <Meals>()
                {
                    meal
                }
            };
            var pred = new Func <Meals, bool>(x => x.IsActive && !x.IsDeleted);

            iMealsConnectionLibrary.Setup(x => x.GetListByPredicate(It.Is <Func <Meals, bool> >(y => y.GetType() == pred.GetType()))).Returns(Task.FromResult(baseResult));
            //Act
            Task <BaseResult <List <Meals> > > result = mealPlanRepository.GetMeals();

            //Assert
            Assert.IsTrue(result.Result != null);
            Assert.IsTrue(result.Result is BaseResult <List <Meals> >);
        }