Example #1
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.Admin);
     category1 = testDatabase.AddCategory();
 }
 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();
 }
Example #3
0
        /// <summary>
        /// Is responsible for handling any modifications to category items
        /// </summary>
        /// <param name="category">Edited category</param>
        /// <returns>Boolean indicating whether the modification took effect</returns>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="InvalidOperationException"></exception>
        public Boolean edit(category category)
        {
            CategoryIM im = new CategoryIM(db);
            category dbVersion = im.find(category.id);
            if (dbVersion.version == category.version)
            {
                ((IObjectContextAdapter)db).ObjectContext.Detach(dbVersion);
                db.Entry(category).State = EntityState.Modified;

                category.version = category.version + 1;
                db.SaveChanges();
                return true;
            }
            return false;
        }
Example #4
0
        /// <summary>
        /// Adds a category entry to the database
        /// </summary>
        /// <returns>The created category entity.</returns>
        public category AddCategory()
        {
            //Initialise
            db = new touch_for_foodEntities();
            category testCategory = new category();

            //Set attributes
            testCategory.name = "UnitTest";
            testCategory.version = 0;

            //Save
            db.categories.Add(testCategory);
            db.SaveChanges();
            db.Dispose();

            return testCategory;
        }
Example #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);
        }
Example #6
0
 public void addCategory(category category)
 {
     m_category.Add(category);
 }
Example #7
0
 /// <summary>
 /// Write a category object to the database
 /// </summary>
 /// <param name="category">The category to write</param>
 /// <returns>true if successful, false otherwise.</returns>
 /// <exception cref="InvalidOperationException"></exception>
 public bool Create(category category)
 {
     db.categories.Add(category);
     return (db.SaveChanges() == 1);
 }
        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);
        }
Example #9
0
        public void MyTestInitialize()
        {
            //Add test data (order specific)
            category1 = testDatabase.AddCategory();
            category2 = testDatabase.AddCategory();
            category3 = new category();
            category3.name = "CategoryUnitTest";
            category3.version = 1;
            menuCategory1 = testDatabase.AddMenuCategory(category2, menu1);

            //Session
            target = new CategoryController();
            Session session = new Session(db, target);
        }
Example #10
0
        public void MyTestInitialize()
        {
            //Add test data (order specific)
            menu1 = testDatabase.AddMenu(restaurant1);
            category1 = testDatabase.AddCategory();
            menuCategory1 = testDatabase.AddMenuCategory(category1, menu1);

            //Session
            db = new touch_for_foodEntities();
            target = new MenuController(db);
            Session session = new Session(db, target);
            session.simulateLogin(user1.username, user1.password);
        }
Example #11
0
 public ActionResult Create(category category)
 {
     if (ModelState.IsValid && ValidateCategory(category))
     {
         try
         {
             if (om.Create(category))
             {
                 return RedirectToAction("Index");
             }
         }
         catch (Exception)
         {}
     }
     ViewBag.Error = Global.ServerError;
     return View(category);
 }
Example #12
0
 public bool ValidateCategory(category cat)
 {
     if (String.IsNullOrEmpty(cat.name))
     {
         ViewBag.Error = "Category name cannot be empty";
         return false;
     }
     return true;
 }
Example #13
0
 public ActionResult Edit(category category)
 {
     if (ModelState.IsValid)
     {
         try
         {
             if (om.edit(category))
                 return RedirectToAction("Details", "Menu", new { id = HttpContext.Session["editingMenuId"] });
             else
             {
                 ViewBag.Error = "This record has already been updated. Please refresh and try again";
                 //TODO: delete this message once viewbag implemented on client side
                 //ModelState.AddModelError("name", "This record has already been updated. Please refresh and try again");
             }
         }
         catch (Exception)
         {
             ViewBag.Error = Global.ServerError;
         }
     }
     else
     {
         ViewBag.Error = Global.ServerError;
     }
     return View(category);
 }
Example #14
0
        /// <summary>
        /// Creates an entry of type item in the database.
        /// </summary>
        /// <param name="catagoryEntity">Category that item is related to.</param>
        /// <returns>The created item entry.</returns>
        public item AddItem(category catagoryEntity)
        {
            //Initialise
            db = new touch_for_foodEntities();
            item testItem = new item();

            //Set Attributes
            testItem.name = "UnitTest";
            testItem.category_id = catagoryEntity.id;

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

            return testItem;
        }
Example #15
0
 ///<summary>
 /// Removes a bill from the database.
 /// </summary>
 /// <param name="billEntity">Bill to be removed.</param>
 public void RemoveCategory(category categoryEntity)
 {
     db = new touch_for_foodEntities();
     if (db.categories.Find(categoryEntity.id) != null)
     {
         db.categories.Remove(db.categories.Find(categoryEntity.id));
         db.SaveChanges();
     }
     db.Dispose();
 }
Example #16
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);
 }
Example #17
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);
        }
Example #18
0
        /// <summary>
        /// Creates an entry of type menu category in the database.
        /// </summary>
        /// <param name="categoryEntity">The category the menu category is an extension of</param>
        /// <param name="menuEntity">The menu the category belongs to</param>
        /// <returns>The created menu category</returns>
        public menu_category AddMenuCategory(category categoryEntity, menu menuEntity)
        {
            //Initialise
            db = new touch_for_foodEntities();
            menu_category testMenuCategory = new menu_category();

            //Set Attributes
            testMenuCategory.category_id = categoryEntity.id;
            testMenuCategory.menu_id = menuEntity.id;
            testMenuCategory.is_active = false;

            //Save
            db.menu_category.Add(testMenuCategory);
            db.SaveChanges();
            db.Dispose();

            return testMenuCategory;
        }