Пример #1
0
 public static void MyClassCleanup()
 {
     touch_for_foodEntities db = new touch_for_foodEntities();
     review r = db.reviews.Find(m_review.id);
     db.reviews.Remove(r);
     db.SaveChanges();
     db.Dispose();
 }
Пример #2
0
        public static void MyClassInitialize(TestContext testContext)
        {
            touch_for_foodEntities db = new touch_for_foodEntities();
            m_review = new review();
            m_review.restaurant_id = db.restaurants.First().id;
            m_review.rating = 1;
            m_review.is_anonymous = true;

            db.reviews.Add(m_review);
            db.SaveChanges();
            db.Dispose();
        }
Пример #3
0
        /// <summary>
        /// Creates a friendship entity
        /// </summary>
        /// <param name="user1">The first user in the friendship</param>
        /// <param name="user2">The second user in the friendship</param>
        /// <returns>the created friendship entity</returns>
        public friendship AddFriendship(user user1, user user2)
        {
            //Initialise
            db = new touch_for_foodEntities();
            friendship testFriendship = new friendship();

            //Set Attributes
            testFriendship.first_user = user1.id;
            testFriendship.second_user = user2.id;

            //Save
            db.friendships.Add(testFriendship);
            db.SaveChanges();
            db.Dispose();

            return testFriendship;
        }
Пример #4
0
        public void DeleteItemActiveExceptionTest()
        {
            //Arrange
            db = new touch_for_foodEntities();
            MenuItemOM target = new MenuItemOM(db);
            menuItem1.is_active = true;
            db.Entry(menuItem1).State = EntityState.Modified;
            db.SaveChanges();

            //Act
            int actual = target.delete(menuItem1.id);

            //Assert
            db = new touch_for_foodEntities();
            Assert.IsFalse(db.menu_item.Find(menuItem1.id).is_deleted);
            Assert.IsNotNull(db.order_item.Find(orderItem1.id));
        }
Пример #5
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;
        }
Пример #6
0
        public void DeleteItemActiveExceptionTest()
        {
            //Arrange
            db = new touch_for_foodEntities();
            OrderOM target = new OrderOM(db);
            orderItem1.order_item_status = (int)OrderStatusHelper.OrderItemStatusEnum.PROCESSING;
            db.Entry(orderItem1).State = EntityState.Modified;
            db.SaveChanges();

            //Act
            int actual = target.delete(order1.id);

            //Assert
            db = new touch_for_foodEntities();
            Assert.IsFalse(db.orders.Find(order1.id).order_status ==
                (int)OrderStatusHelper.OrderStatusEnum.DELETED);
            Assert.IsFalse(db.order_item.Find(orderItem1.id).order_item_status ==
                (int)OrderStatusHelper.OrderItemStatusEnum.DELETED);
        }
Пример #7
0
        public void DeleteConfirmedActiveExceptionTest()
        {
            //Arrange
            db = new touch_for_foodEntities();
            item item1 = testDatabase.AddItem();
            menu_item menuItem1 = testDatabase.AddMenuItem(item1, menuCategory1);
            //make menu active
            menu1.is_active = true;
            db.Entry(menu1).State = EntityState.Modified;
            db.SaveChanges();

            //Act
            ActionResult actual = (ActionResult)target.DeleteConfirmed(menu1.id);

            //Assert
            db = new touch_for_foodEntities();
            Assert.IsFalse(db.menus.Find(menu1.id).is_deleted);
            Assert.IsFalse(db.menu_category.Find(menuCategory1.id).is_deleted);
            Assert.IsFalse(db.menu_item.Find(menuItem1.id).is_deleted);

            //Clean-up (order specific)
            testDatabase.RemoveMenuItem(menuItem1);
            testDatabase.RemoveItem(item1);
        }
Пример #8
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;
        }
Пример #9
0
        public void DeleteActiveMenuWarningTest()
        {
            //Arrange
            db = new touch_for_foodEntities();
            testDatabase.RemoveMenuCategory(menuCategory1);
            menu1.is_active= true;
            db.Entry(menu1).State = EntityState.Modified;
            db.SaveChanges();

            //Act
            ViewResult actual = (ViewResult)target.Delete(menu1.id);

            //Assert
            string actualWarning = actual.ViewBag.Warning;
            Assert.IsFalse(String.IsNullOrWhiteSpace(actualWarning));
            menu actualMenu = (menu)actual.ViewData.Model;
            Assert.AreEqual(actualMenu.id, menu1.id);
        }
Пример #10
0
 /// <summary>
 /// Removes a waiter item from the database.
 /// </summary>
 /// <param name="waiterEntity">The waiter to be removed</param>
 public void RemoveWaiter(waiter waiterEntity)
 {
     db = new touch_for_foodEntities();
     if (db.waiters.Find(waiterEntity.id) != null)
     {
         db.waiters.Remove(db.waiters.Find(waiterEntity.id));
         db.SaveChanges();
     }
     db.Dispose();
 }
Пример #11
0
        /// <summary>
        /// Adds a bill entry to the database
        /// </summary>
        /// <param name="orderEntity">The associated order</param>
        /// <returns>The created bill entity.</returns>
        internal bill AddBill(order orderEntity)
        {
            //Initialise
            db = new touch_for_foodEntities();
            bill testBill = new bill();

            //Set attributes
            testBill.order_id = orderEntity.id;
            testBill.is_deleted = false;

            //Save
            db.bills.Add(testBill);
            db.SaveChanges();
            db.Dispose();

            return testBill;
        }
Пример #12
0
 /// <summary>
 /// Remove menu item from database.
 /// </summary>
 /// <param name="menuCategoryEntity">Menu Category item to be removed.</param>
 public void RemoveMenuCategory(menu_category menuCategoryEntity)
 {
     db = new touch_for_foodEntities();
     if (db.menu_category.Find(menuCategoryEntity.id) != null)
     {
         db.menu_category.Remove(db.menu_category.Find(menuCategoryEntity.id));
         db.SaveChanges();
     }
     db.Dispose();
 }
Пример #13
0
 /// <summary>
 /// Removes a table item from the database.
 /// </summary>
 /// <param name="tableEntity">The table to be removed.</param>
 public void RemoveTable(table tableEntity)
 {
     db = new touch_for_foodEntities();
     if (db.tables.Find(tableEntity.id) != null)
     {
         db.tables.Remove(db.tables.Find(tableEntity.id));
         db.SaveChanges();
     }
     db.Dispose();
 }
Пример #14
0
        public void DeleteConfirmedTest()
        {
            //Setup
            db = new touch_for_foodEntities();
            user1.current_table_id = null;
            db.Entry(user1).State = EntityState.Modified;
            db.SaveChanges();

            //CheckSetup
            Assert.IsFalse(db.restaurants.Find(restaurant1.id).is_deleted);
            Assert.IsNotNull(db.tables.Find(table1.id));
            Assert.IsNotNull(db.restaurant_user.Find(restaurantUser1.id).restaurant_id);
            Assert.IsFalse(db.menus.Find(menu1.id).is_deleted);
            Assert.IsNotNull(db.reviews.Find(review1.id));

            //Act
            var actual = target.DeleteConfirmed(restaurant1.id);

            //Assert
            db = new touch_for_foodEntities();
            Assert.IsTrue(db.restaurants.Find(restaurant1.id).is_deleted);
            Assert.IsNull(db.tables.Find(table1.id));
            Assert.IsNull(db.restaurant_user.Find(restaurantUser1.id).restaurant_id);
            Assert.IsTrue(db.menus.Find(menu1.id).is_deleted);
            Assert.IsNull(db.reviews.Find(review1.id));
        }
Пример #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();
 }
Пример #16
0
 /// <summary>
 /// Removes a restaurant_user item from the database.
 /// </summary>
 /// <param name="restaurantEntity">restaurant_user item to be removed.</param>
 public void RemoveRestaurantUser(restaurant_user restaurantUserEntity)
 {
     db = new touch_for_foodEntities();
     if (db.restaurant_user.Find(restaurantUserEntity.id) != null)
     {
         db.restaurant_user.Remove(db.restaurant_user.Find(restaurantUserEntity.id));
         db.SaveChanges();
     }
     db.Dispose();
 }
Пример #17
0
 /// <summary>
 /// Removes a review item from the database.
 /// </summary>
 /// <param name="userEntity">The review to be removed.</param>
 public void RemoveReview(review reviewEntity)
 {
     db = new touch_for_foodEntities();
     if (db.reviews.Find(reviewEntity.id) != null)
     {
         db.reviews.Remove(db.reviews.Find(reviewEntity.id));
         db.SaveChanges();
     }
     db.Dispose();
 }
Пример #18
0
 /// <summary>
 /// Removes an order item from the database.
 /// </summary>
 /// <param name="orderEntity">Order item to be removed.</param>
 public void RemoveOrderItem(order_item orderItem)
 {
     db = new touch_for_foodEntities();
     if(db.order_item.Find(orderItem.id) != null)
     {
         db.order_item.Remove(db.order_item.Find(orderItem.id));
         db.SaveChanges();
     }
     db.Dispose();
 }
Пример #19
0
 /// <summary>
 /// Removes an order from the database.
 /// </summary>
 /// <param name="orderEntity">Order to be removed.</param>
 public void RemoveOrder(order orderEntity)
 {
     db = new touch_for_foodEntities();
     if (orderEntity != null)
     {
         db.orders.Remove(db.orders.Find(orderEntity.id));
         db.SaveChanges();
     }
     db.Dispose();
 }
Пример #20
0
 /// <summary>
 /// Remove menu item item from database.
 /// </summary>
 /// <param name="menuEntity">Menu item item to be removed.</param>
 public void RemoveMenuItem(menu_item menuItemEntity)
 {
     db = new touch_for_foodEntities();
     if (db.menu_item.Find(menuItemEntity.id) != null)
     {
         db.menu_item.Remove(db.menu_item.Find(menuItemEntity.id));
         db.SaveChanges();
     }
     db.Dispose();
 }
Пример #21
0
        public void RemoveMenuCategoryExceptionTest()
        {
            //Arrange
            db = new touch_for_foodEntities();

            //populat db (order specific)
            item item1 = testDatabase.AddItem();
            menu_item menuItem1 = testDatabase.AddMenuItem(item1, menuCategory1);

            //0 rows should have been affected
            int expected = 0;

            //make menu category active
            menuCategory1.is_active = true;
            db.Entry(menuCategory1).State = EntityState.Modified;
            db.SaveChanges();

            //Act
            int actual = target.RemoveMenuCategory(menuCategory1.id);

            //Assert
            db = new touch_for_foodEntities();
            Assert.AreEqual(expected, actual);
            Assert.IsFalse(db.menu_category.Find(menuCategory1.id).is_deleted);
            Assert.IsFalse(db.menu_item.Find(menuItem1.id).is_deleted);

            //Clean-up (order specific)
            testDatabase.RemoveMenuItem(menuItem1);
            testDatabase.RemoveItem(item1);
        }
Пример #22
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();
 }
Пример #23
0
        public void DeleteConfirmedTest()
        {
            //Setup
            db = new touch_for_foodEntities();
            user1.current_table_id = null;
            db.Entry(user1).State = EntityState.Modified;
            db.SaveChanges();

            //CheckSetup
            Assert.IsNotNull(db.tables.Find(table1.id));
            Assert.IsNotNull(db.orders.Find(order1.id).table_id);
            Assert.IsNotNull(db.service_request.Find(request1.id).table_id);

            //Act
            var actual = target.DeleteConfirmed(table1.id);

            //Assert
            db = new touch_for_foodEntities();
            Assert.IsNull(db.tables.Find(table1.id));
            Assert.IsNull(db.service_request.Find(request1.id).table_id);
            Assert.AreEqual((request1.version + 1), db.service_request.Find(request1.id).version);
            Assert.IsNull(db.orders.Find(order1.id).table_id);
            Assert.AreEqual((order1.version + 1), db.orders.Find(order1.id).version);
        }
Пример #24
0
 /// <summary>
 /// Remove menu item from database.
 /// </summary>
 /// <param name="menuEntity">Menu item to be removed.</param>
 public void RemoveMenu(menu menuEntity)
 {
     db = new touch_for_foodEntities();
     if (menuEntity != null)
     {
         db.menus.Remove(db.menus.Find(menuEntity.id));
         db.SaveChanges();
     }
     db.Dispose();
 }
Пример #25
0
 public void RemoveReviewOrderItem(review_order_item reviewEntityOI)
 {
     db = new touch_for_foodEntities();
     if (db.review_order_item.Find(reviewEntityOI.id) != null)
     {
         db.review_order_item.Remove(db.review_order_item.Find(reviewEntityOI.id));
         db.SaveChanges();
     }
     db.Dispose();
 }
Пример #26
0
 /// <summary>
 /// Remove friendship item from database.
 /// </summary>
 /// <param name="menuEntity">Friendships item to be removed.</param>
 public void RemoveFriendship(friendship friendshipEntity)
 {
     db = new touch_for_foodEntities();
     if (db.friendships.Find(friendshipEntity.id) != null)
     {
         db.friendships.Remove(db.friendships.Find(friendshipEntity.id));
         db.SaveChanges();
     }
     db.Dispose();
 }
Пример #27
0
        public void DeleteActiveWarningTest()
        {
            //Arrange
            db = new touch_for_foodEntities();
            Menu_CategoryController target = new Menu_CategoryController(db);
            menuCategory1.is_active = true;
            db.Entry(menuCategory1).State = EntityState.Modified;
            db.SaveChanges();
            menu_category expected = menuCategory1;

            //Act
            ViewResult actual = (ViewResult)target.Delete(menuCategory1.id);

            //Assert
            Assert.AreEqual(expected.id, ((menu_category)actual.ViewData.Model).id);
            Assert.IsNotNull(actual.ViewBag.Warning);
        }
Пример #28
0
 /// <summary>
 /// Removes a service request item from the database.
 /// </summary>
 /// <param name="serviceRequest">The service request to be removed.</param>
 public void RemoveServiceRequest(service_request serviceRequest)
 {
     db = new touch_for_foodEntities();
     if (db.service_request.Find(serviceRequest.id) != null)
     {
         db.service_request.Remove(db.service_request.Find(serviceRequest.id));
         db.SaveChanges();
     }
     db.Dispose();
 }
Пример #29
0
        public void DeleteConfirmedTestItemActiveException()
        {
            // Arrange
            db = new touch_for_foodEntities();
            Menu_ItemController target = new Menu_ItemController();
            int expectedMenuItems = db.menu_item.ToList<menu_item>().Count();
            menuItem1 = db.menu_item.Find(menuItem1.id);
            menuItem1.is_active = true;
            db.Entry(menuItem1).State = EntityState.Modified;
            db.SaveChanges();

            // Act
            var actualResult = target.DeleteConfirmed(menuItem1.id) as RedirectToRouteResult;

            // Assertions
            db = new touch_for_foodEntities();
            var actualResultURI = actualResult.RouteValues["action"];
            int actualMenuItems = db.menu_item.ToList<menu_item>().Count();

            Assert.AreEqual(expectedMenuItems, actualMenuItems);
            Assert.IsFalse(db.menu_item.Find(menuItem1.id).is_deleted);
            Assert.AreEqual("Index", actualResultURI);
        }
Пример #30
0
 /// <summary>
 /// Removes a side item from the database.
 /// </summary>
 /// <param name="testSide">The side to be removed.</param>
 public void RemoveSide(side testSide)
 {
     db = new touch_for_foodEntities();
     if (db.sides.Find(testSide.id) != null)
     {
         db.sides.Remove(db.sides.Find(testSide.id));
         db.SaveChanges();
     }
     db.Dispose();
 }