Beispiel #1
0
        public virtual async Task <IEventSourcedEntity> GetAsync(Type aggregateType, string streamName, int minRevision = 0, int maxRevision = int.MaxValue)
        {
            if (streamName.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(streamName));
            }

            var streamEntries = await persistenceEngine
                                .LoadStreamEntriesByStreamAsync(streamName)
                                .ToListAsync();

            if (streamEntries.Count == 0)
            {
                return(null);
            }

            var instance = (IEventSourcedEntity)instanceProvider.GetInstance(aggregateType);

            var events = new List <IEvent>();

            for (var i = 0; i < streamEntries.Count; i++)
            {
                var rawStreamEntry = streamEntries[i];

                events.Add((IEvent)persistenceEngine.Serializer.Deserialize(rawStreamEntry.Payload));
            }

            instance.LoadEvents(events);

            return(instance);
        }
        public async Task Can_save_and_load_stream_entry_by_streamname()
        {
            var expected = config.WriteModel.GenerateRawStreamEntry();

            var number = await persistenceEngine.GetCurrentEventStoreCheckpointNumberAsync();

            number.Should().Be(-1);

            await persistenceEngine.SaveStreamEntriesAsync(new[] { expected });

            var streamEntry = await persistenceEngine.LoadStreamEntriesByStreamAsync(config.RawStreamEntryStreamname)
                              .FirstAsync();

            streamEntry.Payload.Should().Be(expected.Payload);
        }