Skip to content

Commit 20de88f

Browse files
committed
Updated pivot zone snippets syntax; formatted snippets correctly
1 parent 64ec2dd commit 20de88f

File tree

9 files changed

+210
-127
lines changed

9 files changed

+210
-127
lines changed

aspnetcore/test/integration-tests.md

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,17 @@ The following test class, `BasicTests`, uses the `WebApplicationFactory` to boot
6666

6767
:::zone pivot="xunit"
6868

69-
:::code language="csharp" source="integration-tests/snippets/xunit/IntegrationTests/BasicTests.cs?name=snippet1":::
69+
:::code language="csharp" source="integration-tests/snippets/xunit/IntegrationTests/BasicTests.cs" id="snippet1":::
7070

7171
:::zone-end
7272
:::zone pivot="mstest"
7373

74-
:::code language="csharp" source="integration-tests/snippets/mstest/IntegrationTests/BasicTests.cs?name=snippet1":::
74+
:::code language="csharp" source="integration-tests/snippets/mstest/IntegrationTests/BasicTests.cs" id="snippet1":::
7575

7676
:::zone-end
7777
:::zone pivot="nunit"
7878

79-
:::code language="csharp" source="integration-tests/snippets/nunit/IntegrationTests/BasicTests.cs?name=snippet1":::
79+
:::code language="csharp" source="integration-tests/snippets/nunit/IntegrationTests/BasicTests.cs" id="snippet1":::
8080

8181
:::zone-end
8282

@@ -96,17 +96,17 @@ Web host configuration can be created independently of the test classes by inher
9696

9797
:::zone pivot="xunit"
9898

99-
:::code language="csharp" source="integration-tests/snippets/xunit/CustomWebApplicationFactory.cs?name=snippet1":::
99+
:::code language="csharp" source="integration-tests/snippets/xunit/CustomWebApplicationFactory.cs" id="snippet1":::
100100

101101
:::zone-end
102102
:::zone pivot="mstest"
103103

104-
:::code language="csharp" source="integration-tests/snippets/mstest/CustomWebApplicationFactory.cs?name=snippet1":::
104+
:::code language="csharp" source="integration-tests/snippets/mstest/CustomWebApplicationFactory.cs" id="snippet1":::
105105

106106
:::zone-end
107107
:::zone pivot="nunit"
108108

109-
:::code language="csharp" source="integration-tests/snippets/nunit/CustomWebApplicationFactory.cs?name=snippet1":::
109+
:::code language="csharp" source="integration-tests/snippets/nunit/CustomWebApplicationFactory.cs" id="snippet1":::
110110

111111
:::zone-end
112112

@@ -127,17 +127,17 @@ Web host configuration can be created independently of the test classes by inher
127127

128128
:::zone pivot="xunit"
129129

130-
:::code language="csharp" source="integration-tests/snippets/xunit/IntegrationTests/IndexPageTests.cs?name=snippet1":::
130+
:::code language="csharp" source="integration-tests/snippets/xunit/IntegrationTests/IndexPageTests.cs" id="snippet1":::
131131

132132
:::zone-end
133133
:::zone pivot="mstest"
134134

135-
:::code language="csharp" source="integration-tests/snippets/mstest/IntegrationTests/IndexPageTests.cs?name=snippet1":::
135+
:::code language="csharp" source="integration-tests/snippets/mstest/IntegrationTests/IndexPageTests.cs" id="snippet1":::
136136

137137
:::zone-end
138138
:::zone pivot="nunit"
139139

140-
:::code language="csharp" source="integration-tests/snippets/nunit/IntegrationTests/IndexPageTests.cs?name=snippet1":::
140+
:::code language="csharp" source="integration-tests/snippets/nunit/IntegrationTests/IndexPageTests.cs" id="snippet1":::
141141

142142
:::zone-end
143143

@@ -147,17 +147,17 @@ Web host configuration can be created independently of the test classes by inher
147147

148148
:::zone pivot="xunit"
149149

150-
:::code language="csharp" source="integration-tests/snippets/xunit/IntegrationTests/IndexPageTests.cs?name=snippet2":::
150+
:::code language="csharp" source="integration-tests/snippets/xunit/IntegrationTests/IndexPageTests.cs" id="snippet2":::
151151

152152
:::zone-end
153153
:::zone pivot="mstest"
154154

155-
:::code language="csharp" source="integration-tests/snippets/mstest/IntegrationTests/IndexPageTests.cs?name=snippet2":::
155+
:::code language="csharp" source="integration-tests/snippets/mstest/IntegrationTests/IndexPageTests.cs" id="snippet2":::
156156

157157
:::zone-end
158158
:::zone pivot="nunit"
159159

160-
:::code language="csharp" source="integration-tests/snippets/nunit/IntegrationTests/IndexPageTests.cs?name=snippet2":::
160+
:::code language="csharp" source="integration-tests/snippets/nunit/IntegrationTests/IndexPageTests.cs" id="snippet2":::
161161

162162
:::zone-end
163163

@@ -194,17 +194,17 @@ Because another test in the `IndexPageTests` class performs an operation that de
194194

195195
:::zone pivot="xunit"
196196

197-
:::code language="csharp" source="integration-tests/snippets/xunit/IntegrationTests/IndexPageTests.cs?name=snippet3":::
197+
:::code language="csharp" source="integration-tests/snippets/xunit/IntegrationTests/IndexPageTests.cs" id="snippet3":::
198198

199199
:::zone-end
200200
:::zone pivot="mstest"
201201

202-
:::code language="csharp" source="integration-tests/snippets/mstest/IntegrationTests/IndexPageTests.cs?name=snippet3":::
202+
:::code language="csharp" source="integration-tests/snippets/mstest/IntegrationTests/IndexPageTests.cs" id="snippet3":::
203203

204204
:::zone-end
205205
:::zone pivot="nunit"
206206

207-
:::code language="csharp" source="integration-tests/snippets/nunit/IntegrationTests/IndexPageTests.cs?name=snippet3":::
207+
:::code language="csharp" source="integration-tests/snippets/nunit/IntegrationTests/IndexPageTests.cs" id="snippet3":::
208208

209209
:::zone-end
210210

@@ -216,21 +216,21 @@ Create the `WebApplicationFactoryClientOptions` class and pass it to the <xref:M
216216

217217
:::zone pivot="xunit"
218218

219-
:::code language="csharp" source="integration-tests/snippets/xunit/IntegrationTests/IndexPageTests.cs?name=snippet1":::
219+
:::code language="csharp" source="integration-tests/snippets/xunit/IntegrationTests/IndexPageTests.cs" id="snippet1":::
220220

221221
:::zone-end
222222
:::zone pivot="mstest"
223223

224-
:::code language="csharp" source="integration-tests/snippets/mstest/IntegrationTests/IndexPageTests.cs?name=snippet1":::
224+
:::code language="csharp" source="integration-tests/snippets/mstest/IntegrationTests/IndexPageTests.cs" id="snippet1":::
225225

226226
:::zone-end
227227
:::zone pivot="nunit"
228228

229-
:::code language="csharp" source="integration-tests/snippets/nunit/IntegrationTests/IndexPageTests.cs?name=snippet1":::
229+
:::code language="csharp" source="integration-tests/snippets/nunit/IntegrationTests/IndexPageTests.cs" id="snippet1":::
230230

231231
:::zone-end
232232

233-
***NOTE:*** To avoid HTTPS redirection warnings in logs when using HTTPS Redirection Middleware, set `BaseAddress = new Uri("https://localhost")`
233+
**_NOTE:_** To avoid HTTPS redirection warnings in logs when using HTTPS Redirection Middleware, set `BaseAddress = new Uri("https://localhost")`
234234

235235
## Inject mock services
236236

@@ -275,35 +275,35 @@ To test the service and quote injection in an integration test, a mock service i
275275

276276
:::zone pivot="xunit"
277277

278-
:::code language="csharp" source="integration-tests/snippets/xunit/IntegrationTests/IndexPageTests.cs?name=snippet4":::
278+
:::code language="csharp" source="integration-tests/snippets/xunit/IntegrationTests/IndexPageTests.cs" id="snippet4":::
279279

280280
:::zone-end
281281
:::zone pivot="mstest"
282282

283-
:::code language="csharp" source="integration-tests/snippets/mstest/IntegrationTests/IndexPageTests.cs?name=snippet4":::
283+
:::code language="csharp" source="integration-tests/snippets/mstest/IntegrationTests/IndexPageTests.cs" id="snippet4":::
284284

285285
:::zone-end
286286
:::zone pivot="nunit"
287287

288-
:::code language="csharp" source="integration-tests/snippets/nunit/IntegrationTests/IndexPageTests.cs?name=snippet4":::
288+
:::code language="csharp" source="integration-tests/snippets/nunit/IntegrationTests/IndexPageTests.cs" id="snippet4":::
289289

290290
:::zone-end
291291

292292
`ConfigureTestServices` is called, and the scoped service is registered:
293293

294294
:::zone pivot="xunit"
295295

296-
:::code language="csharp" source="integration-tests/snippets/xunit/IntegrationTests/IndexPageTests.cs?name=snippet5&highlight=7-10,17,20-21":::
296+
:::code language="csharp" source="integration-tests/snippets/xunit/IntegrationTests/IndexPageTests.cs" id="snippet5" highlight="7-10,17,20-21":::
297297

298298
:::zone-end
299299
:::zone pivot="mstest"
300300

301-
:::code language="csharp" source="integration-tests/snippets/mstest/IntegrationTests/IndexPageTests.cs?name=snippet5&highlight=7-10,17,20-21":::
301+
:::code language="csharp" source="integration-tests/snippets/mstest/IntegrationTests/IndexPageTests.cs" id="snippet5" highlight="7-10,17,20-21":::
302302

303303
:::zone-end
304304
:::zone pivot="nunit"
305305

306-
:::code language="csharp" source="integration-tests/snippets/nunit/IntegrationTests/IndexPageTests.cs?name=snippet5&highlight=7-10,17,20-21":::
306+
:::code language="csharp" source="integration-tests/snippets/nunit/IntegrationTests/IndexPageTests.cs" id="snippet5" highlight="7-10,17,20-21":::
307307

308308
:::zone-end
309309

@@ -329,17 +329,17 @@ In the `Get_SecurePageRedirectsAnUnauthenticatedUser` test, a <xref:Microsoft.As
329329

330330
:::zone pivot="xunit"
331331

332-
:::code language="csharp" source="integration-tests/snippets/xunit/IntegrationTests/AuthTests.cs?name=snippet2":::
332+
:::code language="csharp" source="integration-tests/snippets/xunit/IntegrationTests/AuthTests.cs" id="snippet2":::
333333

334334
:::zone-end
335335
:::zone pivot="mstest"
336336

337-
:::code language="csharp" source="integration-tests/snippets/mstest/IntegrationTests/AuthTests.cs?name=snippet2":::
337+
:::code language="csharp" source="integration-tests/snippets/mstest/IntegrationTests/AuthTests.cs" id="snippet2":::
338338

339339
:::zone-end
340340
:::zone pivot="nunit"
341341

342-
:::code language="csharp" source="integration-tests/snippets/nunit/IntegrationTests/AuthTests.cs?name=snippet2":::
342+
:::code language="csharp" source="integration-tests/snippets/nunit/IntegrationTests/AuthTests.cs" id="snippet2":::
343343

344344
:::zone-end
345345

@@ -352,35 +352,35 @@ The test app can mock an <xref:Microsoft.AspNetCore.Authentication.Authenticatio
352352

353353
:::zone pivot="xunit"
354354

355-
:::code language="csharp" source="integration-tests/snippets/xunit/IntegrationTests/AuthTests.cs?name=snippet4&highlight=11-18":::
355+
:::code language="csharp" source="integration-tests/snippets/xunit/IntegrationTests/AuthTests.cs" id="snippet4" highlight="11-18":::
356356

357357
:::zone-end
358358
:::zone pivot="mstest"
359359

360-
:::code language="csharp" source="integration-tests/snippets/mstest/IntegrationTests/AuthTests.cs?name=snippet4&highlight=11-18":::
360+
:::code language="csharp" source="integration-tests/snippets/mstest/IntegrationTests/AuthTests.cs" id="snippet4" highlight="11-18":::
361361

362362
:::zone-end
363363
:::zone pivot="nunit"
364364

365-
:::code language="csharp" source="integration-tests/snippets/nunit/IntegrationTests/AuthTests.cs?name=snippet4&highlight=11-18":::
365+
:::code language="csharp" source="integration-tests/snippets/nunit/IntegrationTests/AuthTests.cs" id="snippet4" highlight="11-18":::
366366

367367
:::zone-end
368368

369369
The `TestAuthHandler` is called to authenticate a user when the authentication scheme is set to `TestScheme` where `AddAuthentication` is registered for `ConfigureTestServices`. It's important for the `TestScheme` scheme to match the scheme your app expects. Otherwise, authentication won't work.
370370

371371
:::zone pivot="xunit"
372372

373-
:::code language="csharp" source="integration-tests/snippets/xunit/IntegrationTests/AuthTests.cs?name=snippet3&highlight=7-12":::
373+
:::code language="csharp" source="integration-tests/snippets/xunit/IntegrationTests/AuthTests.cs" id="snippet3" highlight="7-12":::
374374

375375
:::zone-end
376376
:::zone pivot="mstest"
377377

378-
:::code language="csharp" source="integration-tests/snippets/mstest/IntegrationTests/AuthTests.cs?name=snippet3&highlight=7-12":::
378+
:::code language="csharp" source="integration-tests/snippets/mstest/IntegrationTests/AuthTests.cs" id="snippet3" highlight="7-12":::
379379

380380
:::zone-end
381381
:::zone pivot="nunit"
382382

383-
:::code language="csharp" source="integration-tests/snippets/nunit/IntegrationTests/AuthTests.cs?name=snippet3&highlight=7-12":::
383+
:::code language="csharp" source="integration-tests/snippets/nunit/IntegrationTests/AuthTests.cs" id="snippet3" highlight="7-12":::
384384

385385
:::zone-end
386386

@@ -396,17 +396,17 @@ Set the [environment](xref:fundamentals/environments) in the custom application
396396

397397
:::zone pivot="xunit"
398398

399-
:::code language="csharp" source="integration-tests/snippets/xunit/CustomWebApplicationFactory.cs?name=snippet1&highlight=36":::
399+
:::code language="csharp" source="integration-tests/snippets/xunit/CustomWebApplicationFactory.cs" id="snippet1" highlight="36":::
400400

401401
:::zone-end
402402
:::zone pivot="mstest"
403403

404-
:::code language="csharp" source="integration-tests/snippets/mstest/CustomWebApplicationFactory.cs?name=snippet1&highlight=36":::
404+
:::code language="csharp" source="integration-tests/snippets/mstest/CustomWebApplicationFactory.cs" id="snippet1" highlight="36":::
405405

406406
:::zone-end
407407
:::zone pivot="nunit"
408408

409-
:::code language="csharp" source="integration-tests/snippets/nunit/CustomWebApplicationFactory.cs?name=snippet1&highlight=36":::
409+
:::code language="csharp" source="integration-tests/snippets/nunit/CustomWebApplicationFactory.cs" id="snippet1" highlight="36":::
410410

411411
:::zone-end
412412

aspnetcore/test/integration-tests/snippets/mstest/CustomWebApplicationFactory.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ namespace RazorPagesProject.Tests;
1111

1212
// <snippet1>
1313
public class CustomWebApplicationFactory<TProgram>
14-
: WebApplicationFactory<TProgram> where TProgram : class {
15-
protected override void ConfigureWebHost(IWebHostBuilder builder) {
16-
builder.ConfigureServices(services => {
14+
: WebApplicationFactory<TProgram> where TProgram : class
15+
{
16+
protected override void ConfigureWebHost(IWebHostBuilder builder)
17+
{
18+
builder.ConfigureServices(services =>
19+
{
1720
var dbContextDescriptor = services.SingleOrDefault(
1821
d => d.ServiceType ==
1922
typeof(IDbContextOptionsConfiguration<ApplicationDbContext>));
@@ -27,14 +30,16 @@ protected override void ConfigureWebHost(IWebHostBuilder builder) {
2730
services.Remove(dbConnectionDescriptor);
2831

2932
// Create open SqliteConnection so EF won't automatically close it.
30-
services.AddSingleton<DbConnection>(container => {
33+
services.AddSingleton<DbConnection>(container =>
34+
{
3135
var connection = new SqliteConnection("DataSource=:memory:");
3236
connection.Open();
3337

3438
return connection;
3539
});
3640

37-
services.AddDbContext<ApplicationDbContext>((container, options) => {
41+
services.AddDbContext<ApplicationDbContext>((container, options) =>
42+
{
3843
var connection = container.GetRequiredService<DbConnection>();
3944
options.UseSqlite(connection);
4045
});

0 commit comments

Comments
 (0)