public void non_admin_order_list_order_lines()
        {
            //Arrange
            var controller = new OrderController(new OrderBLL(new OrderDALStub()));

            //Act
            var result = (RedirectToRouteResult)controller.ListOrderLines(0,null, null, null);

            //Assert
            Assert.AreEqual("LogIn", result.RouteValues["Action"]);
            Assert.AreEqual("Main", result.RouteValues["Controller"]);
        }
        public void order_listOrderlines_sort_totalsum_desc()
        {
            //Arrange
            TestControllerBuilder builder = new TestControllerBuilder();
            var controller = new OrderController(new OrderBLL(new OrderDALStub()));
            builder.InitializeController(controller);
            builder.HttpContext.Session["loggedInUser"] = new Customer() { admin = true };

            //Act
            var actrow = (ViewResult)controller.ListOrderLines(298423, null, null, "total_desc");
            var result = (IPagedList<OrderLineViewModel>)actrow.Model;

            Assert.IsTrue(result[0].orderlineSum > result[1].orderlineSum);
            Assert.IsNotNull(result[0].orderlineSum);

        }
        public void order_listOrderlines_sort_pname()
        {
            //Arrange
            TestControllerBuilder builder = new TestControllerBuilder();
            var controller = new OrderController(new OrderBLL(new OrderDALStub()));
            builder.InitializeController(controller);
            builder.HttpContext.Session["loggedInUser"] = new Customer() { admin = true };

            //Act
            var actrow = (ViewResult)controller.ListOrderLines(298423, 1, 2, "PName");
            var result = (IPagedList<OrderLineViewModel>)actrow.Model;

            Assert.AreEqual(result.PageNumber, 1);
            Assert.AreEqual(result.PageSize, result.Count);
            Assert.IsTrue(string.Compare(result[0].product.name, result[1].product.name) <= 0);
            Assert.IsNotNull(result[0].product.name);

        }
        public void order_listOrderlines_sort_id_desc()
        {
            //Arrange
            TestControllerBuilder builder = new TestControllerBuilder();
            var controller = new OrderController(new OrderBLL(new OrderDALStub()));
            builder.InitializeController(controller);
            builder.HttpContext.Session["loggedInUser"] = new Customer() { id = 1, admin = true };

            //Act
            var actrow = (ViewResult)controller.ListOrderLines(298423,null, 2, "id_desc");
            var result = (IPagedList<OrderLineViewModel>)actrow.Model;

            Assert.AreEqual(result.PageNumber, 1);
            Assert.AreEqual(result.PageSize, 2);
            Assert.IsTrue(result[0].id >= result[1].id);
            Assert.IsNotNull(result[0].id);

        }
        public void order_orderlineslist_contains_orderlines()
        {
            TestControllerBuilder builder = new TestControllerBuilder();
            //Arrange
            var bll = new OrderController(new OrderBLL(new OrderDALStub()));
            builder.InitializeController(bll);
            builder.HttpContext.Session["loggedInUser"] = new Customer() { admin = true };
            List<OrderLineViewModel> expected = new List<OrderLineViewModel>();
            var o = new OrderLineViewModel()
            {
                id = 1,
                productid = 100001.ToString(),
                quantity = 3,
                customerid = 1,
                orderdate = DateTime.Now, 
                orderId = 298423,
                orderlineSum = 300,
                price = 50.ToString(),
                productname = "hei"

            };

            expected.Add(o);
            expected.Add(o);
            expected.Add(o);
            // Act
            var actual = (ViewResult)bll.ListOrderLines(298423, null, 2, null);
            var result = (PagedList<OrderLineViewModel>)actual.Model;
            // Assert
            Assert.AreEqual(2, result.Count);
            Assert.AreEqual(result[0].orderlineSum, (int.Parse(result[0].price) * result[0].quantity) );
            
        }
        public void order_listOrderLines_is_not_null()
        {
            // Arrange
            TestControllerBuilder builder = new TestControllerBuilder();
            var controller = new OrderController(new OrderBLL(new OrderDALStub()));
            builder.InitializeController(controller);
            builder.HttpContext.Session["loggedInUser"] = new Customer() { admin = true };
            var order = new Order()
            {
                id = 298423,
                customerid = 1,
                orderdate = DateTime.Now
            };

            // Act 
            var actrow = (ViewResult)controller.ListOrderLines(298423, null, null, null);
            var result = (IPagedList<OrderLineViewModel>)actrow.Model;

            // Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(IPagedList<OrderLineViewModel>));
            Assert.AreEqual(result[0].orderId , order.id ); 
            Assert.IsTrue(result[0].id <= result[1].id);

        }