public async Task CreateOrderWIthLoggedUser_ShouldReturnOrderId()
        {
            //Arrange
            var db = this.SetDb();

            await this.SeedProducts(db);

            await this.SeedUser(db);

            var productRepo = new Repository <Product>(db);
            var repo        = new Repository <Order>(db);
            var userRepo    = new Repository <CakeItUser>(db);
            var wrapper     = new TestCartSessionWrapper();
            var cartManager = new CartManager(wrapper);

            var item1 = new Item()
            {
                Product = await productRepo.GetByIdAsync(1), Quantity = 1
            };

            cartManager.SetCartItem(new List <Item> {
                item1
            });

            var orderService = new OrderService(repo, userRepo, cartManager, this.Mapper);

            var userName = this.user.UserName;

            //Act
            var result = await orderService.CreateOrder(userName);

            //Asser
            Assert.Equal(1, result);
        }
        public async Task AddToCart_WithValidProductId_ShouldAddNewItemToCart()
        {
            //Arrange
            var db = this.SetDb();

            await this.SeedProducts(db);

            var productRepo = new Repository <Product>(db);
            var wrapper     = new TestCartSessionWrapper();
            var cartManager = new CartManager(wrapper);

            var cartService = new CartService(productRepo, cartManager);

            //Act
            await cartService.AddToCart(1);

            var expectedNumber   = 1;
            var expectedItemName = "Chocolate Peanut Cake";
            var actualItemName   = cartManager.GetCartItem().First().Product.Name;
            var actualNumber     = cartManager.GetCartItem().Count;

            //Assert
            Assert.Equal(expectedNumber, actualNumber);
            Assert.Equal(expectedItemName, actualItemName);
        }
        public async Task GetAllOrdersByUser_WithNoOrders_ShouldReturnEmptyCollectionOfOrders()
        {
            //Arrange
            var db = this.SetDb();

            await this.SeedProducts(db);

            await this.SeedUser(db);

            var repo        = new Repository <Order>(db);
            var userRepo    = new Repository <CakeItUser>(db);
            var wrapper     = new TestCartSessionWrapper();
            var cartManager = new CartManager(wrapper);

            var orderService = new OrderService(repo, userRepo, cartManager, this.Mapper);

            var userName = this.user.UserName;

            //Act
            var orders        = orderService.GetAllOrdersByUser(userName);
            var expectedCount = 0;
            var ectualCount   = orders.Count();

            //Asser
            Assert.Equal(expectedCount, ectualCount);
        }
        public async Task RemoveFromCart_WithCartAmountingToTwo_ShouldReturnCartItemsCount1()
        {
            //Arrange
            var db = this.SetDb();

            await this.SeedProducts(db);

            var productRepo = new Repository <Product>(db);
            var wrapper     = new TestCartSessionWrapper();
            var cartManager = new CartManager(wrapper);

            var cartService = new CartService(productRepo, cartManager);

            await cartService.AddToCart(1);

            await cartService.AddToCart(2);

            //Act
            await cartService.RemoveFromCart(1);

            var expected = 1;
            var actual   = cartManager.GetCartItem().Count;

            //Assert
            Assert.Equal(expected, actual);
        }
        public async Task GetCartItems_WithTwoItems_ShouldReturnItemCount2()
        {
            //Arrange
            var db = this.SetDb();

            await this.SeedProducts(db);

            var productRepo = new Repository <Product>(db);
            var wrapper     = new TestCartSessionWrapper();
            var cartManager = new CartManager(wrapper);

            var cartService = new CartService(productRepo, cartManager);

            await cartService.AddToCart(1);

            await cartService.AddToCart(2);

            //Act
            var result = cartService.GetCartItems();

            var expectedResultCount = 2;
            var actualResultCount   = result.CartItems.Count;

            //Assert
            Assert.Equal(expectedResultCount, actualResultCount);
        }
        public async Task AddToCart_WhitInValidProductId_ShouldNotAddItem()
        {
            //Arrange
            var db = this.SetDb();

            await this.SeedProducts(db);

            var productRepo = new Repository <Product>(db);
            var wrapper     = new TestCartSessionWrapper();
            var cartManager = new CartManager(wrapper);

            var cartService = new CartService(productRepo, cartManager);

            //Arrange
            try
            {
                await cartService.AddToCart(3);
            }
            catch (Exception)
            { }

            var expectedCartCount = 0;
            var actualCartCount   = cartManager.GetCartItem().Count;

            //Assert
            Assert.Equal(expectedCartCount, actualCartCount);
        }
        public async Task SetOrderDetailsId_WithValidId_ShouldSetOrderDetailsToOrder()
        {
            //Arrange
            var db = this.SetDb();

            await this.SeedProducts(db);

            await this.SeedUser(db);

            var productRepo = new Repository <Product>(db);
            var repo        = new Repository <Order>(db);
            var userRepo    = new Repository <CakeItUser>(db);
            var wrapper     = new TestCartSessionWrapper();
            var cartManager = new CartManager(wrapper);

            var item1 = new Item()
            {
                Product = await productRepo.GetByIdAsync(1), Quantity = 1
            };

            cartManager.SetCartItem(new List <Item> {
                item1
            });

            var orderService = new OrderService(repo, userRepo, cartManager, this.Mapper);

            var userName = this.user.UserName;

            var result = await orderService.CreateOrder(userName);

            var detailsRepo         = new Repository <OrderDetails>(db);
            var orderDetailsService = new OrderDetailsService(detailsRepo, this.Mapper);

            var model = new OrderDetailsViewModel
            {
                FirstName   = "Test",
                LastName    = "TestTest",
                Email       = "*****@*****.**",
                PhoneNumber = "+359/888777666",
                City        = "Test",
                Country     = "Test",
                Address     = "Test test test 6"
            };

            var id = await orderDetailsService.AddOrderDetails(model);

            //Act
            await orderService.SetOrderDetailsId(id);

            var expectedOrderDetailsId = 1;
            var actualOrerDetailsId    = (await repo.GetByIdAsync(1)).OrderDetailsId;

            //Assert
            Assert.Equal(expectedOrderDetailsId, actualOrerDetailsId);
        }
        public async Task AddToCart_WhitInValidProductId_ShouldThrow()
        {
            //Arrange
            var db = this.SetDb();

            await this.SeedProducts(db);

            var productRepo = new Repository <Product>(db);
            var wrapper     = new TestCartSessionWrapper();
            var cartManager = new CartManager(wrapper);

            var cartService = new CartService(productRepo, cartManager);

            //Assert
            await Assert.ThrowsAsync <NullReferenceException>(async() => await cartService.AddToCart(3));
        }
        public async Task GetAllItemsPerOrder_WithTwoDifferentItems_ShouldReturnCollectionOfTwoItems()
        {
            //Arrange
            var db = this.SetDb();

            await this.SeedProducts(db);

            await this.SeedUser(db);

            var productRepo = new Repository <Product>(db);

            var repo        = new Repository <Order>(db);
            var userRepo    = new Repository <CakeItUser>(db);
            var wrapper     = new TestCartSessionWrapper();
            var cartManager = new CartManager(wrapper);

            var item1 = new Item()
            {
                Product = await productRepo.GetByIdAsync(1), Quantity = 2
            };
            var item2 = new Item()
            {
                Product = await productRepo.GetByIdAsync(2), Quantity = 1
            };

            cartManager.SetCartItem(new List <Item> {
                item1, item2
            });

            var orderService = new OrderService(repo, userRepo, cartManager, this.Mapper);

            var userName = this.user.UserName;

            await orderService.CreateOrder(userName);

            //Act
            var result        = orderService.GetAllItemsPerOrder(1);
            var expectedCount = 2
            ;
            var actualCount = result.Count();

            //Assert
            Assert.Equal(expectedCount, actualCount);
        }
        public async Task CreateOrder_WithEmptyShoppingCart_ShouldThrow()
        {
            //Arrange
            var db = this.SetDb();

            await this.SeedProducts(db);

            await this.SeedUser(db);

            var repo        = new Repository <Order>(db);
            var userRepo    = new Repository <CakeItUser>(db);
            var wrapper     = new TestCartSessionWrapper();
            var cartManager = new CartManager(wrapper);

            var orderService = new OrderService(repo, userRepo, cartManager, this.Mapper);

            var userName = this.user.UserName;

            //Asser
            await Assert.ThrowsAsync <InvalidOperationException>(async() => await orderService.CreateOrder(userName));
        }
Esempio n. 11
0
        public async Task EmptyCart_ShouldEmptyCart()
        {
            //Arange
            var db = this.SetDb();

            await this.SeedProducts(db);

            var productRepo = new Repository <Product>(db);
            var wrapper     = new TestCartSessionWrapper();
            var cartManager = new CartManager(wrapper);

            var cartService = new CartService(productRepo, cartManager);

            await cartService.AddToCart(1);

            //Act
            cartService.EmptyCart();

            //Assert
            Assert.Empty(cartManager.GetCartItem());
        }
        public async Task GetAllOrdersByUser_ShouldReturnCollectionOfOrders()
        {
            //Arrange
            var db = this.SetDb();

            await this.SeedProducts(db);

            await this.SeedUser(db);

            var productRepo = new Repository <Product>(db);

            var repo        = new Repository <Order>(db);
            var userRepo    = new Repository <CakeItUser>(db);
            var wrapper     = new TestCartSessionWrapper();
            var cartManager = new CartManager(wrapper);

            var item1 = new Item()
            {
                Product = await productRepo.GetByIdAsync(1), Quantity = 1
            };

            cartManager.SetCartItem(new List <Item> {
                item1
            });

            var orderService = new OrderService(repo, userRepo, cartManager, this.Mapper);

            var userName = this.user.UserName;

            await orderService.CreateOrder(userName);

            //Act
            var orders        = orderService.GetAllOrdersByUser(userName);
            var expectedCount = 1;
            var ectualCount   = orders.Count();

            //Asser
            Assert.Equal(expectedCount, ectualCount);
        }
Esempio n. 13
0
        public async Task RemoveFromCart_WithItemCategoryTwo_ShouldReturnEmptyCart()
        {
            //Arrange
            var db = this.SetDb();

            var repo              = new Repository <CustomCakeImg>(db);
            var productRepo       = new Repository <Product>(db);
            var productService    = new CakeService(null, productRepo, this.Mapper);
            var customCakeService = new CustomCakeService(productRepo, repo, this.Mapper, null);

            var wrapper     = new TestCartSessionWrapper();
            var cartManager = new CartManager(wrapper);

            var cartService = new CartService(productRepo, cartManager);

            CustomCakeOrderViewModel model = new CustomCakeOrderViewModel
            {
                Sponge           = "Vanilla",
                FirstLayerCream  = "Whipped",
                SecondLayerCream = "Whipped",
                Filling          = "No_Filling",
                SideDecoration   = "White_Chocolate_Cigarettes",
                TopDecoration    = "Habana",
                NumberOfSlices   = 6,
                Img = null,
            };

            var product = customCakeService.CreateCustomProduct(model);

            await productService.AddCakeToDb(product);

            await cartService.AddToCart(1);

            //Act
            await cartService.RemoveFromCart(1);

            //Assert
            Assert.Empty(cartManager.GetCartItem());
        }
Esempio n. 14
0
        public async Task AddToCart_AddSecondTimeOneItem_ShouldIncreaseItemQuantity()
        {
            //Arrange
            var db = this.SetDb();

            await this.SeedProducts(db);

            var productRepo = new Repository <Product>(db);
            var wrapper     = new TestCartSessionWrapper();
            var cartManager = new CartManager(wrapper);

            var cartService = new CartService(productRepo, cartManager);

            //Act
            await cartService.AddToCart(1);

            await cartService.AddToCart(1);

            var expected = 2;
            var actual   = cartManager.GetCartItem().FirstOrDefault(i => i.Product.Id == 1).Quantity;

            //Assert
            Assert.Equal(expected, actual);
        }