Exemple #1
0
        public async Task SendValidRequest_WithConnectionOptions(TestServerEndpointName endpointName, string?version, bool success)
        {
            SetExpectedErrorsFilter(writeContext =>
            {
                return(!success);
            });

            // Arrage
            Version.TryParse(version, out var v);
            var channel = CreateGrpcWebChannel(endpointName, v);

            var client = new EchoService.EchoServiceClient(channel);

            // Act
            var call = client.EchoAsync(new EchoRequest {
                Message = "test"
            }).ResponseAsync.DefaultTimeout();

            // Assert
            if (success)
            {
                Assert.AreEqual("test", (await call).Message);
            }
            else
            {
                await ExceptionAssert.ThrowsAsync <RpcException>(async() => await call);
            }
        }
        public async Task SendValidRequest_SuccessResponse()
        {
            // Arrage
            var httpClient = CreateGrpcWebClient();
            var channel    = GrpcChannel.ForAddress(httpClient.BaseAddress, new GrpcChannelOptions
            {
                HttpClient    = httpClient,
                LoggerFactory = LoggerFactory
            });

            var client = new EchoService.EchoServiceClient(channel);

            // Act
            var response = await client.EchoAsync(new EchoRequest { Message = "test" }).ResponseAsync.DefaultTimeout();

            // Assert
            Assert.AreEqual("test", response.Message);
        }
Exemple #3
0
        public async Task SendValidRequest_WithConnectionOptions(TestServerEndpointName endpointName, string?version, bool success)
        {
#if NET6_0_OR_GREATER
            if (endpointName == TestServerEndpointName.Http3WithTls &&
                !RequireHttp3Attribute.IsSupported(out var message))
            {
                Assert.Ignore(message);
            }
#endif

            SetExpectedErrorsFilter(writeContext =>
            {
                return(!success);
            });

            // Arrage
            Version.TryParse(version, out var v);
            var channel = CreateGrpcWebChannel(endpointName, v);

            var client = new EchoService.EchoServiceClient(channel);

            // Act
            var call = client.EchoAsync(new EchoRequest {
                Message = "test"
            }).ResponseAsync.DefaultTimeout();

            // Assert
            if (success)
            {
                Assert.AreEqual("test", (await call.DefaultTimeout()).Message);
            }
            else
            {
                await ExceptionAssert.ThrowsAsync <RpcException>(async() => await call).DefaultTimeout();
            }
        }
Exemple #4
0
        private async Task GrpcWebUnaryAsync(EchoService.EchoServiceClient client)
        {
            var response = await client.EchoAsync(new EchoRequest { Message = "test" });

            Assert.AreEqual("test", response.Message);
        }