Esempio n. 1
0
        public async Task <HttpStatusCode> MakeGetRequestStatusCode(string url, string accessToken)
        {
            _wrapper.SetAccessToken(accessToken);
            var response = await _wrapper.GetAsync(url);

            return(response.StatusCode);
        }
Esempio n. 2
0
        public void MakeGetRequestMakesASuccessfulCall()
        {
            // Arrange
            var url         = "http://google.co.uk";
            var accessToken = "ABC";
            var expected    = new HttpResponseMessage();

            expected.Content = new StringContent("No Exception");
            A.CallTo(() => _wrapper.GetAsync(url))
            .Returns(expected);

            // Act

            // Assert
            Assert.DoesNotThrowAsync(() => _getRequestMaker.MakeGetRequest(url, accessToken));
        }
Esempio n. 3
0
        public void SetUp()
        {
            _httpClient = Substitute.For <IHttpWrapper>();
            _httpClient
            .GetAsync("http://health0/health")
            .Returns(CreateFakeResponse(HttpStatusCode.OK, SuccessfulContent));

            _httpClient
            .GetAsync("http://health1/health")
            .Returns(CreateFakeResponse(HttpStatusCode.InternalServerError, EmptyContent));

            _locationServices = new Dictionary <string, string>
            {
                { "health0", "health0" },
                { "health1", "health1" }
            };
        }
Esempio n. 4
0
 public async Task<Dictionary<string, int>> CheckHealthOfServices()
 {
     var results = new Dictionary<string, int>();
     foreach (var serviceLocation in _serviceLocations)
     {
         var response = await _httpClient.GetAsync($"http://{serviceLocation.Value.ToString()}/health");
         if (response.StatusCode == HttpStatusCode.OK)
         {
             var content = JsonConvert.DeserializeObject<StatusResponse>(await response.Content.ReadAsStringAsync());
             if (content.Status == "up") results.Add(serviceLocation.Key, 1);
         }
         else
         {
             results.Add(serviceLocation.Key, 0);
         }
     }
     return results;
 }