Inheritance: DomainBase
 public void Is_invalid_when_item_amount_does_not_equal_item_amount_times_product_price()
 {
     var orderItem = new OrderItem() { Amount = 30, Quantity = 3 };
     var product = new Product { Price = 11 };
     var rule = new OrderItemAmountValidityRule(orderItem, product);
     rule.Validate().IsValid.ShouldBe(false);
     rule.ErrorMessage.ShouldNotBe(null);
 }
 public void Execution_should_fail_when_all_required_params_are_not_set()
 {
     var product = new Product();
     var command = CreateCommand(product);
     var result = command.Execute();
     result.Success.ShouldBe(false);
     result.Errors.Count().ShouldBe(3);
 }
 public void Is_invalid_when_item_price_does_not_equal_product_price()
 {
     var orderItem = new OrderItem() { Price = 10 };
     var product = new Product { Price = 11 };
     var rule = new OrderItemPriceValidityRule(orderItem, product);
     rule.Validate().IsValid.ShouldBe(false);
     rule.ErrorMessage.ShouldNotBe(null);
 }
 public void Is_valid_when_item_price_equals_product_price()
 {
     var orderItem = new OrderItem() { Price = 10 };
     var product = new Product { Price = 10 };
     var rule = new OrderItemPriceValidityRule(orderItem, product);
     rule.Validate().IsValid.ShouldBe(true);
     rule.ErrorMessage.ShouldBe(null);
 }
 public override ICommand<Product> InsertCommand(Product entity)
 {
     var dataProxy = DataProxy as IProductDataProxy;
     return new ServiceCommand<Product>
     (
         executeMethod: () => dataProxy.Insert(entity), 
         executeAsyncMethod: () => dataProxy.InsertAsync(entity)
     );
 }
 public async Task Is_valid_when_item_amount_equals_item_quantity_times_product_price_async()
 {
     var orderItem = new OrderItem() { Amount = 30, Quantity = 3 };
     var product = new Product { Price = 10 };
     var rule = new OrderItemAmountValidityRule(orderItem, product);
     await rule.ValidateAsync();
     rule.IsValid.ShouldBe(true);
     rule.ErrorMessage.ShouldBe(null);
 }
        public void Execution_should_fail_when_all_required_params_are_not_set_behavior_based()
        {
            var product = new Product();
            var command = new CreateProductCommand(product,
                                                   Mock.Of<IProductDataProxy>(),
                                                   Mock.Of<IInventoryItemService>(),
                                                   new TransactionContextStub());

            var result = command.Execute();
            result.Success.ShouldBe(false);
            result.Errors.Count().ShouldBe(3);
        }
        public void Execution_deletes_product_and_associated_inventory_items()
        {
            var orderProxy = new Mock<IOrderDataProxy>();
            orderProxy.Setup(proxy => proxy.GetByProduct(1)).Returns(Enumerable.Empty<Order>());

            var product = new Product() { ProductID = 1 };
            var productDataProxy = new ProductRepository();
            productDataProxy.Clear();
            productDataProxy.Insert(product);

            var inventoryDataProxy = new InventoryItemRepository();
            inventoryDataProxy.Clear();
            inventoryDataProxy.Insert(new InventoryItem() { ProductID = 1 });

            var command = new DeleteProductCommand(1, productDataProxy,
                                                      new InventoryItemService(inventoryDataProxy), 
                                                      orderProxy.Object,
                                                      new TransactionContextStub());
            var result = command.Execute();
            result.Success.ShouldBe(true);
            result.Errors.ShouldBe(null);
            productDataProxy.GetAll().Count().ShouldBe(0);
            inventoryDataProxy.GetAll().Count().ShouldBe(0);
        }
 public OrderItemAmountValidityRule(OrderItem item, Product product)
 {
     _item = item;
     _product = product;
 }
 private ICommand<Product> CreateCommand(Product product)
 {
     var productDataProxy = new ProductRepository();
     var inventoryDataProxy = new InventoryItemRepository();
     var inventoryService = new InventoryItemService(inventoryDataProxy);
     return new CreateProductCommand(product, productDataProxy, inventoryService, new TransactionContextStub());
 }
 public OrderItemPriceValidityRule(OrderItem item, Product product)
 {
     _item = item;
     _product = product;
 }