public async Task Can_use_with_app_base_with_virtual() { _webBuilder.Register("/test", async context => { await context.Response.WriteAsync("Hello, World! " + context.Request.Path + " " + context.Request.PathBase); }); using (var host = _webBuilder.BuildVirtualHost("")) { using (var client = host.CreateClient()) { var responseMessage = await client.GetAsync("/test"); responseMessage.EnsureSuccessStatusCode(); var response = await responseMessage.Content.ReadAsStringAsync(); Assert.Equal("Hello, World! /test ", response); } } using (var host = _webBuilder.BuildVirtualHost("/appbase")) { using (var client = host.CreateClient()) { var responseMessage = await client.GetAsync("/test"); responseMessage.EnsureSuccessStatusCode(); var response = await responseMessage.Content.ReadAsStringAsync(); Assert.Equal("Hello, World! /test /appbase", response); } } }
public async Task Can_export_path_without_extension() { _webBuilder.Register("/test", context => context.Response.WriteAsync("test content")); using (var host = _webBuilder.BuildVirtualHost()) { await _hostExporter.Export(host, _directory); } File.Exists(Path.Combine(_directory, "test", "index.html")).Should().BeTrue(); }
public async Task Can_serve_files() { using (var testDirectory = new WorkingDirectorySession()) { File.WriteAllText(Path.Combine(testDirectory.Directory, "test.txt"), "test"); Directory.CreateDirectory(Path.Combine(testDirectory.Directory, "nested")); File.WriteAllText(Path.Combine(testDirectory.Directory, "nested", "test2.txt"), "test2"); _webBuilder.RegisterDirectory(testDirectory.Directory); using (var host = _webBuilder.BuildVirtualHost()) { using (var client = host.CreateClient()) { var responseMessage = await client.GetAsync("/test.txt"); responseMessage.EnsureSuccessStatusCode(); var response = await responseMessage.Content.ReadAsStringAsync(); Assert.Equal("test", response); responseMessage = await client.GetAsync("/nested/test2.txt"); responseMessage.EnsureSuccessStatusCode(); response = await responseMessage.Content.ReadAsStringAsync(); Assert.Equal("test2", response); } } using (var host = _webBuilder.BuildVirtualHost("/appbase")) { using (var client = host.CreateClient()) { var responseMessage = await client.GetAsync("/test.txt"); responseMessage.EnsureSuccessStatusCode(); var response = await responseMessage.Content.ReadAsStringAsync(); Assert.Equal("test", response); responseMessage = await client.GetAsync("/nested/test2.txt"); responseMessage.EnsureSuccessStatusCode(); response = await responseMessage.Content.ReadAsStringAsync(); Assert.Equal("test2", response); } } } }
public async Task Can_call_mvc_action() { _webBuilder.RegisterMvc("/somewhere", new { controller = "Test", action = "Index" }); using (var host = _webBuilder.BuildVirtualHost()) { using (var client = host.CreateClient()) { var responseMessage = await client.GetAsync("/somewhere"); responseMessage.EnsureSuccessStatusCode(); var response = await responseMessage.Content.ReadAsStringAsync(); Assert.Equal("test", response); } } }
public IVirtualHost BuildVirtualHost(string appBase = null) { return(_webBuilder.BuildVirtualHost(appBase)); }