public void FoodProduct_UpdateCategoryWitInvalidCategory_ShouldThrowException() { foodProduct = new FoodProduct("Bułka", category); var newCategory = new Category(String.Empty); Assert.Throws(typeof(InvalidInputException), () => foodProduct.UpdateProductCategory(newCategory)); }
public void FoodProduct_UpdateWithEmptyString_ShouldThrowException() { foodProduct = new FoodProduct("Bułka", category); Assert.Throws(typeof(InvalidInputException), () => foodProduct.UpdateProductName("")); Assert.AreEqual(foodProduct.Name, "Bułka"); }
public void FoodProduct_CreateNew_ShouldHaveDomainEvent() { foodProduct = new FoodProduct("Bułka", category); Assert.AreEqual(1, foodProduct.DomainEvents.Count); Assert.AreEqual(typeof(FoodProductAddedEvent), foodProduct.DomainEvents.ElementAt(0).GetType()); }
public async Task <ActionResult <FoodProduct> > PostFoodProduct(FoodProduct foodProduct) { _context.FoodProduct.Add(foodProduct); await _context.SaveChangesAsync(); return(CreatedAtAction("GetFoodProduct", new { id = foodProduct.FoodId }, foodProduct)); }
public async Task <IActionResult> PutFoodProduct(int id, FoodProduct foodProduct) { if (id != foodProduct.FoodId) { return(BadRequest()); } _context.Entry(foodProduct).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!FoodProductExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
private void MapWasteProductViewToModel(FoodProduct bill, Command request, string categoryId) { bill.Price = request.Price; bill.Month = request.Month; bill.Year = request.Year; bill.OrderDay = request.OrderDay; bill.CategoryId = categoryId; }
public IHttpActionResult Post(FoodProduct foodProduct) { var userId = User.Identity.GetUserId(); _shoppingListService.AddProductToUsersCurrentShoppingList(foodProduct, userId); return(Ok()); }
public void EditMeal(FoodProduct foodProduct, float amount) { Guard.Against.Null(foodProduct, nameof(foodProduct)); Guard.Against.Zero(amount, nameof(amount)); FoodProduct = foodProduct; Amount = amount; }
public void FoodProduct_UpdateName_ShouldChangeItsName() { foodProduct = new FoodProduct("Bułka", category); foodProduct.UpdateProductName("Kurczak"); Assert.AreEqual(foodProduct.Name, "Kurczak"); }
/// <summary> /// Method adds a food product in out foodProduct list /// </summary> private void AddFoodProduct() { Console.WriteLine("\nEnter the name of product:"); FoodProduct foodProduct = new FoodProduct(); foodProduct.Name = Console.ReadLine(); foodProductController.AddItem(foodProduct); foodProductList.Add(foodProduct); }
public void FoodProduct_UpdateCategory_ShouldChangeItsCategory() { foodProduct = new FoodProduct("Bułka", category); var newCategory = new Category("Warzywa"); foodProduct.UpdateProductCategory(newCategory); Assert.AreEqual(foodProduct.Category, newCategory); }
public static void UpdateStock(FoodProduct stock, string token) { using (var client = Common.HelperClient.GetClient(token)) { client.BaseAddress = new Uri(Common.Constants.BASE_URI); var putTask = client.PutAsJsonAsync <FoodProduct>(Constants.FOOD_PRODUCT + "/" + stock.FoodId, stock); putTask.Wait(); } }
public void FridgeItem_CreateNewShouldHaveDateTimeNow() { FoodProduct foodProduct = new FoodProduct("Mleko", _category); AmountValue amountValue = new AmountValue(15.3f, Unit.Grams); var fridgeItem = new FridgeItem(foodProduct.FoodProductId, "desc", amountValue); var dateTime = DateTime.Now; Assert.AreEqual(dateTime.ToShortDateString(), fridgeItem.EnteredAt.ToShortDateString()); }
public void FoodProduct_UpdateCategory_ShouldChangeItsCategoryAndName() { foodProduct = new FoodProduct("Bułka", category); var newCategory = new Category("Warzywa"); foodProduct.UpdateFoodProduct("Kurczak", newCategory); Assert.AreEqual(foodProduct.Category, newCategory); Assert.AreEqual(foodProduct.Name, "Kurczak"); }
private FoodProduct MapWasteProductViewToModel(Command command, string categoryId) { var res = new FoodProduct(); res.Month = command.Month; res.Price = command.Price; res.Year = command.Year; res.OrderDay = command.OrderDay; res.CategoryId = categoryId; return(res); }
public void FridgeItem_ConsumeWithSameAmountValue_ShouldSetIsConsumed() { FoodProduct foodProduct = new FoodProduct("Mleko", _category); AmountValue amountValue = new AmountValue(100.0f, Unit.Mililiter); FridgeItem fridgeItem = new FridgeItem(foodProduct.FoodProductId, "desc", amountValue); AmountValue amountValToConsume = new AmountValue(100.0f, Unit.Mililiter); fridgeItem.ConsumeFridgeItem(amountValToConsume); Assert.AreEqual(true, fridgeItem.IsConsumed); }
private void AssignProductsToMeal(Food meal, IEnumerable <string> products) { foreach (var product in products) { var productId = DbContext.Products.FirstOrDefault(p => p.Name == product).Id; var foodProduct = new FoodProduct { FoodId = meal.Id, ProductId = productId }; meal.FoodProducts.Add(foodProduct); } }
public void FridgeItem_UpdateItemNote_ShouldHaveNewValue() { FoodProduct foodProduct = new FoodProduct("Mleko", _category); AmountValue amountValue = new AmountValue(15.3f, Unit.Grams); var fridgeItem = new FridgeItem(foodProduct.FoodProductId, "desc", amountValue); string noteUpdated = "updatedDesc"; fridgeItem.UpdateFridgeItemNote(noteUpdated); Assert.AreEqual(fridgeItem.Note, noteUpdated); }
public async Task <Unit> Handle(AddFoodProductCommand command, CancellationToken cancellationToken) { var category = await _foodProductRepository.GetCategoryByIdAsync(command.CategoryId); var foodProduct = new FoodProduct(command.Name, category); await _foodProductRepository.AddAsync(foodProduct); await _unitOfWork.CommitAsync(cancellationToken); return(Unit.Value); }
public void FridgeItem_UpdateConsumed_ShouldThrowException() { FoodProduct foodProduct = new FoodProduct("Mleko", _category); AmountValue amountValue = new AmountValue(100.0f, Unit.Mililiter); FridgeItem fridgeItem = new FridgeItem(foodProduct.FoodProductId, "desc", amountValue); AmountValue amountValToConsume = new AmountValue(100.0f, Unit.Mililiter); fridgeItem.ConsumeFridgeItem(amountValToConsume); // first consume Assert.AreEqual(true, fridgeItem.IsConsumed); Assert.Throws(typeof(DomainException), () => fridgeItem.UpdateFridgeItemNote("updated")); }
public IActionResult Put([FromBody] FoodProduct foodProduct) { if (foodProduct != null) { using (var scope = new TransactionScope()) { _readChangeProduct.UpdateProduct(foodProduct); scope.Complete(); return(new OkResult()); } } return(new NoContentResult()); }
/// <summary> /// Method adds new ingredient to the list of ingredients in CommonMethodOfMenu /// </summary> private void AddIngredientToList() { temp = foodProductList.ElementAt(result - 1).Name; Console.WriteLine($"\nEnter the quantity of product {temp} and its measure:"); FoodProduct foodProduct = new FoodProduct(); foodProduct.Name = temp; RecipeIngredient recipeIngredient = new RecipeIngredient(); recipeIngredient.FoodProduct = foodProduct; recipeIngredient.QuantityOfFoodProduct = Console.ReadLine(); ingredients.Add(recipeIngredient); }
public async Task <FoodProduct> PutAsync(FoodProduct t) { Guard.Against.ModelStateIsInvalid(t, nameof(FoodProduct)); var foodProduct = await _foodProductRepository.GetByIdAsync(t.Id); Guard.Against.EntityNotFound(foodProduct, nameof(FoodProduct)); foodProduct.Name = t.Name; foodProduct.UnitOfMeasureId = t.UnitOfMeasureId; foodProduct.Calories = t.Calories; foodProduct.Protein = t.Protein; foodProduct.Carbohydrates = t.Carbohydrates; await _foodProductRepository.UpdateAsync(foodProduct); return(foodProduct); }
public void AddProductToUsersCurrentShoppingList(FoodProduct foodProduct, string userId) { var curShoppList = _dbContext.ShoppingLists.AsQueryable() .Where(sl => sl.UserId == userId && sl.IsCurrent) .Include(sl => sl.Products) .Single(); var dbFoodProduct = _dbContext.FoodProducts.Single(p => p.Id == foodProduct.Id); if (curShoppList.Products.All(p => p.Id != foodProduct.Id)) { curShoppList.Products.Add(dbFoodProduct); _dbContext.SaveChanges(); } }
private void UpdateStock(List <BillDetail> foods, List <BillDetail> toys, List <BillDetail> costumes) { CredentialModel credential = JsonConvert.DeserializeObject <CredentialModel>(HttpContext.Session.GetString(Constants.VM)); string token = credential.JwToken; //HTTP PUT FOOD foreach (var food in foods) { // get Current Inventory for ProductID FoodProduct stockFood = GetApiFoodProducts.GetFoodProducts().SingleOrDefault(p => p.ProductId == food.ProductId); // update stock amount stockFood.FoodAmount -= food.ProductAmount; // request update GetApiFoodProducts.UpdateStock(stockFood, token); } //HTTP PUT TOY foreach (var toy in toys) { // get Current Inventory for ProductID ToyProduct stock = GetApiToyProducts.GetToyProducts().SingleOrDefault(p => p.ProductId == toy.ProductId); // update stock amount stock.ToyAmount -= toy.ProductAmount; // request update GetApiToyProducts.UpdateStock(stock, token); } //HTTP PUT COSTUME foreach (var costume in costumes) { // get Size of billDetail string size = costume.NoteSize; // get Current Inventory for ProductID CostumeProduct stock = GetApiCostumeProducts.GetCostumeProducts().SingleOrDefault(p => p.ProductId == costume.ProductId && p.CostumeSize == costume.NoteSize); // update stock amount stock.CostumeAmountSize -= costume.ProductAmount; // request update GetApiCostumeProducts.UpdateStock(stock, token); } }
public FoodProduct DeleteById(Guid id) { FoodProduct foodProduct = new FoodProduct(); try { foodProduct = foodProducts.Where(fp => fp.Id == id).FirstOrDefault(); if (foodProduct != null) { foodProducts.Remove(foodProduct); } } catch (Exception ex) { throw ex; } return(foodProduct); }
private void CreateAmountFood(int productId) { FoodProduct food = new FoodProduct() { ProductId = productId, FoodAmount = 0, FoodExpiredDate = DateTime.MaxValue }; CredentialManage credential = JsonConvert.DeserializeObject <CredentialManage>(HttpContext.Session.GetString(Constants.VM_MANAGE)); string token = credential.JwToken; using (HttpClient client = Common.HelperClient.GetClient(token)) { client.BaseAddress = new Uri(Common.Constants.BASE_URI); var postTask = client.PostAsJsonAsync <FoodProduct>(Constants.FOOD_PRODUCT, food); postTask.Wait(); } }
private FoodProductGetAllViewItem MapFoodProductToView(FoodProduct product) { var res = new FoodProductGetAllViewItem(); res.Id = product.Id; res.CategoryId = product.CategoryId; res.CreationDate = product.CreationDate; res.Month = product.Month; res.Year = product.Year; res.Price = product.Price; res.OrderDay = product.OrderDay; res.Category = new FoodCategoryView { CreationDate = product.Category.CreationDate, Id = product.Category.Id, Name = product.Category.Name }; return(res); }
public IActionResult CancelBill(int billId) { //get credential CredentialModel credential = HttpContext.Session.GetObject <CredentialModel>(Constants.VM); //get token string token = credential.JwToken; // get bill and billdetail Bill bill = GetApiMyBills.GetBills(credential).SingleOrDefault(p => p.BillId == billId); List <BillDetailModel> billDetails = GetBills().SingleOrDefault(p => p.BillId == bill.BillId).BillDetail; // Update status for bill want to be canceled bill.IsCancel = true; UpdateBill(bill, credential); // update amount foreach (var detail in billDetails) { if (IsFood(detail.ProductId)) { FoodProduct food = GetApiFoodProducts.GetFoodProducts().SingleOrDefault(p => p.ProductId == detail.ProductId); food.FoodAmount += detail.Amount; GetApiFoodProducts.UpdateStock(food, token); } else if (IsToy(detail.ProductId)) { ToyProduct toy = GetApiToyProducts.GetToyProducts().SingleOrDefault(p => p.ProductId == detail.ProductId); toy.ToyAmount += detail.Amount; GetApiToyProducts.UpdateStock(toy, token); } else { CostumeProduct costume = GetApiCostumeProducts.GetCostumeProducts().SingleOrDefault(p => p.ProductId == detail.ProductId && p.CostumeSize == detail.NoteSize); costume.CostumeAmountSize += detail.Amount; GetApiCostumeProducts.UpdateStock(costume, token); } } return(RedirectToAction("Index")); }
public void InsertFoodProduct_Returns_AddNewProduct() { FoodProduct newFoodProduct = new FoodProduct { Id = new Guid(), Name = "Falafel", Price = (decimal)49.99, ImageUrl = "https://www.themediterraneandish.com/wp-content/uploads/2020/02/falafel-recipe-10-1024x1536.jpg", Description = "Special" }; int productCount = _foodProductRepository.GetAll().Count(); Assert.Equal(8, productCount);// Verify the expected Number pre-insert //// try saving our new product _foodProductRepository.InsertProduct(newFoodProduct); //// demand a recount productCount = _foodProductRepository.GetAll().Count; Assert.Equal(9, productCount); // Verify the expected Number post-insert }