Beispiel #1
0
 // Can't just call MethodAsync(...).Result due to limitations of FakeScheduler
 public SimpleResponse MethodSync(SimpleRequest request, CallSettings callSettings)
 {
     CallTimes.Add(_scheduler.Clock.GetCurrentDateTimeUtc());
     CallSettingsReceived.Add(callSettings);
     _scheduler.Delay(_callDuration).Wait();
     if (_failuresToReturn > 0)
     {
         _failuresToReturn--;
         throw new RpcException(new Status(_failureCode, "Bang"));
     }
     return(new SimpleResponse {
         Name = request.Name
     });
 }
Beispiel #2
0
            public async Task <SimpleResponse> MethodAsync(SimpleRequest request, CallSettings callSettings)
            {
                CallTimes.Add(scheduler.Clock.GetCurrentDateTimeUtc());
                CallSettingsReceived.Add(callSettings);
                await scheduler.Delay(callDuration);

                if (failuresToReturn > 0)
                {
                    failuresToReturn--;
                    throw new RpcException(new Status(failureCode, "Bang"));
                }
                return(new SimpleResponse {
                    Name = request.Name
                });
            }
Beispiel #3
0
            public AsyncServerStreamingCall <SimpleResponse> ServerStreamingMethodSync(SimpleRequest request, CallSettings callSettings)
            {
                CallTimes.Add(_scheduler.Clock.GetCurrentDateTimeUtc());
                CallSettingsReceived.Add(callSettings);
                var responseStream = new AsyncStreamReader <SimpleResponse>(new SimpleResponse {
                    Name = request.Name
                });
                var responseHeaders = Task.Run(async() =>
                {
                    await _scheduler.Delay(_callDuration, callSettings.CancellationToken.GetValueOrDefault());
                    if (_failuresToReturn > 0)
                    {
                        _failuresToReturn--;
                        throw new RpcException(new Status(_failureCode, "Bang"));
                    }
                    return(Metadata.Empty);
                });
                var response = new AsyncServerStreamingCall <SimpleResponse>(responseStream, responseHeaders, null, null, null);

                return(response);
            }