public async Task SaveEvents_inserts_Correlation_entity_correctly()
        {
            // Arrange
            var userId = Guid.NewGuid();

            var created       = new FakeUserCreated();
            var correlationId = Guid.NewGuid();

            created.Raise(userId);
            DateTime now = DateTime.UtcNow;

            var sut = new SqlEventStore(
                () => new FakeEventStoreDbContext(_dbContextOptions),
                new JsonMessageSerializer());

            // Act
            await sut.SaveEvents <FakeUser>(new[] { created }, correlationId : correlationId);

            // Assert
            using (var db = new FakeEventStoreDbContext(_dbContextOptions))
            {
                Correlation correlation = await db
                                          .Correlations
                                          .Where(
                    c =>
                    c.AggregateType == typeof(FakeUser).FullName &&
                    c.AggregateId == userId &&
                    c.CorrelationId == correlationId)
                                          .SingleOrDefaultAsync();

                correlation.Should().NotBeNull();
                correlation.HandledAt.Should().BeCloseTo(now, precision: 100);
            }
        }
Exemplo n.º 2
0
        public async Task SaveEvents_inserts_Correlation_entity_correctly(
            FakeUserCreated created, Guid correlationId)
        {
            RaiseEvents(userId, created);
            var now = DateTimeOffset.Now;

            await sut.SaveEvents <FakeUser>(new[] { created }, correlationId);

            using (var db = new DataContext())
            {
                Correlation correlation = await db
                                          .Correlations
                                          .Where(
                    c =>
                    c.AggregateId == userId &&
                    c.CorrelationId == correlationId)
                                          .SingleOrDefaultAsync();

                correlation.Should().NotBeNull();
                correlation.HandledAt.Should().BeCloseTo(now);
            }
        }
        public async Task SaveEvents_inserts_Correlation_entity_correctly()
        {
            FakeUserCreated created       = _fixture.Create <FakeUserCreated>();
            var             correlationId = Guid.NewGuid();

            RaiseEvents(_userId, created);
            DateTime now = DateTime.UtcNow;

            await _sut.SaveEvents <FakeUser>(new[] { created }, correlationId : correlationId);

            using (var db = new DataContext())
            {
                Correlation correlation = await db
                                          .Correlations
                                          .Where(
                    c =>
                    c.AggregateId == _userId &&
                    c.CorrelationId == correlationId)
                                          .SingleOrDefaultAsync();

                correlation.Should().NotBeNull();
                correlation.HandledAt.Should().BeCloseTo(now);
            }
        }