[Mvc] Undo MVC breaking change (#10962)

* Undo MVC breaking change
This commit is contained in:
Javier Calvarro Nelson 2019-06-06 15:57:10 -07:00 committed by GitHub
parent ba8c6ccf6f
commit 0a25c28173
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 13 additions and 31 deletions

View File

@ -1,9 +1,11 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.AspNetCore.TestHost;
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
@ -40,9 +42,16 @@ namespace Microsoft.AspNetCore.Identity.FunctionalTests
});
}
public override void EnsureDatabaseCreated()
protected override TestServer CreateServer(IWebHostBuilder builder)
{
using (var scope = Services.CreateScope())
var result = base.CreateServer(builder);
EnsureDatabaseCreated(result);
return result;
}
public void EnsureDatabaseCreated(TestServer server)
{
using (var scope = server.Host.Services.CreateScope())
{
scope.ServiceProvider.GetService<TContext>().Database.EnsureCreated();
}

View File

@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
@ -289,8 +289,6 @@ namespace Microsoft.AspNetCore.Identity.FunctionalTests
var server = ServerFactory.WithWebHostBuilder(whb => whb.ConfigureServices(ConfigureTestServices));
ServerFactory.EnsureDatabaseCreated();
var client = server.CreateClient();
var newClient = server.CreateClient();
@ -313,8 +311,6 @@ namespace Microsoft.AspNetCore.Identity.FunctionalTests
var server = ServerFactory.WithWebHostBuilder(whb => whb.ConfigureServices(ConfigureTestServices));
ServerFactory.EnsureDatabaseCreated();
var client = server.CreateClient();
var resetPasswordClient = server.CreateClient();
var newClient = server.CreateClient();

View File

@ -289,8 +289,6 @@ namespace Microsoft.AspNetCore.Identity.FunctionalTests
.WithWebHostBuilder(whb => whb.ConfigureTestServices(ConfigureTestServices))
.CreateClient();
ServerFactory.EnsureDatabaseCreated();
var userName = $"{Guid.NewGuid()}@example.com";
var guid = Guid.NewGuid();
var email = userName;

View File

@ -31,8 +31,6 @@ namespace Microsoft.AspNetCore.Identity.FunctionalTests
.WithWebHostBuilder(whb => whb.ConfigureServices(ConfigureTestServices))
.CreateClient();
ServerFactory.EnsureDatabaseCreated();
var userName = $"{Guid.NewGuid()}@example.com";
var password = $"!Test.Password1$";
@ -51,8 +49,6 @@ namespace Microsoft.AspNetCore.Identity.FunctionalTests
var client = server.CreateClient();
var client2 = server.CreateClient();
ServerFactory.EnsureDatabaseCreated();
var userName = $"{Guid.NewGuid()}@example.com";
var password = $"!Test.Password1$";
@ -85,8 +81,6 @@ namespace Microsoft.AspNetCore.Identity.FunctionalTests
var client = server.CreateClient();
var client2 = server.CreateClient();
ServerFactory.EnsureDatabaseCreated();
var userName = $"{Guid.NewGuid()}@example.com";
var password = $"!Test.Password1$";
@ -108,8 +102,6 @@ namespace Microsoft.AspNetCore.Identity.FunctionalTests
.WithWebHostBuilder(whb => whb.ConfigureServices(ConfigureTestServices))
.CreateClient();
ServerFactory.EnsureDatabaseCreated();
var userName = $"{Guid.NewGuid()}@example.com";
var password = $"!Test.Password1$";
@ -129,8 +121,6 @@ namespace Microsoft.AspNetCore.Identity.FunctionalTests
.WithWebHostBuilder(whb => whb.ConfigureServices(ConfigureTestServices))
.CreateClient();
ServerFactory.EnsureDatabaseCreated();
var guid = Guid.NewGuid();
var userName = $"{guid}";
var email = $"{guid}@example.com";
@ -151,8 +141,6 @@ namespace Microsoft.AspNetCore.Identity.FunctionalTests
.WithWebHostBuilder(whb => whb.ConfigureServices(ConfigureTestServices))
.CreateClient();
ServerFactory.EnsureDatabaseCreated();
var guid = Guid.NewGuid();
var userName = $"{guid}";
var email = $"{guid}@example.com";
@ -174,8 +162,6 @@ namespace Microsoft.AspNetCore.Identity.FunctionalTests
.WithWebHostBuilder(whb => whb.ConfigureServices(ConfigureTestServices))
.CreateClient();
ServerFactory.EnsureDatabaseCreated();
var guid = Guid.NewGuid();
var userName = $"{guid}";
var email = $"{guid}@example.com";

View File

@ -39,7 +39,6 @@ namespace Microsoft.AspNetCore.Mvc.Testing
protected virtual Microsoft.AspNetCore.Hosting.IWebHostBuilder CreateWebHostBuilder() { throw null; }
public void Dispose() { }
protected virtual void Dispose(bool disposing) { }
public virtual void EnsureDatabaseCreated() { }
~WebApplicationFactory() { }
protected virtual System.Collections.Generic.IEnumerable<System.Reflection.Assembly> GetTestAssemblies() { throw null; }
public Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory<TEntryPoint> WithWebHostBuilder(System.Action<Microsoft.AspNetCore.Hosting.IWebHostBuilder> configuration) { throw null; }

View File

@ -162,12 +162,6 @@ namespace Microsoft.AspNetCore.Mvc.Testing
SetContentRoot(builder);
_configuration(builder);
_server = CreateServer(builder);
EnsureDatabaseCreated();
}
public virtual void EnsureDatabaseCreated()
{
}
private void SetContentRoot(IWebHostBuilder builder)