Exemplo n.º 1
0
        public void CanAddBasketItem()
        {
            //Arrange
            IRepository <Basket>   basketContext   = new MockContext <Basket>();
            IRepository <Product>  productContext  = new MockContext <Product>();
            IRepository <Order>    orderContext    = new MockContext <Order>();
            IRepository <Customer> customerContext = new MockContext <Customer>();
            HttpContextBase        httpContext     = new MockHttpContext();

            IBasketService basketService = new BasketService(basketContext, productContext);
            IOrderService  orderService  = new OrderService(orderContext);

            BasketController controller = new BasketController(basketService, orderService, customerContext);

            controller.ControllerContext = new System.Web.Mvc.ControllerContext(httpContext, new System.Web.Routing.RouteData(), controller);

            //Act
            basketService.AddToBasket(httpContext, "1");
            Basket basket = basketContext.Collection().FirstOrDefault();

            //Assert
            Assert.IsNotNull(basket);
            Assert.AreEqual(1, basket.BasketItems.Count());
            Assert.AreEqual("1", basket.BasketItems.ToList().FirstOrDefault().ProductId);
        }
        public void CanAddBasketItem()
        {
            //Setup Info
            IRepository <Basket>   baskets   = new MockContext <Basket>();
            IRepository <Product>  products  = new MockContext <Product>();
            IRepository <Order>    orders    = new MockContext <Order>();
            IRepository <Customer> customers = new MockContext <Customer>();

            var httpContext = new MockHttpContext();

            IBasketService basketService = new BasketService(products, baskets);
            IOrderService  orderService  = new OrderService(orders);
            var            controller    = new BasketController(basketService, orderService, customers);

            controller.ControllerContext = new System.Web.Mvc.ControllerContext(httpContext, new System.Web.Routing.RouteData(), controller);

            //Act on Info
            controller.AddToBasket("1");

            basketService.AddToBasket(httpContext, "1");

            Basket basket = baskets.Collection().FirstOrDefault();

            //Confirm on Info
            Assert.IsNotNull(basket);
            Assert.AreEqual(1, basket.BasketItems.Count);
            Assert.AreEqual("1", basket.BasketItems.ToList().FirstOrDefault().ProductId);
        }
Exemplo n.º 3
0
        //Basket related

        public ActionResult AddToCart(int id)
        {
            //  baskets.GetById(id);
            basketService.AddToBasket(this.HttpContext, id, 1);

            return(RedirectToAction("BasketSummary"));
        }
Exemplo n.º 4
0
        public void NotAddProductDueToLackOfStock()
        {
            //arrange
            var productDto = new ProductDto
            {
                Id   = 1,
                Name = "product"
            };

            var requestDto = new AddToBasketRequestDto()
            {
                CityId    = 1,
                ProductId = 1,
                Quantity  = 1
            };

            ConstraintHelper.mockProductStock.Setup(x => x.GetProductForCityId(1, 1, 1)).Returns(Task.FromResult(productDto));

            //act
            var service = new BasketService(ConstraintHelper.mockBasketProduct.Object, ConstraintHelper.mockBasket.Object, ConstraintHelper.mockProductStock.Object, ConstraintHelper.mockUnitOfWork.Object, ConstraintHelper.mockLogger.Object);
            var actual  = service.AddToBasket(ConstraintHelper.UserId, requestDto);

            Assert.AreEqual(AddToBasketReturnTypes.Err_ProductNotFound, actual.Result.ResponseCode);
            Assert.AreEqual(false, actual.Result.IsSuccess);
            Assert.AreEqual(false, actual.Result.Data);
        }
        public void CanAddBasketItem()
        {
            // Arrange
            IRepository <Basket>   baskets   = new MockContext <Basket>();
            IRepository <Product>  products  = new MockContext <Product>();
            IRepository <Order>    orders    = new MockContext <Order>();
            IRepository <Customer> customers = new MockContext <Customer>();

            var httpContext = new MockHttpContext();

            IBasketService basketService = new BasketService(products, baskets);
            IOrderService  orderService  = new OrderService(orders);

            var controller = new BasketController(basketService, orderService, customers);

            // Act
            basketService.AddToBasket(httpContext, "1");

            Basket basket = baskets.Collection().FirstOrDefault();

            // Assert
            Assert.IsNotNull(basket);
            Assert.AreEqual(1, basket.BasketItems.Count());
            Assert.AreEqual("1", basket.BasketItems.ToList().FirstOrDefault().ProductId);
        }
Exemplo n.º 6
0
        public async Task <bool> Handle(AddToBasketCommand request, CancellationToken cancellationToken)
        {
            var model = _mapper.Map <AddToBasketCommand, Domain.Basket>(request);

            model.ProductIds = new List <int>()
            {
                request.ProductId
            };
            var service = new BasketService(_readonlyBasketRepository, _writeonlyBasketRepository);
            await service.AddToBasket(model);

            return(true);
        }
Exemplo n.º 7
0
        public void SuccessfullyAddProduct()
        {
            var productDto = new ProductDto
            {
                Id    = 1,
                Name  = "product",
                Stock = new StockDto()
                {
                    Id = 1, CityId = 1, Quantity = 10
                },
                MinOrderQuantity = 1,
                MaxOrderQuantity = 100
            };

            var basketId = 1;

            var basketProductEntity = new BasketProduct()
            {
                BasketId  = 1,
                ProductId = 1,
                Quantity  = 2
            };

            var productResponseDto = new ProductDto()
            {
                Id    = 1,
                Stock = new StockDto()
                {
                    Id = 1, CityId = 1, Quantity = 8
                },
            };

            var requestDto = new AddToBasketRequestDto()
            {
                CityId    = 1,
                ProductId = 1,
                Quantity  = 2
            };

            ConstraintHelper.mockProductStock.Setup(x => x.GetProductForCityId(1, 1, 2)).Returns(Task.FromResult(productDto));
            ConstraintHelper.mockBasket.Setup(x => x.GetOrCreateBasketId(ConstraintHelper.UserId)).Returns(Task.FromResult(basketId));
            ConstraintHelper.mockBasketProduct.Setup(x => x.AddToBasket(basketProductEntity));
            ConstraintHelper.mockBasketProduct.Setup(x => x.BeginTransaction()).Returns(ConstraintHelper.mockContextTransaction.Object);
            ConstraintHelper.mockProductStock.Setup(x => x.UpdateStock(1, 8));

            var service = new BasketService(ConstraintHelper.mockBasketProduct.Object, ConstraintHelper.mockBasket.Object, ConstraintHelper.mockProductStock.Object, ConstraintHelper.mockUnitOfWork.Object, ConstraintHelper.mockLogger.Object);
            var actual  = service.AddToBasket(ConstraintHelper.UserId, requestDto);

            Assert.AreEqual(true, actual.Result.IsSuccess);
            Assert.AreEqual(AddToBasketReturnTypes.Success, actual.Result.ResponseCode);
        }
Exemplo n.º 8
0
        public void CanAddBasketItem_BasketService()
        {
            IRepository <Product> products = new MockContext <Product>();
            IRepository <Basket>  baskets  = new MockContext <Basket>();
            var httpContext = new MockHttpContext();

            IBasketService basketService = new BasketService(products, baskets);

            basketService.AddToBasket(httpContext, "1");

            Basket basket = baskets.Collection().FirstOrDefault();

            Assert.IsNotNull(basketService);
            Assert.AreEqual(1, basket.BasketItems.Count);
            Assert.AreEqual("1", basket.BasketItems.ToList().FirstOrDefault().ProductId);
        }
        public void CanAddBasketItem()
        {
            //Arrange
            IRepository <Product> _productsContext = new Mocks.MockContext <Product>();
            IRepository <Basket>  _BasketContext   = new Mocks.MockContext <Basket>();
            IBasketService        basketService    = new BasketService(_productsContext, _BasketContext);
            //Act
            var httpContext = new Mocks.MockHttpContext();

            basketService.AddToBasket(httpContext, "1");
            Basket basket = _BasketContext.Collection().FirstOrDefault();

            //Assert
            Assert.IsNotNull(basket);
            Assert.AreEqual(1, basket.BasketItems.Count);
            Assert.AreEqual("1", basket.BasketItems.ToList().FirstOrDefault().ProductId);
        }
Exemplo n.º 10
0
        public void CanAddBasketItem()
        {
            // Arrange
            const string             productId          = "1";
            IRepository <Basket>     basketContext      = new MockContext <Basket>();
            IRepository <BasketItem> basketItemsContext = new MockContext <BasketItem>();
            IRepository <Product>    productContext     = new MockContext <Product>();
            MockHttpContext          httpContext        = new MockHttpContext();

            IBasketService basketService = new BasketService(productContext, basketContext, basketItemsContext);

            // Act
            basketService.AddToBasket(httpContext, productId);

            Basket basket = basketContext.Collection().FirstOrDefault();

            // Assert
            Assert.IsNotNull(basket);
            Assert.AreEqual(1, basket.BasketItems.Count);
            Assert.AreEqual(productId, basket.BasketItems.ToList().FirstOrDefault().ProductId);
        }
Exemplo n.º 11
0
        public void CanAddBasketItem()
        {
            IRepository <Product>  product_context  = new MockRepository <Product>();
            IRepository <Basket>   basket_context   = new MockRepository <Basket>();
            IRepository <Order>    order_context    = new MockRepository <Order>();
            IRepository <Customer> customer_context = new MockRepository <Customer>();

            var httpContext = new MockHttpContext();

            IBasketService basketService = new BasketService(product_context, basket_context);
            IOrderService  orderService  = new OrderService(order_context);

            BasketController basketController = new BasketController(basketService, orderService, customer_context);

            basketService.AddToBasket(httpContext, "1");

            Basket basket = basket_context.Collection().FirstOrDefault();

            Assert.IsNotNull(basket);
            Assert.AreEqual(1, basket.basketItems.Count);
            Assert.AreEqual("1", basket.basketItems.FirstOrDefault().product_id);
        }
Exemplo n.º 12
0
        public void CanAddBasketItem()
        {
            //setup
            IRepository <Basket>  baskets  = new MockContext <Basket>();
            IRepository <Product> products = new MockContext <Product>();

            var httpContext = new MockHttpContext();

            IBasketService basketService = new BasketService(products, baskets);
            var            controller    = new BasketController(basketService);

            controller.ControllerContext = new System.Web.Mvc.ControllerContext(httpContext, new System.Web.Routing.RouteData(), controller);
            controller.AddToBasket("1");
            //act
            basketService.AddToBasket(httpContext, "1");

            Basket basket = baskets.Collection().FirstOrDefault();

            //assert
            Assert.IsNotNull(basket);
            Assert.AreEqual(1, basket.BasketItems.Count);
            Assert.AreEqual("1", basket.BasketItems.ToList().FirstOrDefault().ProductId);
        }
Exemplo n.º 13
0
        public ActionResult AddToBasket(string Id, string quantity)
        {
            basketService.AddToBasket(Id, quantity);

            return(RedirectToAction("Index", "Home"));
        }
Exemplo n.º 14
0
 public ActionResult AddToBasket(int id)
 {
     basketService.AddToBasket(this.HttpContext, id, 1);//always add one to the basket
     return(RedirectToAction("BasketSummary"));
 }