Fix build break in Identity tests

By configuring the service provider warning to log instead of throw
This commit is contained in:
Arthur Vickers 2019-02-08 13:30:21 -08:00
parent 0b0d5b98dc
commit 64e137ba38
11 changed files with 55 additions and 23 deletions

View File

@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using ApiAuthSample.Data; using ApiAuthSample.Data;
@ -23,7 +24,9 @@ namespace ApiAuthSample
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
{ {
services.AddDbContext<ApplicationDbContext>(options => services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlite(Configuration.GetConnectionString("DefaultConnection"))); options
.ConfigureWarnings(b => b.Log(CoreEventId.ManyServiceProvidersCreatedWarning))
.UseSqlite(Configuration.GetConnectionString("DefaultConnection")));
services.AddDefaultIdentity<ApplicationUser>() services.AddDefaultIdentity<ApplicationUser>()
.AddEntityFrameworkStores<ApplicationDbContext>(); .AddEntityFrameworkStores<ApplicationDbContext>();

View File

@ -10,6 +10,7 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity.Test; using Microsoft.AspNetCore.Identity.Test;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Xunit; using Xunit;
@ -24,7 +25,10 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore.InMemory.Test
{ {
var services = new ServiceCollection(); var services = new ServiceCollection();
services.AddHttpContextAccessor(); services.AddHttpContextAccessor();
services.AddDbContext<InMemoryContextWithGenerics>(options => options.UseInMemoryDatabase("Scratch")); services.AddDbContext<InMemoryContextWithGenerics>(
options => options
.UseInMemoryDatabase("Scratch")
.ConfigureWarnings(b => b.Log(CoreEventId.ManyServiceProvidersCreatedWarning)));
_context = services.BuildServiceProvider().GetRequiredService<InMemoryContextWithGenerics>(); _context = services.BuildServiceProvider().GetRequiredService<InMemoryContextWithGenerics>();
} }
@ -330,4 +334,4 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore.InMemory.Test
} }
#endregion #endregion
} }

View File

@ -5,7 +5,9 @@ using System;
using System.Data.SqlClient; using System.Data.SqlClient;
using System.Linq; using System.Linq;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Xunit; using Xunit;
namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore.Test namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore.Test
@ -21,7 +23,9 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore.Test
services.AddHttpContextAccessor(); services.AddHttpContextAccessor();
services.AddDbContext<TContext>(options => services.AddDbContext<TContext>(options =>
{ {
options.UseSqlServer(connectionString); options
.ConfigureWarnings(b => b.Log(CoreEventId.ManyServiceProvidersCreatedWarning))
.UseSqlServer(connectionString);
}); });
return services; return services;
} }
@ -101,4 +105,4 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore.Test
} }
} }
} }

View File

@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Builder.Internal;
using Microsoft.AspNetCore.Identity.Test; using Microsoft.AspNetCore.Identity.Test;
using Microsoft.AspNetCore.Testing.xunit; using Microsoft.AspNetCore.Testing.xunit;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Xunit; using Xunit;
@ -23,7 +24,9 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore.Test
services services
.AddSingleton<IConfiguration>(new ConfigurationBuilder().Build()) .AddSingleton<IConfiguration>(new ConfigurationBuilder().Build())
.AddDbContext<IdentityDbContext>(o => o.UseSqlServer(fixture.ConnectionString)) .AddDbContext<IdentityDbContext>(o =>
o.UseSqlServer(fixture.ConnectionString)
.ConfigureWarnings(b => b.Log(CoreEventId.ManyServiceProvidersCreatedWarning)))
.AddIdentity<IdentityUser, IdentityRole>() .AddIdentity<IdentityUser, IdentityRole>()
.AddEntityFrameworkStores<IdentityDbContext>(); .AddEntityFrameworkStores<IdentityDbContext>();
@ -58,4 +61,4 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore.Test
IdentityResultAssert.IsSuccess(await userManager.DeleteAsync(user)); IdentityResultAssert.IsSuccess(await userManager.DeleteAsync(user));
} }
} }
} }

View File

@ -5,6 +5,7 @@ using System.Data.SqlClient;
using Microsoft.AspNetCore.Builder.Internal; using Microsoft.AspNetCore.Builder.Internal;
using Microsoft.AspNetCore.Testing.xunit; using Microsoft.AspNetCore.Testing.xunit;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Xunit; using Xunit;
@ -22,7 +23,9 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore.Test
services services
.AddSingleton<IConfiguration>(new ConfigurationBuilder().Build()) .AddSingleton<IConfiguration>(new ConfigurationBuilder().Build())
.AddDbContext<IdentityDbContext>(o => o.UseSqlServer(fixture.ConnectionString)) .AddDbContext<IdentityDbContext>(o =>
o.UseSqlServer(fixture.ConnectionString)
.ConfigureWarnings(b => b.Log(CoreEventId.ManyServiceProvidersCreatedWarning)))
.AddIdentity<IdentityUser, IdentityRole>(o => o.Stores.MaxLengthForKeys = 128) .AddIdentity<IdentityUser, IdentityRole>(o => o.Stores.MaxLengthForKeys = 128)
.AddEntityFrameworkStores<IdentityDbContext>(); .AddEntityFrameworkStores<IdentityDbContext>();
@ -76,4 +79,4 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore.Test
} }
} }
} }
} }

View File

@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Builder.Internal;
using Microsoft.AspNetCore.Identity.Test; using Microsoft.AspNetCore.Identity.Test;
using Microsoft.AspNetCore.Testing.xunit; using Microsoft.AspNetCore.Testing.xunit;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Xunit; using Xunit;
@ -67,7 +68,9 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore.Test
services services
.AddSingleton<IConfiguration>(new ConfigurationBuilder().Build()) .AddSingleton<IConfiguration>(new ConfigurationBuilder().Build())
.AddDbContext<CustomContext>(o => o.UseSqlServer(fixture.ConnectionString)) .AddDbContext<CustomContext>(o =>
o.UseSqlServer(fixture.ConnectionString)
.ConfigureWarnings(b => b.Log(CoreEventId.ManyServiceProvidersCreatedWarning)))
.AddIdentityCore<IdentityUser>(o => { }) .AddIdentityCore<IdentityUser>(o => { })
.AddEntityFrameworkStores<CustomContext>(); .AddEntityFrameworkStores<CustomContext>();
@ -103,4 +106,4 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore.Test
} }
} }
} }

View File

@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Builder.Internal;
using Microsoft.AspNetCore.Identity.Test; using Microsoft.AspNetCore.Identity.Test;
using Microsoft.AspNetCore.Testing.xunit; using Microsoft.AspNetCore.Testing.xunit;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Xunit; using Xunit;
@ -28,7 +29,9 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore.Test
services services
.AddSingleton<IConfiguration>(new ConfigurationBuilder().Build()) .AddSingleton<IConfiguration>(new ConfigurationBuilder().Build())
.AddDbContext<TestUserDbContext>(o => o.UseSqlServer(fixture.ConnectionString)) .AddDbContext<TestUserDbContext>(
o => o.UseSqlServer(fixture.ConnectionString)
.ConfigureWarnings(b => b.Log(CoreEventId.ManyServiceProvidersCreatedWarning)))
.AddIdentityCore<IdentityUser>(o => { }) .AddIdentityCore<IdentityUser>(o => { })
.AddEntityFrameworkStores<TestUserDbContext>(); .AddEntityFrameworkStores<TestUserDbContext>();
@ -63,4 +66,4 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore.Test
IdentityResultAssert.IsSuccess(await userManager.DeleteAsync(user)); IdentityResultAssert.IsSuccess(await userManager.DeleteAsync(user));
} }
} }
} }

View File

@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
@ -29,7 +30,8 @@ namespace IdentitySample.DefaultUI
{ {
// Add framework services. // Add framework services.
services.AddDbContext<ApplicationDbContext>( services.AddDbContext<ApplicationDbContext>(
options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"), options => options.ConfigureWarnings(b => b.Log(CoreEventId.ManyServiceProvidersCreatedWarning))
.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"),
x => x.MigrationsAssembly("IdentitySample.DefaultUI"))); x => x.MigrationsAssembly("IdentitySample.DefaultUI")));
services.AddMvc(); services.AddMvc();
@ -39,7 +41,7 @@ namespace IdentitySample.DefaultUI
.AddEntityFrameworkStores<ApplicationDbContext>(); .AddEntityFrameworkStores<ApplicationDbContext>();
} }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{ {
@ -65,4 +67,4 @@ namespace IdentitySample.DefaultUI
}); });
} }
} }
} }

View File

@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
@ -30,7 +31,8 @@ namespace IdentitySample
{ {
// Add framework services. // Add framework services.
services.AddDbContext<ApplicationDbContext>(options => services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); options.ConfigureWarnings(b => b.Log(CoreEventId.ManyServiceProvidersCreatedWarning))
.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddMvc(); services.AddMvc();
@ -77,4 +79,4 @@ namespace IdentitySample
}); });
} }
} }
} }

View File

@ -11,6 +11,7 @@ using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.AspNetCore.Identity.UI.Services; using Microsoft.AspNetCore.Identity.UI.Services;
using Microsoft.AspNetCore.Mvc.Authorization; using Microsoft.AspNetCore.Mvc.Authorization;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
namespace Microsoft.AspNetCore.Identity.FunctionalTests namespace Microsoft.AspNetCore.Identity.FunctionalTests
@ -19,7 +20,8 @@ namespace Microsoft.AspNetCore.Identity.FunctionalTests
{ {
public static IServiceCollection SetupTestDatabase<TContext>(this IServiceCollection services, string databaseName) where TContext : DbContext => public static IServiceCollection SetupTestDatabase<TContext>(this IServiceCollection services, string databaseName) where TContext : DbContext =>
services.AddDbContext<TContext>(options => services.AddDbContext<TContext>(options =>
options.UseInMemoryDatabase(databaseName, memoryOptions => { })); options.ConfigureWarnings(b => b.Log(CoreEventId.ManyServiceProvidersCreatedWarning))
.UseInMemoryDatabase(databaseName, memoryOptions => { }));
public static IServiceCollection SetupTestThirdPartyLogin(this IServiceCollection services) => public static IServiceCollection SetupTestThirdPartyLogin(this IServiceCollection services) =>
services.AddAuthentication() services.AddAuthentication()

View File

@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.UI; using Microsoft.AspNetCore.Identity.UI;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders; using Microsoft.Extensions.FileProviders;
@ -35,10 +36,12 @@ namespace Identity.DefaultUI.WebSite
}); });
services.AddDbContext<TContext>(options => services.AddDbContext<TContext>(options =>
options.UseSqlServer( options
Configuration.GetConnectionString("DefaultConnection"), .ConfigureWarnings(b => b.Log(CoreEventId.ManyServiceProvidersCreatedWarning))
sqlOptions => sqlOptions.MigrationsAssembly("Identity.DefaultUI.WebSite") .UseSqlServer(
)); Configuration.GetConnectionString("DefaultConnection"),
sqlOptions => sqlOptions.MigrationsAssembly("Identity.DefaultUI.WebSite")
));
services.AddDefaultIdentity<TUser>() services.AddDefaultIdentity<TUser>()
.AddDefaultUI(Framework) .AddDefaultUI(Framework)