public async Task request_is_returned() { using (var server = new InMemoryHost(() => { ResourceSpace.Has.ResourcesNamed("resource") .AtUri("/{id}").HandledBy <Handler>(); ResourceSpace.Uses.Diagnostics(new DiagnosticsOptions { TraceMethod = true }); })) { var response = await server.ProcessRequestAsync(new InMemoryRequest() { HttpMethod = "TRACE", Uri = new Uri("http://localhost/1"), Headers = { { "Accept", "*/*" }, { "User-Agent", "stuff" } } }); response.StatusCode.ShouldBe(200); response.Entity.ContentType?.MediaType.ShouldBe("message/http"); using (var reader = new StreamReader(response.Entity.Stream, Encoding.UTF8)) reader.ReadToEnd().ShouldBe( "TRACE /1 HTTP/1.1\r\n" + "Host: http://localhost/\r\n" + "Accept: */*\r\n" + "User-Agent: stuff\r\n\r\n"); } }
public static Task <IResponse> Get(this InMemoryHost host, string uri) { return(host.ProcessRequestAsync(new InMemoryRequest { HttpMethod = "GET", Uri = new Uri($"http://localhost{uri}", UriKind.RelativeOrAbsolute) })); }
static Task <IResponse> ExecuteMethod(InMemoryHost host, string method, string uri, string content, string contentType) { return(host.ProcessRequestAsync(new InMemoryRequest { HttpMethod = method, Uri = new Uri($"http://localhost{uri}", UriKind.RelativeOrAbsolute) }.WriteString(content, contentType))); }
async Task <IResponse> Get(Func <OperationResult> getter) { var server = new InMemoryHost(new ErrorApi(getter)); return(await server.ProcessRequestAsync(new InMemoryRequest() { HttpMethod = "GET" })); }
public async Task negotiated_type_is_specific_mt() { var response = await server.ProcessRequestAsync(new InMemoryRequest { HttpMethod = "GET", Headers = { { "Accept", "application/json" } }, Uri = new Uri("http://localhost/1") }); response.Headers.ContentType.ShouldBe(MediaType.Json); }
public async Task <byte[]> GetAllEventsMemory() { var response = await _memServerNoTrace.ProcessRequestAsync(new InMemoryRequest() { HttpMethod = "GET", Uri = new Uri("http://localhost/events/") }); var body = await response.Entity.Stream.ReadToEndAsync(); VerifyResult(response.StatusCode, body); return(body); }
public async Task <byte[]> MemoryHostNoTrace() { var response = await _memServerNoTrace.ProcessRequestAsync(new InMemoryRequest() { HttpMethod = "GET", Uri = new Uri("http://localhost/.well-known/health") }); var body = await response.Entity.Stream.ReadToEndAsync(); VerifyResult(body); return(body); }
public async Task TestDeepHealthCheckQueryParam(string querystring, bool deepHealthChecksAttempted) { using (var host = new InMemoryHost(new TestConfig(), startup: new StartupProperties { OpenRasta = { Errors = { HandleAllExceptions = false, HandleCatastrophicExceptions = false } } })) { var request = new InMemoryRequest { HttpMethod = "GET", Uri = new Uri($"http://localhost/healthcheck/{querystring}") }; var response = await host.ProcessRequestAsync(request); // response.Should().NotBeNull("whether deep checks are done or not the controller should respond"); response.StatusCode.ShouldBe(200, "both deep and shallow checks return success"); // DeepHealthChecks(deepHealthChecksAttempted); } }
static Task <IResponse> ExecuteMethod(InMemoryHost host, string uri, string method, string content = null, string contentType = null, Action <HttpHeaderDictionary> headers = null) { if (uri.StartsWith('/') == false) { uri = "/" + uri; } var request = new InMemoryRequest { HttpMethod = method, Uri = new Uri($"http://localhost{uri}", UriKind.RelativeOrAbsolute) }; headers?.Invoke(request.Headers); if (content != null) { request = request.WriteString(content, contentType); } return(host.ProcessRequestAsync(request)); }
public async void contains_date_header() { _response = await _host.ProcessRequestAsync(new InMemoryRequest()); _response.Headers.ContainsKey("Date").ShouldBeTrue(); }