示例#1
0
        public async Task InsertAsync_GetAsync_SingleAggregate_MultipleEvents()
        {
            // Given
            const string booId        = "001";
            var          booCreated   = new BooCreated(booId, 100M, false);
            var          booActivated = new BooActivated(booId);

            // When
            var aggregateRecord = new AggregateRecord(booId, "Boo", 0);
            var eventRecords    = new List <EventRecord <DomainEvent> >
            {
                new EventRecord <DomainEvent>(booCreated.Id, booCreated.CreatedAt, booCreated),
                new EventRecord <DomainEvent>(booActivated.Id, booActivated.CreatedAt, booActivated)
            };

            await _eventStoreRepository.SaveAsync(aggregateRecord, eventRecords).ConfigureAwait(false);

            // Then
            var results = await _eventStoreRepository.GetAsync <DomainEvent>(booId).ConfigureAwait(false);

            Assert.Equal(2, results.Count);
            Assert.Equal(booCreated.GetType(), results.Single(x => x.Version == 1).Event.GetType());
            Assert.Equal(booActivated.GetType(), results.Single(x => x.Version == 2).Event.GetType());
        }