5
5
using System . Collections . Generic ;
6
6
using System . Linq ;
7
7
using System . Net ;
8
+ using System . Runtime . InteropServices ;
8
9
using System . Threading . Tasks ;
9
10
using Microsoft . AspNetCore . BrowserTesting ;
10
11
using Microsoft . AspNetCore . Testing ;
16
17
17
18
namespace Templates . Test
18
19
{
19
- [ TestCaseOrderer ( "Templates.Test.PriorityOrderer" , "BlazorTemplates.Tests" ) ]
20
20
public class BlazorServerTemplateTest : BlazorTemplateTest
21
21
{
22
- public BlazorServerTemplateTest ( ProjectFactoryFixture projectFactory )
23
- : base ( projectFactory )
22
+ public BlazorServerTemplateTest ( ProjectFactoryFixture projectFactory , PlaywrightFixture < BlazorServerTemplateTest > fixture , ITestOutputHelper output )
23
+ : base ( fixture )
24
24
{
25
+ ProjectFactory = projectFactory ; ;
26
+ Output = output ;
27
+ BrowserContextInfo = new ContextInformation ( CreateFactory ( output ) ) ;
25
28
}
26
29
27
- public override string ProjectType { get ; } = "blazorserver" ;
30
+ public ProjectFactoryFixture ProjectFactory { get ; set ; }
31
+ public ITestOutputHelper Output { get ; }
32
+ public ContextInformation BrowserContextInfo { get ; }
33
+ public Project Project { get ; private set ; }
28
34
29
- // This test is required to run before BlazorServerTemplateWorks_NoAuth to create and build the project
30
- // If this test is quarantined, BlazorServerTemplateWorks_NoAuth must be quarantined as well
31
- [ Fact , TestPriority ( BUILDCREATEPUBLISH_PRIORITY ) ]
32
- public Task BlazorServerTemplate_CreateBuildPublish_NoAuth ( )
33
- => CreateBuildPublishAsync ( "blazorservernoauth" + BrowserKind . Chromium . ToString ( ) ) ;
34
35
35
- // This tests depends on BlazorServerTemplate_CreateBuildPublish_NoAuth running first
36
36
[ Theory ]
37
37
[ InlineData ( BrowserKind . Chromium ) ]
38
38
[ QuarantinedTest ( "https://github.com/dotnet/aspnetcore/issues/30761" ) ]
39
39
public async Task BlazorServerTemplateWorks_NoAuth ( BrowserKind browserKind )
40
40
{
41
- var project = await ProjectFactory . GetOrCreateProject ( "blazorservernoauth" + browserKind , Output ) ;
41
+ // Additional arguments are needed. See: https://github.com/dotnet/aspnetcore/issues/24278
42
+ Environment . SetEnvironmentVariable ( "EnableDefaultScopedCssItems" , "true" ) ;
42
43
43
- await using var browser = BrowserManager . IsAvailable ( browserKind ) ?
44
- await BrowserManager . GetBrowserInstance ( browserKind , BrowserContextInfo ) :
44
+ Project = await ProjectFactory . GetOrCreateProject ( "blazorservernoauth" + browserKind . ToString ( ) , Output ) ;
45
+
46
+ var createResult = await Project . RunDotNetNewAsync ( "blazorserver" ) ;
47
+ Assert . True ( 0 == createResult . ExitCode , ErrorMessages . GetFailedProcessMessage ( "create/restore" , Project , createResult ) ) ;
48
+
49
+ var publishResult = await Project . RunDotNetPublishAsync ( ) ;
50
+ Assert . True ( 0 == publishResult . ExitCode , ErrorMessages . GetFailedProcessMessage ( "publish" , Project , publishResult ) ) ;
51
+
52
+ // Run dotnet build after publish. The reason is that one uses Config = Debug and the other uses Config = Release
53
+ // The output from publish will go into bin/Release/netcoreappX.Y/publish and won't be affected by calling build
54
+ // later, while the opposite is not true.
55
+
56
+ var buildResult = await Project . RunDotNetBuildAsync ( ) ;
57
+ Assert . True ( 0 == buildResult . ExitCode , ErrorMessages . GetFailedProcessMessage ( "build" , Project , buildResult ) ) ;
58
+
59
+ await using var browser = Fixture . BrowserManager . IsAvailable ( browserKind ) ?
60
+ await Fixture . BrowserManager . GetBrowserInstance ( browserKind , BrowserContextInfo ) :
45
61
null ;
46
62
47
- using ( var aspNetProcess = project . StartBuiltProjectAsync ( ) )
63
+ using ( var aspNetProcess = Project . StartBuiltProjectAsync ( ) )
48
64
{
49
65
Assert . False (
50
66
aspNetProcess . Process . HasExited ,
51
- ErrorMessages . GetFailedProcessMessageOrEmpty ( "Run built project" , project , aspNetProcess . Process ) ) ;
67
+ ErrorMessages . GetFailedProcessMessageOrEmpty ( "Run built project" , Project , aspNetProcess . Process ) ) ;
52
68
53
69
await aspNetProcess . AssertStatusCode ( "/" , HttpStatusCode . OK , "text/html" ) ;
54
70
55
- if ( BrowserManager . IsAvailable ( browserKind ) )
71
+ if ( Fixture . BrowserManager . IsAvailable ( browserKind ) )
56
72
{
57
73
var page = await browser . NewPageAsync ( ) ;
58
74
await aspNetProcess . VisitInBrowserAsync ( page ) ;
59
- await TestBasicNavigation ( project , page ) ;
75
+ await TestBasicNavigation ( page ) ;
60
76
await page . CloseAsync ( ) ;
61
77
}
62
78
else
@@ -65,18 +81,18 @@ await BrowserManager.GetBrowserInstance(browserKind, BrowserContextInfo) :
65
81
}
66
82
}
67
83
68
- using ( var aspNetProcess = project . StartPublishedProjectAsync ( ) )
84
+ using ( var aspNetProcess = Project . StartPublishedProjectAsync ( ) )
69
85
{
70
86
Assert . False (
71
87
aspNetProcess . Process . HasExited ,
72
- ErrorMessages . GetFailedProcessMessageOrEmpty ( "Run published project" , project , aspNetProcess . Process ) ) ;
88
+ ErrorMessages . GetFailedProcessMessageOrEmpty ( "Run published project" , Project , aspNetProcess . Process ) ) ;
73
89
74
90
await aspNetProcess . AssertStatusCode ( "/" , HttpStatusCode . OK , "text/html" ) ;
75
- if ( BrowserManager . IsAvailable ( browserKind ) )
91
+ if ( Fixture . BrowserManager . IsAvailable ( browserKind ) )
76
92
{
77
93
var page = await browser . NewPageAsync ( ) ;
78
94
await aspNetProcess . VisitInBrowserAsync ( page ) ;
79
- await TestBasicNavigation ( project , page ) ;
95
+ await TestBasicNavigation ( page ) ;
80
96
await page . CloseAsync ( ) ;
81
97
}
82
98
else
@@ -86,41 +102,49 @@ await BrowserManager.GetBrowserInstance(browserKind, BrowserContextInfo) :
86
102
}
87
103
}
88
104
89
- // This test is required to run before BlazorServerTemplateWorks_IndividualAuth to create and build the project
90
- // If this test is quarantined, BlazorServerTemplateWorks_IndividualAuth must be quarantined as well
91
- [ Theory , TestPriority ( BUILDCREATEPUBLISH_PRIORITY ) ]
92
- [ MemberData ( nameof ( BlazorServerTemplateWorks_IndividualAuthData ) ) ]
93
- public Task BlazorServerTemplate_CreateBuildPublish_IndividualAuth ( BrowserKind browserKind , bool useLocalDB )
94
- => CreateBuildPublishAsync ( "blazorserverindividual" + browserKind + ( useLocalDB ? "uld" : "" ) ) ;
95
-
96
105
public static IEnumerable < object [ ] > BlazorServerTemplateWorks_IndividualAuthData =>
97
106
BrowserManager . WithBrowsers ( new [ ] { BrowserKind . Chromium } , true , false ) ;
98
107
99
- // This tests depends on BlazorServerTemplate_CreateBuildPublish_IndividualAuth running first
100
108
[ Theory ]
101
109
[ MemberData ( nameof ( BlazorServerTemplateWorks_IndividualAuthData ) ) ]
102
110
[ QuarantinedTest ( "https://github.com/dotnet/aspnetcore/issues/30807" ) ]
103
111
[ SkipOnHelix ( "https://github.com/dotnet/aspnetcore/issues/30825" , Queues = "All.OSX" ) ]
104
112
public async Task BlazorServerTemplateWorks_IndividualAuth ( BrowserKind browserKind , bool useLocalDB )
105
113
{
106
- var project = await ProjectFactory . GetOrCreateProject ( "blazorserverindividual" + browserKind + ( useLocalDB ? "uld" : "" ) , Output ) ;
114
+ // Additional arguments are needed. See: https://github.com/dotnet/aspnetcore/issues/24278
115
+ Environment . SetEnvironmentVariable ( "EnableDefaultScopedCssItems" , "true" ) ;
116
+
117
+ Project = await ProjectFactory . GetOrCreateProject ( "blazorserverindividual" + browserKind + ( useLocalDB ? "uld" : "" ) , Output ) ;
118
+
119
+ var createResult = await Project . RunDotNetNewAsync ( "blazorserver" , auth : "Individual" , useLocalDB : useLocalDB ) ;
120
+ Assert . True ( 0 == createResult . ExitCode , ErrorMessages . GetFailedProcessMessage ( "create/restore" , Project , createResult ) ) ;
107
121
108
- var browser = ! BrowserManager . IsAvailable ( browserKind ) ?
122
+ var publishResult = await Project . RunDotNetPublishAsync ( ) ;
123
+ Assert . True ( 0 == publishResult . ExitCode , ErrorMessages . GetFailedProcessMessage ( "publish" , Project , publishResult ) ) ;
124
+
125
+ // Run dotnet build after publish. The reason is that one uses Config = Debug and the other uses Config = Release
126
+ // The output from publish will go into bin/Release/netcoreappX.Y/publish and won't be affected by calling build
127
+ // later, while the opposite is not true.
128
+
129
+ var buildResult = await Project . RunDotNetBuildAsync ( ) ;
130
+ Assert . True ( 0 == buildResult . ExitCode , ErrorMessages . GetFailedProcessMessage ( "build" , Project , buildResult ) ) ;
131
+
132
+ var browser = ! Fixture . BrowserManager . IsAvailable ( browserKind ) ?
109
133
null :
110
- await BrowserManager . GetBrowserInstance ( browserKind , BrowserContextInfo ) ;
134
+ await Fixture . BrowserManager . GetBrowserInstance ( browserKind , BrowserContextInfo ) ;
111
135
112
- using ( var aspNetProcess = project . StartBuiltProjectAsync ( ) )
136
+ using ( var aspNetProcess = Project . StartBuiltProjectAsync ( ) )
113
137
{
114
138
Assert . False (
115
139
aspNetProcess . Process . HasExited ,
116
- ErrorMessages . GetFailedProcessMessageOrEmpty ( "Run built project" , project , aspNetProcess . Process ) ) ;
140
+ ErrorMessages . GetFailedProcessMessageOrEmpty ( "Run built project" , Project , aspNetProcess . Process ) ) ;
117
141
118
142
await aspNetProcess . AssertStatusCode ( "/" , HttpStatusCode . OK , "text/html" ) ;
119
- if ( BrowserManager . IsAvailable ( browserKind ) )
143
+ if ( Fixture . BrowserManager . IsAvailable ( browserKind ) )
120
144
{
121
145
var page = await browser . NewPageAsync ( ) ;
122
146
await aspNetProcess . VisitInBrowserAsync ( page ) ;
123
- await TestBasicNavigation ( project , page ) ;
147
+ await TestBasicNavigation ( page ) ;
124
148
await page . CloseAsync ( ) ;
125
149
}
126
150
else
@@ -129,18 +153,18 @@ public async Task BlazorServerTemplateWorks_IndividualAuth(BrowserKind browserKi
129
153
}
130
154
}
131
155
132
- using ( var aspNetProcess = project . StartPublishedProjectAsync ( ) )
156
+ using ( var aspNetProcess = Project . StartPublishedProjectAsync ( ) )
133
157
{
134
158
Assert . False (
135
159
aspNetProcess . Process . HasExited ,
136
- ErrorMessages . GetFailedProcessMessageOrEmpty ( "Run published project" , project , aspNetProcess . Process ) ) ;
160
+ ErrorMessages . GetFailedProcessMessageOrEmpty ( "Run published project" , Project , aspNetProcess . Process ) ) ;
137
161
138
162
await aspNetProcess . AssertStatusCode ( "/" , HttpStatusCode . OK , "text/html" ) ;
139
- if ( BrowserManager . IsAvailable ( browserKind ) )
163
+ if ( Fixture . BrowserManager . IsAvailable ( browserKind ) )
140
164
{
141
165
var page = await browser . NewPageAsync ( ) ;
142
166
await aspNetProcess . VisitInBrowserAsync ( page ) ;
143
- await TestBasicNavigation ( project , page ) ;
167
+ await TestBasicNavigation ( page ) ;
144
168
await page . CloseAsync ( ) ;
145
169
}
146
170
else
@@ -150,7 +174,7 @@ public async Task BlazorServerTemplateWorks_IndividualAuth(BrowserKind browserKi
150
174
}
151
175
}
152
176
153
- private async Task TestBasicNavigation ( Project project , IPage page )
177
+ private async Task TestBasicNavigation ( IPage page )
154
178
{
155
179
var socket = BrowserContextInfo . Pages [ page ] . WebSockets . SingleOrDefault ( ) ??
156
180
( await page . WaitForEventAsync ( PageEvent . WebSocket ) ) . WebSocket ;
@@ -165,7 +189,7 @@ private async Task TestBasicNavigation(Project project, IPage page)
165
189
166
190
await page . WaitForSelectorAsync ( "ul" ) ;
167
191
// <title> element gets project ID injected into it during template execution
168
- Assert . Equal ( project . ProjectName . Trim ( ) , ( await page . GetTitleAsync ( ) ) . Trim ( ) ) ;
192
+ Assert . Equal ( Project . ProjectName . Trim ( ) , ( await page . GetTitleAsync ( ) ) . Trim ( ) ) ;
169
193
170
194
// Initially displays the home page
171
195
await page . WaitForSelectorAsync ( "h1 >> text=Hello, world!" ) ;
@@ -187,15 +211,29 @@ private async Task TestBasicNavigation(Project project, IPage page)
187
211
Assert . Equal ( 5 , ( await page . QuerySelectorAllAsync ( "p+table>tbody>tr" ) ) . Count ( ) ) ;
188
212
}
189
213
190
- [ Theory , TestPriority ( BUILDCREATEPUBLISH_PRIORITY ) ]
214
+ [ Theory ]
191
215
[ InlineData ( "IndividualB2C" , null ) ]
192
216
[ InlineData ( "IndividualB2C" , new string [ ] { "--called-api-url \" https://graph.microsoft.com\" " , "--called-api-scopes user.readwrite" } ) ]
193
217
[ InlineData ( "SingleOrg" , null ) ]
194
218
[ InlineData ( "SingleOrg" , new string [ ] { "--called-api-url \" https://graph.microsoft.com\" " , "--called-api-scopes user.readwrite" } ) ]
195
219
[ InlineData ( "SingleOrg" , new string [ ] { "--calls-graph" } ) ]
196
220
[ QuarantinedTest ( "https://github.com/dotnet/aspnetcore/issues/30882" ) ]
197
- public Task BlazorServerTemplate_IdentityWeb_BuildAndPublish ( string auth , string [ ] args )
198
- => CreateBuildPublishAsync ( "blazorserveridweb" + Guid . NewGuid ( ) . ToString ( ) . Substring ( 0 , 10 ) . ToLowerInvariant ( ) , auth , args ) ;
221
+ public async Task BlazorServerTemplat_IdentityWeb_BuildAndPublish ( string auth , string [ ] args )
222
+ {
223
+ Project = await ProjectFactory . GetOrCreateProject ( "blazorserveridweb" + Guid . NewGuid ( ) . ToString ( ) . Substring ( 0 , 10 ) . ToLowerInvariant ( ) , Output ) ;
199
224
225
+ var createResult = await Project . RunDotNetNewAsync ( "blazorserver" , auth : auth , args : args ) ;
226
+ Assert . True ( 0 == createResult . ExitCode , ErrorMessages . GetFailedProcessMessage ( "create/restore" , Project , createResult ) ) ;
227
+
228
+ var publishResult = await Project . RunDotNetPublishAsync ( ) ;
229
+ Assert . True ( 0 == publishResult . ExitCode , ErrorMessages . GetFailedProcessMessage ( "publish" , Project , publishResult ) ) ;
230
+
231
+ // Run dotnet build after publish. The reason is that one uses Config = Debug and the other uses Config = Release
232
+ // The output from publish will go into bin/Release/netcoreappX.Y/publish and won't be affected by calling build
233
+ // later, while the opposite is not true.
234
+
235
+ var buildResult = await Project . RunDotNetBuildAsync ( ) ;
236
+ Assert . True ( 0 == buildResult . ExitCode , ErrorMessages . GetFailedProcessMessage ( "build" , Project , buildResult ) ) ;
237
+ }
200
238
}
201
239
}
0 commit comments