public MenuItem(MenuItemEntity menuItem)
     : base(menuItem)
 {
     Name = menuItem.Name;
     Description = menuItem.Description;
     Category = new MenuItemCategory(menuItem.Category);
     Price = menuItem.Price;
 }
 public MenuItem(MenuItemEntity menuItem)
     : base(menuItem)
 {
     Name        = menuItem.Name;
     Description = menuItem.Description;
     Category    = new MenuItemCategory(menuItem.Category);
     Price       = menuItem.Price;
 }
        public MenuItem(MenuItem menuItemToCopy)
            : base(menuItemToCopy)
        {
            if(menuItemToCopy == null)
                throw new ArgumentNullException("menuItemToCopy");

            Name = menuItemToCopy.Name;
            Description = menuItemToCopy.Description;
            Category = new MenuItemCategory(menuItemToCopy.Category);
            Price = menuItemToCopy.Price;
        }
        /// <summary>
        /// Konstruktor kopiujący
        /// </summary>
        /// <param name="menuItemCategoryToCopy">Kategoria do skopiowania</param>
        public MenuItemCategory(MenuItemCategory menuItemCategoryToCopy)
            : base(menuItemCategoryToCopy)
        {
            if (menuItemCategoryToCopy == null)
            {
                throw new ArgumentNullException("menuItemCategoryToCopy");
            }

            Name        = menuItemCategoryToCopy.Name;
            Description = menuItemCategoryToCopy.Description;
        }
        public void AddNewCategoryTest()
        {
            ManagerLogInTest();

            category1 = managerDataAccess.AddMenuItemCategory(managerContext1.Id, categoryName1, categoryDescription1);

            Assert.IsNotNull(category1);
            Assert.AreNotEqual(category1.Id, 0);
            Assert.AreEqual(category1.Name, categoryName1);
            Assert.AreEqual(category1.Description, categoryDescription1);

            ManagerLogOutTest();
        }
        public MenuItem(MenuItem menuItemToCopy)
            : base(menuItemToCopy)
        {
            if (menuItemToCopy == null)
            {
                throw new ArgumentNullException("menuItemToCopy");
            }

            Name        = menuItemToCopy.Name;
            Description = menuItemToCopy.Description;
            Category    = new MenuItemCategory(menuItemToCopy.Category);
            Price       = menuItemToCopy.Price;
        }
        public void List_show_menu_item_list_with_less_number_than_page_size()
        {
            //Arrange
            var testCategory = new MenuItemCategory()
            {
                Description = "MenuITemCategoryDescription1",
                Name = "MenuItemCategoryName1",
                Id = 1
            };

            var menuItemsCount = MenuController.PageSize / 2;

            _menuItemList = new List<MenuItem>();
            for (var i = 0; i < menuItemsCount; i++)
            {
                _menuItemList.Add(new MenuItem()
                {
                    Category = testCategory,
                    Description = "MenuItemDescription" + (i + 1),
                    Id = i + 1,
                    Name = "MenuItemName" + (i + 1),
                    Price = new Money() { Amount = 10 * (i + 1), Currency = "PLN" }
                });
            }

            InitilizeBaseDataAccessWithList(_menuItemList);
            _controller = GetMenuControllerInstance();

            //Act
            var result = _controller.List(null);
            var model = (MenuListViewModel)result.Model;

            //Assert
            Assert.IsNotNull(model);
            Assert.AreEqual(null, model.CurrentCategory);
            Assert.AreEqual(1, model.PagingInfo.CurrentPage);
            Assert.AreEqual(menuItemsCount, model.PagingInfo.TotalItems);
            Assert.IsNotNull(model.MenuItems);
            Assert.AreEqual(_menuItemList.Count, model.MenuItems.Count());
            foreach (var menuItem in model.MenuItems)
            {
                Assert.IsTrue(_menuItemList.Contains(menuItem));
            }
        }
        public void List_show_menu_items_from_current_category()
        {
            //Arrange
            var testCategory1 = new MenuItemCategory()
            {
                Description = "MenuITemCategoryDescription1",
                Name = "MenuItemCategoryName1",
                Id = 1
            };

            var testCategory2 = new MenuItemCategory()
            {
                Description = "MenuITemCategoryDescription2",
                Name = "MenuItemCategoryName2",
                Id = 2
            };

            _menuItemList = new List<MenuItem>();

            var menuItemsFirstCategoryCount = MenuController.PageSize + 1;

            for (var i = 0; i < menuItemsFirstCategoryCount; i++)
            {
                _menuItemList.Add(new MenuItem()
                {
                    Category = testCategory1,
                    Description = "MenuItemDescription" + (i + 1),
                    Id = i + 1,
                    Name = "MenuItemName" + (i + 1),
                    Price = new Money() { Amount = 10 * (i + 1), Currency = "PLN" }
                });
            }
            var firstPageCount = MenuController.PageSize;
            var secondPageCount = 1;

            var menuItemsSecondCategoryCount = MenuController.PageSize + 2;

            for (var i = 0; i < menuItemsSecondCategoryCount; i++)
            {
                _menuItemList.Add(new MenuItem()
                {
                    Category = testCategory2,
                    Description = "MenuItemDescription" + (menuItemsFirstCategoryCount + i + 1),
                    Id = menuItemsFirstCategoryCount + i + 1,
                    Name = "MenuItemName" + (menuItemsFirstCategoryCount + i + 1),
                    Price = new Money() { Amount = 10 * (i + 1), Currency = "PLN" }
                });
            }

            InitilizeBaseDataAccessWithList(_menuItemList);
            _controller = GetMenuControllerInstance();

            var secondCategoryFirstPageCount = MenuController.PageSize;
            var secondCategorySecondPageCount = 2;

            //Act && Assert
            CheckCurrentPageCurrentCategory(testCategory1, menuItemsFirstCategoryCount, firstPageCount, 1);
            CheckCurrentPageCurrentCategory(testCategory1, menuItemsFirstCategoryCount, secondPageCount, 2);
            CheckCurrentPageCurrentCategory(testCategory2, menuItemsSecondCategoryCount, secondCategoryFirstPageCount, 1);
            CheckCurrentPageCurrentCategory(testCategory2, menuItemsSecondCategoryCount, secondCategorySecondPageCount, 2);
        }
        private void CheckCurrentPageCurrentCategory(MenuItemCategory testCategory, int menuItemsCount, int currentPageItemsCount, int currentPageNumber)
        {
            //Act
            var resultCategory = _controller.List(testCategory.Name,currentPageNumber);
            var modelCategory = (MenuListViewModel)resultCategory.Model;

            //Assert
            Assert.IsNotNull(modelCategory);
            Assert.AreEqual(testCategory.Name, modelCategory.CurrentCategory);
            Assert.AreEqual(currentPageNumber, modelCategory.PagingInfo.CurrentPage);
            Assert.AreEqual(menuItemsCount, modelCategory.PagingInfo.TotalItems);
            Assert.IsNotNull(modelCategory.MenuItems);
            Assert.AreEqual(currentPageItemsCount, modelCategory.MenuItems.Count());
            foreach (var menuItem in modelCategory.MenuItems)
            {
                Assert.IsTrue(_menuItemList.Contains(menuItem));
            }
        }
Example #10
0
        /// <summary>
        /// Edytuje kategorię elementów menu
        /// </summary>
        /// <param name="managerId">Identyfikator użytkownika o roli menedżera systemu</param>
        /// <param name="menuItemCategoryToEdit">Kategoria elementów menu do edycji</param>
        /// <remarks>Identyfikator kategorii musi być taki sam jak identyfikator kategorii do edycji. Pozostałe pola mogą być zmienione.</remarks>
        /// <returns></returns>
        public bool EditMenuItemCategory(int managerId, MenuItemCategory menuItemCategoryToEdit)
        {
            if (!CheckHasUserRole(managerId, UserRole.Manager))
                throw new SecurityException(String.Format("User id = {0} is not logged in or is no manager", managerId));

            if (menuItemCategoryToEdit == null)
                throw new ArgumentNullException("menuItemCategoryToEdit");

            using(var db = new DataAccessProvider())
            {
                MenuItemCategoryEntity editedMenuItemCategoryEntity = db.MenuItemCategories.Find(menuItemCategoryToEdit.Id);
                if (editedMenuItemCategoryEntity == null || editedMenuItemCategoryEntity.IsDeleted)
                    return false;

                //db.Entry(editedMenuItemCategory).State = System.Data.Entity.EntityState.Detached;
                //db.MenuItemCategories.Attach(menuItemCategoryToEdit);
                //db.Entry(menuItemCategoryToEdit).State = System.Data.Entity.EntityState.Modified;

                editedMenuItemCategoryEntity.CopyData(menuItemCategoryToEdit);
                db.Entry(editedMenuItemCategoryEntity).State = EntityState.Modified;
                db.SaveChanges();
                return true;
            }
        }
        public void TestCleanup()
        {
            if (order1 != null)
                dataWipe.WipeOrder(order1.Id);

            if (managerContext1 != null)
                dataWipe.WipeUser(managerContext1.Id);

            if (clientContext1 != null)
                dataWipe.WipeUser(clientContext1.Id);

            if (waiterContext1 != null)
                dataWipe.WipeUser(waiterContext1.Id);

            if (waiterContext2 != null)
                dataWipe.WipeUser(waiterContext2.Id);

            if (menuItem1 != null)
                dataWipe.WipeMenuItem(menuItem1.Id);

            if (menuItem2 != null)
                dataWipe.WipeMenuItem(menuItem2.Id);

            if (menuItem3 != null)
                dataWipe.WipeMenuItem(menuItem3.Id);

            if (category1 != null)
                dataWipe.WipeMenuItemCategory(category1.Id);

            if (table1 != null)
                dataWipe.WipeTable(table1.Id);

            order1 = null;
            managerContext1 = null;
            waiterContext1 = null;
            waiterContext2 = null;
            clientContext1 = null;
            category1 = null;
            menuItem1 = null;
            menuItem2 = null;
            menuItem3 = null;
            table1 = null;
        }
        /// <summary>
        /// Konstruktor kopiujący
        /// </summary>
        /// <param name="menuItemCategoryToCopy">Kategoria do skopiowania</param>
        public MenuItemCategory(MenuItemCategory menuItemCategoryToCopy)
            : base(menuItemCategoryToCopy)
        {
            if(menuItemCategoryToCopy == null)
                throw new ArgumentNullException("menuItemCategoryToCopy");

            Name = menuItemCategoryToCopy.Name;
            Description = menuItemCategoryToCopy.Description;
        }
 public bool EditMenuItemCategory(int managerId, MenuItemCategory menuItemCategoryToEdit)
 {
     return EditMenuItemCategoryWeb(managerId, menuItemCategoryToEdit);
 }