aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/csharp/Grpc.Core.Tests
diff options
context:
space:
mode:
authorGravatar Mehrdad Afshari <mmx@google.com>2018-02-11 23:29:51 -0800
committerGravatar Mehrdad Afshari <mmx@google.com>2018-02-21 18:30:19 -0800
commit2354a1d76eecef541083f674a6c21592556ac54a (patch)
tree9ce09446db6864e7281f0e6f1dbdbb8469348b10 /src/csharp/Grpc.Core.Tests
parent4bc49f5c4b9b22c2d90e1933d3223799755c1e81 (diff)
Add Intercept(metadata=>metadata) helper function
Diffstat (limited to 'src/csharp/Grpc.Core.Tests')
-rw-r--r--src/csharp/Grpc.Core.Tests/Interceptors/ClientInterceptorTest.cs29
1 files changed, 9 insertions, 20 deletions
diff --git a/src/csharp/Grpc.Core.Tests/Interceptors/ClientInterceptorTest.cs b/src/csharp/Grpc.Core.Tests/Interceptors/ClientInterceptorTest.cs
index 91c7d54181..880e4d2b19 100644
--- a/src/csharp/Grpc.Core.Tests/Interceptors/ClientInterceptorTest.cs
+++ b/src/csharp/Grpc.Core.Tests/Interceptors/ClientInterceptorTest.cs
@@ -32,38 +32,27 @@ namespace Grpc.Core.Interceptors.Tests
{
public class ClientInterceptorTest
{
- private class AddHeaderClientInterceptor : GenericInterceptor
- {
- readonly Metadata.Entry header;
- public AddHeaderClientInterceptor(string key, string value)
- {
- this.header = new Metadata.Entry(key, value);
- }
- protected override ClientCallArbitrator<TRequest, TResponse> InterceptCall<TRequest, TResponse>(ClientInterceptorContext<TRequest, TResponse> context, bool clientStreaming, bool serverStreaming, TRequest request)
- {
- context.Options.Headers.Add(this.header);
- return new ClientCallArbitrator<TRequest, TResponse> { Context = context };
- }
-
- public Metadata.Entry Header => this.header;
- }
-
const string Host = "127.0.0.1";
[Test]
public void AddRequestHeaderInClientInterceptor()
{
+ const string HeaderKey = "x-client-interceptor";
+ const string HeaderValue = "hello-world";
var helper = new MockServiceHelper(Host);
- var interceptor = new AddHeaderClientInterceptor("x-client-interceptor", "hello world");
helper.UnaryHandler = new UnaryServerMethod<string, string>((request, context) =>
{
- var interceptorHeader = context.RequestHeaders.Last(m => (m.Key == interceptor.Header.Key)).Value;
- Assert.AreEqual(interceptorHeader, interceptor.Header.Value);
+ var interceptorHeader = context.RequestHeaders.Last(m => (m.Key == HeaderKey)).Value;
+ Assert.AreEqual(interceptorHeader, HeaderValue);
return Task.FromResult("PASS");
});
var server = helper.GetServer();
server.Start();
- var callInvoker = helper.GetChannel().Intercept(interceptor);
+ var callInvoker = helper.GetChannel().Intercept(metadata =>
+ {
+ metadata.Add(new Metadata.Entry(HeaderKey, HeaderValue));
+ return metadata;
+ });
Assert.AreEqual("PASS", callInvoker.BlockingUnaryCall(new Method<string, string>(MethodType.Unary, MockServiceHelper.ServiceName, "Unary", Marshallers.StringMarshaller, Marshallers.StringMarshaller), Host, new CallOptions().WithHeaders(new Metadata()), ""));
}
}