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);

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

            Basket basket = baskets.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);
        }
Esempio n. 3
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>();
            MockHttpContext        httpContext     = new MockHttpContext();

            IBasketService   basketService = new BasketService(productContext, basketContext);
            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");
            controller.AddToBasket("1");
            Basket basket = basketContext.Collection().FirstOrDefault();

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

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

            customers.Insert(new Customer {
                Id = "1", Email = "*****@*****.**", ZipCode = "11000"
            });
            var fakeUser = new GenericPrincipal(new GenericIdentity("*****@*****.**", "Forms"), null);

            httpContext.User = fakeUser;
            var controller = new BasketController(basketService, orderService, customers);

            controller.ControllerContext = new ControllerContext(httpContext, new RouteData(), controller);

            // act
            //basketService.AddToBasket(httpContext, "1");
            controller.AddToBasket("1");

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

            // assert
            Assert.IsNotNull(basket);
            Assert.AreEqual(1, basket.BasketItems.Count);
            Assert.AreEqual("1", basket.BasketItems.ToList().FirstOrDefault().ProductId);
        }
Esempio n. 5
0
        public void CanAddCartItem()
        {
            //SetUp
            IRepository <Cart>     carts     = new MockContext <Cart>();
            IRepository <Product>  products  = new MockContext <Product>();
            IRepository <Order>    Orders    = new MockContext <Order>();
            IRepository <Customer> customers = new MockContext <Customer>();

            var httpContext = new MockHttpContext();

            ICartService  cartService  = new CartService(products, carts);
            IOrderService orderService = new OrderService(Orders);
            var           controller   = new CartController(cartService, orderService, customers);

            controller.ControllerContext = new ControllerContext(httpContext, new RouteData(), controller);

            //Act

            //cartService.AddToCart(httpContext, "1");
            controller.AddToCart("1");
            Cart cart = carts.Collection().FirstOrDefault();

            //Assert
            Assert.IsNotNull(cart);
            Assert.AreEqual(1, cart.CartItems.Count);
            Assert.AreEqual("1", cart.CartItems.ToList().FirstOrDefault().ProductId);
        }
Esempio n. 6
0
        public void CanAddBasketItem()
        {
            IRepository <Product> productContext = new MockContext <Product>();
            //IRepository<ProductCategory> productCategoryContext = new MockContext<ProductCategory>();
            IRepository <Basket>   basketContext      = new MockContext <Basket>();
            IRepository <Customer> customerRepository = new MockContext <Customer>();


            IBasketService basketService = new BasketService(productContext, basketContext);
            IOrderService  orderService  = new OrderService(new MockContext <Order>());
            //setting up
            BasketController basketController = new BasketController(basketService, orderService, customerRepository);

            basketController.ControllerContext = new System.Web.Mvc.ControllerContext(new MockHttpContext(), new System.Web.Routing.RouteData(), basketController);
            //basketService.AddToBasket(new MockHttpContext(),"1");

            //act
            basketController.AddToBasket("1");
            var basket = basketContext.Collection().FirstOrDefault();

            //Assert
            Assert.IsNotNull(basket);
            Assert.AreEqual(1, basket.BasketItems.Count());
            Assert.AreEqual("1", basket.BasketItems.ToList().FirstOrDefault().ProductId);
        }
Esempio n. 7
0
        public void CanAddBasketItem()
        {
            // Setup
            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);

            // This is so we can test add to bask throught the controller
            var controller = new BasketController(basketService, orderService, customers);

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

            // Act
            // This is to test the basket service itself
            //basketService.AddToBasket(httpContext, "1");
            controller.AddToBasket("1");

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

            // Test
            // Test if Basket is not Empty
            Assert.IsNotNull(basket);

            // Test that there is only one item in the basket
            Assert.AreEqual(1, basket.BasketItems.Count);

            // Tests that the first item productid is 1
            Assert.AreEqual("1", basket.BasketItems.ToList().FirstOrDefault().ProductId);
        }
        public void CanAddBasketItem()
        {
            //Send in Mock repositories
            //Set Up
            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);



            //TestCategoryAttribute the basket service directly
            //Act
            // basketService.AddToBasket(httpContext, "1");
            controller.AddToBasket("1");

            // Looking for basket collection
            Basket basket = baskets.Collection().FirstOrDefault();



            //Test an d check
            //Assert
            Assert.IsNotNull(basket);
            Assert.AreEqual(1, basket.BasketItems.Count);
            Assert.AreEqual("1", basket.BasketItems.ToList().FirstOrDefault().ProductId);
        }
Esempio n. 9
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);
        }
Esempio n. 10
0
        public void CanAddBasketItem()
        {
            //setup
            IRepository <Basket>   baskets   = new MockContext <Basket>(); // created the mock repositories
            IRepository <Product>  products  = new MockContext <Product>();
            IRepository <Order>    orders    = new MockContext <Order>();
            IRepository <Customer> customers = new MockContext <Customer>();


            var httpContext = new MockHttpContext();                             //created our httpContext

            IBasketService basketService = new BasketService(products, baskets); // ceated our basketService which takes our products, baskets context

            IOrderService orderService = new OrderService(orders);

            //// for testing the BasketService
            //basketService.AddToBasket(httpContext, "1"); // to test the service directly

            //Basket basket = baskets.Collection().FirstOrDefault(); // checks if theres any baskets in our basket collection

            //Assert.IsNotNull(basket); // checks basket to make sure it is not null
            //Assert.AreEqual(1, basket.BasketItems.Count); // checks if there is one item in the basket
            //Assert.AreEqual("1", basket.BasketItems.ToList().FirstOrDefault().ProductId); // checks to make sure the productId in the basket is the one we just injected


            // for testing the BasketController

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

            controller.ControllerContext = new System.Web.Mvc.ControllerContext(httpContext, new System.Web.Routing.RouteData(), controller);
            // how we inject the httpContext into the controller

            controller.AddToBasket("1");

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


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

            var httpContext = new MockHttpContext();

            IBasketService basketService = new BasketService(products, baskets);
            IOrderService  orderService  = new OrderService(orders);
            //var controller = new BasketController(basketService, orderService);
            //controller.ControllerContext = new System.Web.Mvc.ControllerContext(httpContext, new System.Web.Routing.RouteData(), controller);

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

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

            Assert.IsNull(basket);
        }
Esempio n. 12
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);
        }
Esempio n. 13
0
        public void CanAddBasketItem_BasketController()
        {
            IRepository <Product>  products  = new MockContext <Product>();
            IRepository <Basket>   baskets   = new MockContext <Basket>();
            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);

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

            basketController.ControllerContext = new ControllerContext(httpContext, new RouteData(), basketController);
            basketController.AddToBasket("1");


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

            Assert.IsNotNull(basketService);
            Assert.AreEqual(1, basket.BasketItems.Count);
            Assert.AreEqual("1", basket.BasketItems.ToList().FirstOrDefault().ProductId);
        }