Пример #1
0
        public void add_item ()
        {
            Cart cart = new Cart();

            cart.Add(new CartItem()
            {
                Id = Guid.NewGuid(),
                ProductId = Guid.NewGuid(),
                Quantity = 5
            });
            
            cart.ChangeUser(new User() {Id = Guid.NewGuid()});

            var newCart = new Cart();
            newCart.FillFromHistory(cart.AppliedEvents);

            foreach (var e in newCart.AppliedEvents)
            {
                Console.WriteLine(e.Version + " " + e.GetType().FullName);
            }

            Assert.AreEqual(2, newCart.AppliedEvents.Count());
        }
        public void should_applyEvents_toAnyEventSource()
        {
            EventReplayer.ClearRegistry();
            EventReplayer.Register<Cart, ItemAddedToCart>((es, ev) => es.Add(new CartItem()));
            EventReplayer.Register<Cart, CartUserChanged>((es, ev) => es.ChangeUser(ev.User));

            var store = CreateEventStore();

            Cart cart = new Cart();
            cart.Add(new CartItem()
            {
                Id = Guid.NewGuid(),
                ProductId = Guid.NewGuid(),
                Quantity = 1
            });

            store.SaveEvents(cart, cart.AppliedEvents);
            var events = store.ListEvents(cart);

            var newCart = new Cart();
            newCart.FillFromHistory(events);

            Assert.AreEqual(1, newCart.Items.Count());
        }