protected override void PersistenceContext()
 {
     _product = new ProductBuilder().Build();
     _customer = new CustomerBuilder()
         .WithProductInBasket(_product, 23)
         .Build();
     Save(_product, _customer);
 }
 protected override void PersistenceContext()
 {
     _product = new ProductBuilder().Build();
     var customer = new CustomerBuilder()
         .WithProductInBasket(_product, ProductQuantity)
         .WithDeliveryAddress()
         .Build();
     _order = new OrderBuilder()
         .WithCustomer(customer)
         .Build();
     Save(_product, _order);
 }
Beispiel #3
0
 public virtual void UpdateProductQuantityInBasket(Product product, int newCount)
 {
     var basketItem = _basketItems.First(x => x.Product == product);
     if (newCount == 0)
     {
         _basketItems.Remove(basketItem);
     }
     else
     {
         basketItem.UpdateQuantity(newCount);
     }
 }
Beispiel #4
0
 public virtual void AddProductToBasket(Product product, int count)
 {
     var basketItemWithTheProduct = _basketItems.FirstOrDefault(x => x.Product == product);
     if (basketItemWithTheProduct != null)
     {
         basketItemWithTheProduct.AddQuantity(count);
     }
     else
     {
         _basketItems.Add(new BasketItem(this, product, count));
     }
 }
        public void Context()
        {
            const int customerId = 45;
            _customer = Mock<Customer>();
            var customerRepository = Stub<IRepository<Customer>>().Stubs(x => x.GetById(customerId)).Returns(_customer);
            const int productId = 23;
            _product = Stub<Product>();
            var productRepository = Stub<IRepository<Product>>().Stubs(x => x.GetById(productId)).Returns(_product);
            var handler = new UpdateProductQuantityInBasketCommandHandler(customerRepository, productRepository);

            handler.Execute(new UpdateProductQuantityInBasketCommand
                                {
                                    CustomerId = customerId,
                                    ProductId = productId,
                                    Quantity = NewQuantity
                                });
        }
        public void Context()
        {
            _customerRepository = Mock<IRepository<Customer>>();
            const int productId = 23;
            _product = Stub<Product>();
            var productRepository = Stub<IRepository<Product>>().Stubs(x => x.GetById(productId)).Returns(_product);
            _customer = Mock<Customer>().Stubs(x => x.Id).Returns(CustomerId);
            var customerFactory = Stub<ICustomerFactory>().Stubs(x => x.Create()).Returns(_customer);
            var handler = new AddProductToBasketCommandHandler(_customerRepository, productRepository, customerFactory);
            handler.CommandExecuted += (sender, args) => _customerIdRaisedByEvent = (int)args.Args; // todo: refactor CoreDdd to support generic event handling

            handler.Execute(new AddProductToBasketCommand
                                {
                                    CustomerId = default(int),
                                    ProductId = productId,
                                    Quantity = Quantity
                                });
        }
        protected override void PersistenceContext()
        {
            _productOne = new ProductBuilder()
                .WithName(ProductOneName)
                .WithPrice(ProductOnePrice)
                .Build();
            _productTwo = new ProductBuilder()
                .WithName(ProductTwoName)
                .WithPrice(ProductTwoPrice)
                .Build();
            _customer = new CustomerBuilder()
                .WithProductInBasket(_productOne, ProductOneQuantity)
                .WithProductInBasket(_productTwo, ProductTwoQuantity)
                .Build();
            var anotherCustomer = new CustomerBuilder()
                .WithProductInBasket(_productOne, ProductOneQuantity)
                .Build();

            Save(_productOne, _productTwo, _customer, anotherCustomer);
        }
 public CustomerBuilder WithProductInBasket(Product product, int quantity)
 {
     _basketItems.Add(new BasketItemInfo { Product = product, Quantity = quantity });
     return this;
 }
 protected override void PersistenceQuery()
 {
     _retrievedProduct = Get<Product>(_product.Id);
 }
 protected override void PersistenceContext()
 {
     _product = new ProductBuilder().Build();
     Save(_product);
 }