示例#1
0
        public void AddToShoppingCart()
        {
            //arrange
            //gettingstock

            List <IStockFunctions.StockResponse> stockResponses = new List <IStockFunctions.StockResponse>();
            List <StockDTO> stockList   = new List <StockDTO>();
            int             productId   = 4;
            string          productDesc = "testProductDesc";
            string          productName = "testProduct";

            int    stockId       = 1;
            int    stockQuantity = 3;
            string stockDesc     = "teststockdesc";

            stockList.Add(new StockDTO()
            {
                Id          = stockId,
                Description = stockDesc,
                Quantity    = stockQuantity,
                ProductId   = productId
            });
            IStockFunctions.StockResponse stockResponse = new IStockFunctions.StockResponse()
            {
                Id          = productId,
                Description = productDesc,
                Name        = productName,
                Stock       = stockList
            };

            stockResponses.Add(stockResponse);
            stockFunctions.Setup(x => x.GetStock()).Returns(stockResponses);

            //cart
            CartProductViewModel product = new CartProductViewModel()
            {
                Name     = "testProduct",
                Quantity = 2,
                StockId  = 3,
                Value    = "4"
            };
            var value = new byte[0];

            session.Setup(x => x.TryGetValue(It.IsAny <string>(), out value));
            session.Setup(x => x.Set(It.IsAny <string>(), It.IsAny <byte[]>()));

            //act
            Cart.AddToShoppingCart(product);

            //assert
            session.Verify(x => x.TryGetValue(It.IsAny <string>(), out value));
            session.Verify(x => x.Set(It.IsAny <string>(), It.IsAny <byte[]>()));
        }
示例#2
0
        public void GetStock()
        {
            //arrange
            List <IStockFunctions.StockResponse> stockResponses = new List <IStockFunctions.StockResponse>();
            List <StockDTO> stockList   = new List <StockDTO>();
            int             productId   = 4;
            string          productDesc = "testProductDesc";
            string          productName = "testProduct";

            int    stockId       = 1;
            int    stockQuantity = 3;
            string stockDesc     = "teststockdesc";

            stockList.Add(new StockDTO()
            {
                Id          = stockId,
                Description = stockDesc,
                Quantity    = stockQuantity,
                ProductId   = productId
            });
            IStockFunctions.StockResponse stockResponse = new IStockFunctions.StockResponse()
            {
                Id          = productId,
                Description = productDesc,
                Name        = productName,
                Stock       = stockList
            };

            stockResponses.Add(stockResponse);
            iStockFunctions.Setup(x => x.GetStock()).Returns(stockResponses);

            //act
            var products = stockFunctions.RunGetStock();

            //assert
            foreach (var p in products)
            {
                Assert.AreEqual(productId, p.Id);
                Assert.AreEqual(productName, p.Name);
                Assert.AreEqual(productDesc, p.Description);

                foreach (var s in p.Stock)
                {
                    Assert.AreEqual(stockId, s.Id);
                    Assert.AreEqual(stockDesc, s.Description);
                    Assert.AreEqual(stockQuantity, s.Quantity);
                    Assert.AreEqual(productId, s.ProductId);
                }
            }
        }
示例#3
0
        public void CreateOrder()
        {
            //arrange
            List <IStockFunctions.StockResponse> stockResponses = new List <IStockFunctions.StockResponse>();
            List <StockDTO> stockList   = new List <StockDTO>();
            int             productId   = 4;
            string          productDesc = "testProductDesc";
            string          productName = "testProduct";

            int    stockId       = 1;
            int    stockQuantity = 3;
            string stockDesc     = "teststockdesc";

            int OrderId = 4;

            stockList.Add(new StockDTO()
            {
                Id          = stockId,
                Description = stockDesc,
                Quantity    = stockQuantity,
                ProductId   = productId
            });
            IStockFunctions.StockResponse stockResponse = new IStockFunctions.StockResponse()
            {
                Id          = productId,
                Description = productDesc,
                Name        = productName,
                Stock       = stockList
            };

            stockResponses.Add(stockResponse);

            OrderViewModel ordervm = new OrderViewModel()
            {
                Adress         = "Heraut 45",
                City           = "Oss",
                Postcode       = "5346TF",
                OrderReference = "1+3 "
            };

            iOrderFunctions.Setup(x => x.CreateOrder(It.IsAny <OrderDTO>())).Returns(new OrderDTO()
            {
                Id             = OrderId,
                Adress         = ordervm.Adress,
                City           = ordervm.City,
                Postcode       = ordervm.Postcode,
                OrderReference = "1+3 "
            });

            iProductFunctions.Setup(x => x.GetProductByStockId(It.IsAny <int>())).Returns(new ProductDTO()
            {
                Id          = 3,
                Description = "productDesc",
                Name        = "product",
                Value       = 2
            });
            iStock.Setup(x => x.UpdateStock(It.IsAny <StockDTO>()));

            iStockFunctions.Setup(x => x.GetStock()).Returns(stockResponses);

            //act
            var Order = orderFunctions.CreateOrder(ordervm);

            //assert
            Assert.AreEqual(OrderId, Order.Id);
            Assert.AreEqual(ordervm.Adress, Order.Adress);
            Assert.AreEqual(ordervm.City, Order.City);
            Assert.AreEqual(ordervm.Postcode, Order.Postcode);
        }