예제 #1
0
 public static void MyClassInitialize(TestContext testContext)
 {
     //Add test data (order specific)
     testDatabase = new TestDatabaseHelper();
     restaurant1 = testDatabase.AddRestaurant();
     menu1 = testDatabase.AddMenu(restaurant1);
     category1 = testDatabase.AddCategory();
     item1 = testDatabase.AddItem();
 }
예제 #2
0
        public static void MyClassInitialize(TestContext testContext)
        {
            testDatabase = new TestDatabaseHelper();

            //Add test data (order specific)
            restaurant1 = testDatabase.AddRestaurant();
            table1 = testDatabase.AddTable(restaurant1);
            order1 = testDatabase.AddOrder(table1);
            item1 = testDatabase.AddItem();
            category1 = testDatabase.AddCategory();
            menu1 = testDatabase.AddMenu(restaurant1);
            menuCategory1 = testDatabase.AddMenuCategory(category1, menu1);
            menuItem1 = testDatabase.AddMenuItem(item1, menuCategory1);
        }
예제 #3
0
파일: ItemOM.cs 프로젝트: pmoda/TFFCode
        public Boolean edit(item item)
        {
            ItemIM im = new ItemIM(db);
            item dbVersion = im.find(item.id);
            if (dbVersion.version == item.version)
            {
                ((IObjectContextAdapter)db).ObjectContext.Detach(dbVersion);
                db.Entry(item).State = EntityState.Modified;

                item.version = item.version + 1;
                db.SaveChanges();
                return true;
            }
            return false;
        }
예제 #4
0
        /// <summary>
        /// Creates an entry of type item in the database.
        /// </summary>
        /// <returns>The created item entry.</returns>
        public item AddItem()
        {
            //Initialise
            db = new touch_for_foodEntities();
            item testItem = new item();

            //Set Attributes
            testItem.name = "UnitTest";

            //Save
            db.items.Add(testItem);
            db.SaveChanges();
            db.Dispose();

            return testItem;
        }
예제 #5
0
        public static void MyClassInitialize(TestContext testContext)
        {
            //Add test data (order specific)
            testDatabase = new TestDatabaseHelper();
            restaurant1 = testDatabase.AddRestaurant();
            table1 = testDatabase.AddTable(restaurant1);
            user1 = testDatabase.AddUser("*****@*****.**", table1, (int)SiteRoles.Customer);
            order1 = testDatabase.AddOrder(table1);
            item1 = testDatabase.AddItem();
            category1 = testDatabase.AddCategory();
            menu1 = testDatabase.AddMenu(restaurant1);
            menuCategory1 = testDatabase.AddMenuCategory(category1, menu1);
            menuItem1 = testDatabase.AddMenuItem(item1, menuCategory1);
            orderItem1 = testDatabase.AddOrderItem(order1, menuItem1);

            //Session
            db = new touch_for_foodEntities();
            ReviewController target = new ReviewController();
            Session session = new Session(db, target);
            session.simulateLogin(user1.username, user1.password);
        }
예제 #6
0
        public static void MyClassInitialize(TestContext testContext)
        {
            testDatabase = new TestDatabaseHelper();

            //Add test data (order specific)
            item1 = testDatabase.AddItem();
            category1 = testDatabase.AddCategory();
            restaurant1 = testDatabase.AddRestaurant();
            menu1 = testDatabase.AddMenu(restaurant1);
            menuCategory1 = testDatabase.AddMenuCategory(category1, menu1);
            table1 = testDatabase.AddTable(restaurant1);
            order1 = testDatabase.AddOrder(table1);
            user1 = testDatabase.AddUser("*****@*****.**", table1, (int)SiteRoles.Admin);
            review1 = testDatabase.AddReview(restaurant1, order1, user1);
        }
예제 #7
0
 public void MyTestInitialize()
 {
     //Add test data (order specific)
     category1 = testDatabase.AddCategory();
     restaurant1 = testDatabase.AddRestaurant();
     menu1 = testDatabase.AddMenu(restaurant1);
     menuCategory1 = testDatabase.AddMenuCategory(category1, menu1);
     table1 = testDatabase.AddTable(restaurant1);
     order1 = testDatabase.AddOrder(table1);
     item1 = testDatabase.AddItem(category1);
     menuItem1 = testDatabase.AddMenuItem(item1, menuCategory1);
     orderItem1 = testDatabase.AddOrderItem(order1, menuItem1);
 }
예제 #8
0
 public ActionResult Edit(item item)
 {
     if (ModelState.IsValid)
     {
         try
         {
             if (om.edit(item))
                 return RedirectToAction("Details", "Menu_Category", new { id = HttpContext.Session["editingMenuCatId"] });
             else
             {
                 ViewBag.Error = "This record has already been updated. Please refresh and try again";
             }
         }
         catch (Exception)
         {
             ViewBag.Error = Global.ServerError;
         }
     }
     ViewBag.category_id = new SelectList(db.categories, "id", "name", item.category_id);
     return View(item);
 }
예제 #9
0
        public ActionResult Create(item item)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (om.Create(item))
                    {
                        return RedirectToAction("Index");
                    }
                }
                catch (Exception) { }
            }

            ViewBag.Error = Global.ServerError;
            ViewBag.category_id = new SelectList(db.categories, "id", "name", item.category_id);
            return View(item);
        }
예제 #10
0
        public void MyTestInitialize()
        {
            //Add test data (order specific)
            item1 = testDatabase.AddItem(category1);
            menu1 = testDatabase.AddMenu(restaurant1);
            menuCategory1 = testDatabase.AddMenuCategory(category1, menu1);

            //Session
            db = new touch_for_foodEntities();
            target = new ItemController(db);
            Session session = new Session(db, target);
            session.simulateLogin(user1.username, user1.password);
        }
예제 #11
0
        public void CreateItemTest()
        {
            //Arrange
            db = new touch_for_foodEntities();
            int numberOfTotalItemsBefore = db.items.ToList<item>().Count();
            item item2 = new item();
            item2.category_id = category1.id;

            //Act
            ActionResult actual = (ActionResult)target.Create(item2);

            //Assert
            db = new touch_for_foodEntities();
            int numberOfTotalItemsAfter = db.items.ToList<item>().Count();
            Assert.IsTrue((numberOfTotalItemsBefore + 1) == numberOfTotalItemsAfter);
        }
예제 #12
0
파일: ItemOM.cs 프로젝트: pmoda/TFFCode
 /// <summary>
 /// Write an item object to the database
 /// </summary>
 /// <param name="item">The item to be written</param>
 /// <returns>true if successful, false otherwise</returns>
 /// <exception cref="InvalidOperationException"></exception>
 public bool Create(item item)
 {
     db.items.Add(item);
     return (db.SaveChanges() == 1);
 }
예제 #13
0
 /// <summary>
 /// Remove item item from database.
 /// </summary>
 /// <param name="menuEntity">Item item to be removed.</param>
 public void RemoveItem(item itemEntity)
 {
     db = new touch_for_foodEntities();
     if (db.items.Find(itemEntity.id) != null)
     {
         db.items.Remove(db.items.Find(itemEntity.id));
         db.SaveChanges();
     }
     db.Dispose();
 }
예제 #14
0
        /// <summary>
        /// Creates an entry of type menu itemin the database.
        /// </summary>
        /// <param name="itemEntity">The item the menu item represents.</param>
        /// <param name="menuCategory">Category the menu item belongs to</param>
        /// <returns>The created menu item entry.</returns>
        public menu_item AddMenuItem(item itemEntity, menu_category menuCategory)
        {
            //Initialise
            db = new touch_for_foodEntities();
            menu_item testMenuItem = new menu_item();

            //Set Attributes
            testMenuItem.item_id = itemEntity.id;
            testMenuItem.menu_category_id = menuCategory.id;
            testMenuItem.price = new decimal(10.99);
            testMenuItem.is_active = false;

            //Save
            db.menu_item.Add(testMenuItem);
            db.SaveChanges();
            db.Dispose();

            return testMenuItem;
        }
예제 #15
0
 public void addItem(item item)
 {
     items.Add(item);
 }