private void Run_ShouldWriteEventData(IEventSerializer serializer)
        {
            var configuration = SetupDatabase();

            var subscriber = new DatabaseEventSubscriber <IEvent>(configuration, serializer);

            var aggregateId  = Guid.NewGuid().ToString();
            var expectedData = $"This is my random data {Guid.NewGuid()}";
            var testEvent    = new EventWithData(aggregateId, expectedData);

            subscriber.OnEvent(testEvent);

            var connection = configuration.CreateConnection();

            connection.Open();
            var command = connection.CreateCommand();

            command.CommandText = $"select data from {configuration.TableName}";

            var actualBytes = command.ExecuteScalar();
            var actual      = serializer.Deserialize(testEvent.Type, (byte[])actualBytes);

            Assert.IsType <EventWithData>(actual);
            Assert.Equal(expectedData, ((EventWithData)actual).Data);
        }
        private void Run_ShouldSaveEvents(IEventSerializer eventSerializer)
        {
            var configuration = SetupDatabase();

            var subscriber = new DatabaseEventSubscriber <IEvent>(configuration, eventSerializer);

            var aggregateId = Guid.NewGuid().ToString();

            subscriber.OnEvent(new TestEvent1(aggregateId));
            subscriber.OnEvent(new TestEvent2(aggregateId));

            var connection = configuration.CreateConnection();

            connection.Open();
            var command = connection.CreateCommand();

            command.CommandText = $"select count(*) from {configuration.TableName}";

            var actual = command.ExecuteScalar();

            Assert.Equal(2L, actual);
        }
예제 #3
0
 private void Save(EventList newEvents)
 {
     newEvents.ForEach(x => _store.OnEvent(x));
 }