private Uri CreateBaseUrl() { var serviceUrl = ServiceUrls.ByEnvironment(_environment); var uri = new Uri(serviceUrl); return(uri); }
public async Task OfTShouldCreateHttpRequestMessage() { // arrange var url = ServiceUrls.ByEnvironment(Enums.ReloadlyEnvironment.Live); var reloadlyRequest = new ReloadlyRequest <object>(HttpMethod.Get, new Uri(url)) .SetHeader("Accept", "application/json") .SetBody(new { name = "bodyValue" }) .SetQueryParameter("param", "queryValue"); // act var request = reloadlyRequest.CreateHttpRequestMessage(); // assert Assert.AreEqual(new Uri(url).Host, request.RequestUri.Host); var requestBody = await request.Content.ReadAsStringAsync(); Assert.IsTrue(requestBody.Contains("\"name\":\"bodyValue\"")); Assert.AreEqual("?param=queryValue", request.RequestUri.Query); }
public async Task ShouldThrowRateLimitException() { var mhMock = new Mock <HttpMessageHandler>(); var baseUrl = ServiceUrls.ByEnvironment(ReloadlyEnvironment.Sandbox); var mockResponse = new HttpResponseMessage { RequestMessage = new HttpRequestMessage() { RequestUri = new System.Uri(baseUrl) }, StatusCode = HttpStatusCode.TooManyRequests }; mockResponse.Headers.TryAddWithoutValidation("X-RateLimit-Limit", "10"); mockResponse.Headers.TryAddWithoutValidation("X-RateLimit-Remaining", "0"); mockResponse.Headers.TryAddWithoutValidation("X-RateLimit-Reset", "0"); mhMock.Protected() .Setup <Task <HttpResponseMessage> >( "SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>()) .ReturnsAsync(mockResponse); var httpClient = new HttpClient(mhMock.Object); var httpClientFactoryMock = new Mock <IHttpClientFactory>(); httpClientFactoryMock.Setup(m => m.CreateClient(It.IsAny <string>())).Returns(httpClient); var reloadlyHttpClient = new ReloadlyHttpClient( httpClientFactoryMock.Object, ReloadlyApiVersion.AirtimeV1, disableTelemetry: false); var response = await reloadlyHttpClient .SendAsync(new ReloadlyRequest <object>(HttpMethod.Get, new System.Uri(ServiceUrls.AirtimeSandbox))); }