/// <summary>
        /// Executes the given request in the function in an in-memory test server,
        /// validates that the response status code is 200, and returns the text of the
        /// response body. FunctionTestServer{T} is provided by the
        /// Google.Cloud.Functions.Invoker.Testing package.
        /// </summary>
        private static async Task <string> ExecuteRequest(HttpRequestMessage request)
        {
            using (var server = new FunctionTestServer <Function>())
            {
                using (HttpClient client = server.CreateClient())
                {
                    HttpResponseMessage response = await client.SendAsync(request);

                    Assert.Equal(HttpStatusCode.OK, response.StatusCode);
                    return(await response.Content.ReadAsStringAsync());
                }
            }
        }
        public async Task FunctionWritesHelloFunctionsFramework()
        {
            using (var server = new FunctionTestServer <SimpleHttpFunction.Function>())
            {
                var client = server.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);
            }
        }
예제 #3
0
        public async Task LogEntryIsRecorded()
        {
            using (var server = new FunctionTestServer <SimpleDependencyInjection.Function>())
            {
                // We shouldn't have any log entries (for the function's category) at the start of the test.
                Assert.Empty(server.GetFunctionLogEntries());
                // Note: server.GetFunctionLogEntries() is equivalent to
                // server.GetLogEntries(typeof(SimpleDependencyInjection.Function)

                var client = server.CreateClient();

                // Make a request to the function.
                var response = await client.GetAsync("sample-path");

                response.EnsureSuccessStatusCode();

                // Check that we got the expected log entry.
                var logs  = server.GetFunctionLogEntries();
                var entry = Assert.Single(logs);

                Assert.Equal(LogLevel.Information, entry.Level);
                Assert.Equal("Function called with path /sample-path", entry.Message);
            }
        }
예제 #4
0
 public SimpleHttpFunctionTest_WithTestServerFixture(FunctionTestServer <SimpleHttpFunction.Function> server) =>