public void IfResponseIsKnowError_DoNotRetry_ThrowServerException_Async(int status, string exceptionType, string exceptionMessage) { var response = CreateServerExceptionResponse(status, exceptionType, exceptionMessage); using (var fake = new AutoFake(callsDoNothing: true)) { var connectionPool = new StaticConnectionPool(new[] { new Uri("http://localhost:9200"), new Uri("http://localhost:9201"), }); var connectionConfiguration = new ConnectionConfiguration(connectionPool) .ThrowOnElasticsearchServerExceptions() .ExposeRawResponse(false); fake.Provide <IConnectionConfigurationValues>(connectionConfiguration); FakeCalls.ProvideDefaultTransport(fake); var pingCall = FakeCalls.PingAtConnectionLevelAsync(fake); pingCall.Returns(FakeResponse.OkAsync(connectionConfiguration)); var getCall = FakeCalls.GetCall(fake); getCall.Returns(FakeResponse.AnyAsync(connectionConfiguration, status, response: response)); var client = fake.Resolve <ElasticsearchClient>(); var e = Assert.Throws <ElasticsearchServerException>(async() => await client.InfoAsync()); AssertServerErrorsOnResponse(e, status, exceptionType, exceptionMessage); //make sure a know ElasticsearchServerException does not cause a retry //In this case we want to fail early getCall.MustHaveHappened(Repeated.Exactly.Once); } }