コード例 #1
0
        public void Ship()
        {
            if (this.ShippingStatus.Result != ShippingResult.Unshipped)
            {
                throw new InvalidOperationException($"Unable to ship an {nameof(Order)} with status {this.ShippingStatus}.");
            }

            this.ShippingStatus = new ShippingStatus(Clock.Now, ShippingResult.Shipped);
        }
コード例 #2
0
        public void CancelShipment()
        {
            if (this.ShippingStatus.Result != ShippingResult.Unshipped)
            {
                throw new InvalidOperationException($"Unable to cancel shipment of an {nameof(Order)} with status {this.ShippingStatus}.");
            }

            this.ShippingStatus = new ShippingStatus(Clock.Now, ShippingResult.Cancelled);
        }
コード例 #3
0
        public Order(OrderDescription description)
        {
            // Note how the domain constraints are enforced on construction
            // More specific constraints (such as the contents of OrderDescription) have been enforced on construction of the respective types

            this.Id = IdGenerator.Current.CreateId();

            this.CreationDateTime = Clock.Now;

            this.Description = description ?? throw new ArgumentNullException(nameof(description));

            this.ShippingStatus = new ShippingStatus(this.CreationDateTime, ShippingResult.Unshipped);
        }