protected void btnInsert_Click(object sender, EventArgs e) { foreach (GridViewRow row in gvToppings.Rows) { if (row.Cells[2].Text.ToLower().Equals(tbToppingName.Text.ToLower())) { if (!ClientScript.IsClientScriptBlockRegistered("script")) { ClientScript.RegisterStartupScript(this.GetType(), "script", "<script language = 'javascript'>alert('Topping already exists')</script>"); } return; } } if (tbToppingName.Text != String.Empty) { Topping topping = new Topping(); topping.name = tbToppingName.Text; topping.active = "yes"; using (MaryPizzaEntities ctx = new MaryPizzaEntities()) { ctx.Toppings.Add(topping); ctx.SaveChanges(); gvToppings.DataBind(); if (!ClientScript.IsClientScriptBlockRegistered("script")) { ClientScript.RegisterStartupScript(this.GetType(), "script", "<script language = 'javascript'>alert('Topping successfully created!')</script>"); } } } }
protected void btnAddTopping_Click(object sender, EventArgs e) { var ctx = new MaryPizzaEntities(); Topping newTopping = new Topping(); newTopping.name = tbToppingName.Text; newTopping.active = cbActive.Checked ? "yes" : "no"; ctx.Toppings.Add(newTopping); ctx.SaveChanges(); gvToppings.DataBind(); }
public void Can_create_instance_with_default_vaules() { var topping = new Topping(); topping.ShouldNotBeNull(); topping.Id.ShouldBe(default(int)); topping.Name.ShouldBeNull(); topping.Color.ShouldBeNull(); topping.DonutId.ShouldBe(default(int)); topping.Donut.ShouldBeNull(); }
public ActionResult <Topping> Put(Topping x) { try { repo.Update(x); return(Ok()); } catch (Exception ex) { return(StatusCode(400, ex.Message)); } }
static void Main() { try { Topping topping = new Topping("meat", 30); Console.WriteLine(topping.GetCalories()); } catch (ArgumentException e) { Console.WriteLine(e.Message); } }
public async Task DeleteByModel(Topping topping, Topping other) { await Toppings.AddMany(topping, other); await Toppings.Delete(topping); var results = (await Toppings.GetAll()).ToList(); Assert.Single(results); Assert.Contains(other, results); Assert.DoesNotContain(topping, results); }
public async Task GetManyEnumerable(List <Topping> toppings, Topping other) { await Toppings.AddMany(toppings); await Toppings.Add(other); var results = (await Toppings.GetMany(toppings.Select(t => t.Id))).ToList(); Assert.Equal(toppings.Count, results.Count); Assert.DoesNotContain(other, results); Assert.All(results, t => Assert.Contains(t, toppings)); }
public void ShouldCalculateCalories() { // Arrange var topping = new Topping(35, "veggies"); const int expectedCalories = 56; // Act var caloriesResult = topping.GetToppingCalories(); // Assert Assert.AreEqual(expectedCalories, caloriesResult); }
public async Task <IActionResult> PostTopping([FromBody] Topping topping) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.Topping.Add(topping); await _context.SaveChangesAsync(); return(CreatedAtAction("GetTopping", new { id = topping.ToppingID }, topping)); }
internal Topping Edit(Topping original) { string sql = @" UPDATE toppings SET name = @Name, kcal = @Kcal WHERE id = @Id; SELECT * FROM toppings WHERE id = @Id;"; return(_db.QueryFirstOrDefault <Topping>(sql, original)); }
private static void FacadePatternPizza() { Dough dough = new Dough(); Sauce sauce = new Sauce("Tomatto"); Topping topping = new Topping("Green Pepper"); Cheese cheese = new Cheese("white"); Oven oven = new Oven(5); PizzaFacade pizza = new PizzaFacade(dough, sauce, topping, cheese, oven); pizza.MakePizza(); }
public void ToppingMeat30() { // arrange var toppingType = "meat"; var weight = 30; // act var topping = new Topping(toppingType, weight); // assert Assert.AreEqual(72, topping.Calories); }
public void CanComputeCost() { var order1 = new Order(); var goldjalapenos = new Topping("goldjalapenos"); order1.AddToOrderItems(goldjalapenos); var actual = order1.ComputeTotalPrice(); var expected = goldjalapenos.Price; Assert.True(actual == expected); }
public void test_Repository_saveTopping() { Topping topping = new Topping { id = 1, description = "ham is good", name = "Ham" }; using (var context = new PizzaShopEntities()) { context.Toppings.Add(topping); context.SaveChanges(); } }
public Result RemoveTopping(Topping topping) { var pizzaTopping = _pizzaToppings.FirstOrDefault(pt => pt.Topping == topping); if (pizzaTopping is null) { return(Result.Fail("The topping you are trying to remove is not part of this pizza. Thats odd...")); } _pizzaToppings.Remove(pizzaTopping); return(Result.Success()); }
public static void view() { var os = OrderSingleton.Instance; var orders = os.Deserialize(); Console.WriteLine("Please enter your name:"); var input = Console.ReadLine(); foreach (Order o in orders) { if (o.Customer.Name == input) { Console.WriteLine(o.Pizzas.Count + " pizza(s): "); foreach (APizza p in o.Pizzas) { Console.Write(p.Size.Name + " pizza with " + p.Crust.Name.ToLower() + " crust and "); Topping last = p.Toppings.Last(); bool repeat; foreach (Topping t in p.Toppings) { repeat = false; var index1 = p.Toppings.IndexOf(t); foreach (Topping c in p.Toppings) { var index2 = p.Toppings.IndexOf(c); if (index1 != index2 && index2 > index1 && t.Name == c.Name) { repeat = true; } } if (!repeat) { if (t != last) { Console.Write(t.Name + ", "); } else { Console.WriteLine("and " + t.Name + " - " + p.Price); } } } } Console.WriteLine("Total Price: " + o.Price); Console.WriteLine(); } } }
public async Task Add(Topping model) { using (var transaction = _db.CreateAsyncTransactionScope()) { await _db.ExecuteAsync( "INSERT INTO toppings VALUES (@id, @name, @description, @price)", new { id = model.Id, name = model.Name, description = model.Description, price = model.Price } ); transaction.Complete(); } }
void AddTopping(Topping topping) { var hasToppingAlready = Pizza.Toppings.Any(pt => pt.Topping == topping); if (!hasToppingAlready) { Pizza.Toppings.Add(new PizzaTopping() { Topping = topping }); } }
public IActionResult Create(Topping topping) { if (ModelState.IsValid) { _db.Toppings.Add(topping); _db.SaveChanges(); return(RedirectToAction("Read")); } return(View()); }
private List <Topping> ToppingListFactory() { string lineInput = string.Empty; List <Topping> listToping = new List <Topping>(); while ((lineInput = Console.ReadLine()) != "END") { Topping topping = ToppingFactory(lineInput); listToping.Add(topping); } return(listToping); }
public void Should_Create_Instance_Of_Topping() { const decimal price = 1.1m; var sut = new Topping("Mushrooms", price); var serialize = sut.ShouldSerializePrice(); Assert.IsInstanceOf <Topping>(sut); Assert.NotNull(sut.Id); Assert.IsInstanceOf <Guid>(sut.Id); Assert.AreEqual(price, sut.Price); Assert.AreEqual(true, serialize); }
static void Main(string[] args) { try { var inputLine = Console.ReadLine(); while (inputLine != "END") { var linePerts = inputLine.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (linePerts[0] == "Dough") { var newDough = new Dough(linePerts[1], linePerts[2], double.Parse(linePerts[3])); Console.WriteLine($"{newDough.GetCalories():f2}"); } else if (linePerts[0] == "Topping") { var newTopping = new Topping(linePerts[1], double.Parse(linePerts[2])); Console.WriteLine($"{newTopping.GetCalories():f2}"); } else if (linePerts[0] == "Pizza") { var pizzaName = linePerts[1]; var numberOfToppings = int.Parse(linePerts[2]); if (numberOfToppings > 10) { Console.WriteLine("Number of toppings should be in range [0..10]."); return; } var input = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var dough = new Dough(input[1], input[2], double.Parse(input[3])); var pizza = new Pizza(pizzaName, dough); for (int i = 0; i < numberOfToppings; i++) { var lineTopingInfo = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); pizza.AddToppings(new Topping(lineTopingInfo[1], double.Parse(lineTopingInfo[2]))); } Console.WriteLine($"{pizza.Name} - {pizza.GetTotalcalories():f2} Calories."); } inputLine = Console.ReadLine(); } } catch (ArgumentException ex) { Console.WriteLine(ex.Message); } }
public void Test_AddNewPizza() { var options = new DbContextOptionsBuilder <StoreContext>() .UseInMemoryDatabase(databaseName: "TestDb16") .Options; using (var context = new StoreContext(options)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); StoreRepository storeRepo = new StoreRepository(context); StoreLogic sl = new StoreLogic(storeRepo); AStore store = new AStore(); store.Name = "Store1"; ItemType item = new ItemType("toppings"); APizzaComponent testCrust = new APizzaComponent("testcrust", item); APizzaComponent testTopping = new APizzaComponent("testtopping", item); Crust tempCrust = new Crust(store, 0, 1, testCrust); Topping tempTopping = new Topping(store, 0, 1, testTopping); context.Add <AStore>(store); context.Add <ItemType>(item); context.Add <APizzaComponent>(testCrust); context.Add <APizzaComponent>(testTopping); context.Add <Crust>(tempCrust); context.Add <Topping>(tempTopping); context.SaveChanges(); RawComp rawCrust = new RawComp(); rawCrust.ID = tempCrust.CrustID; rawCrust.Inventory = 0; rawCrust.Name = "testcrust"; rawCrust.Price = 0; RawComp rawTopping = new RawComp(); rawTopping.ID = tempTopping.ToppingID; rawTopping.Inventory = 0; rawTopping.Name = "testtopping"; rawTopping.Price = 0; RawNewPizza rawTest = new RawNewPizza(); rawTest.ID = store.StoreID; rawTest.Name = "testpizza"; rawTest.Crust = rawCrust; rawTest.AllToppings = new List <RawComp>(); rawTest.AllToppings.Add(rawTopping); Assert.True(sl.AddNewPizza(rawTest)); } }
public FakePizzaRepository() { var fakeTopping1 = new Topping { ToppingId = 255, Name = "FakeCheeseS", Size = "Small", Price = 0.90 }; var fakeTopping2 = new Topping { ToppingId = 256, Name = "FakeTomatoSauceS", Size = "Small", Price = 0.90 }; var fakeTopping3 = new Topping { ToppingId = 257, Name = "FakeCheeseM", Size = "Medium", Price = 1.00 }; var fakeTopping4 = new Topping { ToppingId = 258, Name = "FakeTomatoSauceM", Size = "Medium", Price = 1.00 }; var fakeTopping5 = new Topping { ToppingId = 259, Name = "FakeCheeseL", Size = "Large", Price = 1.10 }; var fakeTopping6 = new Topping { ToppingId = 260, Name = "FakeTomatoSauceL", Size = "Large", Price = 1.10 }; Pizzas.Add(new Pizza { PizzaId = 255, Name = "FakePizza1", Size = "Small", Price = 8.00, InMenu = true, Toppings = new List <Topping> { fakeTopping1, fakeTopping2 } }); Pizzas.Add(new Pizza { PizzaId = 256, Name = "FakePizza2", Size = "Small", Price = 8.00, InMenu = true, Toppings = new List <Topping> { fakeTopping1, fakeTopping2 } }); Pizzas.Add(new Pizza { PizzaId = 257, Name = "FakePizza3", Size = "Medium", Price = 9.00, InMenu = true, Toppings = new List <Topping> { fakeTopping3, fakeTopping4 } }); Pizzas.Add(new Pizza { PizzaId = 258, Name = "FakePizza4", Size = "Medium", Price = 9.00, InMenu = true, Toppings = new List <Topping> { fakeTopping3, fakeTopping4 } }); Pizzas.Add(new Pizza { PizzaId = 259, Name = "FakePizza5", Size = "Large", Price = 10.00, InMenu = true, Toppings = new List <Topping> { fakeTopping5, fakeTopping6 } }); Pizzas.Add(new Pizza { PizzaId = 260, Name = "FakePizza6", Size = "Large", Price = 10.00, InMenu = true, Toppings = new List <Topping> { fakeTopping5, fakeTopping6 } }); }
public void Test_ToppingType(float expected, ToppingType type) { // arrange var sut = new Topping(type); // var expected = 0.6F; // act -- part that we want to test var actual = sut.Price; // assert Assert.Equal(expected, actual); }
public void ExecuteThrowsExceptionWhenRepositoryThrows() { // Arrange var pizzaBase = new PizzaBase("Test Base", 0); var topping = new Topping("Test Topping"); var pizza = new Pizza(pizzaBase, topping); _mockPizzaFactory.Setup(x => x.GeneratePizzas()).Returns(new[] { pizza }); _mockPizzaRepository.Setup(x => x.SavePizza(It.IsAny <Pizza>())).Throws(new Exception()); // Act & Assert Assert.Throws <Exception>(() => _sut.Execute()); }
private void reStart() { loadListLoaiThucUong(); loadListThucUongByLoaiThucUongId(); loadListTopping(); drink = cbThucUong.SelectedItem as Drink; topping = cbTopping.SelectedItem as Topping; numericUpDownCountOrder.Value = 1; listTopping = new List <Topping>(); btnAddOrder.Focus(); btnThanhToan.Enabled = false; btnDatHang.Enabled = true; }
public IActionResult ToppingSelected(Topping topping) { var pizzaTopping = client.GetAllToppings().FirstOrDefault(s => s.ID == topping.ID); var sessionOrder = Utils.GetCurrentOrder(HttpContext.Session); var currentPizza = sessionOrder.Pizzas.Last(); currentPizza.Toppings.Add(pizzaTopping); Utils.SaveOrder(HttpContext.Session, sessionOrder); return(View("Index", currentPizza)); }
public List <Topping> AddToping(Topping newTopping, List <Topping> toppings) { if (toppings.Count > 10) { throw new ArgumentException("Number of toppings should be in range [0..10]."); } else { toppings.Add(newTopping); } return(toppings); }
private static void AddToppings(Pizza pizza) { string[] toppingInput; while ((toppingInput = Console.ReadLine().Split(' '))[0] != "END") { string type = toppingInput[1].ToUpper().First() + toppingInput[1].ToLower().Substring(1); Topping topping = new Topping(type, double.Parse(toppingInput[2])); pizza.AddTopping(topping); } }
public async Task <Topping> UpdateToppingAsync(int id, Topping topping) { if (!await context.Toppings.AnyAsync(t => t.Id == id)) { throw new ValueNotFoundException($"Topping with id = {id} was not found"); } topping.Id = id; context.Toppings.Update(topping); // TODO: it can only add related entities, but not delete them await context.SaveChangesAsync(); return(topping); // TODO: it doesn't return related entities }
public async Task <IActionResult> UpdateToppingAsync(Guid id, [FromBody] Topping topping) { var search = await _toppingsRepo.GetToppingAsync(id); if (search == null) { return(BadRequest()); } topping.ToppingId = id; await _toppingsRepo.UpdateToppingAsync(topping); return(NoContent()); }
public SelectableTopping(Topping topping) { _topping = topping; }
public void AddTopping(Topping topping) { Topping = topping; }