public void when_handling_item_added()
        {
            var orderStatusBuilder = new OrderStatusModelHandler();

            var model = new OrderStatusModel() { Created = new DateTime(2013, 06, 21), LastChange = new DateTime(2013, 06, 21) , Status = Status.New};

            var eventContext = new EventContext()
            {
                Event = new ItemAddedToOrder() { OrderId = OrderId, ProductId = Guid.NewGuid() },
                EventNumber = 2,
                Headers =
                    new Dictionary<string, object>()
                                               {
                                                   {
                                                       "_Timestamp",
                                                       new DateTime(2013, 06, 24,
                                                                    13, 37, 42,
                                                                    18)
                                                   }
                                               }
            };

            var lastEvent = orderStatusBuilder.HandleAll(ref model, new[] { eventContext });

            model.ShouldNotBeNull();
            model.LastChange.ShouldEqual(new DateTime(2013, 06, 24, 13, 37, 42, 18));
            lastEvent.ShouldEqual(2);
        }
        public void when_handling_order_created()
        {
            var orderStatusBuilder = new OrderStatusModelHandler();

            OrderStatusModel model = null;
            var eventContext = new EventContext()
                                   {
                                       Event = new OrderCreated() {OrderId = OrderId},
                                       EventNumber = 1,
                                       Headers =
                                           new Dictionary<string, object>()
                                               {
                                                   {
                                                       "_Timestamp",
                                                       new DateTime(2013, 06, 24,
                                                                    13, 37, 42,
                                                                    17)
                                                   }
                                               }
                                   };

            var lastEvent = orderStatusBuilder.HandleAll(ref model, new[] { eventContext });

            model.ShouldNotBeNull();
            model.Status.ShouldEqual(Status.New);
            lastEvent.ShouldEqual(1);
        }
        private static void StoreCommandData(ResolvedEvent evt, EventContext deserializedEvent, IDocumentSession session)
        {
            var commandId = deserializedEvent.Headers["CommandId"] as string;

            var commandModel = session.Load<CommandStatusModel>(commandId);
            if (commandModel == null)
            {
                commandModel = new CommandStatusModel() { Id = commandId };
                commandModel.Events = new List<EventStatusModel>();
                session.Store(commandModel);
            }
            commandModel.Events.Add(new EventStatusModel() { StreamId = evt.Event.EventStreamId, EventNumber = evt.Event.EventNumber, Type = evt.Event.EventType});
        }