示例#1
0
        private async Task UpdateService(string serviceId)
        {
            var service = new Service
            {
                Id          = _serviceId,
                ServiceType = _serviceType,
                Address     = _serviceAddress,
                HealthCheck = new HealthCheck
                {
                    HealthCheckType = _healthCheckType,
                    Address         = _healthEndpoint,
                    Interval        = _healthInterval,
                    DeregisterCriticalServiceAfter = _deregisterCriticalServiceAfter
                }
            };

            var jsonString  = JsonConvert.SerializeObject(service);
            var httpContent = new StringContent(jsonString, Encoding.UTF8, "application/json");

            var httpClient = ApiTestServer.GetHttpClient();

            _response = await httpClient.PutAsync($"/api/services/{serviceId}", httpContent);

            _responseContent = await _response.Content.ReadAsStringAsync();

            var response = await httpClient.GetAsync($"/api/services/{serviceId}");

            if (response.IsSuccessStatusCode)
            {
                var responseContent = await response.Content.ReadAsStringAsync();

                _responseObject = JObject.Parse(responseContent);
            }
        }
示例#2
0
        private async Task ThenServiceNotExists(string serviceId)
        {
            var httpClient = ApiTestServer.GetHttpClient();
            var response   = await httpClient.GetAsync($"/api/services/{serviceId}");

            Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
        }
示例#3
0
        private async Task WhenListOfServicesIsDownloaded()
        {
            var httpClient = ApiTestServer.GetHttpClient();

            _response = await httpClient.GetAsync($"/api/services");

            _responseContent = await _response.Content.ReadAsStringAsync();
        }
示例#4
0
        private async Task ThenServiceWasRegistered(string serviceId)
        {
            var httpClient      = ApiTestServer.GetHttpClient();
            var serviceResponse = await httpClient.GetStringAsync($"/api/services/{serviceId}");

            var service = JsonConvert.DeserializeObject <Service>(serviceResponse);

            Assert.NotNull(service);
        }
示例#5
0
        private async Task ThenServiceHealthIs(string healthStatus)
        {
            Thread.Sleep(2000);
            var httpClient          = ApiTestServer.GetHttpClient();
            var httpResponseMessage = await httpClient.GetAsync($"/api/services/{_serviceId}/health/current");

            var response = await httpResponseMessage.Content.ReadAsStringAsync();

            dynamic parsedResponse = JObject.Parse(response);

            Assert.Equal(healthStatus, (string)parsedResponse.healthState);
        }
示例#6
0
        private async Task WhenGetServiceWithId(string serviceId)
        {
            var httpClient = ApiTestServer.GetHttpClient();

            _response = await httpClient.GetAsync($"/api/services/{serviceId}");

            _responseContent = await _response.Content.ReadAsStringAsync();

            if (_response.IsSuccessStatusCode)
            {
                _serviceObject = JObject.Parse(_responseContent);
            }
        }
示例#7
0
        private async Task RegisterService()
        {
            var service = new Service
            {
                Id          = _serviceId,
                ServiceType = _serviceType,
                Address     = _serviceAddress,
                HealthCheck = new HealthCheck
                {
                    HealthCheckType = _healthCheckType
                }
            };

            var jsonString  = JsonConvert.SerializeObject(service);
            var httpContent = new StringContent(jsonString, Encoding.UTF8, "application/json");

            var httpClient = ApiTestServer.GetHttpClient();

            _response = await httpClient.PostAsync("/api/services", httpContent);
        }
示例#8
0
        private async Task WhenServiceIsDeleting(string serviceId)
        {
            var httpClient = ApiTestServer.GetHttpClient();

            _response = await httpClient.DeleteAsync($"/api/services/{serviceId}");
        }