예제 #1
0
        /// <summary>
        ///  Method to map selected meals to MealPlan viewmodel
        /// </summary>
        /// <param name="mealPlanListDetail"></param>
        /// <returns></returns>
        public static BaseResult <List <MealPlanViewModel> > MapMealPlan(BaseResult <List <HotelMeal> > hotelMealList, BaseResult <List <HotelMealType> > hotelMealTypeList)
        {
            BaseResult <List <MealPlanViewModel> > mealPlanViewModelList = new BaseResult <List <MealPlanViewModel> >();
            List <MealPlanViewModel> modelList = new List <MealPlanViewModel>();

            foreach (var hotelMealItem in hotelMealList.Result)
            {
                MealPlanViewModel model = new MealPlanViewModel
                {
                    HotelId    = hotelMealItem.HotelId,
                    MealId     = hotelMealItem.MealId,
                    IsSelected = true
                };
                model.MealPlanOptions            = new MealOptionViewModel();
                model.MealPlanOptions.CurrencyId = hotelMealItem.CurrencyId;
                model.MealPlanOptions.Price      = hotelMealItem.Price;

                foreach (var hotelMealTypeItem in hotelMealTypeList.Result)
                {
                    if (hotelMealTypeItem.MealId == hotelMealItem.MealId)    //Take Cusine list of related Meal only
                    {
                        CuisineTypeViewModel cuisineTypeViewModel = new CuisineTypeViewModel
                        {
                            Id         = hotelMealTypeItem.CuisineTypeId,
                            IsSelected = true
                        };
                        model.MealPlanOptions.CuisineOptions.Add(cuisineTypeViewModel);
                    }
                }
                modelList.Add(model);
            }
            mealPlanViewModelList.Result = modelList;
            return(mealPlanViewModelList);
        }
예제 #2
0
        public void TestCreateMealPlan_Success_OKResponse()
        {
            //Arrange
            BaseResult <HotelMealType> baseResult = new BaseResult <HotelMealType>();

            baseResult.Result = new HotelMealType()
            {
                Id = 1
            };
            List <MealPlanViewModel> mealPlanViewModelList = new List <MealPlanViewModel>();

            List <CuisineTypeViewModel> cuisineTypeViewModelList = new List <CuisineTypeViewModel>();
            CuisineTypeViewModel        cuisine1 = new CuisineTypeViewModel()
            {
                Id          = 1,
                Cusine      = "Indian",
                IsSelected  = true,
                ObjectState = ObjectState.Added
            };
            CuisineTypeViewModel cuisine2 = new CuisineTypeViewModel()
            {
                Id          = 2,
                Cusine      = "Asian",
                IsSelected  = true,
                ObjectState = ObjectState.Added
            };

            cuisineTypeViewModelList.Add(cuisine1);
            cuisineTypeViewModelList.Add(cuisine2);

            MealPlanViewModel mealPlanViewModel = new MealPlanViewModel()
            {
                HotelId         = 1103,
                MealId          = 1,
                IsSelected      = true,
                ObjectState     = ObjectState.Added,
                MealPlanOptions = new MealOptionViewModel()
                {
                    CurrencyId  = 1,
                    Price       = 1000,
                    ObjectState = ObjectState.Added,
                }
            };

            mealPlanViewModel.MealPlanOptions.CuisineOptions.AddRange(cuisineTypeViewModelList);
            mealPlanViewModelList.Add(mealPlanViewModel);

            mockMealPlanRepository.Setup(x => x.SaveAndUpdateHotelMealAndMealType(It.IsAny <List <MealPlanViewModel> >(), It.IsAny <string>())).Returns(Task.FromResult(new BaseResult <HotelMealType>()
            {
                Result = baseResult.Result
            })).Verifiable();

            //Act
            var result = mockMealPlanController.CreateMealPlan(mealPlanViewModelList);

            //Assert
            mockMealPlanRepository.Verify();
            Assert.IsTrue(result.Result is OkObjectResult);
            Assert.AreEqual(((OkObjectResult)result.Result).StatusCode, 200);
        }
예제 #3
0
        public void TestCreateMealPlan_Exception_Failed_NoContentResponse()
        {
            //Arrange
            List <MealPlanViewModel> mealPlanViewModelList = new List <MealPlanViewModel>();

            List <CuisineTypeViewModel> cuisineTypeViewModelList = new List <CuisineTypeViewModel>();
            CuisineTypeViewModel        cuisine1 = new CuisineTypeViewModel()
            {
                Id          = 1,
                Cusine      = "Indian",
                IsSelected  = true,
                ObjectState = ObjectState.Added
            };
            CuisineTypeViewModel cuisine2 = new CuisineTypeViewModel()
            {
                Id          = 2,
                Cusine      = "Asian",
                IsSelected  = true,
                ObjectState = ObjectState.Added
            };

            cuisineTypeViewModelList.Add(cuisine1);
            cuisineTypeViewModelList.Add(cuisine2);

            MealPlanViewModel mealPlanViewModel = new MealPlanViewModel()
            {
                HotelId         = 1103,
                MealId          = 1,
                IsSelected      = true,
                ObjectState     = ObjectState.Added,
                MealPlanOptions = new MealOptionViewModel()
                {
                    CurrencyId  = 1,
                    Price       = 1000,
                    ObjectState = ObjectState.Added,
                }
            };

            mealPlanViewModel.MealPlanOptions.CuisineOptions.AddRange(cuisineTypeViewModelList);
            mealPlanViewModelList.Add(mealPlanViewModel);

            mockMealPlanRepository.Setup(a => a.SaveAndUpdateHotelMealAndMealType(It.IsAny <List <MealPlanViewModel> >(), It.IsAny <string>())).Returns(Task.FromResult(new BaseResult <HotelMealType> {
                Result = new HotelMealType()
            }));
            mockMealPlanRepository.Setup(a => a.SaveAndUpdateHotelMealAndMealType(It.IsAny <List <MealPlanViewModel> >(), It.IsAny <string>())).Returns(Task.FromResult(new BaseResult <HotelMealType> {
                Result = null
            })).Verifiable();

            //Act
            Task <IActionResult> actionResult = mockMealPlanController.CreateMealPlan(mealPlanViewModelList);

            //Assert
            mockMealPlanRepository.Verify();
            Assert.IsTrue(actionResult != null);
            Assert.AreEqual(((Microsoft.AspNetCore.Mvc.StatusCodeResult)actionResult.Result).StatusCode, 204);
        }
예제 #4
0
        public async Task TestSaveAndUpdateHotelMeal_Save_Failed_Error()
        {
            //Arrange
            List <MealPlanViewModel> mealPlanViewModelList = new List <MealPlanViewModel>();

            List <CuisineTypeViewModel> cuisineTypeViewModelList = new List <CuisineTypeViewModel>();
            CuisineTypeViewModel        cuisine1 = new CuisineTypeViewModel()
            {
                Id          = 1,
                Cusine      = "Indian",
                IsSelected  = true,
                ObjectState = ObjectState.Added
            };
            CuisineTypeViewModel cuisine2 = new CuisineTypeViewModel()
            {
                Id          = 2,
                Cusine      = "Asian",
                IsSelected  = true,
                ObjectState = ObjectState.Added
            };

            cuisineTypeViewModelList.Add(cuisine1);
            cuisineTypeViewModelList.Add(cuisine2);

            MealPlanViewModel mealPlanViewModel = new MealPlanViewModel()
            {
                HotelId         = 1103,
                MealId          = 1,
                IsSelected      = true,
                ObjectState     = ObjectState.Added,
                MealPlanOptions = new MealOptionViewModel()
                {
                    CurrencyId  = 1,
                    Price       = 1000,
                    ObjectState = ObjectState.Added,
                }
            };

            mealPlanViewModel.MealPlanOptions.CuisineOptions.AddRange(cuisineTypeViewModelList);
            mealPlanViewModelList.Add(mealPlanViewModel);
            iHotelMealConnectionLibrary.Setup(x => x.InsertEntity(It.IsAny <HotelMeal>())).Returns(Task.FromResult(new BaseResult <long>()
            {
                IsError          = true,
                ExceptionMessage = Helper.Common.GetMockException()
            })).Verifiable();

            //Act
            Task <BaseResult <HotelMealType> > actionResult = mealPlanRepository.SaveAndUpdateHotelMealAndMealType(mealPlanViewModelList, It.IsAny <string>());

            //Assert
            Assert.IsTrue(actionResult.Result.IsError);
            Assert.IsTrue(actionResult.Result.ExceptionMessage != null);
        }
예제 #5
0
        /// <summary>
        ///  Return the mapped CuisineType viewmodel
        /// </summary>
        /// <param name="cuisineTypeListDetail"></param>
        /// <returns></returns>
        public static BaseResult <List <CuisineTypeViewModel> > MapCuisineType(BaseResult <List <CuisineType> > cuisineTypeListDetail)
        {
            BaseResult <List <CuisineTypeViewModel> > cuisineTypeViewModelList = new BaseResult <List <CuisineTypeViewModel> >();
            List <CuisineTypeViewModel> modelList = new List <CuisineTypeViewModel>();

            foreach (var item in cuisineTypeListDetail.Result)
            {
                CuisineTypeViewModel model = new CuisineTypeViewModel
                {
                    Id     = item.Id,
                    Cusine = item.Cusine
                };
                modelList.Add(model);
            }
            cuisineTypeViewModelList.Result = modelList;
            return(cuisineTypeViewModelList);
        }
예제 #6
0
        public List <CuisineTypeViewModel> GetUserCuisineTypes()
        {
            List <CuisineTypeViewModel> data = new List <CuisineTypeViewModel>();

            foreach (var item in DataBase.Instance.Query <CuisineFilterDTO>())
            {
                var cuisineType = new CuisineTypeViewModel()
                {
                    Description = item.Description, Code = item.Code
                };
                foreach (var item2 in DataBase.Instance.Query <CuisineDTO>().Where(x => x.CuisineTypeCode == item.Code))
                {
                    cuisineType.Cuisines.Add(new CuisineViewModel()
                    {
                        Code        = item2.Code,
                        Description = item2.Description,
                        IsSelected  = DataBase.Instance.Query <CuisineSelectedDTO>().SingleOrDefault(x => x.Code == item2.Code) != null
                    });
                }
                data.Add(cuisineType);
            }

            return(data);
        }
예제 #7
0
        public async Task TestSaveAndUpdateHotelMeal_Update_ByHotelMealPredicate_Failed_Error()
        {
            //Arrange
            BaseResult <HotelMealType> baseResult = new BaseResult <HotelMealType>();

            baseResult.Result = new HotelMealType()
            {
            };
            List <MealPlanViewModel> mealPlanViewModelList = new List <MealPlanViewModel>();

            List <CuisineTypeViewModel> cuisineTypeViewModelList = new List <CuisineTypeViewModel>();
            CuisineTypeViewModel        cuisine1 = new CuisineTypeViewModel()
            {
                Id          = 1,
                Cusine      = "Indian",
                IsSelected  = true,
                ObjectState = ObjectState.Added
            };
            CuisineTypeViewModel cuisine2 = new CuisineTypeViewModel()
            {
                Id          = 2,
                Cusine      = "Asian",
                IsSelected  = true,
                ObjectState = ObjectState.Added
            };

            cuisineTypeViewModelList.Add(cuisine1);
            cuisineTypeViewModelList.Add(cuisine2);

            MealPlanViewModel mealPlanViewModel = new MealPlanViewModel()
            {
                HotelId         = 1103,
                MealId          = 1,
                IsSelected      = true,
                ObjectState     = ObjectState.Modified,
                MealPlanOptions = new MealOptionViewModel()
                {
                    CurrencyId  = 1,
                    Price       = 1000,
                    ObjectState = ObjectState.Modified,
                }
            };

            mealPlanViewModel.MealPlanOptions.CuisineOptions.AddRange(cuisineTypeViewModelList);
            mealPlanViewModelList.Add(mealPlanViewModel);

            var hotelMeal = new HotelMeal()
            {
            };
            var hotelMealbaseResult = new BaseResult <List <HotelMeal> >()
            {
                Result = new List <HotelMeal>()
                {
                    hotelMeal
                }
            };
            var pred = new Func <HotelMeal, bool>(x => x.HotelId == hotelMeal.HotelId && !x.IsDeleted);

            iHotelMealConnectionLibrary.Setup(x => x.GetListByPredicate(It.Is <Func <HotelMeal, bool> >(y => y.GetType() == pred.GetType()))).Returns(Task.FromResult(hotelMealbaseResult));

            //Act
            Task <BaseResult <HotelMealType> > actionResult = mealPlanRepository.SaveAndUpdateHotelMealAndMealType(mealPlanViewModelList, It.IsAny <string>());

            //Assert
            Assert.IsTrue(actionResult.Result.IsError);
            Assert.IsTrue(actionResult.Result.ExceptionMessage != null);
        }