public async void UpdateAsync_ReturnsMealModified_WhenIdExist()
        {
            var meal         = GetADefaultMeal();
            var mealModified = new Meal
            {
                Id        = meal.Id,
                Name      = "newName",
                TypeId    = meal.TypeId + 1,
                UpdatedBy = "updater"
            };

            using (var context = new MSLunchesContext(GetDbOptions("UpdateAsync_ReturnsMealModified_WhenIdExist")))
            {
                await context.Meals.AddAsync(meal);

                await context.SaveChangesAsync();
            }

            Meal result = null;

            using (var context = new MSLunchesContext(GetDbOptions("UpdateAsync_ReturnsMealModified_WhenIdExist")))
            {
                var classUnderTest = new MealService(context);
                result = await classUnderTest.UpdateAsync(mealModified);
            }

            Assert.NotNull(result);
            Assert.Equal(mealModified.Id, result.Id);
            Assert.NotEqual(mealModified.UpdatedOn, result.UpdatedOn);
            Assert.Equal(mealModified.UpdatedBy, result.UpdatedBy);
            Assert.Equal(mealModified.TypeId, result.TypeId);
            Assert.Equal(mealModified.Name, result.Name);
        }
        public async Task GetAsync_ReturnsMeals()
        {
            var meal1 = GetADefaultMeal(Guid.NewGuid());
            var meal2 = GetADefaultMeal(Guid.NewGuid());

            var dbOptions = GetDbOptions("GetAsync_ReturnsMeals");

            using (var context = new MSLunchesContext(dbOptions))
            {
                context.MealTypes.Add(GetSampleMealType());
                context.Meals.Add(meal1);
                context.Meals.Add(meal2);
                context.SaveChanges();
            }

            IEnumerable <Meal> result = null;

            using (var context = new MSLunchesContext(dbOptions))
            {
                var classUnderTest = new MealService(context);
                result = await classUnderTest.GetAsync();
            }

            Assert.NotNull(result);
            Assert.Contains(result, meal => Equals(meal, meal1));
            Assert.Contains(result, meal => Equals(meal, meal2));
        }
Пример #3
0
        protected override async void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.MyMealsDetail);

            try
            {
                FindViews();
                HandleEvents();
                service = new MealService();

                MealId = Intent.Extras.GetInt("MealId");
                meal   = await service.GetMealById(MealId);

                if (meal != null)
                {
                    BindDetailView(meal);
                }
            }
            catch (Exception ex)
            {
                string err = ex.Message;
            }
        }
Пример #4
0
        public void WhenUsingAnyParamValueReturnAlwaysTheResults()
        {
            var tipCalculationService = MockRepository.GenerateStub <ITipCalculationService>();

            tipCalculationService.Stub(x => x.CalculateTip(Arg <Double> .Is.Anything, Arg <Double> .Is.Anything)).Return(115);
            var mealService = new MealService();

            mealService.TipCalculationService = tipCalculationService;
            // get tip
            Meal meal = new Meal()
            {
                Cost = 100, Tip = .15
            };
            var tip = mealService.GetTip(meal);

            Assert.IsTrue(tip == 115);

            // get nothing
            Meal meal2 = new Meal()
            {
                Cost = 222, Tip = .11
            };
            var tip2 = mealService.GetTip(meal2);

            Assert.IsTrue(tip2 == 115);
        }
Пример #5
0
        public MealPlannerViewModel(MealService mealService, FoodService _foodService, User user, DateTime d)
        {
            _mealService = mealService;
            FirstTime    = false;
            //Put each meal in a mealviewmodel

            var m = _mealService.getUserMealsByDate(user.UserID, d);

            meals = new List <MealDetailsViewModel>();
            foreach (Meal i in m)
            {
                var mealVM = new MealDetailsViewModel(_mealService, _foodService, i);
                meals.Add(mealVM);
                totalCals += mealVM.Cals;
                totalMacC += mealVM.MacC;
                totalMacF += mealVM.MacF;
                totalMacP += mealVM.MacP;
            }
            targetCals = user.TargetCals;
            targetMacF = user.TargetMacF;
            targetMacP = user.TargetMacP;
            targetMacC = user.TargetMacC;

            targetMacCTotal = Convert.ToInt32(targetCals * (targetMacC * .01)) / 4;
            targetMacPTotal = Convert.ToInt32(targetCals * (targetMacP * .01)) / 9;
            targetMacFTotal = Convert.ToInt32(targetCals * (targetMacF * .01)) / 4;


            Date = d.ToShortDateString();

            Month   = DateTimeFormatInfo.CurrentInfo.GetAbbreviatedMonthName(d.Month);
            Year    = d.Year.ToString();
            Day     = d.Day.ToString();
            DayWord = d.DayOfWeek.ToString();
        }
Пример #6
0
        public ActionResult GetMeals(long Category_Id)
        {
            MealService x = new MealService();
            var         y = x.GetMeals(Category_Id);

            return(Json(y, JsonRequestBehavior.AllowGet));
        }
Пример #7
0
        public IHttpActionResult Get()
        {
            MealService mealService = CreateMealService();
            var         meals       = mealService.GetMeals();

            return(Ok(meals));
        }
Пример #8
0
 public Response Update(Request <MealUpdate> request)
 {
     try
     {
         ValidateBaseRequest(request);
         var mealService = MealService.GetInstance();
         return(mealService.Update(request));
     }
     catch (RestaurantException ex)
     {
         return(new Response
         {
             ErrorCode = ex.ErrorCode
         });
     }
     catch (Exception e)
     {
         return(new Response
         {
             ErrorCode = new ErrorCode
             {
                 ErrorMessage = e.Message,
                 ErrorNumber = ErrorNumber.GeneralError
             }
         });
     }
 }
Пример #9
0
        public IActionResult Update(POCO.Meal m)
        {
            var        mealService       = new MealService(_genericAccess, _foodAccess, _mealAccess, _foodsInMealAccess);
            var        foodInMealService = new FoodsInMealService(_genericAccess, _foodAccess, _mealAccess, _foodsInMealAccess);
            var        foodService       = new FoodService(_genericAccess, _foodAccess);
            JsonResult mealResult;
            JsonResult foodInMealResult;

            try
            {
                var ret = mealService.update(m);
                mealResult            = Json(ret);
                mealResult.StatusCode = 200;
            }
            catch (Exception e)
            {
                mealResult            = Json(e);
                mealResult.StatusCode = 400;
            }

            try
            {
                var ret = foodInMealService.updateFoodsInMeal(m);
                foodInMealResult      = Json(ret);
                mealResult.StatusCode = 200;
            }
            catch (Exception e)
            {
                foodInMealResult            = Json(e);
                foodInMealResult.StatusCode = 400;
            }

            return(mealResult);
        }
Пример #10
0
        public void RemoveProductFromMeal()
        {
            //Arrange
            ItemInMeal  item        = new ItemInMeal(new Item(10, "", 50, 50, 50, 50, 0), 500);
            MealService mealService = new MealService();
            DayService  dayService  = new DayService();
            Meal        meal        = new Meal("Name", 10);

            meal.ProductsInMeal.Add(item);
            Day day = new Day(new DateTime(2020, 10, 10), 10);

            day.mealList    = dayService.AddDomainMealsToDay(mealService);
            day.mealList[0] = meal;
            dayService.RecalculateMacrosInMeal(meal);
            Debug.WriteLine("***************************************************************************");

            Debug.WriteLine($"MEAL Macros: {meal.TotalCarbs}, {meal.TotalFat}, {meal.TotalKcal}, {meal.TotalProtein}.");
            dayService.RecalculateMacrosInDay(day);
            Debug.WriteLine($"DAY Macros: {day.TotalCarbs}, {day.TotalFat}, {day.TotalKcal}, {day.TotalProtein}.");


            //Act
            var output = dayService.RemoveProductFromMeal(item, meal, day);

            Debug.WriteLine("***************************************************************************");

            Debug.WriteLine($"MEAL Macros: {meal.TotalCarbs}, {meal.TotalFat}, {meal.TotalKcal}, {meal.TotalProtein}.");
            Debug.WriteLine($"DAY Macros: {day.TotalCarbs}, {day.TotalFat}, {day.TotalKcal}, {day.TotalProtein}.");
            //Assert
            output.IsSameOrEqualTo(10);
            day.mealList[0].ProductsInMeal.Should().NotContain(item);
        }
Пример #11
0
        public IHttpActionResult GetByCategory(TypeofMealCategory category)
        {
            MealService mealService = CreateMealService();
            var         meal        = mealService.GetMealsByCategory(category);

            return(Ok(meal));
        }
Пример #12
0
        public MealService CreateMealService()
        {
            var userId  = Guid.Parse(User.Identity.GetUserId());
            var service = new MealService(userId);

            return(service);
        }
Пример #13
0
        public IHttpActionResult Get(int id)
        {
            MealService mealService = CreateMealService();
            var         meal        = mealService.GetMealById(id);

            return(Ok(meal));
        }
Пример #14
0
        // GET: Meal
        public ActionResult Index()
        {
            var userId = Guid.Parse(User.Identity.GetUserId());
            var model  = MealService.GetUserMeals(userId);

            return(View(model));
        }
Пример #15
0
        public ActionResult <Statistics> Get([FromServices] MealService mealService, string userId)
        {
            var        meals = mealService.GetMeals(userId);
            Statistics averageMealNutrients = statisticsService.GetAverageMealNutrients(meals);

            return(Ok(averageMealNutrients));
        }
Пример #16
0
        public void WhenUsingMockingLinqDependenciesReturnDesiredResults()
        {
            /*
             * note: when doing linq, simple create the fake list and let linq do its thing.
             */

            var meals = new List <Meal>()
            {
                new Meal()
                {
                    ServerGender = 1, ServerName = "ana", Cost = 333, Tip = .15, Id = 1, Date = new DateTime(2018, 6, 1)
                },
                new Meal()
                {
                    ServerGender = 2, ServerName = "papo", Cost = 222, Tip = .15, Id = 2, Date = new DateTime(2018, 5, 14)
                }
            };

            var session             = MockRepository.GenerateStub <ISession>();
            IQueryable <Meal> query = MockRepository.GenerateStub <IQueryable <Meal> >();

            session.Stub(s => s.Query <Meal>()).Return(meals.AsQueryable());

            var mealService = new MealService();

            mealService.Session = session;
            var todayMeals = mealService.GetMealsByGender(meals, 1);

            Assert.IsTrue(todayMeals.Count == 1);
        }
Пример #17
0
        public ActionResult DeleteMeal(int id)
        {
            MealService.Delete(id);

            TempData["SaveResult"] = "Your meal was deleted";

            return(RedirectToAction("Index"));
        }
Пример #18
0
        // GET: Meal
        public ActionResult Index()
        {
            var userID  = Guid.Parse(User.Identity.GetUserId());
            var service = new MealService(userID);
            var meal    = service.GetMeals();

            return(View(meal));
        }
Пример #19
0
        public ActionResult Edit(int id, MealViewEditModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            MealService.Update(model);
            TempData["SaveResult"] = "Your meal was updated.";
            return(RedirectToAction("Index"));
        }
Пример #20
0
        public ActionResult Edit(int id)
        {
            var userId = Guid.Parse(User.Identity.GetUserId());
            var model  = MealService.GetEditById(id);
            var dishes = DishService.GetUserDishSelectList(userId);
            var tags   = TagService.GetUserTagSelectList(userId);

            model.DishData = dishes.ToList();
            model.TagData  = tags.ToList();
            return(View(model));
        }
Пример #21
0
        public MainViewModel()
        {
            mealService = new MealService();

            MenuViewModel      = new MenuViewModel(mealService);
            ShoppingViewModel  = new ShoppingViewModel(mealService);
            RecipiesViewModel  = new RecipiesViewModel(mealService);
            FoodStoreViewModel = new FoodStoreViewModel(mealService.Context);

            LoadData();
        }
Пример #22
0
        public List <Meal> GetMeals(User user, DateTime from, DateTime to)
        {
            MealService mealService = new MealService()
            {
                User = user
            };

            List <Meal> meals = mealService.GetMeals();

            return(meals.Where((m) => { return m.Date >= from && m.Date <= to; }).ToList());
        }
        public async Task DeleteByIdAsync_ReturnsZero_WhenIdNotExist()
        {
            var result = 0;

            using (var context = new MSLunchesContext(GetDbOptions("DeleteByIdAsync_ReturnsCountOfChanges_WhenIdExist")))
            {
                var classUnderTest = new MealService(context);
                result = await classUnderTest.DeleteByIdAsync(Guid.NewGuid());
            }

            Assert.True(result == 0);
        }
Пример #24
0
        public async Task AddMeal(User user, Meal meal)
        {
            if (meal.Foods.Count > 0)
            {
                MealService mealService = new MealService()
                {
                    User = user
                };

                await mealService.AddMeal(meal);
            }
        }
Пример #25
0
        public void IsDateInRangeOK()
        {
            var start   = "2020-02-01";
            var end     = "2020-02-12";
            var toCheck = "2020-02-10";

            var startDate   = DateTime.Parse(start);
            var endDate     = DateTime.Parse(end);
            var toCheckDate = DateTime.Parse(toCheck);

            var result = MealService.IsDateInRange(startDate, endDate, toCheckDate);

            Assert.AreEqual(true, result);
        }
        public async void UpdateAsync_ReturnsNull_WhenIdNotExist()
        {
            var mealModified = GetADefaultMeal();

            Meal result = null;

            using (var context = new MSLunchesContext(GetDbOptions("UpdateAsync_ReturnsNull_WhenIdNotExist")))
            {
                var classUnderTest = new MealService(context);
                result = await classUnderTest.UpdateAsync(mealModified);
            }

            Assert.Null(result);
        }
Пример #27
0
        public async Task <bool> AddMeal([System.Web.Http.FromUri] MealDTO Request)
        {
            var File = this.Request.Files;

            if (File.Count > 0 && File[0].ContentLength > 0)
            {
                var path = Path.Combine(Server.MapPath("~/Images/"),
                                        System.IO.Path.GetFileName(File[0].FileName));
                File[0].SaveAs(path);
                Request.PictureURL = path;
            }
            MealService CurrentService = new MealService();

            return((bool)CurrentService.AddMeal(Request));
        }
Пример #28
0
        public void ValidateMealTestMissingDate()
        {
            Guid correlationId = Guid.NewGuid();

            MealModel mealModel = new MealModel()
            {
                Name       = "Test",
                Restaurant = "TestRestaurant",
            };

            var result = MealService.Validate(mealModel, correlationId, out ErrorModel errorModel);

            Assert.AreEqual(false, result);
            Assert.IsNotNull(errorModel);
        }
Пример #29
0
        public void CheckCreatingMealDetailsAsync()
        {
            var meals = new List <Meal>
            {
                new Meal
                {
                    Id                  = 1,
                    Name                = "TestName",
                    PreparationTime     = "10 mins",
                    CookingTime         = "10 mins",
                    SkillLevel          = SkillLevel.Easy,
                    PortionCount        = "6-8",
                    KCal                = 100,
                    Fat                 = 10,
                    Saturates           = 10,
                    Carbs               = 10,
                    Sugars              = 10,
                    Fibre               = 10,
                    Protein             = 10,
                    Salt                = 10,
                    Description         = "Some text for description",
                    MethodOfPreparation = "Some text for methodOfPreparation",
                    CategoryId          = 1,
                    SubCategoryId       = 1,
                    AddedByUserId       = "userId",
                    SubCategory         = new SubCategory {
                        Name = "Sub"
                    },
                },
            };

            this.mealRepository.Setup(x => x.AllAsNoTracking())
            .Returns(meals
                     .AsQueryable());

            var service = new MealService(
                this.mealRepository.Object,
                this.ingredientRepository.Object,
                this.subCategoryRepository.Object);

            AutoMapperConfig.RegisterMappings(typeof(TestMealModel).Assembly);

            var result     = service.GetMealDetails <TestMealModel>(1);
            var resultName = service.GetMealDetails <TestMealModel>(1);

            Assert.Equal(1, result.Id);
            Assert.Equal("TestName", resultName.Name);
        }
Пример #30
0
        public void GetAll_ShouldReturnAllMealsFromDatabase_WhickAreNotDeleted()
        {
            // Arrange
            var mockedEfRepository = new Mock <IEfRepository <Meal> >();
            var mockedSaveContext  = new Mock <ISaveContext>();

            mockedEfRepository.Setup(x => x.All);

            var service = new MealService(mockedEfRepository.Object, mockedSaveContext.Object);

            // Act
            var result = service.GetAll();

            // Assert
            mockedEfRepository.Verify(x => x.All, Times.Once);
        }