// 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.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using Xunit; namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore.Test { public class IntUser : IdentityUser { public IntUser() { UserName = Guid.NewGuid().ToString(); } } public class IntRole : IdentityRole { public IntRole() { Name = Guid.NewGuid().ToString(); } } public class UserStoreIntTest : SqlStoreTestBase { public UserStoreIntTest(ScratchDatabaseFixture fixture) : base(fixture) { } [Fact] public void AddEntityFrameworkStoresCanInferKey() { var services = new ServiceCollection(); services.AddLogging() .AddSingleton(new TestDbContext(new DbContextOptionsBuilder().Options)); // This used to throw var builder = services.AddIdentity().AddEntityFrameworkStores(); var sp = services.BuildServiceProvider(); using (var csope = sp.CreateScope()) { Assert.NotNull(sp.GetRequiredService>()); Assert.NotNull(sp.GetRequiredService>()); } } [Fact] public void AddEntityFrameworkStoresCanInferKeyWithGenericBase() { var services = new ServiceCollection(); services.AddLogging() .AddSingleton(new TestDbContext(new DbContextOptionsBuilder().Options)); // This used to throw var builder = services.AddIdentityCore>().AddRoles>().AddEntityFrameworkStores(); var sp = services.BuildServiceProvider(); using (var csope = sp.CreateScope()) { Assert.NotNull(sp.GetRequiredService>>()); Assert.NotNull(sp.GetRequiredService>>()); } } } }