public void non_admin_category_list_categories()
        {
            var controller = new CategoryController(new CategoryBLL(new CategoryDALStub()));

            var result = (RedirectToRouteResult)controller.ListCategories(null, null, null, null, null);

            Assert.AreEqual("LogIn", result.RouteValues["Action"]);
            Assert.AreEqual("Main", result.RouteValues["Controller"]);
        }
        public void category_list_categories_sort_category()
        {
            //Arrange
            TestControllerBuilder builder = new TestControllerBuilder();
            var controller = new CategoryController(new CategoryBLL(new CategoryDALStub()));
            builder.InitializeController(controller);
            builder.HttpContext.Session["loggedInUser"] = new Customer() { id = 1, admin = true };

            //Act
            var action = (ViewResult)controller.ListCategories(null, null, "Cat", null, null);
            var result = (IPagedList<CategoryInfo>)action.Model;

            //Assert
            Assert.IsTrue(string.Compare(result[0].name,result[1].name) < 0);
        }
        public void category_list_categories_sort_id_desc()
        {
            //Arrange
            TestControllerBuilder builder = new TestControllerBuilder();
            var controller = new CategoryController(new CategoryBLL(new CategoryDALStub()));
            builder.InitializeController(controller);
            builder.HttpContext.Session["loggedInUser"] = new Customer() { id = 1, admin = true };

            //Act
            var action = (ViewResult)controller.ListCategories(2, 2, "id_desc", null, "notnull");
            var result = (PagedList<CategoryInfo>) action.Model;
            
            //Assert
            Assert.AreEqual(result.PageNumber, 1);
            Assert.IsTrue(result[0].id > result[1].id);
        }
        public void category_list_categories()
        {
            //Arrange
            TestControllerBuilder builder = new TestControllerBuilder();
            var controller = new CategoryController(new CategoryBLL(new CategoryDALStub()));
            builder.InitializeController(controller);
            builder.HttpContext.Session["loggedInUser"] = new Customer() {id = 1, admin = true };

            //Act
            var action = (ViewResult)controller.ListCategories(2, 2, null, null, null);
            var result = (PagedList<CategoryInfo>)action.Model;

            //Assert
            Assert.AreEqual(result.PageNumber, 2);
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(IPagedList<CategoryInfo>));
            Assert.IsTrue(result[0].id < result[1].id);
        }