public ActionResult Index() { var thisWeekLunches = LunchRepository.GetLunchesForThisWeek().ToList(); var user = UserRepository.GetUserByName(User.Identity.Name); if (user == null) { return(RedirectToAction("LogOff", "Account")); } var model = new EnrollmentModel() { MyLunches = new HashSet <Guid>(user.Enrollments.Select(e => e.EnrolledForLunchId)), Lunches = thisWeekLunches }; var userRatings = MealRepository.GetUserRatings(user.Id); var meals = MealRepository.GetAll(); var ratingModel = new RatingModel() { Meals = meals, UserRatings = userRatings.ToDictionary(m => m.RatedMealId, m => m.Rating) }; model.RatingModel = ratingModel; return(View(model)); }
public void OrderWithinNMeals(int[] mealsId) { //Arranje - cenário PrepareMeal prepareMeal = null; var leilao = new Leilao("Van Gogh", modalidade); var fulano = new Interessada("Fulano", leilao); var maria = new Interessada("Maria", leilao); leilao.IniciaPregao(); for (int i = 0; i < mealsId.Length; i++) { try { var meal = MealRepository.GetById(mealsId[i]); prepareMeal = new PrepareMeal(meal); Meal meal = MealRepository.GetById(id); var valor = ofertas[i]; } catch (Exception ex) { } } //Act - método sob teste leilao.TerminaPregao(); //Assert var valorObtido = leilao.Ganhador.Valor; Assert.Equal(valorEsperado, valorObtido); }
public void IRepositoryDeleteByTransfertObject_ShouldDelete_WhenValidTOIsProvided() { //ASSERT var options = new DbContextOptionsBuilder <MealContext>() .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name) .Options; using (var memoryCtx = new MealContext(options)) { //ARRANGE var MealToUseInTest1 = new MealTO { Id = 0, Name = new MultiLanguageString("Meal1EN", "Meal1FR", "Meal1NL"), Ingredients = new List <IngredientTO> { new IngredientTO { Id = 1, Name = new MultiLanguageString("Ingr1EN", "Ingr1FR", "Ingr1NL"), IsAllergen = false } }, Supplier = new SupplierTO { Name = "Fournisseur1" }, MealType = MealType.Sandwich }; var MealToUseInTest2 = new MealTO { Id = 0, Name = new MultiLanguageString("Meal2EN", "Meal2FR", "Meal2NL"), Ingredients = new List <IngredientTO> { new IngredientTO { Id = 2, Name = new MultiLanguageString("Ingr1EN", "Ingr1FR", "Ingr1NL"), IsAllergen = false } }, Supplier = new SupplierTO { Name = "Fournisseur1" }, MealType = MealType.Sandwich }; var mealRepository = new MealRepository(memoryCtx); //ACT mealRepository.Add(MealToUseInTest1); mealRepository.Add(MealToUseInTest2); memoryCtx.SaveChanges(); MealToUseInTest2.Id = 2; mealRepository.Remove(MealToUseInTest2); memoryCtx.SaveChanges(); var retrievedMeals = mealRepository.GetAll(); Assert.AreEqual(1, retrievedMeals.Count()); Assert.IsFalse(retrievedMeals.Any(x => x.Id == 2)); } }
public HomeService(IMapper mapper, ItemRepository itemRepository, CategoryPortionRepository categoryPortionRepository, CategoryRepository categoryRepository, MealRepository mealRepository, IngredientRepository ingredientRepository) { _mapper = mapper; _itemRepository = itemRepository; _categoryPortionRepository = categoryPortionRepository; _categoryRepository = categoryRepository; _mealRepository = mealRepository; _ingredientRepository = ingredientRepository; }
public JsonResult RateMeal(Guid mealId, double value) { var user = UserRepository.GetUserByName(User.Identity.Name); MealRepository.RateMeal(user.Id, mealId, value); var meal = MealRepository.Get(mealId); return(Json(new { rating = meal.AverageRatingRounded })); }
public ActionResult Delete(Guid id) { var mr = new MealRepository(); var model = mr.GetAll(UserController.currentUser.Id); var toDelete = model.Where(x => id.Equals(x.Id)).FirstOrDefault(); mr.DeleteMeal(toDelete); return(RedirectToAction("Meals")); }
public void OrderMealDoesNotExists() { var id = -100; var meal = MealRepository.GetById(id); Assert.Throws <System.NullReferenceException>( () => new PrepareMeal(meal) ); }
public UnitOfWork() { _dbContext = new ApplicationDbContext(); MealRepository = new MealRepository(_dbContext); CustomerRepository = new CustomerRepository(_dbContext); OrderRepository = new OrderRepository(_dbContext); StoreRepository = new StoreRepository(_dbContext); }
public void IRepositoryDeleteByTranfertObject_ShouldThrowException_WhenDeletingANonExistantMeal() { //ASSERT var options = new DbContextOptionsBuilder <MealContext>() .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name) .Options; using (var memoryCtx = new MealContext(options)) { //ARRANGE var MealToUseInTest1 = new MealTO { Id = 0, Name = new MultiLanguageString("Meal1EN", "Meal1FR", "Meal1NL"), Ingredients = new List <IngredientTO> { new IngredientTO { Id = 1, Name = new MultiLanguageString("Ingr1EN", "Ingr1FR", "Ingr1NL"), IsAllergen = false } }, Supplier = new SupplierTO { Name = "Fournisseur1" }, MealType = MealType.Sandwich }; var MealToUseInTest2 = new MealTO { Id = 0, Name = new MultiLanguageString("Meal2EN", "Meal2FR", "Meal2NL"), Ingredients = new List <IngredientTO> { new IngredientTO { Id = 2, Name = new MultiLanguageString("Ingr1EN", "Ingr1FR", "Ingr1NL"), IsAllergen = false } }, Supplier = new SupplierTO { Name = "Fournisseur1" }, MealType = MealType.Sandwich }; var mealRepository = new MealRepository(memoryCtx); //ACT mealRepository.Add(MealToUseInTest1); mealRepository.Add(MealToUseInTest2); memoryCtx.SaveChanges(); MealToUseInTest2.Id = 2; mealRepository.Remove(MealToUseInTest2); memoryCtx.SaveChanges(); //ASSERT Assert.ThrowsException <Exception>(() => mealRepository.Remove(MealToUseInTest2)); } }
public UnitOfWork(AppDbContext context) { _context = context; RestaurantRepository = new RestaurantRepository(context); MealCategoryRepository = new MealCategoryRepository(context); MealTypeRepository = new MealTypeRepository(context); MealRepository = new MealRepository(context); RestaurantCategoryRepository = new RestaurantCategoryRepository(context); AreaRepository = new AreaRepository(context); }
public void IRepositoryGetAll_ShouldRetrieveMeals_WhenCalled() { //ASSERT var options = new DbContextOptionsBuilder <MealContext>() .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name) .Options; using (var memoryCtx = new MealContext(options)) { //ARRANGE var MealToUseInTest1 = new MealTO { Id = 0, Name = new MultiLanguageString("Meal1EN", "Meal1FR", "Meal1NL"), Ingredients = new List <IngredientTO> { new IngredientTO { Id = 1, Name = new MultiLanguageString("Ingr1EN", "Ingr1FR", "Ingr1NL"), IsAllergen = false } }, Supplier = new SupplierTO { Name = "Fournisseur1" }, MealType = MealType.Sandwich }; var MealToUseInTest2 = new MealTO { Id = 0, Name = new MultiLanguageString("Meal2EN", "Meal2FR", "Meal2NL"), Ingredients = new List <IngredientTO> { new IngredientTO { Id = 2, Name = new MultiLanguageString("Ingr1EN", "Ingr1FR", "Ingr1NL"), IsAllergen = false } }, Supplier = new SupplierTO { Name = "Fournisseur1" }, MealType = MealType.Sandwich }; var mealRepository = new MealRepository(memoryCtx); //ACT mealRepository.Add(MealToUseInTest1); mealRepository.Add(MealToUseInTest2); memoryCtx.SaveChanges(); var retrievedMeals = mealRepository.GetAll(); Assert.AreEqual(2, retrievedMeals.Count()); Assert.AreEqual(1, retrievedMeals.FirstOrDefault().Id); } }
public ActionResult Calendar(string message) { var user = UserController.currentUser; ViewBag.Message = message; ViewBag.ShowLogin = false; ViewBag.ShowTitle = false; ViewBag.Name = user.Name; var cr = new CalendarRepository(); var mr = new MealRepository(); var allMeals = mr.GetAll(user.Id).OrderBy(m => m.Calories).ToList(); ViewBag.Meals = allMeals; var model = cr.GetAll(user.Id).OrderByDescending(c => c.CalendarDate); var lastCalendars = cr.GetLastTwo(user.Id); var caloriesFromMeals = allMeals.OrderBy(m => m.Calories).Select(m => m.Calories).ToList(); var similarCalories = GetSimilarCalories(caloriesFromMeals, Convert.ToInt32(user.CaloriesPerDay), Convert.ToDecimal(user.BMI)); var suggestions = new List <Meal>(); foreach (var item in similarCalories) { suggestions.Add(allMeals.Where(m => m.Calories == item).FirstOrDefault()); } if (lastCalendars.Count > 0 && allMeals.Count > 1) { var toRemove = new List <Meal>(); foreach (var item in suggestions) { if (lastCalendars.Select(lc => lc.Meal).Select(m => m.Name).ToList().Contains(item.Name)) { toRemove.Add(item); } } foreach (var item in toRemove) { suggestions.Remove(item); } } if (Convert.ToDecimal(user.BMI) < 19) { ViewBag.BMI = "Vaša težina je ispod granice normale"; } else if (Convert.ToDecimal(user.BMI) >= 19 && Convert.ToDecimal(user.BMI) <= 25) { ViewBag.BMI = "Vaša težina je u granicama normale"; } else { ViewBag.BMI = "Vaša težina je iznad granica normale"; } ViewBag.Suggestions = suggestions; return(View(model)); }
public UnitOfWork(IApplicationDbContext dbContext) { _dbContext = dbContext; Groups = new GroupRepository(_dbContext); InviteCodes = new InviteCodeRepository(_dbContext); Recipes = new RecipeRepository(_dbContext); Ingredients = new IngredientRepository(_dbContext); Meals = new MealRepository(_dbContext); Users = new ApplicationUserRepository(_dbContext); ShoppingCart = new ShoppingCartRepository(_dbContext); }
public void Arrange() { List <string> _ingredients = new List <string>(); _ingredients.Add("chicken"); _ingredients.Add("noodles"); _ingredients.Add("veggies"); _mealRepo = new MealRepository(); _meal = new Meal(FoodType.Lunch, "Chicken Soup", 5, "Noodles, chicken, and veggies", _ingredients, 12.99M); _mealRepo.AddMealsToMenu(_meal); }
private void buttonSave_Click(object sender, RoutedEventArgs e) { Meal meal = new Meal(); meal.Name = textName.Text; meal.Favourite = Favourite; meal.Notes = Notes; int id = MealRepository.AddMeal(meal); NavigationService.Navigate(new System.Uri(String.Format("/MealPage.xaml?selectedItem={0}", id), UriKind.Relative)); }
public AddOnFormLogic(IMealGroup pMealGroup) { if (pMealGroup == null) { throw new ArgumentNullException("Meal Group is null"); } _mealGroupRepository = new MealGroupRepository(); _mealRepository = new MealRepository(); _mainGroup = pMealGroup; _meals = new HashSet <IMeal>(); }
public void GetMealListTestMethod() { // Arrange MealRepository _repo = new MealRepository(); List <string> royaleIngredients = new List <string> { "double burger", "burger buns", "american cheese", "bacon", "lettuce", "tomato", "egg" }; Meal royale = new Meal(1, "Royale", "Double burger with thick-sliced American cheese, hardwood-smoked bacon,\n" + "lettuce, vine-ripened tomato, and top with a fried egg and mayonnaise.", royaleIngredients, 3.5); _repo.AddMealToList(royale); List <string> westernBBQIngredients = new List <string> { "double burger", "burger buns", "american cheese", "bacon", "onions", "barbecue sauce" }; Meal westernBBQ = new Meal(2, "Western BBQ and Bacon", "Double burger with thick-sliced American cheese, hardwood-smoked bacon,\n" + "diced and fried onions, and sweet and smoky BBQ sauce.", westernBBQIngredients, 3.8); _repo.AddMealToList(westernBBQ); List <string> grilledPortobelloIngredients = new List <string> { "double burger", "burguer buns", "swiss cheese", "onions", "garlic mayonnaise" }; Meal grilledPortobello = new Meal(3, "Grilled Portobello and Swiss Cheese", "Double burger with fresh portobello mushrooms, Swiss cheese, caramelized onions and garlic mayonnaise.", grilledPortobelloIngredients, 3.9); _repo.AddMealToList(grilledPortobello); // Act List <Meal> expected = _repo.GetMealList(); // Assert List <Meal> actual = new List <Meal>(); actual.Add(royale); actual.Add(westernBBQ); actual.Add(grilledPortobello); CollectionAssert.AreEqual(expected, actual); }
public ActionResult Meals() { var user = UserRepository.GetUserByName(User.Identity.Name); var userRatings = MealRepository.GetUserRatings(user.Id); var meals = MealRepository.GetAll(); var ratingModel = new RatingModel() { Meals = meals, UserRatings = userRatings.ToDictionary(m => m.RatedMealId, m => m.Rating) }; return(View(ratingModel)); }
public ActionResult Meals() { ViewBag.ShowLogin = false; ViewBag.ShowTitle = false; ViewBag.Name = UserController.currentUser.Name; var ir = new IngredientRepository(); var mr = new MealRepository(); ViewBag.Meals = mr.GetAll(UserController.currentUser.Id).OrderBy(m => m.Calories); var model = ir.GetAll(UserController.currentUser.Id); return(View(model)); }
public void RemoveFromList_Test() { Meal newMeal = new Meal(1, "taco", "none", "none", 2); Meal newMealTwo = new Meal(); MealRepository repo = new MealRepository(); repo.AddMealToMenu(newMeal); repo.AddMealToMenu(newMealTwo); repo.RemoveMealFromMenu(newMeal.MealNumber); int actualTwo = repo.GetMenuList().Count(); int expectedTwo = 1; Assert.AreEqual(actualTwo, expectedTwo); }
public void AddToList_Test() { //Arrange Meal newMeal = new Meal(); MealRepository repo = new MealRepository(); //Act repo.AddMealToMenu(newMeal); int actual = repo.GetMenuList().Count(); int expected = 1; //Assert Assert.AreEqual(actual, expected); }
public UnitOfWork(RestaurantModelContext context) { _context = context; Customers = new CustomerRepository(_context); Friends = new FriendRepository(_context); FriendsRating = new FriendRatingRepository(_context); Invitations = new InvitationRepository(_context); Meals = new MealRepository(_context); Reservations = new ReservationRepository(_context); ResevatedTables = new ResevatedTableRepository(_context); Restaurants = new RestaurantRepository(_context); Tables = new TableRepository(_context); Users = new UserRepository(_context); }
public ActionResult Create(FormCollection frmc) { var mealName = frmc["name"]; var recipe = frmc["recipe"]; var ir = new IngredientRepository(); var ingredients = ir.GetAll(UserController.currentUser.Id); var mealIngredients = new List <Ingredient>(); var quanitites = new List <int>(); var ingredientsQuantites = new List <MealIngredientQuantity>(); for (int i = 1; i < frmc.Count - 1; i++) { if (i % 2 != 0) { mealIngredients.Add(ingredients.Where(ing => ing.Id.ToString().Equals(frmc[i])).FirstOrDefault()); } else { int quantity; quantity = (Int32.TryParse(frmc[i], out quantity)) ? quantity : 0; quanitites.Add(quantity); } } var mr = new MealRepository(); for (int i = 0; i < mealIngredients.Count; i++) { ingredientsQuantites.Add(new MealIngredientQuantity() { CreatedByUser = UserController.currentUser.Id, IngredientId = mealIngredients.ElementAt(i).Id, IngredientName = mealIngredients.ElementAt(i).Name, IngredientCarbohydrates = mealIngredients.ElementAt(i).Carbohydrates, IngredientFat = mealIngredients.ElementAt(i).Fat, IngredientProteins = mealIngredients.ElementAt(i).Proteins, IngredientCalories = mealIngredients.ElementAt(i).Calories, Quantity = quanitites.ElementAt(i) }); } var meal = mr.Create(new Meal() { Name = mealName, CreatedByUser = UserController.currentUser.Id, MealIngredientQuantites = ingredientsQuantites, Recipe = recipe }); return(RedirectToAction("Meals")); }
public void UpdatetMealByIDTestMethod() { // Arrange MealRepository _repo = new MealRepository(); List <string> royaleIngredients = new List <string> { "double burger", "burger buns", "american cheese", "bacon", "lettuce", "tomato", "egg" }; Meal royale = new Meal(1, "Royale", "Double burger with thick-sliced American cheese, hardwood-smoked bacon,\n" + "lettuce, vine-ripened tomato, and top with a fried egg and mayonnaise.", royaleIngredients, 3.5); _repo.AddMealToList(royale); List <string> grilledPortobelloIngredients = new List <string> { "double burger", "burguer buns", "swiss cheese", "onions", "garlic mayonnaise" }; Meal grilledPortobello = new Meal(1, "Grilled Portobello and Swiss Cheese", "Double burger with fresh portobello mushrooms, Swiss cheese, caramelized onions and garlic mayonnaise.", grilledPortobelloIngredients, 3.9); // OPTION: 1 // Act bool expected = _repo.UpdateMealByID(1, grilledPortobello); // Assert bool actual = true; Assert.AreEqual(expected, actual); //// OPTION: 2 //// Assert //Assert.IsTrue(_repo.UpdateMealByID(1, grilledPortobello)); //// OPTION: 3 //// Act //_repo.UpdateMealByID(1, grilledPortobello); //// Assert //Meal expected = _repo.GetMealByID(1); //Meal actual = royale; // (it should be grilledPortobello) //Assert.AreEqual(expected, actual); }
private async Task <Option <Meal, Error> > PersistMealAsync(RegisterMeal command) { try { var entry = Mapper.Map <Meal>(command); await MealRepository.SaveAsync(entry); return(entry.Some <Meal, Error>()); } catch (Exception e) { Debug.Fail($"Something fail: {e.Message}"); return(Option.None <Meal, Error>( Error.Critical("Critical error occured while persisting the meal in the database!"))); } }
public ActionResult Create(Guid?mealId = null) { var lunchModel = new LunchModel() { LunchDate = LunchRepository.NextLunchDate(), LunchTime = TimeSpan.FromHours(12) + TimeSpan.FromMinutes(30), NumberOfPortions = 10 }; if (mealId.HasValue) { var meal = MealRepository.Get(mealId.Value); lunchModel.CookedMealId = meal.Id; lunchModel.CookedMealName = meal.Name; } return(View(lunchModel)); }
public void IRepositoryUpdate_ShouldUpdateInDb_WhenValidMealIsProvided() { var options = new DbContextOptionsBuilder <MealContext>() .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name) .Options; using (var memoryCtx = new MealContext(options)) { //ARRANGE var MealToUseInTest = new MealTO { Id = 1, Name = new MultiLanguageString("Meal1EN", "Meal1FR", "Meal1NL"), Ingredients = new List <IngredientTO> { new IngredientTO { Id = 2, Name = new MultiLanguageString("Ingr1EN", "Ingr1FR", "Ingr1NL"), IsAllergen = false } }, Supplier = new SupplierTO { Name = "Fournisseur1" }, MealType = MealType.Salad }; var mealRepository = new MealRepository(memoryCtx); //ACT mealRepository.Add(MealToUseInTest); memoryCtx.SaveChanges(); //MealToUseInTest.Id = 1; MealToUseInTest.MealType = MealType.Sandwich; mealRepository.Update(MealToUseInTest); memoryCtx.SaveChanges(); var MealToAssert = mealRepository.GetById(1); //ASSERT Assert.AreEqual(1, mealRepository.GetAll().Count()); Assert.AreEqual(1, MealToAssert.Id); Assert.AreEqual(2, MealToAssert.Ingredients.FirstOrDefault().Id); Assert.AreEqual("Meal1EN", MealToAssert.Name.English); Assert.AreEqual(MealType.Sandwich, MealToAssert.MealType); } }
protected override DinnerBooking DoPostPutDto(Client currentClient, DinnerBookingDTO dto, DinnerBooking entity, string path, object param) { if (entity == null) { entity = new DinnerBooking(); } else { if (dto.PriceHT == null) { dto.PriceHT = entity.PriceHT; } if (dto.PriceTTC == null) { dto.PriceTTC = entity.PriceTTC; } } GetMapper.Map(dto, entity); if (dto.Booking != null && dto.Booking.Id != 0) { entity.Booking = BookingService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, dto.Booking, currentClient, path); } if (dto.MealBookings != null) { MealRepository.DeleteRange(entity.MealBookings.Where(d => !dto.MealBookings.Any(x => x.Id == d.Id))); dto.MealBookings.ForEach(mealBooking => { if (entity.MealBookings.Count != 0 && mealBooking.Id != 0 && entity.MealBookings.Find(p => p.Id == mealBooking.Id) != null) { return; } MealBooking toAdd = MealBookingService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, mealBooking, currentClient, path); if (toAdd != null) { entity.MealBookings.Add(toAdd); } }); } return(entity); }
public void AddMealToListTestMethod() { // Arrange MealRepository _repo = new MealRepository(); List <string> royaleIngredients = new List <string> { "double burger", "burger buns", "american cheese", "bacon", "lettuce", "tomato", "egg" }; Meal royale = new Meal(1, "Royale", "Double burger with thick-sliced American cheese, hardwood-smoked bacon,\n" + "lettuce, vine-ripened tomato, and top with a fried egg and mayonnaise.", royaleIngredients, 3.5); // Act _repo.AddMealToList(royale); // Assert Meal expected = _repo.GetMealByID(1); // This is the info previously introduced to the repository and recovered Meal actual = royale; // This is the info introduced by hand at the top. Assert.AreEqual(expected, actual); // So, this are two differents things that are equal, so it's correct. }
public void IRepositoryGetByID_ShouldRetrieveMeal_WhenValidIdIsProvided() { //ARRANGE var options = new DbContextOptionsBuilder <MealContext>() .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name) .Options; using (var memoryCtx = new MealContext(options)) { var MealToUseInTest = new MealTO { Id = 0, Name = new MultiLanguageString("Meal1EN", "Meal1FR", "Meal1NL"), Ingredients = new List <IngredientTO> { new IngredientTO { Id = 1, Name = new MultiLanguageString("Ingr1EN", "Ingr1FR", "Ingr1NL"), IsAllergen = false } }, Supplier = new SupplierTO { Name = "Fournisseur1" }, MealType = MealType.Sandwich }; var mealRepository = new MealRepository(memoryCtx); //ACT mealRepository.Add(MealToUseInTest); memoryCtx.SaveChanges(); var retrivedMeal = mealRepository.GetById(1); //ASSERT Assert.AreEqual(1, retrivedMeal.Id); Assert.AreEqual("Meal1EN", mealRepository.GetById(1).Name.English); } }
public void Init() { ctx = EFContext.CreateContext(); repo = new MealRepository(ctx); }