Example #1
0
        public async Task GetAsync_by_id_should_return_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 id = Guid.NewGuid().ToString();
            await userManager.CreateAsync(new IdentityUser
            {
                Email    = "*****@*****.**",
                Id       = id,
                UserName = id
            }).ConfigureAwait(false);

            var sut = new IdentityUserLoginStore <IdentityUser>(userManager, context, provider.GetRequiredService <ILogger <IdentityUserLoginStore <IdentityUser> > >());

            await sut.CreateAsync(new UserLogin
            {
                UserId              = id,
                LoginProvider       = id,
                ProviderDisplayName = id,
                ProviderKey         = id
            } as object).ConfigureAwait(false);


            var result = await sut.GetAsync($"{id}@{id}@{id}", null).ConfigureAwait(false);

            Assert.NotNull(result);

            result = await sut.GetAsync($"{Guid.NewGuid()}@{id}@{id}", null).ConfigureAwait(false);

            Assert.Null(result);
        }
Example #2
0
        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);
        }
Example #3
0
        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);
        }