async Task <TestableHttpResponse> GetResponseAsync(ResponseCreator responseCreator) { var request = new TestableHttpRequest(null, null); var retval = new TestableHttpResponse(); await responseCreator.CreateResponseAsync(request, new byte[0], retval, endpoint); return(retval); }
public async Task ScriptsCanSetContentType() { var endpoint = new Endpoint("foo", "bar"); var responseCreator = new LiteralDynamicResponseCreator("ContentType = \"image/png\"; return \"\";", endpoint); var response = new TestableHttpResponse(); await responseCreator.CreateResponseAsync(new TestableHttpRequest("/", null), new byte[0], response, endpoint); Assert.Equal("image/png", response.ContentType); }
public async Task ScriptsCanSetResponseStatusCode() { var endpoint = new Endpoint("foo", "bar"); var responseCreator = new LiteralDynamicResponseCreator("StatusCode = 102; return \"\";", endpoint); var response = new TestableHttpResponse(); await responseCreator.CreateResponseAsync(new TestableHttpRequest("/", null), new byte[0], response, endpoint); Assert.Equal(102, (int)response.HttpStatusCode); }
public async Task ScriptWithoutReturnValueThrowsException() { var endpoint = new Endpoint("foo", "bar"); var responseCreator = new LiteralDynamicResponseCreator("ContentType = \"image/png\";", endpoint); var response = new TestableHttpResponse(); await Assert.ThrowsAsync( typeof(ArgumentNullException), async() => await responseCreator.CreateResponseAsync(new TestableHttpRequest("/", null), new byte[0], response, endpoint) ); }
async public Task ScriptCanUseParams() { var ecr = CreateEndpointWithScript(); var endpoint = ecr.Endpoints.Single(); var responseCreator = endpoint.Responses.Single().Item2; Assert.NotNull(responseCreator); var response = new TestableHttpResponse(); var responseBytes = await responseCreator.CreateResponseAsync( new TestableHttpRequest("/", null), new byte[0], response, endpoint ); Assert.Equal("Hello World", response.WrittenContent); }
async public Task UpdatedParamsReflectedInScripts() { var ecr = CreateEndpointWithScript(); var endpoint = ecr.Endpoints.Single(); endpoint.GetParameter("greeting").Value = "Goodbye"; endpoint.GetParameter("subject").Value = "Cruel World"; var responseCreator = endpoint.Responses.Single().Item2; var response = new TestableHttpResponse(); var responseBytes = await responseCreator.CreateResponseAsync( new TestableHttpRequest("/", null), new byte[0], response, endpoint ); Assert.Equal("Goodbye Cruel World", response.WrittenContent); }