コード例 #1
0
        public async Task <bool> PostToElastic(IEnumerable <KeyValuePair <string, int> > results)
        {
            var request =
                JsonConvert.SerializeObject(new
            {
                index = new
                {
                    _index = "healthchecks",
                    _type  = "snapshot"
                }
            }, Formatting.None).ToString() +
                JsonConvert.SerializeObject(results, Formatting.None).ToString();


            request = string.Join("\n", request) + "\n";

            var stringContent = new StringContent(request, Encoding.UTF8, "application/json");
            var httpContent   = new HttpRequestMessage(HttpMethod.Post, _elasticUri);

            httpContent.Content = stringContent;
            var response = await _httpClient.SendAsync(httpContent);

            var successful = response.IsSuccessStatusCode;

            return(successful);
        }
コード例 #2
0
        public void SetUp()
        {
            var successfulResponse = new HttpResponseMessage()
            {
                Content      = new StringContent("success"),
                ReasonPhrase = "reasonPhrase",
                StatusCode   = HttpStatusCode.OK
            };

            _httpWrapper = Substitute.For <IHttpWrapper>();
            _httpWrapper.SendAsync(Arg.Any <HttpRequestMessage>()).Returns(successfulResponse);

            _pingResults = new Dictionary <string, int>
            {
                { "health0", 1 },
                { "health1", 1 },
                { "health2", 1 },
                { "health3", 0 }
            };
        }