// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Net.Http; using System.Threading.Tasks; using Microsoft.AspNetCore.Testing.xunit; using Xunit; namespace Microsoft.AspNetCore.Mvc.FunctionalTests { public class FlushPointTest : IClassFixture> { public FlushPointTest(MvcTestFixture fixture) { Client = fixture.Client; } public HttpClient Client { get; } [Fact] public async Task FlushPointsAreExecutedForPagesWithLayouts() { var expected = @"Page With Layout RenderBody content Content that takes time to produce "; // Act var body = await Client.GetStringAsync("http://localhost/FlushPoint/PageWithLayout"); // Assert Assert.Equal(expected, body, ignoreLineEndingDifferences: true); } [Fact] public async Task FlushPointsAreExecutedForPagesWithoutLayouts() { var expected = @"Initial content Secondary content Inside partial After flush inside partial
" + @"" + @"
"; // Act var body = await Client.GetStringAsync("http://localhost/FlushPoint/PageWithoutLayout"); // Assert Assert.Equal(expected, body, ignoreLineEndingDifferences: true); } [Theory] [InlineData("PageWithPartialsAndViewComponents", "FlushAsync invoked inside RenderSection")] [InlineData("PageWithRenderSectionAsync", "FlushAsync invoked inside RenderSectionAsync")] public async Task FlushPointsAreExecutedForPagesWithComponentsPartialsAndSections(string action, string title) { var expected = $@"{ title } RenderBody content partial-content Value from TaskReturningString

section-content

component-content Content that takes time to produce More content from layout "; // Act var body = await Client.GetStringAsync("http://localhost/FlushPoint/" + action); // Assert Assert.Equal(expected, body, ignoreLineEndingDifferences: true); } [Fact] public async Task FlushPointsNestedLayout() { // Arrange var expected = @"Inside Nested Layout Nested Page With Layout Nested content that takes time to produce "; // Act var body = await Client.GetStringAsync("http://localhost/FlushPoint/PageWithNestedLayout"); // Assert Assert.Equal(expected, body, ignoreLineEndingDifferences: true); } } }