Beispiel #1
0
        public async Task <IDictionary <string, List <EventStreamUpdated> > > LoadAsync()
        {
            var result      = new Dictionary <string, List <EventStreamUpdated> >();
            var query       = m_table.PrepareEntityGetAllQuery();
            var queryResult = await query.ExecuteAsync();

            foreach (var row in queryResult)
            {
                var rowKey      = (string)row[KnownProperties.RowKey];
                var rowKeyParts = rowKey.Split('|');
                var streamName  = rowKeyParts[0];
                var fromVersion = StreamVersion.Parse(rowKeyParts[1]);
                var toVersion   = StreamVersion.Create((int)row["ToVersion"]);

                List <EventStreamUpdated> streamNotifications;
                if (result.ContainsKey(streamName))
                {
                    streamNotifications = result[streamName];
                }
                else
                {
                    streamNotifications = new List <EventStreamUpdated>();
                    result[streamName]  = streamNotifications;
                }

                streamNotifications.Add(new EventStreamUpdated(streamName, fromVersion, toVersion));
            }

            return(result);
        }
        public async Task CreatedWriter_AppendsEventsAndMovesPositionForward(JournaledEvent[] dummyEvents)
        {
            var writer = await Connection.CreateStreamWriterAsync(StreamName);

            await writer.AppendEventsAsync(dummyEvents);

            Assert.Equal(StreamVersion.Create(dummyEvents.Length), writer.StreamVersion);
        }
        public void Increment_IncreasesVersionByOne(int versionValue)
        {
            var expectedVersion = StreamVersion.Create(versionValue + 1);
            var version         = StreamVersion.Create(versionValue);

            var incrementedVersion = version.Increment();

            Assert.Equal(expectedVersion, incrementedVersion);
        }
Beispiel #4
0
        public async Task AppendEventsAsync_WriteEventsToEndOfStream(string streamName)
        {
            // arrange
            var position = EventStreamHeader.Unknown;

            // act
            position = await AppendEventsAsync(streamName, batchNumber : 3);

            // assert
            Assert.Equal(StreamVersion.Create(30), position.Version);
        }
Beispiel #5
0
        public async Task <IEnumerable <StreamReaderDescription> > GetStreamReadersDescriptionsAsync(string streamName)
        {
            Require.NotEmpty(streamName, nameof(streamName));

            var streamReadersProperties = await m_table.ReadAllStreamReadersPropertiesAsync(streamName);

            var descriptions = streamReadersProperties.Select(streamReaderProperties => new StreamReaderDescription(
                                                                  streamName,
                                                                  EventStreamReaderId.Parse(streamReaderProperties[KnownProperties.RowKey].ToString().Split('|').Last()),
                                                                  StreamVersion.Create((int)streamReaderProperties[EventJournalTableRowPropertyNames.Version])));

            return(descriptions);
        }
Beispiel #6
0
        public async Task <StreamVersion> ReadStreamReaderPositionAsync(string streamName, EventStreamReaderId readerId)
        {
            Require.NotEmpty(streamName, "streamName");
            Require.NotNull(readerId, "readerId");

            var properties = await m_table.ReadStreamReaderPropertiesAsync(streamName, readerId);

            if (properties == null)
            {
                return(StreamVersion.Unknown);
            }

            return(StreamVersion.Create((int)properties[EventJournalTableRowPropertyNames.Version]));
        }
Beispiel #7
0
        public async Task OpenEventStreamFromAsync_ReadPreviousCommitedEvents(string streamName)
        {
            // arrange
            var fromVersion = StreamVersion.Create(101);

            await AppendEventsAsync(streamName, 50, 4);

            // act
            var events = await ReadEventsFromAsync(streamName, fromVersion);

            // assert
            Assert.Equal(100, events.Count);
            Assert.True(events[0].Offset.IsTrue(e => e == fromVersion));
            Assert.True(events[99].Offset.IsTrue(e => e == StreamVersion.Create(200)));
        }
Beispiel #8
0
        public async Task <EventStreamHeader> ReadStreamHeaderAsync(string streamName)
        {
            Require.NotEmpty(streamName, "streamName");

            var headProperties = await m_table.ReadStreamHeadPropertiesAsync(streamName);

            if (headProperties == null)
            {
                return(EventStreamHeader.Unknown);
            }

            var timestamp = (string)headProperties[EventJournalTableRowPropertyNames.ETag];
            var version   = StreamVersion.Create((int)headProperties[EventJournalTableRowPropertyNames.Version]);

            return(new EventStreamHeader(timestamp, version));
        }
        public void Customize(IFixture fixture)
        {
            if (m_emptyCursor)
            {
                fixture.Customize <IEventStreamCursor>(composer => composer
                                                       .FromFactory(() => EventStreamCursor.UninitializedStream));
            }
            else
            {
                fixture.Customize <SortedList <StreamVersion, JournaledEvent> >(composer => composer
                                                                                .FromFactory(() => new SortedList <StreamVersion, JournaledEvent>
                {
                    { StreamVersion.Create(1), fixture.Create <JournaledEvent>() },
                    { StreamVersion.Create(2), fixture.Create <JournaledEvent>() },
                    { StreamVersion.Create(3), fixture.Create <JournaledEvent>() }
                })
                                                                                .OmitAutoProperties());

                fixture.Customize <FetchEvents>(composer => composer
                                                .FromFactory(
                                                    () => version => new FetchEventsResult(
                                                        true,
                                                        fixture.Create <SortedList <StreamVersion, JournaledEvent> >()).YieldTask()));

                fixture.Customize <EventStreamHeader>(composer => composer
                                                      .FromFactory(() => new EventStreamHeader(
                                                                       fixture.Create("ETag"),
                                                                       StreamVersion.Create(3))));

                fixture.Customize <IEventStreamCursor>(composer => composer
                                                       .FromFactory(() => EventStreamCursor.CreateActiveCursor(
                                                                        new EventStreamHeader(fixture.Create("Etag"), StreamVersion.Create(3)),
                                                                        StreamVersion.Start,
                                                                        fixture.Create <FetchEvents>())));
            }
        }
Beispiel #10
0
 public void Customize(IFixture fixture)
 {
     fixture.Customize <StreamVersion>(composer => composer.FromFactory(
                                           (byte version) => StreamVersion.Create(version)));
 }
        public void Start_EqualsFirstVersion()
        {
            var expectedVersion = StreamVersion.Create(1);

            Assert.Equal(expectedVersion, StreamVersion.Start);
        }