public async Task Can_save_stream_entry()
        {
            var number = await persistenceEngine.GetCurrentEventStoreCheckpointNumberAsync();

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

            var rawStreamEntry = config.WriteModel.GenerateRawStreamEntry();
            await persistenceEngine.SaveStreamEntriesAsync(new[] { rawStreamEntry });

            number = await persistenceEngine.GetCurrentEventStoreCheckpointNumberAsync();

            number.Should().BeGreaterThan(-1);
        }
        protected async Task SaveStreamEntryAsync()
        {
            testEvents = CreateTestData(null, null)
                         .Concat(CreateTestData("testgroup", null))
                         .Concat(CreateTestData(null, "testcategory"))
                         .Concat(CreateTestData("testgroup", "testcategory"))
                         .ToArray();

            await persistenceEngine.SaveStreamEntriesAsync(testEvents);

            await FixTestDataAsync();
        }
Пример #3
0
 private async Task SaveRawStreamEntryAsync()
 {
     await engine.SaveStreamEntriesAsync(
         new[]
     {
         config.WriteModel.GetRawStreamEntryFactory().CreateRawStreamEntry(
             engine.Serializer,
             Guid.NewGuid().ToString(),
             Guid.NewGuid().ToString(),
             1,
             new TestCatchUpEvent().ToTypedMessage(Guid.NewGuid().ToString(), null, null, null, DateTime.UtcNow, 0))
     });
 }
Пример #4
0
        public virtual async Task <int> SaveAsync(IEnumerable <IEventSourcedEntity> entities, IDictionary <string, object> commitHeaders = null)
        {
            var commitId = Guid.NewGuid().ToString();
            int result;
            var allMessages      = new List <IMessage>();
            var allStreamEntries = new List <IRawStreamEntry>();

            commitHeaders = commitHeaders ?? new Dictionary <string, object>();

            var distinctEntitiesList = entities
                                       .GroupBy(x => new { x.Id, x.GetType().Name })
                                       .Select(x => x.First())
                                       .ToList();

            foreach (var entity in distinctEntitiesList)
            {
                var streamName = entity.StreamName;

                var baseStreamRevision = entity.Version - entity.UncommittedEvents.Count();

                var messages = entity.UncommittedEvents
                               .Select(@event => @event.ToTypedMessage(
                                           Guid.NewGuid().ToString(),
                                           commitHeaders,
                                           commitHeaders?.ContainsKey(MessageConstants.CorrelationIdKey) == true ?
                                           (commitHeaders[MessageConstants.CorrelationIdKey] ?? "").ToString() :
                                           null,
                                           commitHeaders?.ContainsKey(MessageConstants.CausationIdKey) == true ?
                                           (commitHeaders[MessageConstants.CausationIdKey] ?? "").ToString() :
                                           null,
                                           DateTime.UtcNow,
                                           0))
                               .ToList();

                allMessages.AddRange(messages);

                var streamDTOs = messages
                                 .Select(x => rawStreamEntryFactory.CreateRawStreamEntry(persistenceEngine.Serializer, streamName, commitId, ++baseStreamRevision, x))
                                 .ToList();

                allStreamEntries.AddRange(streamDTOs);
            }

            result = await persistenceEngine.SaveStreamEntriesAsync(allStreamEntries);

            allStreamEntries.Clear();

            foreach (var entity in entities)
            {
                entity.ClearUncommittedEvents();
            }

            foreach (var message in allMessages)
            {
                committedMessagesSubject.OnNext(message);
            }

            allMessages.Clear();

            return(result);
        }