Example #1
0
        public async Task StreamingFromClientTest()
        {
            // init
            var server = new GreeterService(NullLoggerFactory.Instance);

            var callContext   = TestServerCallContext.Create();
            var requestStream = new TestAsyncStreamReader <ExampleRequest>(callContext);

            // act
            using var call = server.StreamingFromClient(requestStream, callContext);
            requestStream.AddMessage(new ExampleRequest {
                PageIndex = 1, PageSize = 10, IsDescending = false
            });
            requestStream.AddMessage(new ExampleRequest {
                PageIndex = 2, PageSize = 10, IsDescending = false
            });
            requestStream.AddMessage(new ExampleRequest {
                PageIndex = 3, PageSize = 10, IsDescending = false
            });
            requestStream.AddMessage(new ExampleRequest {
                PageIndex = 4, PageSize = 10, IsDescending = false
            });
            requestStream.Complete();

            // Assert
            var response = await call;

            Assert.IsTrue(response.Age > 1);
        }
        public async Task SayHelloClientStreamingTest()
        {
            // Arrange
            var service = new TesterService(NullLoggerFactory.Instance);

            var callContext   = TestServerCallContext.Create();
            var requestStream = new TestAsyncStreamReader <HelloRequest>(callContext);

            // Act
            var call = service.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 call;

            Assert.AreEqual("Hello James, Jo, Lee", response.Message);
        }
Example #3
0
        public async Task SayHelloClientStreamingTest()
        {
            // Arrange
            var mockGreeter = new Mock <IGreeter>();

            mockGreeter.Setup(m => m.Greet(It.IsAny <string>())).Returns((string s) => $"Hello {s}");
            var service = new TesterService(mockGreeter.Object);

            var callContext   = TestServerCallContext.Create();
            var requestStream = new TestAsyncStreamReader <HelloRequest>(callContext);

            // Act
            using var call = service.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 call;

            Assert.Equal("Hello James, Jo, Lee", response.Message);
        }
        public async Task GreeterService_SayHelloBidirectionalStreaming_ReturnsCorrectResponse()
        {
            // Arrange
            var service        = new GreeterService(new Logger <GreeterService>(new NullLoggerFactory()));
            var callContext    = TestServerCallContext.Create();
            var requestStream  = new TestAsyncStreamReader <HelloRequest>(callContext);
            var responseStream = new TestServerStreamWriter <HelloReply>(callContext);

            // Act
            var call = service.SayHelloBidirectionalStreaming(requestStream, responseStream, callContext);

            // Assert
            requestStream.AddMessage(new HelloRequest {
                Name = "James"
            });
            Assert.AreEqual("Hello James", (await responseStream.ReadNextAsync()) !.Message);
            requestStream.AddMessage(new HelloRequest {
                Name = "Jo"
            });
            Assert.AreEqual("Hello Jo", (await responseStream.ReadNextAsync()) !.Message);
            requestStream.AddMessage(new HelloRequest {
                Name = "Lee"
            });
            Assert.AreEqual("Hello Lee", (await responseStream.ReadNextAsync()) !.Message);
            requestStream.Complete();
            await call;

            responseStream.Complete();
            Assert.IsNull(await responseStream.ReadNextAsync());
        }
Example #5
0
        public async Task StreamingBothWaysTest()
        {
            // init
            var server         = new GreeterService(NullLoggerFactory.Instance);
            var callContext    = TestServerCallContext.Create();
            var requstStream   = new TestAsyncStreamReader <ExampleRequest>(callContext);
            var responseStream = new TestServerStreamWriter <ExampleResponse>(callContext);

            // act
            using var call = server.StreamingBothWays(requstStream, responseStream, callContext);
            requstStream.AddMessage(new ExampleRequest {
                PageIndex = 1, PageSize = 10, IsDescending = false
            });
            Assert.IsTrue((await responseStream.ReadNextAsync()).Age > 1);
            requstStream.Complete();
            await call;

            responseStream.Complete();
            Assert.IsNull(await responseStream.ReadNextAsync());
        }
Example #6
0
        public async Task SayHelloBidirectionStreamingTest()
        {
            // Arrange
            var mockGreeter = new Mock <IGreeter>();

            mockGreeter.Setup(m => m.Greet(It.IsAny <string>())).Returns((string s) => $"Hello {s}");
            var service = new TesterService(mockGreeter.Object);

            var callContext    = TestServerCallContext.Create();
            var requestStream  = new TestAsyncStreamReader <HelloRequest>(callContext);
            var responseStream = new TestServerStreamWriter <HelloReply>(callContext);

            // Act
            using var call = service.SayHelloBidirectionalStreaming(requestStream, responseStream, callContext);

            // Assert
            requestStream.AddMessage(new HelloRequest {
                Name = "James"
            });
            Assert.Equal("Hello James", (await responseStream.ReadNextAsync()) !.Message);

            requestStream.AddMessage(new HelloRequest {
                Name = "Jo"
            });
            Assert.Equal("Hello Jo", (await responseStream.ReadNextAsync()) !.Message);

            requestStream.AddMessage(new HelloRequest {
                Name = "Lee"
            });
            Assert.Equal("Hello Lee", (await responseStream.ReadNextAsync()) !.Message);

            requestStream.Complete();

            await call;

            responseStream.Complete();

            Assert.Null(await responseStream.ReadNextAsync());
        }
Example #7
0
        public async Task SayHelloBidirectionStreamingTest()
        {
            // Arrange
            var service = new TesterService(CreateGreeterMock().Object);

            var callContext    = TestServerCallContext.Create();
            var requestStream  = new TestAsyncStreamReader <HelloRequest>(callContext);
            var responseStream = new TestServerStreamWriter <HelloReply>(callContext);

            // Act
            using var call = service.SayHelloBidirectionalStreaming(requestStream, responseStream, callContext);

            // Assert
            requestStream.AddMessage(new HelloRequest {
                Name = "James"
            });
            Assert.AreEqual("Hello James", (await responseStream.ReadNextAsync()) !.Message);

            requestStream.AddMessage(new HelloRequest {
                Name = "Jo"
            });
            Assert.AreEqual("Hello Jo", (await responseStream.ReadNextAsync()) !.Message);

            requestStream.AddMessage(new HelloRequest {
                Name = "Lee"
            });
            Assert.AreEqual("Hello Lee", (await responseStream.ReadNextAsync()) !.Message);

            requestStream.Complete();

            await call;

            responseStream.Complete();

            Assert.IsNull(await responseStream.ReadNextAsync());
        }