public async Task Test_events() { using (var eventStore = new MongoEventStore(_mongoClient, DatabaseName)) { var eventStoreTestSuit = new EventStoreTestSuit(eventStore, new ProjectionSerializer(_bsonSerializer)); var aggregate = await eventStoreTestSuit.EventTestsAsync(); using (var projectionRepository = new MongoProjectionRepository(_mongoClient, DatabaseName)) { var projection = await projectionRepository.GetAsync <BarProjection>(nameof(BarProjection), aggregate.Id); projection.Id.Should().Be(aggregate.Id); projection.LastText.Should().Be(aggregate.LastText); projection.UpdatedAt.ToString("G").Should().Be(aggregate.UpdatedAt.ToString("G")); projection.Messages.Count.Should().Be(aggregate.Messages.Count); } using (var projectionRepository = new MongoProjectionRepository <BarProjection>(_mongoClient, DatabaseName)) { var projections = await projectionRepository.FindAsync(e => e.Id == aggregate.Id); projections.Count().Should().BeGreaterOrEqualTo(1); } } }
public async Task Projection_is_rebuilt_by_denormalizer() { //Need to create an aggregate here. var serializer = new EventSerializer(new BsonTextSerializer()); DenormAggregate aggregate; using (var eventStore = new MongoEventStore(_mongoClient, _defaultSettings)) { aggregate = new DenormAggregate(Guid.NewGuid()); for (int i = 0; i < 10; i++) { aggregate.DoThing("Thing_" + i); } var session = new Session(new LoggerFactory(), eventStore, new EventPublisher(StubEventRouter.Ok()), serializer); session.Add(aggregate); await session.CommitAsync(); } var projectionRepository = new MongoProjectionRepository(_mongoClient, _defaultSettings); using (var eventStore = new MongoEventStore(_mongoClient, _defaultSettings)) { var testDenormalizer = new TestDenormalizer(projectionRepository, eventStore, serializer); await testDenormalizer.RebuildAsync(); } var projection = await projectionRepository.RetrieveAsync <TestProjection>("TestDenormalizedProjection"); projection.LastThing.Should().Be(aggregate.LastThing); }
public async Task Projection_can_be_stored_and_retrieved() { var projectionRepo = new MongoProjectionRepository(_mongoClient, _defaultSettings); var projectionId = Guid.NewGuid().ToString(); var firstName = "FirstName" + projectionId; await projectionRepo.UpsertAsync(new TestProjection(projectionId) { FirstName = firstName }, new TestEvent()); var projectionResult = await projectionRepo.RetrieveAsync <TestProjection>(projectionId); projectionResult.ProjectionId.Should().Be(projectionId); projectionResult.FirstName.Should().Be(firstName); }
public async Task Existing_projection_can_be_upserted() { var projectionRepo = new MongoProjectionRepository(_mongoClient, _defaultSettings); var projectionId = Guid.NewGuid().ToString(); var firstName = "FirstName" + projectionId; await projectionRepo.UpsertAsync(new TestProjection(projectionId) { FirstName = firstName }, new TestEvent()); var projectionResult = await projectionRepo.RetrieveAsync <TestProjection>(projectionId); projectionResult.LastName = "UpdatedLastName"; await projectionRepo.UpsertAsync(projectionResult, new TestEvent()); await Task.Delay(200); projectionResult = await projectionRepo.RetrieveAsync <TestProjection>(projectionId); projectionResult.LastName.Should().Be("UpdatedLastName"); }