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 SayHelloClientStreamingTest()
        {
            var svc                     = new TestServices(NullLoggerFactory.Instance);
            var cts                     = new CancellationTokenSource();
            var callContext             = UnitTestServiceContext.Create(cancellationToken: cts.Token);
            var requestStream           = new AsyncStreamRequestReader <HelloRequest>(callContext);
            var sayHelloClientStreaming = svc.SayHelloClientStreaming(requestStream, callContext);

            requestStream.AddMessage(new HelloRequest {
                Name = "James"
            });
            requestStream.AddMessage(new HelloRequest {
                Name = "Jo"
            });
            requestStream.AddMessage(new HelloRequest {
                Name = "Lee"
            });
            requestStream.Complete();

            // Assert
            var response = await sayHelloClientStreaming;

            Assert.Equal("James,Jo,Lee", response.Message);
        }