Ejemplo n.º 1
0
        private static async Task <TResponse> Call <TRequest, TResponse>(
            bool async, ApiServerStreamingCall <TRequest, TResponse> call, TRequest request, CallSettings callSettings)
            where TRequest : class, IMessage <TRequest>
            where TResponse : class, IMessage <TResponse>
        {
            var streamingCall = async ? await call.CallAsync(request, callSettings) : call.Call(request, callSettings);

            // return the first (and only) response message.
            await streamingCall.ResponseStream.MoveNext();

            return(streamingCall.ResponseStream.Current);
        }
        public async Task WithLogging_Async()
        {
            var logger = new MemoryLogger("category");
            var call   = new ApiServerStreamingCall <SimpleRequest, SimpleResponse>(
                "SimpleMethod",
                (req, cs) => Task.FromResult(default(AsyncServerStreamingCall <SimpleResponse>)),
                (req, cs) => null,
                null).WithLogging(logger);
            await call.CallAsync(new SimpleRequest(), null);

            var entries = logger.ListLogEntries();

            Assert.Equal(2, entries.Count);
            Assert.All(entries, entry => Assert.Contains("SimpleMethod", entry.Message));
        }