public async Task UserRoleStore_create_user_add_to_role()
        {
            var user     = _userTestFactory.CreateUser();
            var username = "******";
            await _userStore.SetUserNameAsync(user, username, default(CancellationToken));

            await _userStore.SetNormalizedUserNameAsync(user, username, default(CancellationToken));

            await _userStore.CreateAsync(user, default(CancellationToken));

            var foundUser = await _userStore.FindByIdAsync(user.Id, default(CancellationToken));

            foundUser.UserName.ShouldMatch(user.UserName);

            var role = _roleTestFactory.CreateRole();
            await _roleStore.CreateAsync(role, default(CancellationToken));

            await _roleStore.SetNormalizedRoleNameAsync(role, role.Name, default(CancellationToken));

            await _userRoleStore.AddToRoleAsync(user, role.Name, default(CancellationToken));

            var roles = await _userRoleStore.GetRolesAsync(user, default(CancellationToken));

            roles.Count.ShouldBeGreaterThan(0);

            var users = await _userRoleStore.GetUsersInRoleAsync(role.Name, default(CancellationToken));

            users.Count.ShouldBeGreaterThan(0);

            var firstUser = users.FirstOrDefault();

            firstUser.ShouldNotBeNull();
            firstUser.UserName.ShouldMatch(user.UserName);
        }
Beispiel #2
0
        public async Task RoleStore_create_find_by_id()
        {
            var role = _roleTestFactory.CreateRole();
            await _roleStore.CreateAsync(role, default(CancellationToken));

            await _roleStore.SetNormalizedRoleNameAsync(role, role.Name, default(CancellationToken));

            var fetchedRole = await _roleStore.FindByIdAsync(role.Id, default(CancellationToken));

            role.Name.ShouldMatch(fetchedRole.Name);
        }
Beispiel #3
0
 public async Task SetNormalizedRoleNameAsync(ApplicationRole role, string normalizedName, CancellationToken cancellationToken)
 {
     await roleStore.SetNormalizedRoleNameAsync(role, normalizedName, cancellationToken);
 }