Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
frederikprijck committed Aug 17, 2021
1 parent 37f98a5 commit 9f9fad3
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/Auth0.Core.UnitTests/HttpClientManagementConnectionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,33 @@ public void Should_Not_Retry_When_Limit_Set_To_Zero()

amountOfTimesCalled.Should().Be(1);
}

[Fact]
public void Should_Not_Retry_When_Not_A_RateLimitApiException()
{
var mockHandler = new Mock<HttpMessageHandler>(MockBehavior.Strict);
var amountOfTimesCalled = 0;

mockHandler.Protected()
.Setup<Task<HttpResponseMessage>>(
"SendAsync",
ItExpr.Is<HttpRequestMessage>(req => req.RequestUri.ToString() == $"https://test.com/"),
ItExpr.IsAny<CancellationToken>()
)
.Callback(() => amountOfTimesCalled++)
.ReturnsAsync(new HttpResponseMessage()
{
StatusCode = HttpStatusCode.BadRequest,
Content = new StringContent("", Encoding.UTF8, "application/json"),
});

var httpClient = new HttpClient(mockHandler.Object);
var connection = new HttpClientManagementConnection(httpClient, new HttpClientManagementConnectionOptions { NumberOfHttpRetries = 6 });

Func<Task> getFunc = async () => await connection.SendAsync<object>(HttpMethod.Get, new Uri("https://test.com/"), null, null, null);
getFunc.Should().Throw<ErrorApiException>();

amountOfTimesCalled.Should().Be(1);
}
}
}

0 comments on commit 9f9fad3

Please sign in to comment.