Esempio n. 1
0
        public async Task UdpateAsync_should_update_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 result = await roleManager.CreateAsync(role);

            Assert.True(result.Succeeded);

            var sut = new IdentityRoleStore <IdentityUser, IdentityRole>(roleManager, new ScopedAsynDocumentcSession(documentStore.OpenAsyncSession()), provider.GetRequiredService <ILogger <IdentityRoleStore <IdentityUser, IdentityRole> > >());
            await sut.UpdateAsync(new Role
            {
                Id   = role.Id,
                Name = "test"
            } as object);

            var actual = await roleManager.FindByIdAsync(role.Id);

            Assert.NotNull(actual);
            Assert.Equal("test", actual.Name);
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
    public async Task UpdateAsync()
    {
        var role = await _identityRoleRepository.FindByNormalizedNameAsync(_lookupNormalizer.NormalizeName("moderator"));

        role.ShouldNotBeNull();

        role.IsDefault = true;
        await _identityRoleStore.UpdateAsync(role);

        role.IsDefault.ShouldBeTrue();
    }
Esempio n. 4
0
        public async Task UpdateAsync_should_throw_on_role_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 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> > >());
            await Assert.ThrowsAsync <IdentityException>(() => sut.UpdateAsync(new Role
            {
                Id   = Guid.NewGuid().ToString(),
                Name = Guid.NewGuid().ToString()
            })).ConfigureAwait(false);
        }