public async Task DeleteAsync_should_throw_when_not_found() { var provider = new ServiceCollection() .AddLogging() .AddDbContext <IdentityDbContext <IdentityUser> >(options => options.UseInMemoryDatabase(Guid.NewGuid().ToString())) .AddIdentity <IdentityUser, IdentityRole>() .AddEntityFrameworkStores <IdentityDbContext <IdentityUser> >() .Services.BuildServiceProvider(); var userManager = provider.GetRequiredService <UserManager <IdentityUser> >(); var context = provider.GetRequiredService <IdentityDbContext <IdentityUser> >(); var sut = new IdentityUserLoginStore <IdentityUser>(userManager, context, provider.GetRequiredService <ILogger <IdentityUserLoginStore <IdentityUser> > >()); await Assert.ThrowsAsync <DbUpdateException>(() => sut.DeleteAsync("test@test@test")).ConfigureAwait(false); }
public async Task DeleteAsync_should_delete_Login() { using var documentStore = new RavenDbTestDriverWrapper().GetDocumentStore(); var services = new ServiceCollection() .AddLogging(); services.AddIdentity <IdentityUser, IdentityRole>() .AddRavenDbStores(p => documentStore); IServiceProvider provider = services.AddIdentityServer4AdminRavenDbkStores <IdentityUser, IdentityRole>(p => documentStore).BuildServiceProvider(); using var scope = provider.CreateScope(); provider = scope.ServiceProvider; var userManager = provider.GetRequiredService <UserManager <IdentityUser> >(); var user = new IdentityUser { Id = Guid.NewGuid().ToString(), Email = "*****@*****.**", EmailConfirmed = true, UserName = Guid.NewGuid().ToString() }; var userResult = await userManager.CreateAsync(user); Assert.True(userResult.Succeeded); var providerName = Guid.NewGuid().ToString(); var key = Guid.NewGuid().ToString(); var result = await userManager.AddLoginAsync(user, new UserLoginInfo(providerName, key, providerName)); Assert.True(result.Succeeded); var sut = new IdentityUserLoginStore <IdentityUser>(userManager, new ScopedAsynDocumentcSession(documentStore.OpenAsyncSession()), provider.GetRequiredService <ILogger <IdentityUserLoginStore <IdentityUser> > >()); await sut.DeleteAsync($"{providerName}@{key}"); var Logins = await userManager.GetLoginsAsync(user); Assert.Empty(Logins); }