public AddCartOutputModel add(ProductsModel product, int quantity)
        {
            CartsModel                cartModel         = this.createCart(1);
            CartProductsModel         cartProductsModel = this.addProductToCart(cartModel, product, quantity);
            List <ProductInCartModel> productsInCart    = this.getProductInCart(cartModel.id);

            cartModel = this.calculate(cartModel, productsInCart);
            _context.Carts.Update(cartModel);
            _context.SaveChanges();
            return(new AddCartOutputModel {
                id = cartModel.id
            });
        }
Exemplo n.º 2
0
        private static CartsContext generateCartContext(string databaseName)
        {
            var _cartOptions = new DbContextOptionsBuilder <CartsContext>().UseInMemoryDatabase(databaseName).Options;
            var _cartContext = new CartsContext(_cartOptions);


            CartsModel cartModel = new CartsModel
            {
                id             = 1,
                userId         = 1,
                shippingMethod = "Cash on Delivery",
                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();
            return(_cartContext);
        }
Exemplo n.º 3
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_Order_With_Cart_Should_Be_Return_Order()
        {
            var _orderOptions = new DbContextOptionsBuilder <OrdersContext>().UseInMemoryDatabase("create_order_orders_1").Options;
            var _orderContext = new OrdersContext(_orderOptions);

            var _cartOptions = new DbContextOptionsBuilder <CartsContext>().UseInMemoryDatabase("create_order_carts_detail_1").Options;
            var _cartContext = new CartsContext(_cartOptions);

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

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

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

            OrdersService ordersService = new OrdersService(_cartContext, _productContext, _orderContext);
            var           actualResult  = ordersService.create(1, 1);

            //  CreateOrderOutputModel actualResult = new CreateOrderOutputModel{
            //     id = 1
            //  };

            Assert.Equal(2, actualResult.id);



            using (var context = new ProductsContext(_productOptions))
            {
                _productContext.Database.EnsureDeleted();
            }
            using (var context = new CartsContext(_cartOptions))
            {
                _cartContext.Database.EnsureDeleted();
            }
            using (var context = new OrdersContext(_orderOptions))
            {
                _orderContext.Database.EnsureDeleted();
            }
        }