Пример #1
0
        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);
        }
Пример #2
0
        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);
        }
Пример #3
0
        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);
        }
Пример #4
0
 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)
         );
 }
Пример #5
0
        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);
        }
Пример #6
0
        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);
        }