예제 #1
0
파일: Given.cs 프로젝트: GunioRobot/cqrs
        public void GivenIHavePaidForTheOrder()
        {
            var orderId = EventSourceHelper.GetId<Order>();
            var orderEvents = GivenHelper.GivenEvents(orderId).ToArray();
            var orderPlacedEvent = orderEvents.OfType<OrderPlaced>().Single();
            if (orderEvents.Last() != orderPlacedEvent)
                throw new NotSupportedException("Sorry. This test helper isn't set up to handle updated orders.");

            var e = new OrderPaid(
                orderId,
                orderPlacedEvent.DiningLocation,
                orderPlacedEvent.OrderItems,
                orderPlacedEvent.Price,
                "Jason Dentler",
                "5444444444444444",
                Guid.NewGuid(),
                Guid.NewGuid());
            GivenHelper.Given(orderId, e);
        }
예제 #2
0
파일: Order.cs 프로젝트: GunioRobot/cqrs
 private void Apply(OrderPaid e)
 {
     _state = OrderState.Paid;
 }
예제 #3
0
파일: Order.cs 프로젝트: GunioRobot/cqrs
        public void Pay(string cardHolderName, string cardNumber)
        {
            switch (_state)
            {
                case OrderState.Cancelled:
                    throw new InvalidStateException("You can't pay for this order. It is cancelled. Place a new order.");
                case OrderState.Paid:
                    throw new InvalidStateException("You can't pay for this order. It's already paid.");
            }

            var e = new OrderPaid(
                Id,
                _location,
                _items.ToArray(),
                _price,
                cardHolderName,
                cardNumber,
                Guid.NewGuid(),
                Guid.NewGuid());
            ApplyChange(e);
        }