示例#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;
 }