public void order_is_equal()
        {
            //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.ListOrders(null, null, null);
            var result = (IPagedList<OrderViewModel>)actrow.Model;

            //Assert
           Assert.AreEqual(actrow.ViewName, "" );
           Assert.AreEqual(result[0].id, order.id);
           Assert.AreEqual(result[0].customerid, order.customerid);


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

            //Act
            var result = (RedirectToRouteResult)controller.showReceipt(0);

            //Assert
            Assert.AreEqual("LogIn", result.RouteValues["Action"]);
            Assert.AreEqual("Main", result.RouteValues["Controller"]);
        }
        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_listOrders_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() { admin = true };

            //Act
            var actrow = (ViewResult)controller.ListOrders(2, 2, "id_desc");
            var result = (IPagedList<OrderViewModel>)actrow.Model;

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

        }
        public void order_listOrders_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 };

            // Act 
            var actrow = (ViewResult)controller.ListOrders(2,2,null);
            var result = (IPagedList<OrderViewModel>)actrow.Model;

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(result.PageNumber, 2);
            Assert.IsInstanceOfType(result, typeof(IPagedList<OrderViewModel>));
            Assert.IsTrue(result[0].id < result[1].id);
        }
        public void order_listOrders_sort_cfname()
        {
            //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.ListOrders(null, null, "CFName");
            var result = (IPagedList<OrderViewModel>)actrow.Model;
            //Assert
            Assert.IsTrue(string.Compare(result[0].customer.firstname ,result[1].customer.firstname) < 0);
            Assert.IsNotNull(result[0].customer.firstname);
        }
        public void order_showReciept_not_null()
        {
            TestControllerBuilder builder = new TestControllerBuilder();
            //Arrange
            var controller = new OrderController(new OrderBLL(new OrderDALStub()));
            builder.InitializeController(controller);
            builder.HttpContext.Session["loggedInUser"] = new Customer() { admin = true };
            BillingViewModel expected = new BillingViewModel()
            { 
                ordreid = 12345,
                orderdate =DateTime.Now,
                totsum = 30,
                mva = 8,
                exmva = 28,
                
            };

            //Act
            var action = (ViewResult)controller.showReceipt(12345);
            var result = (BillingViewModel)action.Model;

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(result.sum.Count, result.shoppingcart.Count); 
            
        }
        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_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);

        }
        public void order_list_contains_orders()
        {
            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<OrderViewModel> expected = new List<OrderViewModel>();
            var o = new OrderViewModel()
            {
                id = 1,
                customerid = 1001
            };

            expected.Add(o);
            expected.Add(o);
            expected.Add(o);
            expected.Add(o);
            expected.Add(o);
            expected.Add(o);
            // Act
            var actual = (ViewResult)bll.ListOrders(null, null, null);
            var result = (IPagedList<OrderViewModel>)actual.Model;
            // Assert
            Assert.AreEqual(expected.Count, result.Count);
        }
        public void order_listOrders_sort_date_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.ListOrders(null, null, "date_desc");
            var result = (IPagedList<OrderViewModel>)actrow.Model;
            //Assert
            Assert.IsTrue(result[0].orderdate.Date >= result[1].orderdate.Date);
            Assert.IsNotNull(result[0].orderdate);

        }