public void GetReturns4t6() { var responseHeaders = new Dictionary<string, string[]>(); var responseStream = new MemoryStream(); var requestBody = new MemoryStream(); //set status code defaults to 200, so it's not called Action<int> setStatusCode = i => {}; var runtime = new Runtime(); var resource = new TestResource(); runtime.RegisterResource(resource); var task = runtime.HandleRequest("GET", "foo/yippy", "x=4&y=t6", responseHeaders, requestBody, responseHeaders, responseStream, setStatusCode); Task.WaitAll(task); responseStream.Position = 0; using (var reader = new StreamReader(responseStream, Encoding.UTF8)) { var response = reader.ReadToEnd(); Assert.Equal("4t6", response); } //TODO: test content type, etc once they're not hard coded }
public void GetReturns404() { var responseHeaders = new Dictionary<string, string[]>(); var responseStream = new MemoryStream(); var requestBody = new MemoryStream(); var statusCode = 0; Action<int> setStatusCode = i => { statusCode = i; }; var runtime = new Runtime(); var resource = new TestResource(); runtime.RegisterResource(resource); var task = runtime.HandleRequest("GET", "foo2", "", responseHeaders, requestBody, responseHeaders, responseStream, setStatusCode); Task.WaitAll(task); responseStream.Position = 0; using (var reader = new StreamReader(responseStream, Encoding.UTF8)) { var response = reader.ReadToEnd(); Assert.True(response.EndsWith("not found")); } Assert.Equal(404, statusCode); }
public void TokenizedRouteSetsParameters() { var responseHeaders = new Dictionary<string, string[]>(); var responseStream = new MemoryStream(); var requestBody = new MemoryStream(); //set status code defaults to 200, so it's not called Action<int> setStatusCode = i => {}; var runtime = new Runtime(); var resource = new TestResource(); runtime.RegisterResource(resource); var task = runtime.HandleRequest("GET", "foo/yippy/4/t6", "", responseHeaders, requestBody, responseHeaders, responseStream, setStatusCode); Task.WaitAll(task); responseStream.Position = 0; using (var reader = new StreamReader(responseStream, Encoding.UTF8)) { var response = reader.ReadToEnd(); Assert.Equal("4t6", response); } }