예제 #1
0
파일: Given.cs 프로젝트: GunioRobot/cqrs
        public void GivenIHavePlacedAnOrderForASmallLatteWholeMilk()
        {
            var latteId = EventSourceHelper.GetId<Item>("Latte");
            var orderId = Guid.NewGuid();

            var e = new OrderPlaced(
                orderId,
                DiningLocation.TakeAway,
                new OrderItem[1]
                    {
                        new OrderItem(
                            latteId,
                            new Dictionary<string, string>()
                                {
                                    {"Size", "small"},
                                    {"Milk", "whole"}
                                }, 1)
                    },
                7.60M);

            GivenHelper.Given(orderId, e);
        }
예제 #2
0
파일: Order.cs 프로젝트: GunioRobot/cqrs
        public Order(
            Guid orderId,
            DiningLocation diningLocation,
            OrderItem[] orderItems,
            IProductInfo[] products)
            : this()
        {
            var price = orderItems
                .Select(i => new
                                 {
                                     product = products.Single(p => p.MenuItemId == i.MenuItemId),
                                     item = i
                                 })
                .Select(i => i.item.Quantity*i.product.Price)
                .Sum();

            var e = new OrderPlaced(
                orderId,
                diningLocation,
                orderItems,
                price);
            ApplyChange(e);
        }
예제 #3
0
파일: Order.cs 프로젝트: GunioRobot/cqrs
 private void Apply(OrderPlaced e)
 {
     Id = e.OrderId;
     _state = OrderState.Placed;
     _items.AddRange(e.OrderItems);
     _price = e.Price;
     _location = e.DiningLocation;
 }