public SelectObjectContentEventStreamTests()
        {
            _fixture = new Fixture()
                       .Customize(new AutoMoqCustomization());

            _eventStreamDecoderMock = _fixture.Freeze <Mock <IEventStreamDecoder> >();
            _streamMock             = _fixture.Freeze <Mock <Stream> >();

            _fixture.Customize <SelectObjectContentEventStream>(c => c.FromFactory(
                                                                    new MethodInvoker(
                                                                        new GreedyConstructorQuery())));

            _sut = _fixture.Create <SelectObjectContentEventStream>();
        }
예제 #2
0
        private static IAsyncEnumerable <ResultRow> ReadResponse(ISelectObjectContentEventStream eventStream)
        {
            var pipe = new Pipe();

            Task.Run(async() =>
            {
                var writer = pipe.Writer;

                foreach (var ev in eventStream)
                {
                    if (!(ev is RecordsEvent records))
                    {
                        continue;
                    }

                    while (true)
                    {
                        var buffer = writer.GetMemory(4096);

                        var bytesRead = await records.Payload.ReadAsync(buffer).ConfigureAwait(false);
                        if (bytesRead == 0)
                        {
                            break;
                        }

                        writer.Advance(bytesRead);

                        var flush = await writer.FlushAsync().ConfigureAwait(false);
                        if (flush.IsCompleted)
                        {
                            break;
                        }
                    }
                }

                await writer.CompleteAsync().ConfigureAwait(false);
            });

            return(Reader(pipe.Reader));
        }