public void Ingredients_PersistanceTest() { var compare = new CompareObjects(); compare.IgnoreObjectTypes = true; InAutoRollbackTransaction(uof => { Ingredient ing = new Ingredient { StockQuantity = 1, PricePerUnit = 0.1M, NormalWeight = 1, Name = "ING", ExtraWeight = 2, Recipies = new List<Recipe>() }; uof.Db.Ingredients.Insert(ing); uof.Db.Commit(); uof.Db.ObjectContext().DetachAll(); Ingredient ing2 = uof.Db.Ingredients.Get(ing.IngredientID); Assert.IsTrue(ing != ing2); Assert.IsTrue(compare.Compare(ing, ing2)); ing2.Name = "ING2"; uof.Db.Commit(); uof.Db.ObjectContext().DetachAll(); ing = uof.Db.Ingredients.Get(ing.IngredientID); Assert.IsTrue(ing != ing2); Assert.IsFalse(compare.Compare(ing, ing2)); }); }
public void UpdateIngredient(Ingredient ing, StockIngredientDTO dto) { if (ing.IngredientID != dto.IngredientID) return; ing.ExtraWeight = dto.ExtraWeight; ing.Name = dto.Name; ing.NormalWeight = dto.NormalWeight; ing.PricePerUnit = dto.PricePerUnit; }
public OrderSuppliesDTO ToOrderSuppliesDTO(Ingredient ing) { return new OrderSuppliesDTO() { IngredientID = ing.IngredientID, Name = ing.Name, StockQuantity = ing.StockQuantity, OrderValue = 0 }; }
public OrderIngredientDTO ToOrderIngredientDto(Ingredient ing) { return new OrderIngredientDTO { Name = ing.Name, IngredientID = ing.IngredientID, NormalWeight = ing.NormalWeight, ExtraWeight = ing.ExtraWeight, Price = ing.PricePerUnit, Quantity = ing.StockQuantity }; }
public StockIngredientDTO ToSimpleDto(Ingredient ing) { StockIngredientDTO ingDto = new StockIngredientDTO { ExtraWeight = ing.ExtraWeight, IngredientID = ing.IngredientID, Name = ing.Name, NormalWeight = ing.NormalWeight, PricePerUnit = ing.PricePerUnit, StockQuantity = ing.StockQuantity, IsPartOfRecipe = ing.Recipies != null }; return ingDto; }
public Ingredient ToEntityWithEmptyRecipies(StockIngredientDTO ing) { Ingredient ingDto = new Ingredient { ExtraWeight = ing.ExtraWeight, IngredientID = ing.IngredientID, Name = ing.Name, NormalWeight = ing.NormalWeight, PricePerUnit = ing.PricePerUnit, StockQuantity = ing.StockQuantity, Recipies = new List<Recipe>() }; return ingDto; }
public void Order_RealisationTest() { int originalQuantity = 10; int inOrderQuantity = 6; Ingredient ing = new Ingredient { StockQuantity = originalQuantity, PricePerUnit = 0.1M, NormalWeight = 1, Name = "I", ExtraWeight = 2, Recipies = new List<Recipe>() }; List<OrderIngredient> orings = new List<OrderIngredient> { new OrderIngredient{ Ingredient=ing, Quantity=inOrderQuantity} }; List<OrderDetail> od = new List<OrderDetail> { new OrderDetail{ Size = new Size{SizeValue= Size.MEDIUM}, Ingredients = orings} }; Order order = new Order { Address = "A", CustomerPhone = 123, Date = DateTime.Now, State = new State { StateValue = State.NEW }, OrderDetails = od , User = new User { Address = "A", Email = "A", Name = "B", Password = "******", Phone = 2, Rights = 2 } }; InAutoRollbackTransaction(uof => { uof.Db.Orders.Insert(order); uof.Db.Commit(); uof.Db.ObjectContext().DetachAll(); Order o = uof.Db.Orders.Get(order.OrderID); Assert.IsTrue(SetToInRealisation(o, uof)); Assert.IsTrue(o.State.StateValue == State.IN_REALISATION); Ingredient ingredient = null; foreach (var orderDet in o.OrderDetails) { foreach (var odIng in orderDet.Ingredients) { ingredient = odIng.Ingredient; } } Assert.IsTrue(ingredient.StockQuantity == originalQuantity - inOrderQuantity); o.State.StateValue = State.NEW; Assert.IsFalse(SetToInRealisation(o, uof)); foreach (var orderDet in o.OrderDetails) { foreach (var odIng in orderDet.Ingredients) { ingredient = odIng.Ingredient; } } Assert.IsTrue(ingredient.StockQuantity == originalQuantity - inOrderQuantity); }); }