public async Task DynamoRoleUsersStore_RemoveFromRole_RemovesUserFromRole()
        {
            var user     = new DynamoIdentityUser(TestUtils.RandomString(10));
            var roleName = TestUtils.RandomString(10);

            using (var dbProvider = DynamoDbServerTestUtils.CreateDatabase())
            {
                var roleStore = new DynamoRoleUsersStore <DynamoIdentityRole, DynamoIdentityUser>();
                await roleStore.EnsureInitializedAsync(dbProvider.Client, dbProvider.Context);

                await roleStore.AddToRoleAsync(user, roleName, CancellationToken.None);

                var result = await roleStore.IsInRoleAsync(user, roleName, CancellationToken.None);

                Assert.True(result);

                // ACT
                await roleStore.RemoveFromRoleAsync(user, roleName, CancellationToken.None);

                // ASSERT
                var result2 = await roleStore.IsInRoleAsync(user, roleName, CancellationToken.None);

                Assert.False(result2);
            }
        }
Example #2
0
        private async Task UpdateRole(string userId, string roleName, bool remove, CancellationToken cancellationToken)
        {
            var user = await _userManager.FindByIdAsync(userId);

            if (remove)
            {
                await _roleManager.RemoveFromRoleAsync(user, roleName, cancellationToken);
            }
            else
            {
                await _roleManager.AddToRoleAsync(user, roleName, cancellationToken);
            }
        }