Exemplo n.º 1
0
        public void AddRequestHeaderInServerInterceptor()
        {
            var          helper        = new MockServiceHelper(Host);
            const string MetadataKey   = "x-interceptor";
            const string MetadataValue = "hello world";
            var          interceptor   = new ServerCallContextInterceptor(ctx => ctx.RequestHeaders.Add(new Metadata.Entry(MetadataKey, MetadataValue)));

            helper.UnaryHandler = new UnaryServerMethod <string, string>((request, context) =>
            {
                var interceptorHeader = context.RequestHeaders.Last(m => (m.Key == MetadataKey)).Value;
                Assert.AreEqual(interceptorHeader, MetadataValue);
                return(Task.FromResult("PASS"));
            });
            helper.ServiceDefinition = helper.ServiceDefinition.Intercept(interceptor);
            var server = helper.GetServer();

            server.Start();
            var channel = helper.GetChannel();

            Assert.AreEqual("PASS", Calls.BlockingUnaryCall(helper.CreateUnaryCall(), ""));
        }
Exemplo n.º 2
0
        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 ServerCallContextInterceptor(ctx => stringBuilder.Append("A")))
                                       .Intercept(new ServerCallContextInterceptor(ctx => stringBuilder.Append("B1")),
                                                  new ServerCallContextInterceptor(ctx => stringBuilder.Append("B2")),
                                                  new ServerCallContextInterceptor(ctx => stringBuilder.Append("B3")))
                                       .Intercept(new ServerCallContextInterceptor(ctx => stringBuilder.Append("C")));
            var server = helper.GetServer();

            server.Start();
            var channel = helper.GetChannel();

            Assert.AreEqual("PASS", Calls.BlockingUnaryCall(helper.CreateUnaryCall(), ""));
            Assert.AreEqual("CB1B2B3A", stringBuilder.ToString());
        }