11// Copyright (c) .NET Foundation. All rights reserved.
22// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33
4+ using System ;
45using System . Net ;
56using System . Net . Http ;
67using System . Threading . Tasks ;
78using AngleSharp . Parser . Html ;
89using BasicWebSite ;
910using BasicWebSite . Services ;
11+ using Microsoft . AspNetCore . Hosting ;
1012using Microsoft . Extensions . DependencyInjection ;
1113using Xunit ;
1214
@@ -17,18 +19,17 @@ public class ComponentRenderingFunctionalTests : IClassFixture<MvcTestFixture<Ba
1719 public ComponentRenderingFunctionalTests ( MvcTestFixture < BasicWebSite . StartupWithoutEndpointRouting > fixture )
1820 {
1921 Factory = fixture ;
20- Client = Client ?? CreateClient ( fixture ) ;
2122 }
2223
23- public HttpClient Client { get ; }
24-
2524 public MvcTestFixture < StartupWithoutEndpointRouting > Factory { get ; }
2625
2726 [ Fact ]
2827 public async Task Renders_BasicComponent ( )
2928 {
3029 // Arrange & Act
31- var response = await Client . GetAsync ( "http://localhost/components" ) ;
30+ var client = CreateClient ( Factory ) ;
31+
32+ var response = await client . GetAsync ( "http://localhost/components" ) ;
3233
3334 // Assert
3435 Assert . Equal ( HttpStatusCode . OK , response . StatusCode ) ;
@@ -41,9 +42,7 @@ public async Task Renders_BasicComponent()
4142 public async Task Renders_BasicComponent_UsingRazorComponents_Prerrenderer ( )
4243 {
4344 // Arrange & Act
44- var client = Factory
45- . WithWebHostBuilder ( builder => builder . ConfigureServices ( services => services . AddRazorComponents ( ) ) )
46- . CreateClient ( ) ;
45+ var client = CreateClient ( Factory , builder => builder . ConfigureServices ( services => services . AddRazorComponents ( ) ) ) ;
4746
4847 var response = await client . GetAsync ( "http://localhost/components" ) ;
4948
@@ -58,7 +57,9 @@ public async Task Renders_BasicComponent_UsingRazorComponents_Prerrenderer()
5857 public async Task Renders_RoutingComponent ( )
5958 {
6059 // Arrange & Act
61- var response = await Client . GetAsync ( "http://localhost/components/routable" ) ;
60+ var client = CreateClient ( Factory , builder => builder . ConfigureServices ( services => services . AddRazorComponents ( ) ) ) ;
61+
62+ var response = await client . GetAsync ( "http://localhost/components/routable" ) ;
6263
6364 // Assert
6465 Assert . Equal ( HttpStatusCode . OK , response . StatusCode ) ;
@@ -71,9 +72,7 @@ public async Task Renders_RoutingComponent()
7172 public async Task Renders_RoutingComponent_UsingRazorComponents_Prerrenderer ( )
7273 {
7374 // Arrange & Act
74- var client = Factory
75- . WithWebHostBuilder ( builder => builder . ConfigureServices ( services => services . AddRazorComponents ( ) ) )
76- . CreateClient ( ) ;
75+ var client = CreateClient ( Factory , builder => builder . ConfigureServices ( services => services . AddRazorComponents ( ) ) ) ;
7776
7877 var response = await client . GetAsync ( "http://localhost/components/routable" ) ;
7978
@@ -84,6 +83,21 @@ public async Task Renders_RoutingComponent_UsingRazorComponents_Prerrenderer()
8483 AssertComponent ( "\n Router component\n <p>Routed successfully</p>\n " , "Routing" , content ) ;
8584 }
8685
86+ [ Fact ]
87+ public async Task Renders_ThrowingComponent_UsingRazorComponents_Prerrenderer ( )
88+ {
89+ // Arrange & Act
90+ var client = CreateClient ( Factory , builder => builder . ConfigureServices ( services => services . AddRazorComponents ( ) ) ) ;
91+
92+ var response = await client . GetAsync ( "http://localhost/components/throws" ) ;
93+
94+ // Assert
95+ Assert . Equal ( HttpStatusCode . InternalServerError , response . StatusCode ) ;
96+ var content = await response . Content . ReadAsStringAsync ( ) ;
97+
98+ Assert . Contains ( "InvalidTimeZoneException: test" , content ) ;
99+ }
100+
87101 [ Fact ]
88102 public async Task Renders_AsyncComponent ( )
89103 {
@@ -138,8 +152,8 @@ public async Task Renders_AsyncComponent()
138152 </table>
139153
140154" ;
141-
142- var response = await Client . GetAsync ( "http://localhost/components" ) ;
155+ var client = CreateClient ( Factory ) ;
156+ var response = await client . GetAsync ( "http://localhost/components" ) ;
143157
144158 // Assert
145159 Assert . Equal ( HttpStatusCode . OK , response . StatusCode ) ;
@@ -164,12 +178,16 @@ private class LoopHttpHandler : DelegatingHandler
164178 {
165179 }
166180
167- private HttpClient CreateClient ( MvcTestFixture < BasicWebSite . StartupWithoutEndpointRouting > fixture )
181+ private HttpClient CreateClient ( MvcTestFixture < BasicWebSite . StartupWithoutEndpointRouting > fixture , Action < IWebHostBuilder > configure = null )
168182 {
169183 var loopHandler = new LoopHttpHandler ( ) ;
170184
171185 var client = fixture
172- . WithWebHostBuilder ( builder => builder . ConfigureServices ( ConfigureTestWeatherForecastService ) )
186+ . WithWebHostBuilder ( builder =>
187+ {
188+ configure ? . Invoke ( builder ) ;
189+ builder . ConfigureServices ( ConfigureTestWeatherForecastService ) ;
190+ } )
173191 . CreateClient ( ) ;
174192
175193 // We configure the inner handler with a handler to this TestServer instance so that calls to the
0 commit comments