Ejemplo n.º 1
0
        public async Task LinksCanBeCreated()
        {
            //await EventStoreServer.Instance.Start();

            var connection = await Connect();

            string    projectionStreamName = $"Projection-{Guid.NewGuid()}";
            string    streamName           = $"Foo-{Guid.NewGuid().ToString()}";
            RoomAdded eventObj             = null;

            for (int i = 0; i < 10; i++)
            {
                eventObj = new RoomAdded()
                {
                    Number = "101"
                };

                var metadata  = new EventMetadata(Guid.NewGuid(), typeof(HotelAggregate), Guid.NewGuid(), 0);
                var eventData = new EventData(Uuid.NewUuid(), "RoomAdded", eventObj.ToJsonBytes(), metadata.ToJsonBytes());
                var result    = await connection.AppendToStreamAsync(streamName, AnyStreamRevision.Any,
                                                                     new [] { eventData });

                var linkData = new EventData(Uuid.NewUuid(), "$>", Encoding.UTF8.GetBytes($"{i}@{streamName}"), null);

                var projectionStream = await connection.AppendToStreamAsync(projectionStreamName, AnyStreamRevision.Any, new [] { linkData });
            }

            await foreach (var e in connection.ReadStreamAsync(Direction.Backwards, projectionStreamName,
                                                               StreamRevision.Start, 20, resolveLinkTos:true))
            {
                var data = e.Event.Data.FromJsonBytes <RoomAdded>();
                data.Number.Should().Be(eventObj.Number);
                break;
            }
        }