public void WithMethods()
        {
            var options = new CallOptions();
            
            var metadata = new Metadata();
            Assert.AreSame(metadata, options.WithHeaders(metadata).Headers);

            var deadline = DateTime.UtcNow;
            Assert.AreEqual(deadline, options.WithDeadline(deadline).Deadline.Value);

            var cancellationToken = new CancellationTokenSource().Token;
            Assert.AreEqual(cancellationToken, options.WithCancellationToken(cancellationToken).CancellationToken);

            var writeOptions = new WriteOptions();
            Assert.AreSame(writeOptions, options.WithWriteOptions(writeOptions).WriteOptions);

            var propagationToken = new ContextPropagationToken(CallSafeHandle.NullInstance, DateTime.UtcNow, 
                CancellationToken.None, ContextPropagationOptions.Default);
            Assert.AreSame(propagationToken, options.WithPropagationToken(propagationToken).PropagationToken);

            var credentials = new FakeCallCredentials();
            Assert.AreSame(credentials, options.WithCredentials(credentials).Credentials);

            // Check that the original instance is unchanged.
            Assert.IsNull(options.Headers);
            Assert.IsNull(options.Deadline);
            Assert.AreEqual(CancellationToken.None, options.CancellationToken);
            Assert.IsNull(options.WriteOptions);
            Assert.IsNull(options.PropagationToken);
            Assert.IsNull(options.Credentials);
        }
Exemple #2
0
        /// <summary>
        /// Creates a new call to given method.
        /// </summary>
        /// <param name="method">The method to invoke.</param>
        /// <param name="options">The call options.</param>
        /// <typeparam name="TRequest">Request message type.</typeparam>
        /// <typeparam name="TResponse">Response message type.</typeparam>
        /// <returns>The call invocation details.</returns>
        protected CallInvocationDetails <TRequest, TResponse> CreateCall <TRequest, TResponse>(Method <TRequest, TResponse> method, CallOptions options)
            where TRequest : class
            where TResponse : class
        {
            var interceptor = HeaderInterceptor;

            if (interceptor != null)
            {
                if (options.Headers == null)
                {
                    options = options.WithHeaders(new Metadata());
                }
                interceptor(method, options.Headers);
            }
            return(new CallInvocationDetails <TRequest, TResponse>(channel, method, Host, options));
        }
Exemple #3
0
        /// <summary>
        /// Creates a new call to given method.
        /// </summary>
        protected CallInvocationDetails <TRequest, TResponse> CreateCall <TRequest, TResponse>(Method <TRequest, TResponse> method, CallOptions options)
            where TRequest : class
            where TResponse : class
        {
            var interceptor = HeaderInterceptor;

            if (interceptor != null)
            {
                if (options.Headers == null)
                {
                    options = options.WithHeaders(new Metadata());
                }
                var authUri = authUriBase != null ? authUriBase + method.ServiceName : null;
                interceptor(authUri, options.Headers);
            }
            return(new CallInvocationDetails <TRequest, TResponse>(channel, method, Host, options));
        }
Exemple #4
0
        public void WithMethods()
        {
            var options = new CallOptions();
            
            var metadata = new Metadata();
            Assert.AreSame(metadata, options.WithHeaders(metadata).Headers);

            var deadline = DateTime.UtcNow;
            Assert.AreEqual(deadline, options.WithDeadline(deadline).Deadline.Value);

            var token = new CancellationTokenSource().Token;
            Assert.AreEqual(token, options.WithCancellationToken(token).CancellationToken);

            // Change original instance is unchanged.
            Assert.IsNull(options.Headers);
            Assert.IsNull(options.Deadline);
            Assert.AreEqual(CancellationToken.None, options.CancellationToken);
            Assert.IsNull(options.WriteOptions);
            Assert.IsNull(options.PropagationToken);
            Assert.IsNull(options.Credentials);
        }