Example #1
0
        public async Task NonFunctionPathsGive404(string path)
        {
            var builder = EntryPoint
                          .CreateHostBuilder <SimpleFunction>()
                          .ConfigureWebHost(builder => builder.UseTestServer());

            using (var server = await builder.StartAsync())
            {
                var client   = server.GetTestServer().CreateClient();
                var response = await client.GetAsync(path);

                Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
                var content = await response.Content.ReadAsStringAsync();

                Assert.Empty(content);
            }
        }
Example #2
0
        public async Task CreateHostBuilder()
        {
            var builder = EntryPoint
                          .CreateHostBuilder <SimpleFunction>()
                          .ConfigureWebHost(builder => builder.UseTestServer());

            using (var server = await builder.StartAsync())
            {
                var client = server.GetTestServer().CreateClient();

                var response = await client.GetAsync("relativePath");

                response.EnsureSuccessStatusCode();
                var content = await response.Content.ReadAsStringAsync();

                Assert.Equal("Test message", content);
            }
        }
        public async Task FunctionWritesHelloFunctionsFramework()
        {
            var builder = EntryPoint
                          .CreateHostBuilder <SimpleHttpFunction.Function>()
                          .ConfigureWebHost(builder => builder.UseTestServer());

            using (var server = await builder.StartAsync())
            {
                var client = server.GetTestServer().CreateClient();

                // Make a request to the function, and test that the response looks how we expect it to.
                var response = await client.GetAsync("request-uri");

                response.EnsureSuccessStatusCode();
                var content = await response.Content.ReadAsStringAsync();

                Assert.Equal("Hello, Functions Framework.", content);
            }
        }
Example #4
0
 /// <summary>
 /// Creates a FunctionServerFactory for the specified function type.
 /// </summary>
 /// <param name="functionType">The function type to host in the server.</param>
 public FunctionTestServer(Type functionType)
     : this(EntryPoint.CreateHostBuilder(functionType))
 {
 }
Example #5
0
 /// <summary>
 /// Creates a FunctionServerFactory for the specified environment and function assembly.
 /// </summary>
 /// <param name="environment">The fake environment variables to use when constructing the server.</param>
 /// <param name="functionAssembly">The assembly containing the target function.</param>
 public FunctionTestServer(IReadOnlyDictionary <string, string> environment, Assembly functionAssembly)
     : this(EntryPoint.CreateHostBuilder(environment, Preconditions.CheckNotNull(functionAssembly, nameof(functionAssembly))))
 {
 }