Ejemplo n.º 1
0
        private Task RecreateReadModelContext()
        {
            using (var readModels = new ReadModelContext())
            {
                readModels.Database.EnsureDeleted();
                readModels.Database.EnsureCreated();
            }

            // Should match with ReadModels.
            Rebuilder rebuilder = new Rebuilder(eventStore, eventFormatter);

            rebuilder.AddAll(new CategoryBuilder());
            rebuilder.AddAll(new OutcomeBuilder(domainFacade.PriceFactory));
            return(rebuilder.RunAsync());
        }
Ejemplo n.º 2
0
        public void Base()
        {
            Converts.Repository
            .AddJsonEnumSearchHandler()
            .AddJsonPrimitivesSearchHandler()
            .AddJsonObjectSearchHandler()
            .AddJsonKey()
            .AddJsonTimeSpan();

            CompositeEventFormatter formatter = new CompositeEventFormatter(
                new ReflectionCompositeTypeProvider(new ReflectionCompositeDelegateFactory()),
                Factory.Default <JsonCompositeStorage>()
                );
            MockEventStore eventStore = new MockEventStore();

            // Creation of state.
            Order order = new Order(KeyFactory.Create(typeof(Order)));

            order.AddItem(KeyFactory.Create(typeof(T_EventSourcing_ReadModels_Rebuilder)), 2);
            order.AddItem(KeyFactory.Create(typeof(Rebuilder)), 5);
            eventStore.Save(order.Events.Select(e => new EventModel(order.Key, e.Key, formatter.Serialize(e), e.Version)));

            // Rebuilding model.
            Rebuilder        rebuilder = new Rebuilder(eventStore, formatter);
            ReadModelHandler handler   = new ReadModelHandler();

            rebuilder.AddAll(handler);
            rebuilder.RunAsync().Wait();

            Assert.AreEqual(1, handler.Totals.Count);
            Assert.AreEqual(
                order.Events.OfType <OrderTotalRecalculated>().Last().TotalPrice,
                handler.Totals.FirstOrDefault().Value
                );
        }