Example #1
0
        public void Order_DeleteOrder_BadOrderId()
        {
            // Arrange
            var SessionMock = new TestControllerBuilder();
            var Controller = new OrderController(new OrderBLL(new OrderRepoStub()));
            SessionMock.InitializeController(Controller);

            Controller.Session["Admin"] = true;
            var orderId = 0;

            // Act
            var result = Controller.DeleteOrder(orderId);

            // Assert
            Assert.IsFalse(result);
        }
Example #2
0
        public void Order_OrderPartial_ListCustomerOrders()
        {
            // Arrange
            var Controller = new OrderController(new OrderBLL(new OrderRepoStub()));

            var expOrderViews = new List<OrderView>();
            var expProductViews = new List<ProductView>();
            var expViewName = "";
            var expTitle = "Ordreadministrasjon - Kunde";

            foreach (var o in orderModels)
            {
                var order = new OrderView();
                order.Date = o.Date;
                order.OrderId = o.OrderId;
                order.CustomerId = o.CustomerId;
                order.Orderlines = new List<OrderlineView>();

                foreach (var l in o.Orderlines)
                {
                    var orderline = new OrderlineView();
                    orderline.Count = l.Count;
                    orderline.OrderlineId = l.OrderlineId;
                    orderline.Product = new ProductView()
                    {
                        Price = l.ProductPrice,
                        ProductId = l.ProductId,
                        ProductName = l.ProductName
                    };

                    order.Orderlines.Add(orderline);
                }
                expOrderViews.Add(order);
            }

            foreach (var productModel in productModels)
            {
                var productview = new ProductView()
                {
                    ProductId = productModel.ProductId,
                    ProductName = productModel.ProductName,
                    Description = productModel.Description,
                    Price = productModel.Price,
                    Stock = productModel.Stock,
                    CategoryId = productModel.CategoryId
                };
                expProductViews.Add(productview);
            }

            // Act
            var result = Controller.OrdersPartial(CUSTOMER_ORDERS);

            var viewBagOrders = result.ViewBag.Orders;
            var viewBagProducts = result.ViewBag.Products;
            var viewBagTitle = result.ViewBag.Title;

            //// Assert
            Assert.AreEqual(expViewName, result.ViewName);

            for (int i = 0; i < viewBagOrders.Count; i++)
            {
                Assert.AreEqual(expOrderViews[i].OrderId, viewBagOrders[i].OrderId);
                Assert.AreEqual(expOrderViews[i].CustomerId, viewBagOrders[i].CustomerId);
                Assert.AreEqual(expOrderViews[i].Date, viewBagOrders[i].Date);
                for (int j = 0; j < expOrderViews[i].Orderlines.Count; j++)
                {
                    Assert.AreEqual(expOrderViews[i].Orderlines[j].Count, viewBagOrders[i].Orderlines[j].Count);
                    Assert.AreEqual(expOrderViews[i].Orderlines[j].OrderlineId, viewBagOrders[i].Orderlines[j].Count);
                    Assert.AreEqual(expOrderViews[i].Orderlines[j].Product.ProductId, viewBagOrders[i].Orderlines[j].Product.ProductId);
                    Assert.AreEqual(expOrderViews[i].Orderlines[j].Product.ProductName, viewBagOrders[i].Orderlines[j].Product.ProductName);
                    Assert.AreEqual(expOrderViews[i].Orderlines[j].Product.Price, viewBagOrders[i].Orderlines[j].Product.Price);
                }
            }

            for (int i = 0; i < viewBagProducts.Count; i++)
            {
                Assert.AreEqual(expProductViews[i].ProductId, viewBagProducts[i].ProductId);
                Assert.AreEqual(expProductViews[i].ProductName, viewBagProducts[i].ProductName);
                Assert.AreEqual(expProductViews[i].Price, viewBagProducts[i].Price);
                Assert.AreEqual(expProductViews[i].Description, viewBagProducts[i].Description);
                Assert.AreEqual(expProductViews[i].Stock, viewBagProducts[i].Stock);
                Assert.AreEqual(expProductViews[i].CategoryId, viewBagProducts[i].CategoryId);
            }

            Assert.AreEqual(expTitle, viewBagTitle);
        }
Example #3
0
        public void Order_UpdateOrderline_Ok()
        {
            // Arrange
            var SessionMock = new TestControllerBuilder();
            var Controller = new OrderController(new OrderBLL(new OrderRepoStub()));
            SessionMock.InitializeController(Controller);

            Controller.Session["Admin"] = true;
            var OrderlineId = 1;
            var ProductId = 1;
            var Count = 1;

            // Act
            var result = Controller.UpdateOrderline(OrderlineId, ProductId, Count);

            // Assert
            Assert.IsTrue(result);
        }
Example #4
0
        public void Order_GetOrderSumTotal_Ok()
        {
            // Arrange
            var Controller = new OrderController(new OrderBLL(new OrderRepoStub()));

            var orderId = 1;
            var expResult = 1.0;

            // Act
            var result = Controller.GetOrderSumTotal(orderId);

            // Assert
            Assert.AreEqual(expResult, result);
        }