Beispiel #1
0
        public void EventSourcingWithInlinieAggregation()
        {
            var store = TestDocumentStore.Create(optionsHandler: options =>
            {
                options.Events.AggregateStreamsInlineWith <Route>();
            });

            var routeId = CombGuidIdGeneration.New();

            using (var session = store.OpenSession())
            {
                var route = new Route(routeId);
                route.Plan(DateTime.Now.AddDays(1));
                route.AddSource(new StopName("Home"), new TimeOfDay(17, 30), new Position(51.197894m, 4.481736m));
                route.AddDestination(new StopName("WooRank"), new TimeOfDay(18, 30), new Position(50.828417m, 4.400963m));
                route.AddStop(new StopName("Filling station"), new TimeOfDay(17, 45), new Position(50.828417m, 4.400963m));
                route.Drive(new DateTime(2016, 05, 20, 17, 32, 0));

                session.Events.StartStream <Route>(route.Id, route.GetChanges());

                session.SaveChanges();
            }

            using (var session = store.OpenSession())
            {
                var route = session.Load <Route>(routeId);

                _testOutputHelper.WriteAsJson(route);
            }
        }
Beispiel #2
0
        public void EventSourcingWithInlineProjection()
        {
            var store = TestDocumentStore.Create(optionsHandler: options =>
            {
                options.Events.InlineTransformation(new RouteDetailsViewProjection());
            });

            var routeId = CombGuidIdGeneration.New();

            using (var session = store.OpenSession())
            {
                var route = new Route(routeId);
                route.Plan(DateTime.Now.AddDays(1));
                route.AddSource(new StopName("Home"), new TimeOfDay(17, 30), new Domain.Position(51.197894m, 4.481736m));
                route.AddDestination(new StopName("WooRank"), new TimeOfDay(18, 30), new Domain.Position(50.828417m, 4.400963m));
                route.AddStop(new StopName("Filling station"), new TimeOfDay(17, 45), new Domain.Position(50.828417m, 4.400963m));
                route.Drive(new DateTime(2016, 05, 20, 17, 32, 0));

                var events = route.GetChanges();
                //_testOutputHelper.WriteAsJson(events);

                session.Events.StartStream <Route>(route.Id);
                session.Events.Append(route.Id, events);

                session.SaveChanges();
            }

            //load the view by route id
            using (var session = store.OpenSession())
            {
                var view = session.Load <RouteDetails>(routeId);

                _testOutputHelper.WriteAsJson(view);
            }
        }
Beispiel #3
0
        public void EventSourcingShowTheEvents()
        {
            var store   = TestDocumentStore.Create();
            var routeId = CombGuidIdGeneration.New();

            using (var session = store.OpenSession())
            {
                var route = new Route(routeId);
                route.Plan(DateTime.Now.AddDays(1));
                route.AddSource(new StopName("Home"), new TimeOfDay(17, 30), new Position(51.197894m, 4.481736m));
                route.AddDestination(new StopName("WooRank"), new TimeOfDay(18, 30), new Position(50.828417m, 4.400963m));
                route.AddStop(new StopName("Filling station"), new TimeOfDay(17, 45), new Position(50.828417m, 4.400963m));
                route.Drive(new DateTime(2016, 05, 20, 17, 32, 0));

                var events = route.GetChanges();
                //_testOutputHelper.WriteAsJson(events);

                session.Events.StartStream <Route>(route.Id);
                session.Events.Append(route.Id, events);

                session.SaveChanges();
            }

            using (var session = store.OpenSession())
            {
                var eventStream = session.Events.FetchStream(routeId);

                _testOutputHelper.WriteAsJson(eventStream);
            }
        }
Beispiel #4
0
        public void LoadAggregateById()
        {
            var slaveStore = TestDocumentStore.Create(ConnectionString.Slave,
                                                      optionsHandler: options =>
            {
                options.UpsertType = PostgresUpsertType.Legacy;
                options.AutoCreateSchemaObjects = AutoCreate.None;
            }, clear: false);
            var masterStore = TestDocumentStore.Create(ConnectionString.Master, optionsHandler: options => options.UpsertType = PostgresUpsertType.Legacy);

            var tempRouteId = CombGuidIdGeneration.New();
            var routeId     = CombGuidIdGeneration.New();

            using (var massWriter = new Writer(masterStore))
                using (var listenerMaster = new Listener("master", _testOutputHelper, masterStore, routeId, tempRouteId))
                    using (var listenerSlave = new Listener("slave", _testOutputHelper, slaveStore, routeId, tempRouteId))
                        using (var session = masterStore.OpenSession())
                        {
                            session.Store(new Route {
                                ID = tempRouteId
                            });
                            session.SaveChanges();

                            massWriter.Start();

                            Thread.Sleep(5000);

                            listenerSlave.Stored();
                            listenerMaster.Stored();

                            session.Store(new Route {
                                ID = routeId
                            });
                            session.SaveChanges();

                            listenerMaster.Start();
                            listenerSlave.Start();


                            _testOutputHelper.WriteLine($"Route stored");

                            Thread.Sleep(500);
                        }
        }