상속: DomainBase, IOrderStatusIDContainer
예제 #1
0
        public void Execution_reduces_inventory_and_sets_order_item_to_a_shipped_state()
        {
            var productID = 1;
            var orderItemID = 1;
            var inventoryItem = new InventoryItem { QuantityOnHand = 5, ProductID = productID };
            var orderItem = new OrderItem { ProductID = productID, Quantity = 5, OrderStatusID = OrderStatusConstants.SUBMITTED_STATUS, ShippedDate = null, BackorderedDate = null };

            var inventoryDataProxy = new Mock<IInventoryItemDataProxy>();
            inventoryDataProxy.Setup(p => p.GetByProduct(productID)).Returns(inventoryItem);
            inventoryDataProxy.Setup(p => p.Update(It.IsAny<InventoryItem>()))
                              .Callback<InventoryItem>((item) => inventoryItem = item);
            
            var orderItemDataProxy = new Mock<IOrderItemDataProxy>();
            orderItemDataProxy.Setup(p => p.GetByID(orderItemID)).Returns(orderItem);
            orderItemDataProxy.Setup(p => p.Ship(It.IsAny<OrderItem>())).Returns(orderItem);

            var command = new ShipOrderItemCommand(orderItemID, orderItemDataProxy.Object, inventoryDataProxy.Object, new TransactionContextStub());
            var result = command.Execute();

            orderItem = result.Value;
            orderItem.ShippedDate.Value.Date.ShouldBe(DateTime.Now.ToUniversalTime().Date);
            orderItem.OrderStatus().IsShipped.ShouldBeTrue();
            orderItem.BackorderedDate.ShouldBeNull();
            inventoryItem.QuantityOnHand.ShouldBe(0);
        }
 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 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);
 }
예제 #5
0
 public void Is_invalid_when_an_order_item_is_submitted()
 {
     var item = new OrderItem();
     item.OrderStatusID = OrderStatusConstants.SUBMITTED_STATUS;
     var rule = new CanSubmitOrderItemRule(item);
     rule.Validate().IsValid.ShouldBe(false);
     rule.ErrorMessage.ShouldNotBe(null);
 }
 public void Is_valid_when_item_status_is_not_shipped()
 {
     var item = new OrderItem();
     item.OrderStatusID = OrderStatusConstants.PENDING_STATUS;
     var rule = new ValidOrderItemStatusForDeleteRule(item);
     rule.Validate().IsValid.ShouldBe(true);
     rule.ErrorMessage.ShouldBe(null);
 }
예제 #7
0
 public void Is_invalid_when_an_order_item_is_pending()
 {
     var item = new OrderItem();
     item.OrderStatusID = OrderStatusConstants.PENDING_STATUS;
     var rule = new CanSubmitOrderItemRule(item);
     rule.Validate().IsValid.ShouldBe(true);
     rule.ErrorMessage.ShouldBe(null);
 }
 public void Is_valid_when_item_status_is_submitted()
 {
     var item = new OrderItem();
     item.OrderStatusID = OrderStatusConstants.SUBMITTED_STATUS;
     var rule = new ValidOrderItemStatusForUpdateRule(item);
     rule.Validate().IsValid.ShouldBe(true);
     rule.ErrorMessage.ShouldBe(null);
 }
예제 #9
0
 public void Is_valid_when_an_order_item_is_backordered()
 {
     var item = new OrderItem();
     item.OrderStatusID = OrderStatusConstants.BACK_ORDERED_STATE;
     var rule = new CanShipOrderItemRule(item);
     rule.Validate().IsValid.ShouldBe(true);
     rule.ErrorMessage.ShouldBe(null);
 }
 public void Is_invalid_when_item_status_is_shipped()
 {
     var item = new OrderItem();
     item.OrderStatusID = OrderStatusConstants.SHIPPED_STATUS;
     var rule = new ValidOrderItemStatusForUpdateRule(item);
     rule.Validate().IsValid.ShouldBe(false);
     rule.ErrorMessage.ShouldBe("Shipped items cannot be changed");
 }
 public void Is_invalid_when_item_status_is_backordered()
 {
     var item = new OrderItem();
     item.OrderStatusID = OrderStatusConstants.BACK_ORDERED_STATE;
     var rule = new ValidOrderItemStatusForUpdateRule(item);
     rule.Validate().IsValid.ShouldBe(false);
     rule.ErrorMessage.ShouldBe("Backordered items cannot be changed");
 }
 public void Is_invalid_when_item_status_is_shipped()
 {
     var item = new OrderItem();
     item.OrderStatusID = OrderStatusConstants.SHIPPED_STATUS;
     var rule = new ValidOrderItemStatusForDeleteRule(item);
     rule.Validate().IsValid.ShouldBe(false);
     rule.ErrorMessage.ShouldNotBe(null);
 }
예제 #13
0
 public async Task Is_invalid_when_an_order_item_is_pending_async()
 {
     var item = new OrderItem();
     item.OrderStatusID = OrderStatusConstants.PENDING_STATUS;
     var rule = new CanShipOrderItemRule(item);
     await rule.ValidateAsync();
     rule.IsValid.ShouldBe(false);
     rule.ErrorMessage.ShouldNotBe(null);
 }
예제 #14
0
 public async Task Is_valid_when_an_order_item_is_submitted_async()
 {
     var item = new OrderItem();
     item.OrderStatusID = OrderStatusConstants.SUBMITTED_STATUS;
     var rule = new CanShipOrderItemRule(item);
     await rule.ValidateAsync();
     rule.IsValid.ShouldBe(true);
     rule.ErrorMessage.ShouldBe(null);
 }
예제 #15
0
 public async Task Is_invalid_when_an_order_item_is_backordered_async()
 {
     var item = new OrderItem();
     item.OrderStatusID = OrderStatusConstants.BACK_ORDERED_STATE;
     var rule = new CanSubmitOrderItemRule(item);
     await rule.ValidateAsync();
     rule.IsValid.ShouldBe(false);
     rule.ErrorMessage.ShouldNotBe(null);
 }
 public async Task Is_valid_when_item_status_is_pending_async()
 {
     var item = new OrderItem();
     item.OrderStatusID = OrderStatusConstants.PENDING_STATUS;
     var rule = new ValidOrderItemStatusForUpdateRule(item);
     await rule.ValidateAsync();
     rule.IsValid.ShouldBe(true);
     rule.ErrorMessage.ShouldBe(null);
 }
 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);
 }
예제 #18
0
 public OrderItemAmountValidityRule(OrderItem item, Product product)
 {
     _item = item;
     _product = product;
 }
예제 #19
0
 public OrderItemPriceValidityRule(OrderItem item, Product product)
 {
     _item = item;
     _product = product;
 }
 public ValidOrderItemStatusForDeleteRule(OrderItem item)
 {
     _item = item;
 }
예제 #21
0
 public CanSubmitOrderItemRule(OrderItem orderItem)
 {
     _orderItem = orderItem;
 }
예제 #22
0
 public CanShipOrderItemRule(OrderItem orderItem)
 {
     _orderItem = orderItem;
 }