public void SetResponseFactory(Func <HttpRetryHandlerRequest, Task <HttpResponseMessage> > responseFactory) { HttpSource.RetryHandler = RetryHandlerMock.Object; RetryHandlerMock .Setup(x => x.SendAsync( It.IsAny <HttpRetryHandlerRequest>(), It.IsAny <ILogger>(), It.IsAny <CancellationToken>())) .Returns <HttpRetryHandlerRequest, ILogger, CancellationToken>((r, _, __) => responseFactory(r)); }
public void SetResponseSequence(HttpResponseMessage[] responses) { HttpSource.RetryHandler = RetryHandlerMock.Object; int index = 0; RetryHandlerMock .Setup(x => x.SendAsync( It.IsAny <HttpRetryHandlerRequest>(), It.IsAny <ILogger>(), It.IsAny <CancellationToken>())) .Returns(() => Task.FromResult(responses[index++ % responses.Length])); }