Skip to content

Commit 0a25c28

Browse files
authored
[Mvc] Undo MVC breaking change (#10962)
* Undo MVC breaking change
1 parent ba8c6cc commit 0a25c28

File tree

6 files changed

+13
-31
lines changed

6 files changed

+13
-31
lines changed

src/Identity/test/Identity.FunctionalTests/Infrastructure/ServerFactory.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// 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

44
using System;
5+
using Microsoft.AspNetCore.Authentication;
56
using Microsoft.AspNetCore.Hosting;
67
using Microsoft.AspNetCore.Mvc.Testing;
8+
using Microsoft.AspNetCore.TestHost;
79
using Microsoft.Data.Sqlite;
810
using Microsoft.EntityFrameworkCore;
911
using Microsoft.Extensions.DependencyInjection;
@@ -40,9 +42,16 @@ protected override void ConfigureWebHost(IWebHostBuilder builder)
4042
});
4143
}
4244

43-
public override void EnsureDatabaseCreated()
45+
protected override TestServer CreateServer(IWebHostBuilder builder)
4446
{
45-
using (var scope = Services.CreateScope())
47+
var result = base.CreateServer(builder);
48+
EnsureDatabaseCreated(result);
49+
return result;
50+
}
51+
52+
public void EnsureDatabaseCreated(TestServer server)
53+
{
54+
using (var scope = server.Host.Services.CreateScope())
4655
{
4756
scope.ServiceProvider.GetService<TContext>().Database.EnsureCreated();
4857
}

src/Identity/test/Identity.FunctionalTests/LoginTests.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// 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

44
using System;
@@ -289,8 +289,6 @@ void ConfigureTestServices(IServiceCollection services) => services
289289

290290
var server = ServerFactory.WithWebHostBuilder(whb => whb.ConfigureServices(ConfigureTestServices));
291291

292-
ServerFactory.EnsureDatabaseCreated();
293-
294292
var client = server.CreateClient();
295293
var newClient = server.CreateClient();
296294

@@ -313,8 +311,6 @@ void ConfigureTestServices(IServiceCollection services) => services
313311

314312
var server = ServerFactory.WithWebHostBuilder(whb => whb.ConfigureServices(ConfigureTestServices));
315313

316-
ServerFactory.EnsureDatabaseCreated();
317-
318314
var client = server.CreateClient();
319315
var resetPasswordClient = server.CreateClient();
320316
var newClient = server.CreateClient();

src/Identity/test/Identity.FunctionalTests/ManagementTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,6 @@ void ConfigureTestServices(IServiceCollection services) =>
289289
.WithWebHostBuilder(whb => whb.ConfigureTestServices(ConfigureTestServices))
290290
.CreateClient();
291291

292-
ServerFactory.EnsureDatabaseCreated();
293-
294292
var userName = $"{Guid.NewGuid()}@example.com";
295293
var guid = Guid.NewGuid();
296294
var email = userName;

src/Identity/test/Identity.FunctionalTests/RegistrationTests.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ public async Task CanRegisterAUser()
3131
.WithWebHostBuilder(whb => whb.ConfigureServices(ConfigureTestServices))
3232
.CreateClient();
3333

34-
ServerFactory.EnsureDatabaseCreated();
35-
3634
var userName = $"{Guid.NewGuid()}@example.com";
3735
var password = $"!Test.Password1$";
3836

@@ -51,8 +49,6 @@ public async Task CanRegisterAUserWithRequiredConfirmation()
5149
var client = server.CreateClient();
5250
var client2 = server.CreateClient();
5351

54-
ServerFactory.EnsureDatabaseCreated();
55-
5652
var userName = $"{Guid.NewGuid()}@example.com";
5753
var password = $"!Test.Password1$";
5854

@@ -85,8 +81,6 @@ void ConfigureTestServices(IServiceCollection services) {
8581
var client = server.CreateClient();
8682
var client2 = server.CreateClient();
8783

88-
ServerFactory.EnsureDatabaseCreated();
89-
9084
var userName = $"{Guid.NewGuid()}@example.com";
9185
var password = $"!Test.Password1$";
9286

@@ -108,8 +102,6 @@ void ConfigureTestServices(IServiceCollection services) =>
108102
.WithWebHostBuilder(whb => whb.ConfigureServices(ConfigureTestServices))
109103
.CreateClient();
110104

111-
ServerFactory.EnsureDatabaseCreated();
112-
113105
var userName = $"{Guid.NewGuid()}@example.com";
114106
var password = $"!Test.Password1$";
115107

@@ -129,8 +121,6 @@ void ConfigureTestServices(IServiceCollection services) =>
129121
.WithWebHostBuilder(whb => whb.ConfigureServices(ConfigureTestServices))
130122
.CreateClient();
131123

132-
ServerFactory.EnsureDatabaseCreated();
133-
134124
var guid = Guid.NewGuid();
135125
var userName = $"{guid}";
136126
var email = $"{guid}@example.com";
@@ -151,8 +141,6 @@ void ConfigureTestServices(IServiceCollection services) =>
151141
.WithWebHostBuilder(whb => whb.ConfigureServices(ConfigureTestServices))
152142
.CreateClient();
153143

154-
ServerFactory.EnsureDatabaseCreated();
155-
156144
var guid = Guid.NewGuid();
157145
var userName = $"{guid}";
158146
var email = $"{guid}@example.com";
@@ -174,8 +162,6 @@ void ConfigureTestServices(IServiceCollection services) =>
174162
.WithWebHostBuilder(whb => whb.ConfigureServices(ConfigureTestServices))
175163
.CreateClient();
176164

177-
ServerFactory.EnsureDatabaseCreated();
178-
179165
var guid = Guid.NewGuid();
180166
var userName = $"{guid}";
181167
var email = $"{guid}@example.com";

src/Mvc/Mvc.Testing/ref/Microsoft.AspNetCore.Mvc.Testing.netcoreapp3.0.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ protected virtual void ConfigureWebHost(Microsoft.AspNetCore.Hosting.IWebHostBui
3939
protected virtual Microsoft.AspNetCore.Hosting.IWebHostBuilder CreateWebHostBuilder() { throw null; }
4040
public void Dispose() { }
4141
protected virtual void Dispose(bool disposing) { }
42-
public virtual void EnsureDatabaseCreated() { }
4342
~WebApplicationFactory() { }
4443
protected virtual System.Collections.Generic.IEnumerable<System.Reflection.Assembly> GetTestAssemblies() { throw null; }
4544
public Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory<TEntryPoint> WithWebHostBuilder(System.Action<Microsoft.AspNetCore.Hosting.IWebHostBuilder> configuration) { throw null; }

src/Mvc/Mvc.Testing/src/WebApplicationFactory.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,6 @@ private void EnsureServer()
162162
SetContentRoot(builder);
163163
_configuration(builder);
164164
_server = CreateServer(builder);
165-
166-
EnsureDatabaseCreated();
167-
}
168-
169-
public virtual void EnsureDatabaseCreated()
170-
{
171165
}
172166

173167
private void SetContentRoot(IWebHostBuilder builder)

0 commit comments

Comments
 (0)