Esempio n. 1
0
        public async Task SayHelloBidirectionalStreamingTest()
        {
            var svc           = new TestServices(NullLoggerFactory.Instance);
            var cts           = new CancellationTokenSource();
            var callContext   = UnitTestServiceContext.Create(cancellationToken: cts.Token);
            var requestStream = new AsyncStreamRequestReader <HelloRequest>(callContext);
            var replyStream   = new AsyncStreamRequestWriter <HelloReply>(callContext);
            var call          = svc.SayHelloBidirectionalStreaming(requestStream, replyStream, callContext);

            requestStream.AddMessage(new HelloRequest()
            {
                Name = "Test1"
            });
            requestStream.AddMessage(new HelloRequest()
            {
                Name = "Test2"
            });
            requestStream.AddMessage(new HelloRequest()
            {
                Name = "Test3"
            });
            requestStream.Complete();
            await call;

            replyStream.ChannelWriter.Complete();
            await foreach (var item in replyStream.ChannelReader.ReadAllAsync())
            {
                _testOutputHelper.WriteLine(item.Message);
            }
        }
Esempio n. 2
0
        public async Task SayHelloServerStreamingTest()
        {
            var svc           = new TestServices(NullLoggerFactory.Instance);
            var cts           = new CancellationTokenSource();
            var callContext   = UnitTestServiceContext.Create(cancellationToken: cts.Token);
            var requestStream = new AsyncStreamRequestReader <HelloRequest>(callContext);
            var request       = new HelloRequest()
            {
                Name = "Message"
            };
            var streamWriter = new AsyncStreamRequestWriter <HelloReply>(callContext);

            svc.SayHelloServerStreaming(request, streamWriter, callContext);

            cts.Cancel();
            await Task.Delay(1000);

            streamWriter.ChannelWriter.Complete();
            await foreach (var item in streamWriter.ChannelReader.ReadAllAsync())
            {
                _testOutputHelper.WriteLine(item.Message);
            }
        }