예제 #1
0
        public async Task ReadEvent_Success()
        {
            var credentials        = new UserCredentials("admin", "changeit");
            var connectionSettings = new ConnectionSettings(credentials, "127.0.0.1", 1113, "myConnection");
            var connection         = new EventStoreConnection(connectionSettings);

            await connection.ConnectAsync().ConfigureAwait(false);

            var streamId = $"TestStream-{Guid.NewGuid():N}";
            var events   = new List <CreateEvent>()
            {
                new CreateEvent()
                {
                    Id        = Guid.NewGuid(),
                    EventType = "TestType",
                    IsJson    = true,
                    Data      = Encoding.UTF8.GetBytes("{\"Key\": \"Value\"}"),
                    MetaData  = Encoding.UTF8.GetBytes("{}")
                }
            };

            await connection.WriteEvents(events, streamId, -1).ConfigureAwait(false);

            var readEvents = await connection.ReadEvents(streamId, 0, 4095, true).ConfigureAwait(false);

            var readEventsList = readEvents.ToList();

            Assert.IsNotNull(readEvents);
            Assert.AreEqual(events.Count, readEventsList.Count);
            Assert.AreEqual(events[0].Id, readEventsList[0].Id);
            Assert.AreEqual(streamId, readEventsList[0].Stream);
            Assert.AreEqual(events[0].IsJson, readEventsList[0].IsJson);
            Assert.AreEqual(events[0].Data.ToString(), readEventsList[0].Data.ToString());
            Assert.AreEqual(events[0].MetaData.ToString(), readEventsList[0].MetaData.ToString());
        }