Ejemplo n.º 1
0
        public override async Task GetBetaStream(GetBetaRequest request, IServerStreamWriter <BetaDto> responseStream, ServerCallContext context)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            logger.LogInformation(request.ToString());

            var iteration = 1;

            while (!context.CancellationToken.IsCancellationRequested && iteration <= 10)
            {
                await Task.Delay(100);

                var response = new BetaDto
                {
                    Id   = iteration,
                    Data = $"record_{iteration}"
                };

                logger.LogInformation(response.ToString());

                await responseStream.WriteAsync(response);

                iteration++;
            }

            if (context.CancellationToken.IsCancellationRequested)
            {
                logger.LogInformation("The request canceled by the client!");
            }
        }
Ejemplo n.º 2
0
        public override async Task <GetBetaResponse> GetBeta(GetBetaRequest request, ServerCallContext context)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            logger.LogInformation(request.ToString());

            var data = Enumerable
                       .Range(1, 10)
                       .Select(x => new BetaDto
            {
                Id   = x,
                Data = $"record_{x}"
            })
                       .ToArray();

            var response = new GetBetaResponse
            {
                Id   = request.Id,
                Data = { data }
            };

            await Task.Delay(50);

            logger.LogInformation(response.ToString());

            return(response);
        }
Ejemplo n.º 3
0
        public async IAsyncEnumerable <BetaDto> GetBetaStreamAsync(GetBetaRequest request, [EnumeratorCancellation] CancellationToken cancellationToken = default)
        {
            var client = new Beta.BetaClient(channel);

            using (var stream = client.GetBetaStream(request, cancellationToken: cancellationToken))
            {
                await foreach (var dto in stream.ResponseStream.ReadAllAsync(cancellationToken))
                {
                    yield return(dto);
                }
            }
        }
Ejemplo n.º 4
0
        public async Task GetBeta_Success()
        {
            var request = new GetBetaRequest
            {
                Id = Guid.NewGuid().ToString()
            };

            var response = await client.GetBetaAsync(request);

            Assert.NotNull(response);
            Assert.Equal(request.Id, response.Id);
            Assert.Equal(DataCount, response.Data.Count);
        }
Ejemplo n.º 5
0
        public async Task GetBetaStream_Success()
        {
            var request = new GetBetaRequest
            {
                Id = Guid.NewGuid().ToString()
            };

            var stream = client.GetBetaStreamAsync(request);

            var iteration = 0;

            await foreach (var dto in stream)
            {
                iteration++;

                Assert.NotNull(dto);
                Assert.Equal(iteration, dto.Id);
            }

            Assert.Equal(DataCount, iteration);
        }
Ejemplo n.º 6
0
        public async Task <GetBetaResponse> GetBetaAsync(GetBetaRequest request, CancellationToken cancellationToken = default)
        {
            var client = new Beta.BetaClient(channel);

            return(await client.GetBetaAsync(request, cancellationToken : cancellationToken));
        }