コード例 #1
0
        public async Task throw_on_write_when_expected_version_does_not_match()
        {
            var connectionProvider = new EventStoreConnectionProvider(Options.Create(_fixture.EventStoreConnectionOptions));

            var aggregateId = Guid.NewGuid();
            var streamId    =
                StreamIdBuilder.Create()
                .WithAggregateId(aggregateId)
                .WithAggregateType <DummyAggregate>()
                .Build();

            var writeEvents = new List <Event> {
                new DummyCreatedEvent(aggregateId, "The name", "https://url.example.com"),
                new DummyNameChangedEvent(aggregateId, "The new name"),
                new DummyUrlChangedEvent(aggregateId, "https://newurl.example.com")
            };

            //Write 3 events to the stream, this sets the version to 2
            var sut = new EventStoreStreamWriter(connectionProvider, _serializer);
            await sut.AppendEventsToStream(streamId, writeEvents);

            //Write should fail
            var changeEvent = new DummyUrlChangedEvent(aggregateId, "https://newnewurl.example.com");
            await Assert.ThrowsAsync <WrongExpectedVersionException>(
                async() => await sut.AppendEventsToStream(streamId, new List <Event> {
                changeEvent
            }, 1));
        }
コード例 #2
0
        public async Task write_events_to_stream()
        {
            var connectionProvider = new EventStoreConnectionProvider(Options.Create(_fixture.EventStoreConnectionOptions));

            var aggregateId = Guid.NewGuid();
            var streamId    =
                StreamIdBuilder.Create()
                .WithAggregateId(aggregateId)
                .WithAggregateType <DummyAggregate>()
                .Build();

            var writeEvents = new List <Event> {
                new DummyCreatedEvent(aggregateId, "The name", "https://url.example.com"),
                new DummyNameChangedEvent(aggregateId, "The new name"),
                new DummyUrlChangedEvent(aggregateId, "https://newurl.example.com")
            };

            var sut = new EventStoreStreamWriter(connectionProvider, _serializer);
            await sut.AppendEventsToStream(streamId, writeEvents);

            var reader = new EventStoreStreamReader(connectionProvider, _serializer);

            var count      = 0;
            var enumerator = reader.ReadAllEventsFromStreamAsync(streamId).GetAsyncEnumerator();

            while (await enumerator.MoveNextAsync())
            {
                count++;
            }
            await enumerator.DisposeAsync();

            count.Should().Be(3);
        }
コード例 #3
0
        public async Task write_events_to_stream_when_expected_version_matches()
        {
            var connectionProvider = new EventStoreConnectionProvider(Options.Create(_fixture.EventStoreConnectionOptions));

            var aggregateId = Guid.NewGuid();
            var streamId    =
                StreamIdBuilder.Create()
                .WithAggregateId(aggregateId)
                .WithAggregateType <DummyAggregate>()
                .Build();

            var writeEvents = new List <Event> {
                new DummyCreatedEvent(aggregateId, "The name", "https://url.example.com"),
                new DummyNameChangedEvent(aggregateId, "The new name"),
                new DummyUrlChangedEvent(aggregateId, "https://newurl.example.com")
            };

            var sut = new EventStoreStreamWriter(connectionProvider, _serializer);
            await sut.AppendEventsToStream(streamId, writeEvents);

            var changeEvent = new DummyUrlChangedEvent(aggregateId, "https://newnewurl.example.com");
            await sut.AppendEventsToStream(streamId, new List <Event> {
                changeEvent
            }, 2);
        }
コード例 #4
0
        private EventRepository <T> CreateRepository <T>()
            where T : AggregateRoot
        {
            var connectionProvider = new EventStoreConnectionProvider(Options.Create(_fixture.EventStoreConnectionOptions));

            var reader = new EventStoreStreamReader(connectionProvider, _serializer);
            var writer = new EventStoreStreamWriter(connectionProvider, _serializer);

            var sut = new EventRepository <T>(writer, reader);

            return(sut);
        }