Exemplo n.º 1
0
        public async Task UpdateAsync_should_update_role()
        {
            var provider = new ServiceCollection()
                           .AddLogging()
                           .AddDbContext <IdentityDbContext <IdentityUser> >(options => options.UseInMemoryDatabase(Guid.NewGuid().ToString()))
                           .AddIdentity <IdentityUser, IdentityRole>()
                           .AddEntityFrameworkStores <IdentityDbContext <IdentityUser> >()
                           .Services.BuildServiceProvider();

            var roleManager = provider.GetRequiredService <RoleManager <IdentityRole> >();
            var context     = provider.GetRequiredService <IdentityDbContext <IdentityUser> >();
            var sut         = new IdentityRoleStore <IdentityUser, IdentityRole>(roleManager, context, provider.GetRequiredService <ILogger <IdentityRoleStore <IdentityUser, IdentityRole> > >());

            var name = Guid.NewGuid().ToString();
            var role = new IdentityRole
            {
                Id   = Guid.NewGuid().ToString(),
                Name = name
            };
            await roleManager.CreateAsync(role).ConfigureAwait(false);

            await sut.UpdateAsync(new Role
            {
                Id   = role.Id,
                Name = Guid.NewGuid().ToString()
            } as object).ConfigureAwait(false);

            var actual = await sut.GetAsync(role.Id, null);

            Assert.NotEqual(name, actual.Name);
        }
Exemplo n.º 2
0
        public async Task GetAsync_by_id_should_return_role()
        {
            using var documentStore = new RavenDbTestDriverWrapper().GetDocumentStore();
            var provider = new ServiceCollection()
                           .AddLogging()
                           .AddIdentity <IdentityUser, IdentityRole>()
                           .AddRavenDbStores(p => documentStore)
                           .Services.BuildServiceProvider();
            var roleManager = provider.GetRequiredService <RoleManager <IdentityRole> >();
            var role        = new IdentityRole
            {
                Id   = Guid.NewGuid().ToString(),
                Name = Guid.NewGuid().ToString()
            };
            var roleResult = await roleManager.CreateAsync(role);

            Assert.True(roleResult.Succeeded);


            var sut = new IdentityRoleStore <IdentityUser, IdentityRole>(roleManager, new ScopedAsynDocumentcSession(documentStore.OpenAsyncSession()), provider.GetRequiredService <ILogger <IdentityRoleStore <IdentityUser, IdentityRole> > >());

            var result = await sut.GetAsync(role.Id, null);

            Assert.NotNull(result);
        }
Exemplo n.º 3
0
        public async Task GetAsync_by_id_should_expand_claims()
        {
            using var documentStore = new RavenDbTestDriverWrapper().GetDocumentStore();
            var provider = new ServiceCollection()
                           .AddLogging()
                           .AddIdentity <IdentityUser, IdentityRole>()
                           .AddRavenDbStores(p => documentStore)
                           .Services.BuildServiceProvider();
            var roleManager = provider.GetRequiredService <RoleManager <IdentityRole> >();
            var role        = new IdentityRole
            {
                Id   = Guid.NewGuid().ToString(),
                Name = Guid.NewGuid().ToString()
            };
            var roleResult = await roleManager.CreateAsync(role);

            Assert.True(roleResult.Succeeded);

            var claimId = Guid.NewGuid().ToString();
            await roleManager.AddClaimAsync(role, new Claim(claimId, claimId)).ConfigureAwait(false);

            var sut = new IdentityRoleStore <IdentityUser, IdentityRole>(roleManager, new ScopedAsynDocumentcSession(documentStore.OpenAsyncSession()), provider.GetRequiredService <ILogger <IdentityRoleStore <IdentityUser, IdentityRole> > >());

            var result = await sut.GetAsync(role.Id, new GetRequest
            {
                Expand = nameof(Role.RoleClaims)
            });

            Assert.NotNull(result);
            Assert.Single(result.RoleClaims);
            Assert.Equal(claimId, result.RoleClaims.First().ClaimType);
            Assert.Equal($"{role.Id}@0", result.RoleClaims.First().Id);
        }
Exemplo n.º 4
0
        public async Task GetAsync_by_page_request_should_find_roles()
        {
            using var documentStore = new RavenDbTestDriverWrapper().GetDocumentStore();
            var provider = new ServiceCollection()
                           .AddLogging()
                           .AddIdentity <IdentityUser, IdentityRole>()
                           .AddRavenDbStores(p => documentStore)
                           .Services.BuildServiceProvider();
            var roleManager = provider.GetRequiredService <RoleManager <IdentityRole> >();
            var role        = new IdentityRole
            {
                Id   = Guid.NewGuid().ToString(),
                Name = Guid.NewGuid().ToString()
            };
            var roleResult = await roleManager.CreateAsync(role);

            Assert.True(roleResult.Succeeded);


            var sut = new IdentityRoleStore <IdentityUser, IdentityRole>(roleManager, new ScopedAsynDocumentcSession(documentStore.OpenAsyncSession()), provider.GetRequiredService <ILogger <IdentityRoleStore <IdentityUser, IdentityRole> > >());

            var rolesResult = await sut.GetAsync(new PageRequest
            {
                Filter = $"Name eq '{role.Name}'"
            });

            Assert.NotNull(rolesResult);
            Assert.Equal(1, rolesResult.Count);
            Assert.Single(rolesResult.Items);
        }