示例#1
0
        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);
        }
示例#2
0
        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));
        }