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 ActionResult <bool> AddNewPizza([FromBody] RawNewPizza obj) { if (!ModelState.IsValid) { return(StatusCode(400, "Failed to create models")); } else { if (storeLogic.AddNewPizza(obj)) { return(StatusCode(201, "Failed to create models")); } else { return(StatusCode(500, "Failed to add pizza")); } } }