diff options
author | Mehrdad Afshari <mmx@google.com> | 2018-02-12 01:25:08 -0800 |
---|---|---|
committer | Mehrdad Afshari <mmx@google.com> | 2018-02-21 18:30:19 -0800 |
commit | 62f9f53b7a5cfd88f59fc4d2f88e114307f0628b (patch) | |
tree | 56fc441c494ca9170d5b890dfa454c501429c891 /src/csharp | |
parent | 0126b1c6e93c70f7b55d54765e3b32d926065a61 (diff) |
Add more tests for ServerInterceptor
Diffstat (limited to 'src/csharp')
-rw-r--r-- | src/csharp/Grpc.Core.Tests/Interceptors/ServerInterceptorTest.cs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/csharp/Grpc.Core.Tests/Interceptors/ServerInterceptorTest.cs b/src/csharp/Grpc.Core.Tests/Interceptors/ServerInterceptorTest.cs index a602d081ae..fbace51db5 100644 --- a/src/csharp/Grpc.Core.Tests/Interceptors/ServerInterceptorTest.cs +++ b/src/csharp/Grpc.Core.Tests/Interceptors/ServerInterceptorTest.cs @@ -19,6 +19,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text; using System.Threading; using System.Threading.Tasks; using Grpc.Core; @@ -75,5 +76,42 @@ namespace Grpc.Core.Interceptors.Tests var channel = helper.GetChannel(); Assert.AreEqual("PASS", Calls.BlockingUnaryCall(helper.CreateUnaryCall(), "")); } + + private class ArbitraryActionInterceptor : GenericInterceptor + { + readonly Action action; + + + public ArbitraryActionInterceptor(Action action) + { + this.action = action; + } + + protected override Task<ServerCallArbitrator<TRequest, TResponse>> InterceptHandler<TRequest, TResponse>(ServerCallContext context, bool clientStreaming, bool serverStreaming, TRequest request) + { + action(); + return Task.FromResult<ServerCallArbitrator<TRequest, TResponse>>(null); + } + } + + [Test] + public void VerifyInterceptorOrdering() + { + var helper = new MockServiceHelper(Host); + helper.UnaryHandler = new UnaryServerMethod<string, string>((request, context) => + { + return Task.FromResult("PASS"); + }); + var stringBuilder = new StringBuilder(); + helper.ServiceDefinition = helper.ServiceDefinition + .Intercept(new ArbitraryActionInterceptor(() => stringBuilder.Append("A"))) + .Intercept(new ArbitraryActionInterceptor(() => stringBuilder.Append("B"))) + .Intercept(new ArbitraryActionInterceptor(() => stringBuilder.Append("C"))); + var server = helper.GetServer(); + server.Start(); + var channel = helper.GetChannel(); + Assert.AreEqual("PASS", Calls.BlockingUnaryCall(helper.CreateUnaryCall(), "")); + Assert.AreEqual("CBA", stringBuilder.ToString()); + } } } |