public Product Save(Product product) { using (ITransaction transaction = session.BeginTransaction()) { session.Save(product); transaction.Commit(); } return product; }
public CartDataBuilder WithProduct(Product product, int quantity) { for (int i = 0; i < quantity; i++) { cart.AddProduct(product); } return this; }
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)); } }
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); }
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); }
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); }
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); }
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); }
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(); }
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); }
public Product Save(Product product) { throw new System.NotImplementedException(); }
public CartItem(Product product) { this.Product = product; this.Quantity = 1; }
public CartDataBuilder WithProduct(Product product) { cart.AddProduct(product); return this; }