示例#1
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);
        }