public void AddToQuantityShouldIncreaseTheQuantityWithOne()
        {
            DbContextOptions <UltimateMoviesDbContext> options = new DbContextOptionsBuilder <UltimateMoviesDbContext>()
                                                                 .UseInMemoryDatabase(databaseName: "Carts_AddToQuantity_Database")
                                                                 .Options;
            UltimateMoviesDbContext db = new UltimateMoviesDbContext(options);

            ICartsService cartsService = new CartsService(db);

            db.Users.Add(new UMUser
            {
                UserName = "******"
            });

            db.SaveChanges();

            db.CartMovies.Add(new CartMovie
            {
                MovieId  = 1,
                UserId   = db.Users.Last().Id,
                Quantity = 1
            });

            db.SaveChanges();

            cartsService.AddToQuantity("Test", 1);

            int quantity = db.CartMovies.Last().Quantity;

            Assert.Equal(2, quantity);
        }
        public void AddMovieToCartShouldAddMovieAndUserToCartMovies()
        {
            DbContextOptions <UltimateMoviesDbContext> options = new DbContextOptionsBuilder <UltimateMoviesDbContext>()
                                                                 .UseInMemoryDatabase(databaseName: "Carts_AddMovieToCart_Database")
                                                                 .Options;
            UltimateMoviesDbContext db = new UltimateMoviesDbContext(options);

            ICartsService cartsService = new CartsService(db);

            db.Users.Add(new UMUser
            {
                UserName = "******"
            });

            db.SaveChanges();

            db.Movies.Add(new Movie
            {
                Name = "Test Movie"
            });

            db.SaveChanges();

            cartsService.AddMovieToCart(db.Users.ToList()[0].UserName, db.Movies.ToList()[0].Id);

            int    cartMoviesCount   = db.CartMovies.ToList().Count();
            string cartMoviesUserId  = db.CartMovies.ToList()[0].UserId;
            int    cartMoviesMovieId = db.CartMovies.ToList()[0].MovieId;

            Assert.Equal(1, cartMoviesCount);
            Assert.Equal(db.Users.ToList()[0].Id, cartMoviesUserId);
            Assert.Equal(db.Movies.ToList()[0].Id, cartMoviesMovieId);
        }
Exemplo n.º 3
0
        public void When_Calculate_Cart_With_Two_Products_Price_12_95_and_110_95_Should_Be_Total_equal_173_90()
        {
            var _cartOptions = new DbContextOptionsBuilder <CartsContext>().UseInMemoryDatabase("carts").Options;
            var _cartContext = new CartsContext(_cartOptions);

            var        _productOptions = new DbContextOptionsBuilder <ProductsContext>().UseInMemoryDatabase("products").Options;
            var        _productContext = new ProductsContext(_productOptions);
            CartsModel cartModel       = new CartsModel {
                userId         = 1,
                createDatetime = DateTime.Now,
                updateDatetime = DateTime.Now
            };
            List <ProductInCartModel> productsInCart = new List <ProductInCartModel>();

            productsInCart.Add(new ProductInCartModel {
                price    = 12.95M,
                quantity = 1
            });
            productsInCart.Add(new ProductInCartModel {
                price    = 110.95M,
                quantity = 1
            });

            CartsService cartsService = new CartsService(_cartContext, _productContext);
            var          actualResult = cartsService.calculate(cartModel, productsInCart);

            Assert.Equal(123.90M, actualResult.subtotal);
            Assert.Equal(148.90M, actualResult.total);
        }
Exemplo n.º 4
0
        public void When_Calculate_Cart_With_One_Product_Price_119_95_Should_Be_Total_equal_169_95()
        {
            var _cartOptions = new DbContextOptionsBuilder <CartsContext>().UseInMemoryDatabase("calculate_carts").Options;
            var _cartContext = new CartsContext(_cartOptions);

            var        _productOptions = new DbContextOptionsBuilder <ProductsContext>().UseInMemoryDatabase("calculate_products").Options;
            var        _productContext = new ProductsContext(_productOptions);
            CartsModel cartModel       = new CartsModel {
                userId         = 1,
                createDatetime = DateTime.Now,
                updateDatetime = DateTime.Now
            };
            List <ProductInCartModel> productsInCart = new List <ProductInCartModel>();

            productsInCart.Add(new ProductInCartModel {
                price    = (Decimal)119.95,
                quantity = 1
            });

            CartsService cartsService = new CartsService(_cartContext, _productContext);
            var          actualResult = cartsService.calculate(cartModel, productsInCart);

            Assert.Equal((Decimal)119.95, actualResult.subtotal);
            Assert.Equal((Decimal)144.95, actualResult.total);
        }
Exemplo n.º 5
0
        public void When_Create_New_Cart_With_Product_ID2_And_Quantity2_And_Should_Be_Get_CartID1()
        {
            var _cartOptions = new DbContextOptionsBuilder <CartsContext>().UseInMemoryDatabase("create_new_cart_carts").Options;
            var _cartContext = new CartsContext(_cartOptions);

            var _productOptions = new DbContextOptionsBuilder <ProductsContext>().UseInMemoryDatabase("create_new_cart_products").Options;
            var _productContext = new ProductsContext(_productOptions);

            ProductsModel productsData = new ProductsModel {
                id                = 2,
                name              = "43 Piece dinner Set",
                price             = (Decimal)12.95,
                availability      = "InStock",
                stockAvailability = 10,
                age               = "3_to_5",
                gender            = "FEMALE",
                brand             = "CoolKidz"
            };

            _productContext.Products.Add(productsData);
            _productContext.SaveChanges();

            CartsService cartsService = new CartsService(_cartContext, _productContext);
            var          actualResult = cartsService.add(productsData, 1);

            Assert.Equal(1, actualResult.id);
        }
Exemplo n.º 6
0
        public async System.Threading.Tasks.Task testCartGetAsync()
        {
            var carts = new List <Cart>
            {
                new Cart()
                {
                    Id = "test1"
                },
                new Cart()
                {
                    Id = "test2"
                },
            };

            var fakeRepositoryMock = new Mock <ICartsRepository>();

            fakeRepositoryMock.Setup(x => x.GetAll()).ReturnsAsync(carts);


            var cartService = new CartsService(fakeRepositoryMock.Object);

            var resultCarts = await cartService.GetCarts();

            Xunit.Assert.Collection(resultCarts, cart =>
            {
                Xunit.Assert.Equal("test1", cart.Id);
            },
                                    cart =>
            {
                Xunit.Assert.Equal("test2", cart.Id);
            });
        }
        public CartsTest()
        {
            _cartModel    = new CartsModel();
            _cartsService = new CartsService(null, null);

            _productsInCart = new List <ProductInCartModel>();
        }
Exemplo n.º 8
0
        public async System.Threading.Tasks.Task testCartAddAsync()
        {
            var fakeRepository = Mock.Of <ICartsRepository>();
            var cartService    = new CartsService(fakeRepository);

            var cart = new Cart()
            {
                Id = "test"
            };
            await cartService.AddAndSave(cart);
        }
        public void RemoveMovieFromCartShouldRemoveAMovieFromTheCart()
        {
            DbContextOptions <UltimateMoviesDbContext> options = new DbContextOptionsBuilder <UltimateMoviesDbContext>()
                                                                 .UseInMemoryDatabase(databaseName: "Carts_RemoveMovieFromCart_Database")
                                                                 .Options;
            UltimateMoviesDbContext db = new UltimateMoviesDbContext(options);

            ICartsService cartsService = new CartsService(db);

            db.Users.Add(new UMUser
            {
                UserName = "******"
            });

            db.SaveChanges();

            db.Movies.Add(new Movie
            {
                Name = "Test Movie"
            });

            db.Movies.Add(new Movie
            {
                Name = "Test Movie 2"
            });

            db.SaveChanges();

            db.CartMovies.Add(new CartMovie
            {
                UserId   = db.Users.Last().Id,
                MovieId  = db.Movies.ToList()[0].Id,
                Quantity = 1
            });

            db.CartMovies.Add(new CartMovie
            {
                UserId   = db.Users.Last().Id,
                MovieId  = db.Movies.ToList()[1].Id,
                Quantity = 1
            });

            db.SaveChanges();

            cartsService.RemoveMovieFromCart("Test", db.Movies.FirstOrDefault(m => m.Name == "Test Movie 2").Id);

            int cartMoviesCount = db.CartMovies.ToList().FindAll(c => c.UserId == db.Users.Last().Id).Count();

            Assert.Equal(1, cartMoviesCount);
        }
Exemplo n.º 10
0
        public void When_Get_Cart_By_Id_1_And_Should_Be_Get_This_Cart_Detail()
        {
            var _cartOptions = new DbContextOptionsBuilder <CartsContext>().UseInMemoryDatabase("get_carts_carts_detail").Options;
            var _cartContext = new CartsContext(_cartOptions);

            var _productOptions = new DbContextOptionsBuilder <ProductsContext>().UseInMemoryDatabase("get_carts_carts_products_detail").Options;
            var _productContext = new ProductsContext(_productOptions);

            CartsModel cartModel = new CartsModel {
                id          = 1,
                userId      = 1,
                subtotal    = (Decimal)12.95,
                shippingFee = (Decimal)50.00,
                total       = (Decimal)62.95
            };

            _cartContext.Carts.Add(cartModel);

            CartProductsModel cartProduct = new CartProductsModel {
                id        = 1,
                productId = 2,
                cartId    = 1,
                quantity  = 1,
            };

            _cartContext.CartProducts.Add(cartProduct);
            _cartContext.SaveChanges();

            ProductsModel productData = new ProductsModel {
                id                = 2,
                name              = "43 Piece dinner Set",
                price             = (Decimal)12.95,
                availability      = "InStock",
                stockAvailability = 10,
                age               = "3_to_5",
                gender            = "FEMALE",
                brand             = "CoolKidz"
            };

            _productContext.Products.Add(productData);
            _productContext.SaveChanges();

            CartsService cartsService = new CartsService(_cartContext, _productContext);
            var          actualResult = cartsService.getCart(1, 1);

            Assert.Equal(cartModel, actualResult);
        }
        public void When_Create_New_Cart_With_43_Piece_Dinner_Set_With_1_Qty_Should_Return_Cart_Detail_With_43_Piece_Dinner_Set()
        {
            ProductsModel adding_product  = _fixture._2_43_Piece_dinner_Set;
            int           adding_quantity = 1;

            CartsContext _cartContext = createCartsContext("create_new_cart_carts2");
            CartsModel   expectedCart = createCartInfo(adding_product, adding_quantity);

            CartsService       cartService = new CartsService(_cartContext, _productContext);
            AddCartOutputModel cartOutput  = cartService.add(adding_product, adding_quantity);
            CartsModel         actualCart  = cartService.getCart(cartOutput.id, DEFAULT_USER_ID);

            Assert.Equal(expectedCart.CartProducts, actualCart.CartProducts);
            Assert.Equal(expectedCart.userId, actualCart.userId);
            Assert.Equal(expectedCart.total, actualCart.total);
            Assert.Equal(expectedCart.subtotal, actualCart.subtotal);
            Assert.Equal(expectedCart.shippingFee, actualCart.shippingFee);
            Assert.Equal(expectedCart.shippingMethod, actualCart.shippingMethod);
        }
Exemplo n.º 12
0
        public void When_Calculate_Cart_With_Zero_Product_Should_Be_Total_equal_0()
        {
            var _cartOptions = new DbContextOptionsBuilder <CartsContext>().UseInMemoryDatabase("carts").Options;
            var _cartContext = new CartsContext(_cartOptions);

            var        _productOptions = new DbContextOptionsBuilder <ProductsContext>().UseInMemoryDatabase("products").Options;
            var        _productContext = new ProductsContext(_productOptions);
            CartsModel cartModel       = new CartsModel {
                userId         = 1,
                createDatetime = DateTime.Now,
                updateDatetime = DateTime.Now
            };
            List <ProductInCartModel> productsInCart = new List <ProductInCartModel>();
            CartsService cartsService = new CartsService(_cartContext, _productContext);
            var          actualResult = cartsService.calculate(cartModel, productsInCart);

            Assert.Equal(0.00M, actualResult.subtotal);
            Assert.Equal(0.00M, actualResult.total);
        }
 public CartsController(HoneyStoreContext context)
 {
     cartsService = new CartsService(context);
 }
Exemplo n.º 14
0
 public CartBL(Credential credential)
 {
     cartService = new CartsService(credential);
 }
 public CartsController(CartsService cs, ShoesService ss)
 {
     _cs = cs;
     _ss = ss;
 }
        public void GetAllMoviesFromUserCartShouldReturnDictionaryOfMoviesAndInts()
        {
            DbContextOptions <UltimateMoviesDbContext> options = new DbContextOptionsBuilder <UltimateMoviesDbContext>()
                                                                 .UseInMemoryDatabase(databaseName: "Carts_GetAllMoviesFromUserCart_Database")
                                                                 .Options;
            UltimateMoviesDbContext db = new UltimateMoviesDbContext(options);

            ICartsService cartsService = new CartsService(db);

            db.Users.Add(new UMUser
            {
                UserName = "******"
            });

            db.SaveChanges();

            db.Movies.Add(new Movie
            {
                Name = "Test Movie"
            });

            db.Movies.Add(new Movie
            {
                Name = "Test Movie 2"
            });

            db.Movies.Add(new Movie
            {
                Name = "Test Movie 3"
            });

            db.SaveChanges();

            db.CartMovies.Add(new CartMovie
            {
                UserId   = db.Users.Last().Id,
                MovieId  = db.Movies.ToList()[0].Id,
                Quantity = 1
            });

            db.CartMovies.Add(new CartMovie
            {
                UserId   = db.Users.Last().Id,
                MovieId  = db.Movies.ToList()[1].Id,
                Quantity = 1
            });

            db.CartMovies.Add(new CartMovie
            {
                UserId   = db.Users.Last().Id,
                MovieId  = db.Movies.ToList()[2].Id,
                Quantity = 1
            });

            db.SaveChanges();

            Dictionary <Movie, int> movies = cartsService.GetAllMoviesFromUserCart("Test");

            int moviesCount = movies.Count();

            Assert.Equal(3, moviesCount);
        }
Exemplo n.º 17
0
 public CartsController(IConfiguration configuration)
 {
     this.connectionString = configuration.GetConnectionString("ConnectionString");
     this.cartsService     = new CartsService(new CartsRepository(connectionString));
 }