private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, int statusCode) { _serviceHandler.GivenThereIsAServiceRunningOn(baseUrl, basePath, context => { if (_count == 0) { context.Response.Cookies.Append("test", "0"); _count++; context.Response.StatusCode = statusCode; return(Task.CompletedTask); } if (context.Request.Cookies.TryGetValue("test", out var cookieValue) || context.Request.Headers.TryGetValue("Set-Cookie", out var headerValue)) { if (cookieValue == "0" || headerValue == "test=1; path=/") { context.Response.StatusCode = statusCode; return(Task.CompletedTask); } } context.Response.StatusCode = 500; return(Task.CompletedTask); }); }
private void GivenThereIsAPossiblyBrokenServiceRunningOn(string url, string responseBody) { _serviceHandler.GivenThereIsAServiceRunningOn(url, async context => { //circuit starts closed if (_requestCount == 0) { _requestCount++; context.Response.StatusCode = 200; await context.Response.WriteAsync(responseBody); return; } //request one times out and polly throws exception, circuit opens if (_requestCount == 1) { _requestCount++; await Task.Delay(1000); context.Response.StatusCode = 200; return; } //after break closes we return 200 OK if (_requestCount == 2) { context.Response.StatusCode = 200; await context.Response.WriteAsync(responseBody); } }); }
private void GivenServiceIsRunning(string baseUrl, int statusCode, string responseBody) { _serviceHandler.GivenThereIsAServiceRunningOn(baseUrl, async context => { context.Response.StatusCode = statusCode; await context.Response.WriteAsync(responseBody); }); }
private void GivenThereIsAFakeConsulServiceDiscoveryProvider(string url) { _serviceHandler.GivenThereIsAServiceRunningOn(url, async context => { if (context.Request.Path.Value == "/v1/health/service/product") { await context.Response.WriteJsonAsync(_serviceEntries); } }); }
private void GivenThereIsAFakeConsulServiceDiscoveryProvider(string url) { _serviceHandler.GivenThereIsAServiceRunningOn(url, async context => { if (context.Request.Path.Value == "/v1/health/service/product") { var json = JsonConvert.SerializeObject(_serviceEntries); context.Response.Headers.Add("Content-Type", "application/json"); await context.Response.WriteAsync(json); } }); }
private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, int statusCode, string responseBody, string expected) { _serviceHandler.GivenThereIsAServiceRunningOn(baseUrl, basePath, async context => { if (context.Request.Headers.TryGetValue("Content-Encoding", out var contentEncoding)) { contentEncoding.First().ShouldBe("gzip"); string text = null; using (var decompress = new GZipStream(context.Request.Body, CompressionMode.Decompress)) { using (var sr = new StreamReader(decompress)) { // Synchronous operations are disallowed. Call ReadAsync or set AllowSynchronousIO to true instead. // text = sr.ReadToEnd(); text = await sr.ReadToEndAsync(); } } if (text != expected) { throw new Exception("not gzipped"); } context.Response.StatusCode = statusCode; await context.Response.WriteAsync(responseBody); } else { context.Response.StatusCode = statusCode; await context.Response.WriteAsync("downstream path didnt match base path"); } }); }
private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, int statusCode, string responseBody, string expectedQueryString) { _serviceHandler.GivenThereIsAServiceRunningOn(baseUrl, basePath, async context => { _downstreamPath = !string.IsNullOrEmpty(context.Request.PathBase.Value) ? context.Request.PathBase.Value : context.Request.Path.Value; if (_downstreamPath != basePath) { context.Response.StatusCode = statusCode; await context.Response.WriteAsync("downstream path didnt match base path"); } else { if (context.Request.QueryString.Value.Contains(expectedQueryString)) { context.Response.StatusCode = statusCode; await context.Response.WriteAsync(responseBody); } else { context.Response.StatusCode = statusCode; await context.Response.WriteAsync("downstream path didnt match base path"); } } }); }
private void GivenThereIsAFakeConsulServiceDiscoveryProvider(string url, string serviceName) { _serviceHandler.GivenThereIsAServiceRunningOn(url, async context => { if (context.Request.Path.Value == $"/v1/health/service/{serviceName}") { if (context.Request.Headers.TryGetValue("X-Consul-Token", out var values)) { _receivedToken = values.First(); } var json = JsonConvert.SerializeObject(_consulServices); context.Response.Headers.Add("Content-Type", "application/json"); await context.Response.WriteAsync(json); } }); }
private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, int statusCode) { _serviceHandler.GivenThereIsAServiceRunningOn(baseUrl, basePath, async context => { context.Response.StatusCode = statusCode; }); }
private void GivenThereIsAServiceRunningOn(string url) { _serviceHandler.GivenThereIsAServiceRunningOn(url, context => { context.Request.Headers.TryGetValue(_steps.RequestIdKey, out var requestId); context.Response.Headers.Add(_steps.RequestIdKey, requestId.First()); return(Task.CompletedTask); }); }
private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, string reasonPhrase) { _serviceHandler.GivenThereIsAServiceRunningOn(baseUrl, basePath, async context => { context.Response.HttpContext.Features.Get <IHttpResponseFeature>().ReasonPhrase = reasonPhrase; await context.Response.WriteAsync("YOYO!"); }); }
private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath) { _serviceHandler.GivenThereIsAServiceRunningOn(baseUrl, basePath, context => { _counterOne++; context.Response.StatusCode = 200; context.Response.WriteAsync(_counterOne.ToString()); return(Task.CompletedTask); }); }
private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, int port, HttpProtocols protocols) { _serviceHandler.GivenThereIsAServiceRunningOn(baseUrl, basePath, async context => { context.Response.StatusCode = 200; var reader = new StreamReader(context.Request.Body); var body = await reader.ReadToEndAsync(); await context.Response.WriteAsync(body); }, port, protocols); }
private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, int statusCode, string responseBody) { _serviceHandler.GivenThereIsAServiceRunningOn(baseUrl, basePath, async context => { _contentType = context.Request.ContentType; _contentLength = context.Request.ContentLength; _contentTypeHeaderExists = context.Request.Headers.TryGetValue("Content-Type", out var value); context.Response.StatusCode = statusCode; await context.Response.WriteAsync(responseBody); }); }
private void GivenThereIsAServiceRunningOn(string url, int statusCode, string responseBody, string key, string value) { _serviceHandler.GivenThereIsAServiceRunningOn(url, async context => { if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(key)) { context.Response.Headers.Add(key, value); } context.Response.StatusCode = statusCode; await context.Response.WriteAsync(responseBody); }); }
private void GivenProductServiceOneIsRunning(string url, int statusCode) { _serviceHandler.GivenThereIsAServiceRunningOn(url, async context => { try { var response = string.Empty; lock (SyncLock) { _counterOne++; response = _counterOne.ToString(); } context.Response.StatusCode = statusCode; await context.Response.WriteAsync(response); } catch (Exception exception) { await context.Response.WriteAsync(exception.StackTrace); } }); }
private void GivenThereIsAServiceRunningOn(string url, int statusCode) { _serviceHandler.GivenThereIsAServiceRunningOn(url, async context => { var customerId = context.Request.Headers.First(x => x.Key == "CustomerId").Value.First(); var locationId = context.Request.Headers.First(x => x.Key == "LocationId").Value.First(); var userType = context.Request.Headers.First(x => x.Key == "UserType").Value.First(); var userId = context.Request.Headers.First(x => x.Key == "UserId").Value.First(); var responseBody = $"CustomerId: {customerId} LocationId: {locationId} UserType: {userType} UserId: {userId}"; context.Response.StatusCode = statusCode; await context.Response.WriteAsync(responseBody); }); }
private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, string queryString, int statusCode, string responseBody) { _serviceHandler.GivenThereIsAServiceRunningOn(baseUrl, basePath, async context => { if ((context.Request.PathBase.Value != basePath) || context.Request.QueryString.Value != queryString) { context.Response.StatusCode = 500; await context.Response.WriteAsync("downstream path didnt match base path"); } else { context.Response.StatusCode = statusCode; await context.Response.WriteAsync(responseBody); } }); }
private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, string expected) { _serviceHandler.GivenThereIsAServiceRunningOn(baseUrl, basePath, async context => { if (context.Request.Method == expected) { context.Response.StatusCode = 200; var reader = new StreamReader(context.Request.Body); var body = await reader.ReadToEndAsync(); await context.Response.WriteAsync(body); } else { context.Response.StatusCode = 500; } }); }
private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, int statusCode, string responseBody, int port) { _serviceHandler.GivenThereIsAServiceRunningOn(baseUrl, basePath, "idsrv3test.pfx", "idsrv3test", port, async context => { _downstreamPath = !string.IsNullOrEmpty(context.Request.PathBase.Value) ? context.Request.PathBase.Value : context.Request.Path.Value; if (_downstreamPath != basePath) { context.Response.StatusCode = statusCode; await context.Response.WriteAsync("downstream path didnt match base path"); } else { context.Response.StatusCode = statusCode; await context.Response.WriteAsync(responseBody); } }); }
private void GivenThereIsAServiceRunningOn(string url) { _serviceHandler.GivenThereIsAServiceRunningOn(url, context => throw new Exception("BLAMMMM")); }
private void GivenThereIsAFakeEurekaServiceDiscoveryProvider(string url, string serviceName) { _serviceHandler.GivenThereIsAServiceRunningOn(url, async context => { if (context.Request.Path.Value == "/eureka/apps/") { var apps = new List <Application>(); foreach (var serviceInstance in _eurekaInstances) { var a = new Application { name = serviceName, instance = new List <Instance> { new Instance { instanceId = $"{serviceInstance.Host}:{serviceInstance}", hostName = serviceInstance.Host, app = serviceName, ipAddr = "127.0.0.1", status = "UP", overriddenstatus = "UNKNOWN", port = new Port { value = serviceInstance.Port, enabled = "true" }, securePort = new SecurePort { value = serviceInstance.Port, enabled = "true" }, countryId = 1, dataCenterInfo = new DataCenterInfo { value = "com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo", name = "MyOwn" }, leaseInfo = new LeaseInfo { renewalIntervalInSecs = 30, durationInSecs = 90, registrationTimestamp = 1457714988223, lastRenewalTimestamp = 1457716158319, evictionTimestamp = 0, serviceUpTimestamp = 1457714988223, }, metadata = new Metadata { value = "java.util.Collections$EmptyMap", }, homePageUrl = $"{serviceInstance.Host}:{serviceInstance.Port}", statusPageUrl = $"{serviceInstance.Host}:{serviceInstance.Port}", healthCheckUrl = $"{serviceInstance.Host}:{serviceInstance.Port}", vipAddress = serviceName, isCoordinatingDiscoveryServer = "false", lastUpdatedTimestamp = "1457714988223", lastDirtyTimestamp = "1457714988172", actionType = "ADDED", }, }, }; apps.Add(a); } var applications = new EurekaApplications { applications = new Applications { application = apps, apps__hashcode = "UP_1_", versions__delta = "1", }, }; var json = JsonConvert.SerializeObject(applications); context.Response.Headers.Add("Content-Type", "application/json"); await context.Response.WriteAsync(json); } }); }