// 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.Threading.Tasks; using Microsoft.AspNetCore.Builder.Internal; using Microsoft.AspNetCore.Identity.Test; using Microsoft.AspNetCore.Testing.xunit; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Xunit; namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore.Test { public class DefaultPocoTest : IClassFixture { private readonly ApplicationBuilder _builder; private const string DatabaseName = nameof(DefaultPocoTest); public DefaultPocoTest(ScratchDatabaseFixture fixture) { var services = new ServiceCollection(); services .AddSingleton(new ConfigurationBuilder().Build()) .AddDbContext(o => o.UseSqlServer(fixture.ConnectionString)) .AddIdentity() .AddEntityFrameworkStores(); services.AddLogging(); var provider = services.BuildServiceProvider(); _builder = new ApplicationBuilder(provider); using(var scoped = provider.GetRequiredService().CreateScope()) using (var db = scoped.ServiceProvider.GetRequiredService()) { db.Database.EnsureCreated(); } } [ConditionalFact] [FrameworkSkipCondition(RuntimeFrameworks.Mono)] [OSSkipCondition(OperatingSystems.Linux)] [OSSkipCondition(OperatingSystems.MacOSX)] public async Task EnsureStartupUsageWorks() { var userStore = _builder.ApplicationServices.GetRequiredService>(); var userManager = _builder.ApplicationServices.GetRequiredService>(); Assert.NotNull(userStore); Assert.NotNull(userManager); const string userName = "admin"; const string password = "1qaz@WSX"; var user = new IdentityUser { UserName = userName }; IdentityResultAssert.IsSuccess(await userManager.CreateAsync(user, password)); IdentityResultAssert.IsSuccess(await userManager.DeleteAsync(user)); } } }