コード例 #1
0
 public Product Save(Product product)
 {
     using (ITransaction transaction = session.BeginTransaction())
     {
         session.Save(product);
         transaction.Commit();
     }
     return product;
 }
コード例 #2
0
        public CartDataBuilder WithProduct(Product product, int quantity)
        {
            for (int i = 0; i < quantity; i++)
            {
                cart.AddProduct(product);
            }

            return this;
        }
コード例 #3
0
ファイル: Cart.cs プロジェクト: SergeyVolodko/WebShopTask
        public virtual void AddProduct(Product product)
        {
            var existing = this.Items.FirstOrDefault(i => i.Product.Id == product.Id);

            if (existing != null)
            {
                existing.Quantity++;
            }
            else
            {
                this.Items.Add(new CartItem(product));
            }
        }
コード例 #4
0
        public void add_product_to_empty_cart_returns_new_cart_containing_product(
            Product product)
        {
            product = productRepository.Save(product);

            var sut = kernel.Get<ICartService>();

            var actual = sut.AddProductToCart(null, product.Id.Value);

            actual
                .Should()
                .NotBeNull();
            actual
                .Items
                .Should()
                .Contain(item => item.Product.Id == product.Id);
        }
コード例 #5
0
        public void add_product_to_cart_twice_should_increase_cart_item_quantity(
            Product product)
        {
            product = productRepository.Save(product);

            var productId = product.Id.Value;

            var sut = kernel.Get<ICartService>();

            var cart = sut.AddProductToCart(null, productId);

            var actual = sut.AddProductToCart(cart.Id, productId);

            actual.Items[0]
                .Quantity
                .Should()
                .Be(2);
        }
コード例 #6
0
        public void post_product_to_empty_cart_returns_cart_with_this_product(
            Product product)
        {
            var cart = new CartDataBuilder()
                .WithProduct(product)
                .Build();

            service.AddProductToCart(null, product.Id.Value)
                .Returns(cart);

            var data = new AddToCartData
            {
                CartId = null,
                ProductId = product.Id.Value
            };

            sut.Post(data)
                .Items
                .Should()
                .Contain(item => item.Product == product);
        }
コード例 #7
0
        public void add_product_to_cart_returns_cart_containing_proprt_cart_item(
            Guid cartId,
            Product product)
        {
            var productId = product.Id.Value;

            productRepository.GetById(productId)
                .Returns(product);

            var cart = new CartDataBuilder()
                .WithId(cartId)
                .Build();

            cartRepository.GetCartById(cartId)
                      .Returns(cart);

            var actual = sut.AddProductToCart(cartId, productId);

            actual.Items
                .Should()
                .Contain(item => item.Product == product);
        }
コード例 #8
0
        public void get_subtotal_for_cart_containing_same_products_returns_correct_sum(
            Guid cartId,
            Product multipleProduct,
            Product product)
        {
            var cart = new CartDataBuilder()
                .WithId(cartId)
                .WithProduct(multipleProduct, 2)
                .WithProduct(product)
                .Build();

            cartRepository.GetCartById(cartId)
                      .Returns(cart);

            var expected = multipleProduct.Price * 2 + product.Price;

            sut.GetSubtotal(cartId)
                .Should()
                .Be(expected);
        }
コード例 #9
0
        public void add_product_to_not_empty_cart_not_invoke_factory_create_cart(
            Guid cartId,
            Product product)
        {
            var cart = new CartDataBuilder()
                .WithId(cartId)
                .WithProduct(product)
                .Build();

            cartRepository.GetCartById(cartId)
                      .Returns(cart);

            sut.AddProductToCart(cartId, product.Id.Value);

            factory.DidNotReceive()
                   .CreateCart();
        }
コード例 #10
0
        public void add_product_to_nonempty_cart_invoke_repo_get_by_id(
            Product product,
            Guid cartId)
        {
            var cart = new CartDataBuilder()
                .WithId(cartId)
                .Build();

            cartRepository.GetCartById(cartId)
                      .Returns(cart);

            sut.AddProductToCart(cartId, product.Id.Value);

            cartRepository.Received()
                      .GetCartById(cartId);
        }
コード例 #11
0
 public Product Save(Product product)
 {
     throw new System.NotImplementedException();
 }
コード例 #12
0
ファイル: CartItem.cs プロジェクト: SergeyVolodko/WebShopTask
 public CartItem(Product product)
 {
     this.Product = product;
     this.Quantity = 1;
 }
コード例 #13
0
 public CartDataBuilder WithProduct(Product product)
 {
     cart.AddProduct(product);
     return this;
 }