Пример #1
0
        public async Task <Group> LoadById(GroupIdentifier identifier, CancellationToken ct = default(CancellationToken))
        {
            var stream = new StreamName($"groups-{identifier.ToGuid():N}");
            var result = await _reader.ReadStreamAsync(stream, ct);

            switch (result.State)
            {
            case ReadResultState.NotFound:
                throw new GroupNotFoundException(identifier);

            case ReadResultState.Deleted:
                throw new GroupDeletedException(identifier);
            }
            return((Group)result.Value);
        }
        public async Task CanReadUsingReaderWhatWasWrittenUsingWriter()
        {
            var stream = _fixture.NextStreamName();

            var random = new Random();
            var value1 = random.Next();
            var value2 = random.Next();

            // write
            var changes = new object[]
            {
                new Event1 {
                    Value = value1
                },
                new Event2 {
                    Value = value2
                }
            };
            var writable = new Entity(changes);
            var writer   = new EventSourceWriter(
                _fixture.Connection,
                new EventSourceWriterConfiguration(
                    StreamNameConversions.PassThru,
                    new EventSourceChangesetTranslator(type => type.FullName, new JsonSerializerSettings())));
            await writer.WriteStreamAsync(stream, writable, Guid.NewGuid(), Guid.NewGuid());

            //read
            var reader = new EventSourceReader(
                () => new Entity(),
                _fixture.Connection,
                new EventSourceReaderConfiguration(
                    StreamNameConversions.PassThru,
                    () => new StreamEventsSliceTranslator(
                        name => Type.GetType(name, true),
                        new JsonSerializerSettings()),
                    new SliceSize(1)));
            var result = await reader.ReadStreamAsync(stream);

            Assert.Equal(ReadResultState.Found, result.State);
            var readable = Assert.IsAssignableFrom <Entity>(result.Value);

            Assert.Equal(value1, readable.Value1);
            Assert.Equal(value2, readable.Value2);
        }