public async Task CreateAsync_should_add_login() { 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> > >()); var id = Guid.NewGuid().ToString(); var user = new IdentityUser { Email = "*****@*****.**", Id = id, UserName = id }; await userManager.CreateAsync(user).ConfigureAwait(false); await sut.CreateAsync(new UserLogin { UserId = id, LoginProvider = id, ProviderDisplayName = id, ProviderKey = id } as object).ConfigureAwait(false); Assert.Single(await userManager.GetLoginsAsync(user).ConfigureAwait(false)); }
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 GetAsync_by_page_request_should_find_role_Logins() { 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); await userManager.AddLoginAsync(user, new UserLoginInfo(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString())); await userManager.AddLoginAsync(user, new UserLoginInfo(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString())); await userManager.AddLoginAsync(user, new UserLoginInfo(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString())); var sut = new IdentityUserLoginStore <IdentityUser>(userManager, new ScopedAsynDocumentcSession(documentStore.OpenAsyncSession()), provider.GetRequiredService <ILogger <IdentityUserLoginStore <IdentityUser> > >()); var LoginsResult = await sut.GetAsync(new PageRequest { Filter = $"UserId eq '{user.Id}'", Take = 1 }); Assert.NotNull(LoginsResult); Assert.Equal(3, LoginsResult.Count); Assert.Single(LoginsResult.Items); }
public async Task UdpateAsync_should_not_be_implemented() { 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 Assert.ThrowsAsync <NotImplementedException>(() => sut.UpdateAsync(new Entity.UserLogin { Id = $"{providerName}@{key}", LoginProvider = providerName, ProviderKey = key, ProviderDisplayName = "test" } as object)); }
public async Task GetAsync_by_id_should_return_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(); await userManager.AddLoginAsync(user, new UserLoginInfo(providerName, key, providerName)); await userManager.AddLoginAsync(user, new UserLoginInfo(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString())); await userManager.AddLoginAsync(user, new UserLoginInfo(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString())); var sut = new IdentityUserLoginStore <IdentityUser>(userManager, new ScopedAsynDocumentcSession(documentStore.OpenAsyncSession()), provider.GetRequiredService <ILogger <IdentityUserLoginStore <IdentityUser> > >()); var result = await sut.GetAsync($"{providerName}@{key}", null); Assert.NotNull(result); }
public async Task CreateAsync_should_return_Login_id() { 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 sut = new IdentityUserLoginStore <IdentityUser>(userManager, new ScopedAsynDocumentcSession(documentStore.OpenAsyncSession()), provider.GetRequiredService <ILogger <IdentityUserLoginStore <IdentityUser> > >()); var result = await sut.CreateAsync(new Entity.UserLogin { UserId = user.Id, LoginProvider = Guid.NewGuid().ToString(), ProviderDisplayName = Guid.NewGuid().ToString(), ProviderKey = Guid.NewGuid().ToString() } as object); Assert.NotNull(result); Assert.NotNull(((Entity.UserLogin)result).Id); }
public async Task CreateAsync_should_throw_on_user_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> > >()); var id = Guid.NewGuid().ToString(); await Assert.ThrowsAsync <IdentityException>(() => sut.CreateAsync(new UserLogin { UserId = id, LoginProvider = id, ProviderDisplayName = id, ProviderKey = id })).ConfigureAwait(false); }
public async Task UpdateAsync_should_not_be_implemented() { 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 <NotImplementedException>(() => sut.UpdateAsync(new UserLogin { } as object)).ConfigureAwait(false); await Assert.ThrowsAsync <NotImplementedException>(() => sut.UpdateAsync(new UserLogin { })).ConfigureAwait(false); }