示例#1
0
文件: Cocina.cs 项目: jvicius/Builder
 public Pizza CocinarPizza(PizzaBuilder pizzaBuilder)
 {
     pizzaBuilder.PasoPrepararMasa();
     pizzaBuilder.PasoAñadirSalsa();
     pizzaBuilder.PasoPrepararRelleno();
     return(pizzaBuilder.ObtenerPizza());
 }
示例#2
0
 public void PreparePizza(PizzaBuilder builder)
 {
     builder.BuildBase();
     builder.BuildSauce();
     builder.BuildTopping();
     builder.BuildName();
 }
示例#3
0
        static void Main(string[] args)
        {
            var pizzaiolo = new PizzaBuilder();

            // Order 01
            pizzaiolo.CreatePizzaWithSize(Size.Medium)
            .WithCrust(Crusts.Classic)
            .WithSauce(Sauces.Barbecue)
            .AddTopping(Toppings.Pepperoni)
            .AddTopping(Toppings.GreenPeppers)
            .AddTopping(Toppings.BlackOlives);

            var pizza01 = pizzaiolo.Bake();

            Console.WriteLine(pizza01.ToString());

            // Order 02
            pizzaiolo.CreatePizzaWithSize(Size.Small)
            .WithCrust(Crusts.Thin)
            .WithSauce(Sauces.No)
            .AddTopping(Toppings.Mozzarella)
            .AddTopping(Toppings.Tomatoes);

            var pizza02 = pizzaiolo.Bake();

            Console.WriteLine(pizza02.ToString());

            Console.ReadKey();
        }
示例#4
0
        public IActionResult EditToppings(string topping, string button)
        {
            int          pn = (int)TempData.Peek("EditPizza");
            OrderBuilder ob = (OrderBuilder)TempData.Peek <Library.OrderBuilder>("OrderBuilder");

            Models.Pizza             currentP    = Models.Mapper.Map(ob.CurOrder.Pizzas[pn]);
            List <Models.Ingredient> ingredients = Models.Mapper.Map(RH.IngRepo.GetToppings()).ToList();
            List <string>            sizes       = RH.SPRepo.GetSizes().ToList();

            ob.SwitchActivePizza(pn);
            if (button.Contains("Add"))
            {
                ob.AddToppingToActivePizza(topping, RH);
            }
            else if (button.Contains("Remove"))
            {
                ob.RemoveToppingFromActivePizza(topping, RH);
            }
            ob.ActivePizza.CalculatePrice(RH.SPRepo.GetBasePrice(ob.ActivePizza.Size), RH.SPRepo.GetToppingPrice(ob.ActivePizza.Size));
            ob.CalculateTotalPrice();
            TempData.Put("OrderBuilder", ob);
            PizzaBuilder pb = new PizzaBuilder {
                P = Models.Mapper.Map(ob.ActivePizza), Ingredients = ingredients, Sizes = sizes
            };

            return(View(pb));
            //return View(nameof(OrderBuilding));
        }
示例#5
0
        private void btnConstruír_Click(object sender, EventArgs e)
        {
            PizzaBuilder builder = (PizzaBuilder)cboLineas.SelectedItem;
            Pizza        pizza   = builder.BuildPizza();

            this.lstEntregas.Items.Add(pizza);
        }
示例#6
0
 public Pizza(PizzaBuilder builder)
 {
     Size       = builder.Size;
     Salami     = builder.Salami;
     Mozzarella = builder.Mozzarella;
     Ruccola    = builder.Ruccola;
 }
        public void ReturnAPizza_WhenBakeIsCalled()
        {
            var customPizza = new PizzaBuilder();

            var actualPizza = customPizza.Bake();

            actualPizza.Should().BeOfType <Pizza>();
        }
示例#8
0
 public void Bake(PizzaBuilder pizzaBuilder)
 {
     pizzaBuilder.SetCheese();
     pizzaBuilder.SetMeat();
     pizzaBuilder.SetMushroom();
     pizzaBuilder.SetSeafood();
     pizzaBuilder.SetTomato();
 }
示例#9
0
 public void Construct(PizzaBuilder pizzaBuilder)
 {
     pizzaBuilder.SetName();
     pizzaBuilder.AddCheese();
     pizzaBuilder.AddHam();
     pizzaBuilder.Bake();
     pizzaBuilder.GetPizza();
 }
示例#10
0
 public Pizza(PizzaBuilder pizzaBuilder)
 {
     this.pizzaBuilder = pizzaBuilder;
     this._name        = pizzaBuilder.Name;
     this._masa        = pizzaBuilder.masa;
     this._salsa       = pizzaBuilder.salsa;
     this._adicionales = pizzaBuilder.adicionales;
 }
示例#11
0
        public void given_a_pizzaBuilder_build_pizza_then_we_got_a_pizza_with_low_heat()
        {
            Heat expectedHeat = Heat.Low;

            Pizza pizza = new PizzaBuilder()
                          .Build();

            Assert.IsNotNull(pizza);
            Assert.AreEqual(expectedHeat, pizza.GetHeat());
        }
示例#12
0
        public void CreateLargePizza_WhenCreatePizzaWithSizeLargeIsCalled()
        {
            var expectedPizza = new LargePizza();
            var customPizza   = new PizzaBuilder();

            customPizza.CreatePizzaWithSize(Size.Large);
            var actualPizza = customPizza.Bake();

            actualPizza.Should().BeEquivalentTo(expectedPizza);
        }
示例#13
0
 public Pizza(PizzaBuilder builder)
 {
     Size      = builder.Size;
     Cheese    = builder.Cheese;
     Sauce     = builder.Sauce;
     Pepperoni = builder.Pepperoni;
     Ham       = builder.Ham;
     Olives    = builder.Olives;
     Mushrooms = builder.Mushrooms;
 }
示例#14
0
        private static void CreatePizza(PizzaBuilder builder)
        {
            Waiter waiter = new Waiter();

            waiter.SetBuilder(builder);
            waiter.Construct();

            var pizza = waiter.GetPizza();

            Console.WriteLine($"{pizza.Type.ToString()} Pizza done with {pizza.Dough} / {pizza.Sauce} / {pizza.Topping}.");
        }
示例#15
0
        public async Task UpdatePizza_Should_Return_Ok()
        {
            //Arrange
            var request = PizzaBuilder.UpdatePizzaRequest();
            var uri     = $"{URL}/update";

            //Act
            var response = await _client.PutAsync(uri, ContentHelper.GetStringContent(request));

            // Assert
            response.EnsureSuccessStatusCode();
        }
示例#16
0
        public void given_a_pizzaBuilder_build_pizza_with_high_heat_then_we_got_a_pizza_with_high_heat()
        {
            Heat expectedHeat = Heat.High;

            var builder = new PizzaBuilder();

            builder.AddHeat(Heat.High);
            Pizza pizza = builder.Build();

            Assert.IsNotNull(pizza);
            Assert.AreEqual(expectedHeat, pizza.GetHeat());
        }
示例#17
0
        public void ReturnStringContainingPizzaSize_WhenToStringIsCalled()
        {
            var expectedString = "Medium Pizza";
            var pizzaiolo      = new PizzaBuilder();

            pizzaiolo.CreatePizzaWithSize(Size.Medium);
            var pizza = pizzaiolo.Bake();

            var result = pizza.ToString();

            result.Should().Contain(expectedString);
        }
        static void Main(string[] args)
        {
            //var bigPizza = new Pizza(30, true, true, true);

            var familyPizza = new PizzaBuilder(45)
                              .Bacon()
                              .Cheese()
                              .Build();

            var s = new StringBuilder();

            s.Append("sdada").Append("dsadas").ToString();
        }
示例#19
0
        public void CreateSmallPizzaWithSauce_WhenWithSauceIsCalled()
        {
            var sauce         = Sauces.Tomato;
            var smallPizza    = new SmallPizza();
            var expectedPizza = new SauceDecorator(smallPizza, sauce);
            var customPizza   = new PizzaBuilder();

            customPizza.CreatePizzaWithSize(Size.Small)
            .WithSauce(sauce);
            var actualPizza = customPizza.Bake();

            actualPizza.Should().BeEquivalentTo(expectedPizza);
        }
        public void ReturnExpectedPizza_WhenCreatePizzaWithSizeAndWithCrustCalled()
        {
            var expectedPizza = new Pizza {
                Size = Size.Large, Crust = Crusts.Stuffed
            };
            var customPizza = new PizzaBuilder();

            customPizza.CreatePizzaWithSize(Size.Large)
            .WithCrust(Crusts.Stuffed);
            var actualPizza = customPizza.Bake();

            actualPizza.Should().BeEquivalentTo(expectedPizza);
        }
示例#21
0
        public void CheckBuildPizzaCreatesPizzaWithExpectedIngredientsTests()
        {
            var classic = new PizzaBuilder()
                          .WithBecon()
                          .WithGarlicSauce()
                          .WithOlives()
                          .Build();

            CollectionAssert.AreEqual(
                new List <string> {
                "crunchy becon", "aromatic garlic sauce", "juicy olives"
            },
                classic.Ingredients);
        }
        public async Task GetAllPizza_Should_Return_Ok()
        {
            //Arrange
            var pizzas = PizzaBuilder.GetPizzasTest();

            //Act
            _mock.Setup(x => x.GetAll()).Returns(pizzas);
            var result = await _controller.GetAll() as OkObjectResult;

            //Assert
            result.Should().NotBeNull("Result is null.");
            result.Value.Should().BeOfType <List <PizzaModel> >($"Return type is not List<PizzaModel>");
            result.StatusCode.Should().Be(200, $"Status Code {result.StatusCode}");
        }
        public async Task GetPizza_By_Id_Should_Return_Ok()
        {
            //Arrange
            var pizza = await PizzaBuilder.GetPizzaTest();

            //Act
            _mock.Setup(x => x.GetById(pizza.Id)).Returns(pizza);
            var result = _controller.GetById(pizza.Id) as OkObjectResult;

            //Assert
            result.Should().NotBeNull("Result is null.");
            result.Value.Should().BeOfType <PizzaModel>($"Return type is not PizzaModel");
            result.StatusCode.Should().Be(200, $"Status Code {result.StatusCode}");
        }
示例#24
0
        public void given_a_pizzaBuilder_build_pizza_then_we_got_a_pizza_with_0_ingredients()
        {
            const int  expectedIngredientsCount = 0;
            string     expectedIngredientsNames = string.Empty;
            const bool expectedHasIngredients   = false;

            Pizza pizza = new PizzaBuilder()
                          .Build();

            Assert.IsNotNull(pizza);
            Assert.AreEqual(expectedIngredientsCount, pizza.GetIngredients().Count);
            Assert.AreEqual(expectedIngredientsNames, pizza.GetIngredientsNames());
            Assert.AreEqual(expectedHasIngredients, pizza.HasIngredients());
        }
示例#25
0
        public void ReturnStringContainingPizzaSizeCrustAndSauce_WhenToStringIsCalled()
        {
            var expectedString = "Medium Pizza with Classic Crust, Tomato Sauce";
            var pizzaiolo      = new PizzaBuilder();

            pizzaiolo.CreatePizzaWithSize(Size.Medium)
            .WithCrust(Crusts.Classic)
            .WithSauce(Sauces.Tomato);
            var pizza = pizzaiolo.Bake();

            var result = pizza.ToString();

            result.Should().Contain(expectedString);
        }
        public async void Update_Should_Return_Ok()
        {
            //Arrange
            var request  = PizzaBuilder.UpdatePizzaRequest();
            var response = new UpdatePizzaResponse();

            //Act
            response.SetSucess(true);
            _mock.Setup(x => x.Update(request)).Returns(response);
            var result = _controller.Update(request) as OkResult;

            //Assert
            result.Should().NotBeNull("Retorno é null");
            result.StatusCode.Should().Be(200, $"Status Code {result.StatusCode}");
        }
        public async Task Delete_Should_Return_Ok()
        {
            //Arrange
            var pizza = await PizzaBuilder.GetPizzaTest();

            var response = new DeletePizzaResponse();

            //Act
            response.SetSucess(true);
            _mock.Setup(x => x.Delete(pizza.Id)).Returns(response);
            var result = _controller.Delete(pizza.Id) as OkResult;

            //Assert
            result.Should().BeOfType <OkResult>("Tipo do resultado não é OkResult");
            result.StatusCode.Should().Be(200, $"Status Code {result.StatusCode}");
        }
示例#28
0
        public IActionResult AddNewPizza()
        {
            List <Models.Ingredient> ingredients = Models.Mapper.Map(RH.IngRepo.GetIngredients()).ToList();
            List <string>            sizes       = RH.SPRepo.GetSizes().ToList();
            OrderBuilder             ob          = ((OrderBuilder)TempData.Peek <Library.OrderBuilder>("OrderBuilder"));

            ob.StartNewPizza(sizes.First(), RH);
            TempData.Put("OrderBuilder", ob);
            Models.Pizza currentP = Models.Mapper.Map(ob.ActivePizza);
            PizzaBuilder pb       = new PizzaBuilder {
                P = currentP, Ingredients = ingredients, Sizes = sizes
            };

            TempData.Remove("EditPizza");
            return(View(nameof(EditPizza), pb));
        }
        public void ReturnExpectedPizza_WhenCreatePizzaWithSizeAndWithCrustAndWithSauceAndAddToppingCalled()
        {
            var expectedPizza = new Pizza {
                Size = Size.Large, Crust = Crusts.Stuffed, Sauce = Sauces.Tomato, Toppings = new List <Toppings> {
                    Toppings.Mushrooms
                }
            };
            var customPizza = new PizzaBuilder();

            customPizza.CreatePizzaWithSize(Size.Large)
            .WithCrust(Crusts.Stuffed)
            .WithSauce(Sauces.Tomato)
            .AddTopping(Toppings.Mushrooms);
            var actualPizza = customPizza.Bake();

            actualPizza.Should().BeEquivalentTo(expectedPizza);
        }
示例#30
0
        static void Main(string[] args)
        {
            // Set Medium size, add Sauce, add Provolone cheese, add Pepperoni, add Olives, then build.
            var pizza = new PizzaBuilder(Size.Medium)
                        .AddSauce()
                        .AddCheese(Cheese.Provolone)
                        .AddPepperoni()
                        .AddOlives()
                        .Build();

            Logging.Log(pizza);

            DateTime birthday = new DateTime(2000, 1, 1);
            int      daysOld  = (DateTime.Today - birthday).Days;

            Logging.Log($"Age is {daysOld} days old.");
        }
示例#31
0
		public void SetPizzaBuilder(PizzaBuilder pb) {
			this._pizzaBuilder = pb;
		}
示例#32
0
 public Waiter(PizzaBuilder pb)
 {
     SetPizzaBuilder(pb);
 }