Added more coverage in functional tests for FlushAsync
This commit is contained in:
parent
68fcb2bfca
commit
9ea5350271
|
|
@ -63,7 +63,18 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
waitService.WaitForServer();
|
||||
|
||||
// Assert - 3
|
||||
Assert.Equal("Final content", GetTrimmedString(stream));
|
||||
Assert.Equal("Inside partial", GetTrimmedString(stream));
|
||||
waitService.WaitForServer();
|
||||
|
||||
// Assert - 4
|
||||
Assert.Equal(@"After flush inside partial
|
||||
<form action=""/FlushPoint/PageWithoutLayout"" method=""post""><input id=""Name1"" name=""Name1"" type=""text"" value="""" />",
|
||||
GetTrimmedString(stream));
|
||||
waitService.WaitForServer();
|
||||
|
||||
// Assert - 5
|
||||
Assert.Equal(@"<input id=""Name2"" name=""Name2"" type=""text"" value="""" /></form>",
|
||||
GetTrimmedString(stream));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
|
|
@ -105,6 +116,59 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
"More content from layout"), GetTrimmedString(stream));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task FlushPointsNestedLayout()
|
||||
{
|
||||
// Arrange
|
||||
var waitService = new WaitService();
|
||||
var serviceProvider = GetServiceProvider(waitService);
|
||||
|
||||
var server = TestServer.Create(serviceProvider, _app);
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var stream = await client.GetStreamAsync("http://localhost/FlushPoint/PageWithNestedLayout");
|
||||
|
||||
// Assert - 1
|
||||
Assert.Equal(@"Inside Nested Layout
|
||||
|
||||
<title>Nested Page With Layout</title>",
|
||||
GetTrimmedString(stream));
|
||||
waitService.WaitForServer();
|
||||
|
||||
// Assert - 2
|
||||
Assert.Equal("<span>Nested content that takes time to produce</span>", GetTrimmedString(stream));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task FlushBeforeCallingLayout()
|
||||
{
|
||||
var waitService = new WaitService();
|
||||
var serviceProvider = GetServiceProvider(waitService);
|
||||
|
||||
var server = TestServer.Create(serviceProvider, _app);
|
||||
var client = server.CreateClient();
|
||||
|
||||
var expectedMessage = "A layout page cannot be rendered after 'FlushAsync' has been invoked.";
|
||||
|
||||
// Act
|
||||
var stream = await client.GetStreamAsync("http://localhost/FlushPoint/PageWithFlushBeforeLayout");
|
||||
|
||||
// Assert - 1
|
||||
Assert.Equal("Initial content", GetTrimmedString(stream));
|
||||
waitService.WaitForServer();
|
||||
|
||||
//Assert - 2
|
||||
try
|
||||
{
|
||||
GetTrimmedString(stream);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Assert.Equal(expectedMessage, ex.InnerException.Message);
|
||||
}
|
||||
}
|
||||
|
||||
private IServiceProvider GetServiceProvider(WaitService waitService)
|
||||
{
|
||||
var services = new ServiceCollection();
|
||||
|
|
|
|||
|
|
@ -28,5 +28,15 @@ namespace RazorWebSite
|
|||
{
|
||||
return View("PageWithSectionInvokedViaRenderSectionAsync");
|
||||
}
|
||||
|
||||
public ViewResult PageWithNestedLayout()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
public ViewResult PageWithFlushBeforeLayout()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
@inject WaitService WaitService
|
||||
Initial content
|
||||
@await FlushAsync()
|
||||
@{
|
||||
WaitService.WaitForClient();
|
||||
}
|
||||
|
||||
@{
|
||||
Layout = "/Views/Shared/_LayoutWithFlush.cshtml";
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
@inject WaitService WaitService
|
||||
@{
|
||||
Layout = "/Views/Shared/_NestedLayoutWithFlush.cshtml";
|
||||
ViewBag.Title = "Nested Page With Layout";
|
||||
}
|
||||
<title>@ViewBag.Title</title>
|
||||
|
|
@ -9,7 +9,16 @@ Secondary content
|
|||
@{
|
||||
WaitService.WaitForClient();
|
||||
}
|
||||
Final content
|
||||
@{
|
||||
await Html.RenderPartialAsync("_PartialWithFlush");
|
||||
}
|
||||
@using (Html.BeginForm())
|
||||
{
|
||||
@Html.TextBox("Name1")
|
||||
@await FlushAsync()
|
||||
WaitService.WaitForClient();
|
||||
@Html.TextBox("Name2")
|
||||
}
|
||||
@{
|
||||
WaitService.NotifyClient();
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
@RenderBody()
|
||||
@await RenderSectionAsync("nestedcontent")
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
@inject WaitService WaitService
|
||||
@{
|
||||
Layout = "/Views/Shared/_LayoutWithRenderSectionOnly.cshtml";
|
||||
ViewBag.Title = "Page With Layout";
|
||||
}
|
||||
Inside Nested Layout
|
||||
@RenderBody()
|
||||
@section nestedcontent
|
||||
{
|
||||
@{
|
||||
await FlushAsync();
|
||||
WaitService.WaitForClient();
|
||||
}
|
||||
<span>Nested content that takes time to produce</span>
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
@inject WaitService WaitService
|
||||
Inside partial
|
||||
@await FlushAsync()
|
||||
@{
|
||||
WaitService.WaitForClient();
|
||||
}
|
||||
After flush inside partial
|
||||
Loading…
Reference in New Issue