/// <summary> /// Map DBCrust => Crust /// Uses enum to determine which crust class to return. /// </summary> /// <param name="entity"></param> /// <returns></returns> public Crust Map(DBCrust entity) { Crust crust = null; switch (entity.CRUST) { case Entities.EntityModels.CRUSTS.DEEPDISH: crust = new DeepDishCrust(); break; case Entities.EntityModels.CRUSTS.STANDARD: crust = new StandardCrust(); break; case Entities.EntityModels.CRUSTS.STUFFED: crust = new StuffedCrust(); break; case Entities.EntityModels.CRUSTS.THIN: crust = new ThinCrust(); break; default: throw new ArgumentException("Crust type not recognized. Crust could not be mapped properly"); } return(crust); }
public void Test_CrustPrice() { // arrange var sut = new StandardCrust(); // act var actual = sut.Price; // assert Assert.True(actual == 1.5m); }
public ActionResult <APizza> GetPizzaInfo(PIZZAS PIZZA, SIZES SIZE, CRUSTS CRUST, [FromQuery] List <TOPPINGS> TOPPING) { APizza pizza; ASize size; ACrust crust; List <ATopping> toppings = new List <ATopping>(); switch (SIZE) { case SIZES.SMALL: size = new SmallSize(); break; case SIZES.MEDIUM: size = new MediumSize(); break; case SIZES.LARGE: size = new LargeSize(); break; default: return(StatusCode(400, "Size not recognized")); } switch (CRUST) { case CRUSTS.DEEPDISH: crust = new DeepDishCrust(); break; case CRUSTS.STANDARD: crust = new StandardCrust(); break; case CRUSTS.STUFFED: crust = new StuffedCrust(); break; case CRUSTS.THIN: crust = new ThinCrust(); break; default: return(StatusCode(400, "Crust not recognized")); } foreach (TOPPINGS toppingEnum in TOPPING) { switch (toppingEnum) { case TOPPINGS.BACON: toppings.Add(new Bacon()); break; case TOPPINGS.CHICKEN: toppings.Add(new Chicken()); break; case TOPPINGS.EXTRACHEESE: toppings.Add(new ExtraCheese()); break; case TOPPINGS.GREENPEPPER: toppings.Add(new GreenPepper()); break; case TOPPINGS.HAM: toppings.Add(new Ham()); break; case TOPPINGS.NOCHEESE: toppings.Add(new NoCheese()); break; case TOPPINGS.PINEAPPLE: toppings.Add(new Pineapple()); break; case TOPPINGS.REDPEPPER: toppings.Add(new RedPepper()); break; case TOPPINGS.SAUSAGE: toppings.Add(new Sausage()); break; default: return(StatusCode(400, "Topping not recognized")); } } pizza = new APizza { PIZZA = PIZZA, Name = Enum.GetName <PIZZAS>(PIZZA), Crust = crust, Toppings = toppings }; switch (PIZZA) { case PIZZAS.MEAT: pizza = new MeatPizza(size); pizza.Crust = crust; pizza.Toppings = toppings; break; case PIZZAS.HAWAIIAN: pizza = new HawaiianPizza(size); pizza.Crust = crust; pizza.Toppings = toppings; break; case PIZZAS.VEGAN: pizza = new VeganPizza(size); pizza.Crust = crust; pizza.Toppings = toppings; break; case PIZZAS.CUSTOM: pizza = new CustomPizza(crust, size, toppings); break; default: return(StatusCode(400, "Size not recognized")); } pizza.CalculatePrice(); return(Ok(pizza)); }