public async Task can_get_snapshot()
        {
            //Given
            var aggregate = new Reviews.Domain.Review();

            aggregate.Apple(AutoFixture.Build <Domain.Events.V1.ReviewCreated>()
                            .With(e => e.Caption, Caption)
                            .With(e => e.Content, Content)
                            .With(e => e.ProductId, ProductId)
                            .With(e => e.Id, AggregateId).Create());
            aggregate.Apple(AutoFixture.Build <Domain.Events.V1.ReviewPublished>().With(e => e.Id, AggregateId).Create());
            aggregate.Apple(AutoFixture.Build <Domain.Events.V1.ReviewApproved>().With(e => e.Id, AggregateId).Create());

            var sut  = new GesSnapshotStore(Connection, null);
            var snap = aggregate.TakeSnapshot();
            await sut.SaveSnapshotAsync <Review>(snap);

            //When
            var result = await sut.GetSnapshotAsync <Review>(AggregateId);

            //Then
            outputHelper.WriteLine($"Snapshot result last Version:{result.Version}");
            result.Should().BeEquivalentTo(new ReviewSnapshot(Guid.Empty, AggregateId, -1, Caption, Content, Status.Approved, ProductId),
                                           o => o.ExcludingFields().Excluding(q => q.Id).Excluding(q => q.CurrentStatus).Excluding(q => q.ProductId));
        }
Ejemplo n.º 2
0
        private async Task BuildEventStore(IServiceCollection services)
        {
            //Create EventStore Connection
            var eventStoreConnection = EventStoreConnection.Create(
                Configuration["EventStore:ConnectionString"],
                ConnectionSettings.Create()
                .KeepReconnecting()
                .EnableVerboseLogging()
                .SetHeartbeatInterval(TimeSpan.FromMilliseconds(5 * 1000))
                .UseDebugLogger(),
                Environment.ApplicationName
                );

            eventStoreConnection.Connected += (sender, args)
                                              => Console.WriteLine($"Connection to {args.RemoteEndPoint} event store established.");

            eventStoreConnection.ErrorOccurred += (sender, args)
                                                  => Console.WriteLine($"Connection error : {args.Exception}");

            await eventStoreConnection.ConnectAsync();

            /*
             * eventStore cluster connection builder
             * var eventStoreConnection= await EventStoreConnectionBuilder.ConfigureStore();
             */
            var aggregateStore   = new GesAggregateStore(eventStoreConnection, null);
            var gesSnapshotStore = new GesSnapshotStore(eventStoreConnection, null);

            var repository = new Repository(aggregateStore, gesSnapshotStore);

            services.AddSingleton <IRepository>(repository);

            services.AddSingleton(new ApplicationService(repository));

            var documentStore = RavenDbConfiguration.Build(Configuration["RavenDb:Url"], Configuration["RavenDb:Database"]);

            IDocumentSession GetSession() => documentStore.OpenSession();

            await ProjectionManager.With
            .Connection(eventStoreConnection)
            .CheckpointStore(new RavenDbCheckPointStore(GetSession))
            .SetProjections(new Projection[]
            {
                new ActiveReviews(GetSession),
                new ReviewsByOwner(GetSession),
                new ReviewsByProducts(GetSession),
            })
            .StartAll();
        }
Ejemplo n.º 3
0
        public async Task can_take_snapshot()
        {
            //Given
            var aggregate = new Reviews.Domain.Review();

            aggregate.Apple(AutoFixture.Create <Domain.Events.V1.ReviewCreated>());
            aggregate.Apple(AutoFixture.Create <Domain.Events.V1.ReviewApproved>());

            var sut = new GesSnapshotStore(Connection, Serializer, EventTypeMapper, (a, b) => $"{a}-{b}", null);

            //When
            var result = await sut.SaveSnapshotAsync(aggregate.TakeSnapshot());

            //Then
            outputHelper.WriteLine($"Snapshot result last position:{result}");
            result.Should().BeGreaterThan(0);
        }
Ejemplo n.º 4
0
        private async Task BuildEventStore(IServiceCollection services)
        {
            //Create EventStore Connection
            var eventStoreConnection = EventStoreConnection.Create(
                Configuration["EventStore:ConnectionString"],
                ConnectionSettings.Create()
                .KeepReconnecting()
                .EnableVerboseLogging()
                .SetHeartbeatInterval(TimeSpan.FromMilliseconds(5 * 1000))
                .UseDebugLogger(),
                Environment.ApplicationName
                );

            eventStoreConnection.Connected += (sender, args)
                                              => Console.WriteLine($"Connection to {args.RemoteEndPoint} event store established.");

            eventStoreConnection.ErrorOccurred += (sender, args)
                                                  => Console.WriteLine($"Connection error : {args.Exception}");

            await eventStoreConnection.ConnectAsync();


            var serializer = new JsonNetSerializer();

            var eventMapper = new EventTypeMapper()
                              .Map <Domain.Events.V1.ReviewCreated>("reviewCreated")
                              .Map <Domain.Events.V1.CaptionAndContentChanged>("reviewUpdated")
                              .Map <Domain.Events.V1.ReviewPublished>("reviewPublished")
                              .Map <Domain.Events.V1.ReviewApproved>("reviewApproved")
                              .Map <Domain.ReviewSnapshot>("reviewSnapshot");


            var aggregateStore = new GesAggrigateStore(
                eventStoreConnection,
                serializer,
                eventMapper,
                (type, id) => $"{type.Name}-{id}",
                null);

            var gesSnapshotStore = new GesSnapshotStore(eventStoreConnection,
                                                        serializer,
                                                        eventMapper,
                                                        (type, id) => $"{type.Name}-{id}",
                                                        null);


            var inMemorySnapshotStore = new InMemorySnapshotStorageProvider("memoryDumpFile.dats");

            var redisSnapshotStore = new RedisSnapshotStoreProvider(Configuration["RedisStore:ConnectionString"]);

            var repository = new Repository(aggregateStore, gesSnapshotStore);

            services.AddSingleton <IRepository>(repository);

            services.AddSingleton(new ApplicationService(repository));

            IAsyncDocumentSession GetSession() => BuildRevenDb().OpenAsyncSession();

            await ProjectionManager.With
            .Connection(eventStoreConnection)
            .CheckpointStore(new RavenDbChecklpointStore(GetSession))
            .Serializer(serializer)
            .TypeMapper(eventMapper)
            .SetProjections(new Projection[]
            {
                new ActiveReviews(GetSession),
                new ReviewsByOwner(GetSession)
            })
            .StartAll();
        }