|
| 1 | +using Fluid.MvcViewEngine; |
| 2 | +using Fluid.Tests.Mocks; |
| 3 | +using Microsoft.AspNetCore.Builder; |
| 4 | +using Microsoft.AspNetCore.Hosting; |
| 5 | +using Microsoft.AspNetCore.Hosting.Server; |
| 6 | +using Microsoft.AspNetCore.Hosting.Server.Features; |
| 7 | +using Microsoft.AspNetCore.Mvc; |
| 8 | +using Microsoft.Extensions.DependencyInjection; |
| 9 | +using System; |
| 10 | +using System.Net.Http; |
| 11 | +using System.Threading.Tasks; |
| 12 | +using Xunit; |
| 13 | + |
| 14 | +namespace Fluid.Tests.MvcViewEngine |
| 15 | +{ |
| 16 | + public class FunctionalServerTests |
| 17 | + { |
| 18 | + [Fact] |
| 19 | + public async Task KestrelWithSynchronousIoDisabled_ShouldRenderView() |
| 20 | + { |
| 21 | + var expected = new string('b', 4096); |
| 22 | + var mockFileProvider = new MockFileProvider(); |
| 23 | + mockFileProvider.Add("Home/Index.liquid", "{{ Model }}"); |
| 24 | + |
| 25 | + var builder = WebApplication.CreateBuilder(); |
| 26 | + builder.WebHost.UseKestrel(options => options.AllowSynchronousIO = false); |
| 27 | + builder.WebHost.UseUrls("http://127.0.0.1:0"); |
| 28 | + |
| 29 | + builder.Services.PostConfigure<FluidMvcViewOptions>(options => |
| 30 | + { |
| 31 | + options.TemplateOptions.OutputBufferSize = 16; |
| 32 | + options.ViewsFileProvider = mockFileProvider; |
| 33 | + options.PartialsFileProvider = mockFileProvider; |
| 34 | + }); |
| 35 | + |
| 36 | + builder.Services |
| 37 | + .AddControllersWithViews() |
| 38 | + .AddApplicationPart(typeof(FunctionalServerTests).Assembly) |
| 39 | + .AddFluid(); |
| 40 | + |
| 41 | + var app = builder.Build(); |
| 42 | + app.UseRouting(); |
| 43 | + app.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}"); |
| 44 | + |
| 45 | + await app.StartAsync(); |
| 46 | + |
| 47 | + try |
| 48 | + { |
| 49 | + var addresses = app.Services.GetRequiredService<IServer>().Features.Get<IServerAddressesFeature>()?.Addresses; |
| 50 | + var serverAddress = Assert.Single(addresses); |
| 51 | + |
| 52 | + using var client = new HttpClient { BaseAddress = new Uri(serverAddress) }; |
| 53 | + var response = await client.GetAsync("/Home/Index"); |
| 54 | + var responseBody = await response.Content.ReadAsStringAsync(); |
| 55 | + |
| 56 | + Assert.True(response.IsSuccessStatusCode, $"Response status code was {(int) response.StatusCode}. Body: {responseBody}"); |
| 57 | + Assert.Equal(expected, responseBody); |
| 58 | + } |
| 59 | + finally |
| 60 | + { |
| 61 | + await app.StopAsync(); |
| 62 | + await app.DisposeAsync(); |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + } |
| 67 | + |
| 68 | + public class HomeController : Controller |
| 69 | + { |
| 70 | + [HttpGet] |
| 71 | + public IActionResult Index() |
| 72 | + { |
| 73 | + return View("Index", new string('b', 4096)); |
| 74 | + } |
| 75 | + } |
| 76 | +} |
0 commit comments