Exemple #1
0
        public void Test_AddNewComp()
        {
            var options = new DbContextOptionsBuilder <StoreContext>()
                          .UseInMemoryDatabase(databaseName: "TestDb14")
                          .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 testComp = new APizzaComponent("test", item);

                context.Add <AStore>(store);
                context.Add <ItemType>(item);
                context.Add <APizzaComponent>(testComp);
                context.SaveChanges();

                RawNewComp rawTest = new RawNewComp();
                rawTest.ID       = store.StoreID;
                rawTest.ItemID   = item.TypeID;
                rawTest.ItemName = item.Name;
                rawTest.CompName = "testcomp";
                rawTest.Price    = 0;

                Assert.True(sl.AddNewComp(rawTest));
            }
        }
Exemple #2
0
 public ActionResult <bool> AddNewComp([FromBody] RawNewComp obj)
 {
     if (!ModelState.IsValid)
     {
         return(StatusCode(400, "Failed to create models"));
     }
     else
     {
         if (storeLogic.AddNewComp(obj))
         {
             return(StatusCode(201, "Successfully added new pizza component"));
         }
         else
         {
             return(StatusCode(500, "Failed to add new pizza component`"));
         }
     }
 }